📄 wmwavegen.h
字号:
/*-----------------------------------------------------------------------------
* Copyright (c) Wolfson Microelectronics plc. All rights reserved.
*
* This software as well as any related documentation is furnished under
* license and may only be used or copied in accordance with the terms of the
* license. The information in this file is furnished for informational use
* only, is subject to change without notice, and should not be construed as
* a commitment by Wolfson Microelectronics plc. Wolfson Microelectronics plc
* assumes no responsibility or liability for any errors or inaccuracies that
* may appear in this document or any software that may be provided in
* association with this document.
*
* Except as permitted by such license, no part of this document may be
* reproduced, stored in a retrieval system, or transmitted in any form or by
* any means without the express written consent of Wolfson Microelectronics plc.
*
* $Id: WMWaveGen.h 4452 2007-05-29 09:40:15Z fb $
*
* Functions for generating different sound waveforms.
*
* Warning:
* This driver is specifically written for Wolfson Codecs. It is not a
* general CODEC device driver.
*
* -----------------------------------------------------------------------------*/
#ifndef __WMWAVEGEN_H__
#define __WMWAVEGEN_H__
/*
* Include files
*/
#include "WMConfig.h"
#include "WMPlatformDefs.h" /* for WM_AUDIO_SAMPLE */
/*
* Definitions
*/
/*!
* WM_WAVEGEN_FORMAT specifies what sort of data to generate.
*
* Stereo data has the right channel in the upper 16 bits and the left channel
* in the lower 16 bits of the 32-bit word.
*/
typedef enum tagWM_WAVEGEN_FORMAT
{
WM_WAVEGEN_CONTIGUOUS_WIDE, /*< samples butting up against each other on a 32 bit wide DMA */
WM_WAVEGEN_CONTIGUOUS, /*< samples butting up against each other */
WM_WAVEGEN_MONO, /*< single-sample mono data */
WM_WAVEGEN_LEFT, /*< stereo data in the left channel of each sample */
WM_WAVEGEN_RIGHT, /*< stereo data in the right channel of each sample */
WM_WAVEGEN_STEREO /*< stereo data duplicated in both channels of each sample */
} WM_WAVEGEN_FORMAT;
/*
* A restart context for the wave generation, allowing the generation to
* continue smoothly across multiple calls.
*/
typedef struct
{
int quot;
int rem;
} WM_WAVEGEN_CTX;
/* A constant to initialise the wave generation to the start of the wave. */
#define WM_START_OF_WAVE { 0 }
/*
* Function prototypes
*/
#ifdef __cplusplus
extern "C" {
#endif
/*-----------------------------------------------------------------------------
* Function: WMGenerateSineWave
*
* Generates a sine wave of the given frequency.
*
* Parameters:
* buffer buffer to receive samples
* nSamples number of samples to generate (mono or stereo,
* according to 'format')
* sampleRate output sample rate (e.g. 44100)
* frequency frequency to generate
* amplitude peak amplitude to generate (0 to 32768)
* format what the resulting data should look like. One of the
* WM_WAVEGEN_FORMAT constants.
* pRestart pointer to a restart context - position after previous call.
* Used to restart the wave where the previous call left off.
* Updated to the start position for the next call.
* Can be NULL - in this case will always start at the start of
* the wave.
*
* Returns: void
*---------------------------------------------------------------------------*/
void WMGenerateSineWave(WM_AUDIO_STEREO_SAMPLE *buffer,
int nSamples,
int sampleRate,
unsigned short frequency,
unsigned short amplitude,
WM_WAVEGEN_FORMAT format,
WM_WAVEGEN_CTX *pRestart
);
/*-----------------------------------------------------------------------------
* Function: WMGenerateSquareWave
*
* Generates as close an approximation as possible to a square wave of the
* given frequency.
*
* Parameters:
* buffer buffer to receive samples
* nSamples number of samples to generate (mono or stereo,
* according to 'format')
* sampleRate output sample rate (e.g. 44100)
* frequency frequency to generate
* amplitude peak amplitude to generate (0 to 32768)
* format what the resulting data should look like. One of the
* WM_WAVEGEN_FORMAT constants.
* pRestart pointer to a restart context - position after previous call.
* Used to restart the wave where the previous call left off.
* Updated to the start position for the next call.
* Can be NULL - in this case will always start at the start of
* the wave.
*
* Returns: void
*---------------------------------------------------------------------------*/
void WMGenerateSquareWave(WM_AUDIO_STEREO_SAMPLE *buffer,
int nSamples,
int sampleRate,
unsigned short frequency,
unsigned short amplitude,
WM_WAVEGEN_FORMAT format,
WM_WAVEGEN_CTX *pRestart
);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* __WMWAVEGEN_H__ */
/*------------------------------ END OF FILE ---------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -