?? hac.c
字號:
* FUNCTION : private_ChangeSampleRate
* DESCRIPTION : Change sampling rate for DAC
* INPUTS : None
* OUTPUTS : None
* DESIGN NOTES :
* CAUTIONS :
*****************************************************************************/
BOOL private_ChangeSampleRate(
ULONG SampleRate
)
{
ULONG Loop_r;
#ifdef DEBUG
Wait_Status((ULONG)0x0002C000);
DEBUGMSG(ZONE_TEST, (TEXT("CODEC Play Sample rate(before) =%08x [%d]\r\n"),(ULONG)READ_REGISTER_ULONG((PULONG)pHAC_CSDR )));
#endif
if( ulCurrentPlaySamplingRate == (SampleRate << 4) )
return TRUE;
Loop_r = 0;
retry_change_samprate:
Loop_r++;
if (Write_codec( (ULONG)0x00002000, (ULONG)0x00080000 ) == FALSE) // Mute Master Volume
goto error_ret5;
if (Write_codec( (ULONG)0x0002C000, ((ULONG)SampleRate << 4) ) == FALSE) // Set Sample rate
goto error_ret5;
if (Write_codec( (ULONG)0x00002000, (ULONG)ulMasterVol ) == FALSE) // Set Master Volume
goto error_ret5;
if ( Wait_Status((ULONG)0x0002C000) == FALSE ) goto error_ret5;
ulCurrentPlaySamplingRate = (ULONG)READ_REGISTER_ULONG((PULONG)pHAC_CSDR );
DEBUGMSG(ZONE_TEST, (TEXT("CODEC Play Sample rate =%08x [%d]\r\n"),
(ULONG)ulCurrentPlaySamplingRate,
(ULONG)ulCurrentPlaySamplingRate ));
DEBUGMSG(ZONE_TEST, (TEXT("Required Play Sample rate=%08x [%d]\r\n"), ((ULONG)SampleRate << 4),
((ULONG)SampleRate << 4) ));
return TRUE;
error_ret5:
if(Loop_r < AC97_RETRTY_MAX) goto retry_change_samprate;
RETAILMSG(1, (TEXT("AC97: Change Sample Rate Error!\r\n")));
return FALSE;
}
/*****************************************************************************
* FUNCTION : private_ChangeRecSampleRate
* DESCRIPTION : Change sampling rate for ADC
* INPUTS : None
* OUTPUTS : None
* DESIGN NOTES :
* CAUTIONS :
*****************************************************************************/
BOOL private_ChangeRecSampleRate(
ULONG SampleRate
)
{
ULONG Loop_r;
if (ulCurrentRecSamplingRate == (SampleRate << 4) )
return TRUE;
Loop_r = 0;
retry_change_recsamprate:
Loop_r++;
if (Write_codec( (ULONG)0x00002000, (ULONG)0x00080000 ) == FALSE) // Mute Master Volume
goto error_ret6;
if (Write_codec( (ULONG)0x00032000, ((ULONG)SampleRate << 4) ) == FALSE) // Set Sample rate
goto error_ret6;
if (Write_codec( (ULONG)0x00032000, ((ULONG)SampleRate << 4) ) == FALSE) // Set Sample rate
goto error_ret6;
if (Write_codec( (ULONG)0x00032000, ((ULONG)SampleRate << 4) ) == FALSE) // Set Sample rate
goto error_ret6;
if (Write_codec( (ULONG)0x00002000, (ULONG)ulMasterVol ) == FALSE) // Set Master Volume
goto error_ret6;
if ( Wait_Status((ULONG)0x00032000) == FALSE )
goto error_ret6;
ulCurrentRecSamplingRate = (ULONG)READ_REGISTER_ULONG((PULONG)pHAC_CSDR );
DEBUGMSG(ZONE_TEST, (TEXT("CODEC Rec Sample rate =%08x [%d]\r\n"),
(ULONG)ulCurrentRecSamplingRate,
(ULONG)ulCurrentRecSamplingRate ));
DEBUGMSG(ZONE_TEST, (TEXT("Required Rec Sample rate=%08x [%d]\r\n"), ((ULONG)SampleRate << 4),
((ULONG)SampleRate << 4) ));
return TRUE;
error_ret6:
if(Loop_r < AC97_RETRTY_MAX) goto retry_change_recsamprate;
RETAILMSG(1, (TEXT("AC97: Change Rec Sample Rate Error!\r\n")));
return FALSE;
}
/*****************************************************************************
* FUNCTION : AudioFillBuffer_M8
* DESCRIPTION : convert sample and fill audio DMA buffer(8bit Mono)
* INPUTS : pSrcPtr - wave audio data Address
* pDstPtr - Audio Buffer Address
* ulSrcSampleCount - Sampling count
* OUTPUTS : None
* DESIGN NOTES : convert 8bit mono to packed 16bit
* CAUTIONS :
*****************************************************************************/
VOID
AudioFillBuffer_M8 (
PBYTE pSrcPtr,
PUSHORT pDstPtr,
ULONG ulSrcSampleCount
)
{
USHORT ulSample;
while (ulSrcSampleCount > 0) {
ulSample = ((PPCM_SAMPLE)pSrcPtr)->m8.sample;
ulSample -= 128;
ulSample <<= 8;
*pDstPtr++ = ulSample;
*pDstPtr++ = ulSample;
pSrcPtr++;
ulSrcSampleCount--;
}
}
/*****************************************************************************
* FUNCTION : AudioFillBuffer_S8
* DESCRIPTION : convert sample and fill audio DMA buffer(8bit Stereo)
* INPUTS : pSrcPtr - wave audio data Address
* pDstPtr - Audio Buffer Address
* ulSrcSampleCount - Sampling count
* OUTPUTS : None
* DESIGN NOTES : convert 8bit stereo to packed 16bit
* CAUTIONS :
*****************************************************************************/
VOID
AudioFillBuffer_S8 (
PUSHORT pSrcPtr,
PUSHORT pDstPtr,
ULONG ulSrcSampleCount
)
{
USHORT ulSample;
while (ulSrcSampleCount > 0) {
ulSample = ((PPCM_SAMPLE)pSrcPtr)->s8.sample_right;
ulSample -= 128;
*pDstPtr++ = ulSample << 8;
ulSample = ((PPCM_SAMPLE)pSrcPtr)->s8.sample_left;
ulSample -= 128;
*pDstPtr++ = ulSample << 8;
pSrcPtr++;
ulSrcSampleCount--;
}
}
/*****************************************************************************
* FUNCTION : AudioFillBuffer_M16
* DESCRIPTION : convert sample and fill audio DMA buffer(16bit Mono)
* INPUTS : pSrcPtr - wave audio data Address
* pDstPtr - Audio Buffer Address
* ulSrcSampleCount - Sampling count
* OUTPUTS : None
* DESIGN NOTES : convert 16bit mono to packed 16bit
* CAUTIONS :
*****************************************************************************/
VOID
AudioFillBuffer_M16 (
PUSHORT pSrcPtr,
PUSHORT pDstPtr,
ULONG ulSrcSampleCount
)
{
while (ulSrcSampleCount > 0) {
*pDstPtr++ = ((PPCM_SAMPLE)pSrcPtr)->m16.sample;
*pDstPtr++ = ((PPCM_SAMPLE)pSrcPtr)->m16.sample;
pSrcPtr++;
ulSrcSampleCount--;
}
}
/*****************************************************************************
* FUNCTION : AudioFillBuffer_S16
* DESCRIPTION : convert sample and fill audio DMA buffer(16bit Stereo)
* INPUTS : pSrcPtr - wave audio data Address
* pDstPtr - Audio Buffer Address
* ulSrcSampleCount - Sampling count
* OUTPUTS : None
* DESIGN NOTES : convert 16bit stereo to packed 16bit
* CAUTIONS :
*****************************************************************************/
VOID
AudioFillBuffer_S16 (
PULONG pSrcPtr,
PUSHORT pDstPtr,
ULONG ulSrcSampleCount
)
{
while (ulSrcSampleCount > 0) {
*pDstPtr++ = ((PPCM_SAMPLE)pSrcPtr)->s16.sample_right;
*pDstPtr++ = ((PPCM_SAMPLE)pSrcPtr)->s16.sample_left;
pSrcPtr++;
ulSrcSampleCount--;
}
}
/*****************************************************************************
* FUNCTION : private_AudioFillBuffer
* DESCRIPTION : fills next buffer from given wave
* toggles ready/empty pointers to double buffer
* INPUTS : wave
* OUTPUTS : None
* DESIGN NOTES :
* CAUTIONS :
*****************************************************************************/
VOID
private_AudioFillBuffer (
PWAVEHDR pwh
)
{
ULONG *lpAudioBuffer;
LONG nDstLen, nSrcLen;
ULONG nSampleCount,nSampleUnit;
volatile DWORD dwDummy; // used to synchronize data fill and DMA
FUNC_VERBOSE("+PDD_AudioFillBuffer");
//Set terminal condition for double-buffer and exit if no data remains
if (pwh == NULL)
{
pDriverGlobals->aud[AUDIO_NO].play_address = (ULONG)NULL;
return;
}
//
// For this line, the number of bytes from this audio stream
// depends on the dma_buffer_size and the sample rate of the stream
//
// What's the maximum number of samples from this stream are needed
// to fill the DMA buffer?
//
lpAudioBuffer = (ULONG *)(pAudioBufferBase + v_nNextPage * AUDIO_DMA_PAGE_SIZE);
//
// For each sample in the buffer...
//
nDstLen = AUDIO_DMA_PAGE_SIZE / sizeof(ULONG);
switch (g_pcmtype[WAPI_OUT])
{
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
while (nDstLen > 0) {
nSrcLen = pwh->dwBufferLength - pwh->dwBytesRecorded;
if (nSrcLen <= 0)
{
pwh = pwh->lpNext;
if (pwh == NULL)
break; // The rest of the buffer will be cleared later.
}
else
{
nSampleCount = nSrcLen / nSampleUnit;
if (nDstLen < (LONG)nSampleCount) nSampleCount = nDstLen;
switch (g_pcmtype[WAPI_OUT])
{
case PCM_TYPE_S16:
AudioFillBuffer_S16((PULONG)(pwh->lpData + pwh->dwBytesRecorded), (PUSHORT)lpAudioBuffer, nSampleCount);
break;
case PCM_TYPE_M16:
AudioFillBuffer_M16((PUSHORT)(pwh->lpData + pwh->dwBytesRecorded), (PUSHORT)lpAudioBuffer, nSampleCount);
break;
case PCM_TYPE_S8:
AudioFillBuffer_S8((PUSHORT)(pwh->lpData + pwh->dwBytesRecorded), (PUSHORT)lpAudioBuffer, nSampleCount);
break;
case PCM_TYPE_M8:
AudioFillBuffer_M8((PBYTE)(pwh->lpData + pwh->dwBytesRecorded), (PUSHORT)lpAudioBuffer, nSampleCount);
break;
} // end switch
pwh->dwBytesRecorded += nSampleCount * nSampleUnit;
nDstLen -= nSampleCount;
lpAudioBuffer += nSampleCount;
} // endif
}
// pad with silence if necessary
memset(lpAudioBuffer, 0, nDstLen * sizeof(ULONG));
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
* OUTPUTS : None
* DESIGN NOTES : convert packed 16bit to 8bit mono
* CAUTIONS :
*****************************************************************************/
VOID
AudioGetBuffer_M8 (
PUSHORT pSrcPtr,
PBYTE pDstPtr,
ULONG ulSrcSampleCount
)
{
ULONG ulSample;
while (ulSrcSampleCount > 0) {
pSrcPtr++;
ulSample = READ_REGISTER_USHORT(pSrcPtr++);
ulSample = (ulSample >> 8) + 128;
((PPCM_SAMPLE)pDstPtr)->m8.sample = (BYTE)ulSample;
pDstPtr++;
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
* OUTPUTS : None
* DESIGN NOTES : convert packed 16bit to 8bit stereo
* CAUTIONS :
*****************************************************************************/
VOID
AudioGetBuffer_S8 (
PUSHORT pSrcPtr,
PUSHORT pDstPtr,
ULONG ulSrcSampleCount
)
{
ULONG ulSample;
while (ulSrcSampleCount > 0) {
// Mic
if( g_VolumeSettings.dwInputSelect == WPDMX_LINE_MIC ){
pSrcPtr++;
ulSample = READ_REGISTER_USHORT(pSrcPtr++);
ulSample = (ulSample >> 8) + 128;
((PPCM_SAMPLE)pDstPtr)->s8.sample_left = (BYTE)ulSample;
((PPCM_SAMPLE)pDstPtr)->s8.sample_right = (BYTE)ulSample;
}
// Line In
else{
ulSample = READ_REGISTER_USHORT(pSrcPtr++);
ulSample = (ulSample >> 8) + 128;
((PPCM_SAMPLE)pDstPtr)->s8.sample_right = (BYTE)ulSample;
ulSample = READ_REGISTER_USHORT(pSrcPtr++);
ulSample = (ulSample >> 8) + 128;
((PPCM_SAMPLE)pDstPtr)->s8.sample_left = (BYTE)ulSample;
}
pDstPtr++;
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
* OUTPUTS : None
* DESIGN NOTES : convert packed 16bit to 16bit mono
* CAUTIONS :
*****************************************************************************/
VOID
AudioGetBuffer_M16 (
PUSHORT pSrcPtr,
PUSHORT pDstPtr,
ULONG ulSrcSampleCount
)
{
ULONG ulSample;
while (ulSrcSampleCount > 0) {
pSrcPtr++;
ulSample = READ_REGISTER_USHORT(pSrcPtr++);
((PPCM_SAMPLE)pDstPtr)->m16.sample = (USHORT)ulSample;
pDstPtr++;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -