?? iekc64_audio.h
字號(hào):
#ifndef __AUDIO_H__
#define __AUDIO_H__
#include <csl_stdinc.h>
#include <csl_edma.h>
#include "iekc64_error.h"
#include "iekc64.h"
#ifdef __cplusplus
extern "C" {
#endif
/*=======================================================================*//*!
\defgroup AUDIO AUDIO - Audio recording and playing
\brief This module concerns for capturing and generating audio.
<h3> Audio module </h3>
<b> How does it work </b>
The AUDIO module captures audio into frames and play frames.
For record, frames are allocated contiguously in a circular buffer
allocated by the user before openning the module. This buffer must be large
enough to allow at least 4 frames to be stored. Using a 4 frames buffer is the
best way to insure that you won't have any overlapping between the
background capture and the processing.
If your process needs to work on more than 1 frame, you don't need to copy
frames to another buffer, you just have to create a buffer large enough
and tell the AUDIO module to always leave the last N frames unmodified.
The AUDIO playing generates audio from frames provided by the user.
Frames are allocated by the user. Their memory location is non important,
as far as each frame start is aligned on a 32 bit word boudary. Frames
for audio generation don't need to be contiguously allocated in the
same buffer like the ones used for audio record. They even doesn't need
to be allocated before openning the module. The user can allocate any
number of frames from 1 to memory limits.
When using 1 single frame, it is possible to work into the frame while it
is played. Depending on the refresh rate that can cause some artifacts.
<b> Openning the module </b>
You open the module by calling the AUDIO_open() function. This function
initializes hardware and software with parameters given in the
IEKC64_AUDIO structure. You must use the default configuration,
IEKC64_AUDIO_CONFIG_DEFAULT, to initialize your own configuration but the
fields FramesLength, nFramesInBuf, nFramesToKeep and pBuffer must be set
before calling the AUDIO_open() function.
The default configuration structure field description is:
<small>
dwSize = sizeof(IEKC64_AUDIO) <br>
Source = SOURCE_LINE <br>
{ <br>
isDACSoftMuteEnabled = FALSE // No software mute <br>
DeEmphasisCtrl = AUDIO_DEEMP48K // de-emphasis filter <br>
isADCHighPassFilterEnabled = TRUE // analog to digital filter enabled <br>
}<br>
SampleRate = AUDIO_SAMPLERATE_44K1 <br>
GainInLeft = 6 <br>
GainInRigth = 6 <br>
GainOutLeft = 6 <br>
GainOutRigth = 6 <br>
LoopBack = FALSE <br>
FramesLength = 0 <br>
nFramesInBuf = 0 <br>
nFramesToKeep = 0 <br>
pBuffer = NULL <br>
dwAudioInEdmaPri = EDMA_OPT_PRI_URGENT <br>
dwAudioOutEdmaPri = EDMA_OPT_PRI_URGENT <br>
</small>
<b> Starting to record </b>
A call to AUDIO_startRecord() will activate the record process. The audio signal
is digitized. The DMA mechanism is hidden to the user by IEKLIB.
Each new audio frame is stored into next frame in the buffer.
<b> Getting next frame </b>
AUDIO_getFrame() will give the next frame pointer from the input buffer.
If no new frame is avalable, depending on the timeout value, you will
get an error or wait until the timeout ends or a new frame is captured.
<b> Starting to play </b>
A call to AUDIO_startPlay() will activate the playing process.
It will pre-activate the playing process. Their will be no audio generation
until the first call to AUDIO_putFrame().
<b> Outputing a frame </b>
With AUDIO_putFrame() the user provides the pointer to the next frame
to be generated.
The frame data will be send to the hardware using DMA. DMA mechanism is
hidden to the user by IEKLIB.
<b> Ending audio record and play </b>
The AUDIO_close() free all DMA and interrupt used by the IEKLIB.
</P>*//*==============================================================*//*@{*/
// AUDIO register, I2C register on Byte for writing
#define AUDIO_REG_INPUTVOLL 0x00
#define AUDIO_REG_INPUTVOLR 0x01
#define AUDIO_REG_HPVOLL 0x02
#define AUDIO_REG_HPVOLR 0x03
#define AUDIO_REG_ANALOGCTRL 0x04
#define AUDIO_REG_DIGITALCTRL 0x05
#define AUDIO_REG_POWERCTRL 0x06
#define AUDIO_REG_DIGITALFORMAT 0x07
#define AUDIO_REG_SAMPLERATE 0x08
#define AUDIO_REG_DIGITALACTIVE 0x09
#define AUDIO_REG_RESET 0x0F
// Register bits for AUDIO_REG_INPUTVOLL and AUDIO_REG_INPUTVOLR
#define AUDIO_LIV 0x003F
#define AUDIO_LIM 0x0080
#define AUDIO_LRS 0x0100
#define AUDIO_POS_LIV 0
#define AUDIO_ZERO_DB_IN 0x17
// Register bits for AUDIO_REG_HPVOLL and AUDIO_REG_HPVOLR
#define AUDIO_LHV 0x007F
#define AUDIO_LZC 0x0080
#define AUDIO_HLRS 0x0100
#define AUDIO_POS_LHV 0
#define AUDIO_ZERO_DB_HP 0x79
// Register bits for AUDIO_REG_ANALOGCTRL
#define AUDIO_MICB 0x0001
#define AUDIO_MICM 0x0002
#define AUDIO_INSEL 0x0004
#define AUDIO_BYP 0x0008
#define AUDIO_DACSEL 0x0010
#define AUDIO_STE 0x0020
#define AUDIO_STA 0x00C0
#define AUDIO_STA6DB 0x0000
#define AUDIO_STA9DB 0x0040
#define AUDIO_STA12DB 0x0080
#define AUDIO_STA15DB 0x00C0
// Register bits for AUDIO_REG_DIGITALCTRL
#define AUDIO_ADCHP 0x0001
#define AUDIO_DEEMP 0x0006
#define AUDIO_DACM 0x0008
#define AUDIO_DEEMPNONE 0x0000
#define AUDIO_DEEMP32K 0x0001
#define AUDIO_DEEMP44K1 0x0002
#define AUDIO_DEEMP48K 0x0003
// Register bits for AUDIO_REG_POWERCTRL
#define AUDIO_LINE 0x0001
#define AUDIO_MIC 0x0002
#define AUDIO_ADC 0x0004
#define AUDIO_DAC 0x0008
#define AUDIO_OUT 0x0010
#define AUDIO_OSC 0x0020
#define AUDIO_CLK 0x0040
#define AUDIO_OFF 0x0080
// Register bits for AUDIO_REG_DIGITALFORMAT
#define AUDIO_FOR 0x0003
#define AUDIO_IWL 0x000C
#define AUDIO_LRP 0x0010
#define AUDIO_LRSWAP 0x0020
#define AUDIO_MS 0x0040
#define AUDIO_FORRIGHT 0x0000
#define AUDIO_FORLEFT 0x0001
#define AUDIO_FORI2S 0x0002
#define AUDIO_FORDSP 0x0003
#define AUDIO_IWL16 0x0000
#define AUDIO_IWL20 0x0004
#define AUDIO_IWL24 0x0008
#define AUDIO_IWL32 0x000C
// Register bits for AUDIO_REG_SAMPLERATE
#define AUDIO_USB 0x0001
#define AUDIO_BOSR 0x0002
#define AUDIO_SR0 0x0004
#define AUDIO_SR1 0x0008
#define AUDIO_SR2 0x0010
#define AUDIO_SR3 0x0020
#define AUDIO_CLKIN 0x0040
#define AUDIO_CLKOUT 0x0080
#define AUDIO_96KHZ AUDIO_SR0 | AUDIO_SR1 | AUDIO_SR2
#define AUDIO_48KHZ 0x0000
#define AUDIO_32KHZ AUDIO_SR1 | AUDIO_SR2
#define AUDIO_8KHZ AUDIO_SR0 | AUDIO_SR1
#define AUDIO_POS_SR 2
// Register bits for AUDIO_REG_DIGITALACTIVE
#define AUDIO_ACT 0x0001
/*--------------------------------------------------------------------------*/
/*! Special timeout values
*/
enum IEKC64_AUDIO_WAIT
{
//! Tell the API not to wait until the function is complete
IEKC64_AUDIO_NO_WAIT = 0,
//! Tell the API to wait until the function complete
IEKC64_AUDIO_WAIT_INFINITE = -1
};
/*--------------------------------------------------------------------------*/
/*! Defines the audio input used
*/
typedef enum
{
//! \Select line source input mode
SOURCE_LINE,
//! \Select mic source mode
SOURCE_MIC,
//! \Select mic
SOURCE_MIC20DB
}
IEKC64_AUDIO_SOURCE;
/*--------------------------------------------------------------------------*/
/*! Defines the audio sample rate used
*/
typedef enum
{
//! \Select sample rate to 8Khz (voice)
AUDIO_SAMPLERATE_8K,
//! \Select sample rate to 11.025Khz
AUDIO_SAMPLERATE_11K025,
//! \Select sample rate to 12Khz
AUDIO_SAMPLERATE_12K,
//! \Select sample rate to 16Khz
AUDIO_SAMPLERATE_16K,
//! \Select sample rate to 22,050Khz
AUDIO_SAMPLERATE_22K05,
//! \Select sample rate to 24Khz
AUDIO_SAMPLERATE_24K,
//! \Select sample rate to 32Khz
AUDIO_SAMPLERATE_32K,
//! \Select sample rate to 44.1Khz
AUDIO_SAMPLERATE_44K1,
//! \Select sample rate to 48Khz
AUDIO_SAMPLERATE_48K,
//! \Select sample rate to 96Khz
AUDIO_SAMPLERATE_96K
}
IEKC64_AUDIO_SAMPLERATE;
/*--------------------------------------------------------------------------*/
/*! Codec specific parameters structure
*/
typedef struct
{
/*! This field define if software mute should be enabled
*/
Bool isDACSoftMuteEnabled;
/*! This field define de-emphasis filter
*/
Uint8 DeEmphasisCtrl;
/*! This field define if the analog to digital filter should be enabled
*/
Bool isADCHighPassFilterEnabled;
}
IEKC64_AUDIO_CODEC_CONF;
/*--------------------------------------------------------------------------*/
/*! Initialization parameters for AUDIO_open().
All fields have to be set before the call.
*/
typedef struct
{
/*! This field must contains the IEKC64_AUDIO structure size
*/
Uint32 dwSize;
/*! This field defines the input source from which you want to acquire audio
*/
IEKC64_AUDIO_SOURCE Source;
/*! This field defines all parameters for digital audio
*/
IEKC64_AUDIO_CODEC_CONF DigitalAudio;
/*! This field defines the sample rate
*/
IEKC64_AUDIO_SAMPLERATE SampleRate;
/*! Left line input channel volume control +12 dB down -34.5 dB in 1.5-dB steps
*/
Int32 GainInLeft;
/*! Right line input channel volume control +12 dB down -34.5 dB in 1.5-dB steps
*/
Int32 GainInRigth;
/*! Left channel headphone volume control +6 dB down to -73 dB in 1-dB steps
*/
Int32 GainOutLeft;
/*! Right channel headphone volume control +6 dB down to -73 dB in 1-dB steps
*/
Int32 GainOutRigth;
/*! This field define if the audio codec is in loopback mode
*/
Uint8 LoopBack;
/*! This field tells the AUDIO module the size to capture before overrun
*/
Uint32 FramesLength;
/*! This field defines the length of the capture buffer in number of frames size
*/
Uint32 nFramesInBuffer;
/*! This field tells the AUDIO module how many frames have to be kept
in the capture buffer before overrun. It must be greater or eaqual
than nFramesInBuffer + 3.
*/
Uint32 nFramesToKeep;
/*! This field tells to the AUDIO module where begins the buffer to
store captured frames.
*/
Uint32* pBuffer;
/*! This field defines to the AUDIO input EDMA priority
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -