?? hssi.c
字號:
dwDummy = *(--lpAudioBuffer);
// Point AudioPlayingAddress to buffer just filled; toggle v_nNextPage
pDriverGlobals->aud[AUDIO_NO].play_address = (ULONG)dma_pagePhysicalAddress[v_nNextPage];
v_nNextPage = 1 - v_nNextPage;
FUNC_VERBOSE("-PDD_AudioFillBuffer");
}
/*****************************************************************************
* FUNCTION : AudioGetBuffer_M8
* DESCRIPTION : get audio DMA buffer and convert sample(8bit Mono)
* INPUTS : pSrcPtr - audio buffer address
* pDstPtr - wave audio buffer address
* ulSrcSampleCount - sampling count
* nReducing - The coefficient for reducing data
* OUTPUTS : None
* DESIGN NOTES : Soft-ware Sampling Rate Convert
* (44.1kHz to 11.025kHz or 22.05kHz)
* convert 20bit to 8bit and stereo to mono
* CAUTIONS :
*****************************************************************************/
VOID
AudioGetBuffer_M8 (
PULONG pSrcPtr,
PBYTE pDstPtr,
ULONG ulSrcSampleCount,
ULONG nReducing
)
{
ULONG ulSample;
while (ulSrcSampleCount > 0) {
ulSample = READ_REGISTER_ULONG(pSrcPtr);
ulSample = ((ulSample + 0x00000800) >> 12) + 128;
*pDstPtr++ = (BYTE)ulSample;
pSrcPtr += (nReducing * 2);
ulSrcSampleCount--;
}
}
/*****************************************************************************
* FUNCTION : AudioGetBuffer_S8
* DESCRIPTION : get audio DMA buffer and convert sample(8bit Stereo)
* INPUTS : pSrcPtr - audio buffer address
* pDstPtr - wave audio buffer address
* ulSrcSampleCount - sampling count
* nReducing - The coefficient for reducing data
* OUTPUTS : None
* DESIGN NOTES : Soft-ware Sampling Rate Convert
* (44.1kHz to 11.025kHz or 22.05kHz)
* convert 20bit to 8bit
* CAUTIONS :
*****************************************************************************/
VOID
AudioGetBuffer_S8 (
PULONG pSrcPtr,
PBYTE pDstPtr,
ULONG ulSrcSampleCount,
ULONG nReducing
)
{
ULONG ulSample;
while (ulSrcSampleCount > 0) {
ulSample = READ_REGISTER_ULONG(pSrcPtr);
ulSample = ((ulSample + 0x00000800) >> 12) + 128;
*pDstPtr++ = (BYTE)ulSample;
// Mic
if( g_VolumeSettings.dwInputSelect == WPDMX_LINE_MIC ){
*pDstPtr++ = (BYTE)ulSample;
}
// Line In
else{
ulSample = READ_REGISTER_ULONG(pSrcPtr+1);
ulSample = ((ulSample + 0x00000800) >> 12) + 128;
*pDstPtr++ = (BYTE)ulSample;
}
pSrcPtr += (nReducing * 2);
ulSrcSampleCount--;
}
}
/*****************************************************************************
* FUNCTION : AudioGetBuffer_M16
* DESCRIPTION : get audio DMA buffer and convert sample(16bit Mono)
* INPUTS : pSrcPtr - audio buffer address
* pDstPtr - wave audio buffer address
* ulSrcSampleCount - sampling count
* nReducing - The coefficient for reducing data
* OUTPUTS : None
* DESIGN NOTES : Soft-ware Sampling Rate Convert
* (44.1kHz to 11.025kHz or 22.05kHz)
* convert 20bit to 16bit and stereo to mono
* CAUTIONS :
*****************************************************************************/
VOID
AudioGetBuffer_M16 (
PULONG pSrcPtr,
PUSHORT pDstPtr,
ULONG ulSrcSampleCount,
ULONG nReducing
)
{
ULONG ulSample;
while (ulSrcSampleCount > 0) {
ulSample = READ_REGISTER_ULONG(pSrcPtr);
ulSample >>= 4;
*pDstPtr++ = (USHORT)ulSample;
pSrcPtr += (nReducing * 2);
ulSrcSampleCount--;
}
}
/*****************************************************************************
* FUNCTION : AudioGetBuffer_S16
* DESCRIPTION : get audio DMA buffer and convert sample(16bit Stereo)
* INPUTS : pSrcPtr - audio buffer address
* pDstPtr - wave audio buffer address
* ulSrcSampleCount - sampling count
* nReducing - The coefficient for reducing data
* OUTPUTS : None
* DESIGN NOTES : Soft-ware Sampling Rate Convert
* (44.1kHz to 11.025kHz or 22.05kHz)
* convert 20bit to 16bit
* CAUTIONS :
*****************************************************************************/
VOID
AudioGetBuffer_S16 (
PULONG pSrcPtr,
PUSHORT pDstPtr,
ULONG ulSrcSampleCount,
ULONG nReducing
)
{
ULONG ulSample;
while (ulSrcSampleCount > 0) {
ulSample = READ_REGISTER_ULONG(pSrcPtr);
ulSample >>= 4;
*pDstPtr++ = (USHORT)ulSample;
// Mic
if( g_VolumeSettings.dwInputSelect == WPDMX_LINE_MIC ){
*pDstPtr++ = (USHORT)ulSample;
}
// Line In
else{
ulSample = READ_REGISTER_ULONG(pSrcPtr+1);
ulSample >>= 4;
*pDstPtr++ = (USHORT)ulSample;
}
pSrcPtr += (nReducing * 2);
ulSrcSampleCount--;
}
}
/*****************************************************************************
* FUNCTION : private_AudioInContinue
* DESCRIPTION : continuerecording a sound - occurs at audio in interrupt
* INPUTS : pwh: wave header to insert sound into
* OUTPUTS : None
* DESIGN NOTES :
* CAUTIONS : pwh can be null for no buffers available
*****************************************************************************/
VOID
private_WaveInContinue(
PWAVEHDR pwh
)
{
ULONG CODEC_SAMPLING_RATE;
ULONG *lpAudioBuffer;
LONG nDstLen, nSrcLen;
ULONG nSampleCount,nSampleUnit;
LONG nReducing = 1;
FUNC_VERBOSE("+PDD_WaveInContinue");
switch (g_pcmtype[WAPI_IN])
{
case PCM_TYPE_S16:
nSampleUnit = 4; // 2 words per sample unit
break;
case PCM_TYPE_M16:
nSampleUnit = 2; // 1 word per sample unit
break;
case PCM_TYPE_S8:
nSampleUnit = 2; // 2 bytes per sample unit
break;
case PCM_TYPE_M8:
nSampleUnit = 1; // 1 byte per sample unit
break;
} // end switch
lpAudioBuffer = (PULONG)(pRecAudioBufferBase + ((1 - v_recPage) * AUDIO_DMA_PAGE_SIZE));
//
// Setting for Soft-ware Sampling Rate Convert
//
CODEC_SAMPLING_RATE = get_CODEC_SAMPLING_RATE(pDriverGlobals->aud[AUDIO_NO].REC_CH); // Get CODEC sampling rate for recording
nReducing = CODEC_SAMPLING_RATE / lpFormat2->nSamplesPerSec ; // The coefficient for reducing data
// process raw audio samples
// copy processed audio sample into WAVEHDR
nSrcLen = AUDIO_DMA_PAGE_SIZE / (sizeof(INT32) * 2 * nReducing);
while (nSrcLen > 0) {
try
{
if( pwh == 0 ) break;
nDstLen = pwh->dwBufferLength - pwh->dwBytesRecorded;
if (nDstLen <= 0)
{
DEBUGMSG(ZONE_TEST,(TEXT("WAVE RECORD: NEXT BUFFER\r\n")));
pwh = pwh->lpNext;
if( pwh == 0 )
{
DEBUGMSG(ZONE_TEST,(TEXT("WAVE RECORD: NO BUFFERS\r\n")));
break;
}
}
else{
nSampleCount = nDstLen / nSampleUnit;
if (nSrcLen < (LONG)nSampleCount) nSampleCount = nSrcLen;
switch( g_pcmtype[WAPI_IN] )
{
case PCM_TYPE_S16: // 16 bit stereo
AudioGetBuffer_S16(lpAudioBuffer, (PUSHORT)(pwh->lpData + pwh->dwBytesRecorded),
nSampleCount, nReducing);
break;
case PCM_TYPE_M16: // 16 bit mono
AudioGetBuffer_M16(lpAudioBuffer, (PUSHORT)(pwh->lpData + pwh->dwBytesRecorded),
nSampleCount, nReducing);
break;
case PCM_TYPE_S8: // 8 bit stereo
AudioGetBuffer_S8(lpAudioBuffer, (PBYTE)(pwh->lpData + pwh->dwBytesRecorded),
nSampleCount, nReducing);
break;
case PCM_TYPE_M8: // 8 bit mono
AudioGetBuffer_M8(lpAudioBuffer, (PBYTE)(pwh->lpData + pwh->dwBytesRecorded),
nSampleCount, nReducing);
break;
default: // really screwed up if we're here!
DEBUGMSG(ZONE_ERROR,(TEXT("WAVE RECORD: invalid pcm type %d\r\n"),
g_pcmtype[WAPI_IN] ));
break;
} //end switch
pwh->dwBytesRecorded += (nSampleCount * nSampleUnit) ;
nSrcLen -= nSampleCount;
lpAudioBuffer += (nSampleCount * 2 * nReducing);
}
}
except ( 1 )
{
DUMPEXCEPTION();
}
} // end while
v_recPage = 1 - v_recPage;
pDriverGlobals->aud[AUDIO_NO].rec_address = dma_pageRecPhysicalAddress[v_recPage];
pDriverGlobals->aud[AUDIO_NO].inInt = (USHORT)NULL;
FUNC_VERBOSE("-PDD_WaveInContinue");
}
/*****************************************************************************
* FUNCTION : set_volume
* DESCRIPTION : sample set to DMA Buffer
* INPUTS : v - Volume
* OUTPUTS : None
* DESIGN NOTES :
* CAUTIONS :
*****************************************************************************/
VOID
set_volume( ULONG v )
{
unsigned char ulLVol, ulRVol;
unsigned char I2CVol[4][2] = {
{CODEC_OADB_1, 0x00}, // 0:(04h)Output Attenuator Data Byte(left ch)
{CODEC_OADB_2, 0x00}, // 1:(05h)Output Attenuator Data Byte(right ch)
{CODEC_DAC_CB, CS4226_DACCB_NORMAL}, // 2:(03h)DAC Control Byte
{CODEC_NONE, 0x00}}; // 3:delimiter
ulLVol = (unsigned char)((SSI_VOL_SCALE * LOWORD(v)) / 0xffff);
ulRVol = (unsigned char)((SSI_VOL_SCALE * HIWORD(v)) / 0xffff);
DEBUGMSG(ZONE_TEST,(TEXT("set_volume 0x%08x => L:0x%02x R:%02x\r\n"),v ,ulLVol, ulRVol));
I2CVol[0][1] = SSI_VOL_SCALE - ulLVol;
I2CVol[1][1] = SSI_VOL_SCALE - ulRVol;
if(v == 0){
I2CVol[2][1] = CS4226_DACCB_MUTE;
}
I2C_SetCODEC(I2CVol);
return;
}
/*****************************************************************************
* FUNCTION : SetMute
* DESCRIPTION : Mute
* INPUTS : Mute
* OUTPUTS : None
* DESIGN NOTES :
* CAUTIONS :
*****************************************************************************/
void SetMute(BOOL muted)
{
MuteSSI(muted);
return;
}
/*****************************************************************************
* FUNCTION : check_SamplesPerSec
* DESCRIPTION : Check Samples Per Sec
* INPUTS : ch - DMA Channel Number
* s - Samples Per Sec
* OUTPUTS : Return TRUE for normal, FALSE for abnormal
* DESIGN NOTES :
* CAUTIONS :
*****************************************************************************/
BOOL
check_SamplesPerSec(
int ch,
DWORD s
)
{
BOOL ret = FALSE;
// SSI0,1(mono) Samples Per Sec is 11.025kHz(CODEC), 22.050kHz, 44.1kHz
if( ch == CH_TX_HSSI_1 || ch == CH_RX_HSSI_1 ){
if( s == Hz11025 || s == Hz22050 || s == Hz44100 ){
return TRUE;
}
}
// SSI2,3(stereo) Samples Per Sec is 11.025kHz, 22.050kHz, 44.1kHz(CODEC)
else if( ch == CH_TX_HSSI_2 || ch == CH_RX_HSSI_2 ){
if( s == Hz11025 || s == Hz22050 || s == Hz44100 ){
return TRUE;
}
}
return ret;
}
/*****************************************************************************
* FUNCTION : set_aud_index
* DESCRIPTION : set aud index
* INPUTS : globals - DRIVER_GLOBALS Address
* i - Audio NUmber
* OUTPUTS : None
* DESIGN NOTES :
* CAUTIONS :
*****************************************************************************/
VOID
set_aud_index(
PDRIVER_GLOBALS globals,
int i
)
{
int ch;
ch = globals->aud[i].PLAY_CH;
if( ch == CH_TX_HSSI_2 ){
globals->aud_index_hssi2 = i;
}
else{
globals->aud_index_hssi1 = i;
}
}
/*****************************************************************************
* FUNCTION : I2C_WriteCODEC
* DESCRIPTION : set data to cs4226 codec
* INPUTS : hCom I2C handle
* codec_Map cs4226 register address
* codec_Data cs4226 register data
* OUTPUTS : Return TRUE for success, FALSE for failure
* DESIGN NOTES :
* CAUTIONS :
*****************************************************************************/
BOOL I2C_WriteCODEC(
HANDLE hCom,
unsigned char codec_Map,
unsigned char codec_Data )
{
DWORD dwSize = 3;
DWORD dwRet;
unsigned char Buffer[3];
Buffer[0] = CS4226_WriteADDR;
Buffer[1] = codec_Map;
Buffer[2] = codec_Data;
WriteFile(hCom, (LPVOID)Buffer, dwSize, &dwRet, NULL);
if ( !dwRet ){
DEBUGMSG(ZONE_ERROR, (TEXT("I2C_WriteCODEC Error! : <I2C 0x%02x> %02x:%02x (%d)\r\n"), CS4226_WriteADDR, codec_Map, codec_Data, GetLastError()));
return FALSE;
}
return TRUE;
}
/*****************************************************************************
* FUNCTION : I2C_ReadCODEC
* DESCRIPTION : get data from cs4226 codec
* INPUTS : hCom I2C handle
* codec_Map codec register address
* bPrint message on or off
* OUTPUTS : read data
* DESIGN NOTES :
* CAUTIONS :
*****************************************************************************/
BYTE I2C_ReadCODEC(
HANDLE hCom,
unsigned char codec_Map,
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -