📄 wavepdd.c
字号:
void ClearDmacRegs()
{
int i;
for (i=0; i< 16; i++)
v_pDMARegs->dcsr[i]=0;
//skip rsvd section rsvd0[44];
//skip rsvd seciton rsvd1[3];
for (i=0; i< 40; i++)
v_pDMARegs->drcmr[i]=0x0;
for (i=0; i<16; i++)
{
v_pDMARegs->dcsr[i]=0x00000000; //no descriptor fetch
v_pDMARegs->ddg[i].ddadr = 0; //write an address and see if it comes back
v_pDMARegs->ddg[i].dsadr = 0;
v_pDMARegs->ddg[i].dtadr = 0;
v_pDMARegs->ddg[i].dcmd = 0;
}
}
void Ac97RegDump()
{
BYTE i;
short int retval=FALSE;
unsigned short int Data;
for (i=0; i<0x7e; i+=2)
{
retval= ShadowReadAC97(i, &Data , DEV_AUDIO );
DEBUGMSG(ZONE_ERROR,(TEXT("reg %x is %x ---"),i,Data));
if ((i %4) == 0)
DEBUGMSG(ZONE_ERROR,(TEXT("\r\n")));
}
}
//------------------------------------------------------------------------------------------------------------
// Function: PDD_AudioGetInterruptType
//
// Purpose: Process an audio interrupt from the MDD
//
// Returns: AUDIO_STATE, indicates the state of audio playback or record to the MDD
//
//-------------------------------------------------------------------------------------------------------------
AUDIO_STATE
PDD_AudioGetInterruptType(
VOID
)
{
AUDIO_STATE retval=AUDIO_STATE_IGNORE ;
DEBUGMSG(ZONE_VERBOSE, (TEXT( "+PDD_AudioGetInterruptType\r\n" )) );
//
// An audio interrupt has occured. We need to tell the MDD who owns it
// and what state that puts us in.
//
// Note, that you can return both an input and an output state simultaneously
// by simply OR'ing the two values together (output and input are held
// in upper and lower nibbles respectively).
//
//
// I N P U T
//
//did we get an input error?
if (v_pDMARegs->dcsr[gInputSrc] & DCSR_BUSERRINTR)
{
DEBUGMSG(ZONE_ERROR, (TEXT( "DCSR_BUSERRINTR ERROR on input\r\n" )) );
DEBUGCHK(0); // a dma interrupt occured
retval |= AUDIO_STATE_IGNORE; //the descriptor was loaded but not ready for use
}
//did we get an input interrupt?
if (v_pDMARegs->dcsr[gInputSrc] & DCSR_ENDINTR) //if the input channel stopped at the end of a buffer xfer
{
v_pDMARegs->dcsr[gInputSrc] |= DCSR_ENDINTR;
if (v_fMoreData[WAPI_IN] == TRUE)
retval |= AUDIO_STATE_IN_RECORDING;
else
retval |= AUDIO_STATE_IN_STOPPED; //TODO: Does the MDD now send a WPDM_STOP message?
}
if (v_pDMARegs->dcsr[gInputSrc] & DCSR_STARTINTR)
{
v_pDMARegs->dcsr[gInputSrc] |= DCSR_STARTINTR; // reset the interrupt
DEBUGMSG(ZONE_VERBOSE, (TEXT( "DCSR_STARTINTER on input\r\n" )) );
retval |= AUDIO_STATE_IN_OVERFLOW; //the descriptor was loaded but not ready for use
}
//did we get an output error?
if (v_pDMARegs->dcsr[DMA_CH_OUT] & DCSR_BUSERRINTR)
{
DEBUGMSG(ZONE_ERROR, (TEXT( "DCSR_BUSERRINTR ERROR on output\r\n" )) );
DEBUGCHK(0); // a dma interrupt occured
retval |= AUDIO_STATE_IGNORE; //the descriptor was loaded but not ready for use
}
//did we get an output interrupt?
if (v_pDMARegs->dcsr[DMA_CH_OUT] & DCSR_ENDINTR) //if the out channel stopped at the end of a buffer xfer
{
v_pDMARegs->dcsr[DMA_CH_OUT] |= DCSR_ENDINTR;
if (v_fMoreData[WAPI_OUT] == TRUE)
retval |= AUDIO_STATE_OUT_PLAYING;
else
retval |= AUDIO_STATE_OUT_STOPPED; //TODO: Does the MDD now send a WPDM_STOP message?
}
if (v_pDMARegs->dcsr[DMA_CH_OUT] & DCSR_STARTINTR)
{
v_pDMARegs->dcsr[DMA_CH_OUT] |= DCSR_STARTINTR; // reset the interrupt
DEBUGMSG(ZONE_ERROR, (TEXT( "DCSR_STARTINTER on output\r\n" )) );
retval |= AUDIO_STATE_OUT_UNDERFLOW; //the descriptor was loaded but not ready for use
}
DEBUGMSG(ZONE_VERBOSE, (TEXT( "-PDD_AudioGetInterruptType\r\n" )) );
return retval;
}
//------------------------------------------------------------------------------------------------------------
// Function: PddpAudioDeallocateVm
//
// Purpose: Unmap all allocated virtual memory locations
//
// Returns: none
//
//-------------------------------------------------------------------------------------------------------------
BOOL PddpAudioDeallocateVm(void)
{
if (v_pDMARegs)
{
VirtualFree ((void*) v_pDMARegs, 0, MEM_RELEASE);
}
if (dma_page[0])
{
VirtualFree ((void*) dma_page[0], 0, MEM_RELEASE);
}
if (v_pAudioRcvA_Virtual)
{
VirtualFree ((void*) v_pAudioRcvA_Virtual, 0, MEM_RELEASE);
}
if (v_pAudioRcvB_Virtual)
{
VirtualFree ((void*) v_pAudioRcvB_Virtual, 0, MEM_RELEASE);
}
if (v_pAudioXmitA_Virtual)
{
VirtualFree ((void*) v_pAudioXmitA_Virtual, 0, MEM_RELEASE);
}
if (v_pAudioXmitB_Virtual)
{
VirtualFree ((void*) v_pAudioXmitB_Virtual, 0, MEM_RELEASE);
}
if (v_pAudioMicA_Virtual)
{
VirtualFree ((void*) v_pAudioMicA_Virtual, 0, MEM_RELEASE);
}
if (v_pAudioMicB_Virtual)
{
VirtualFree ((void*) v_pAudioMicB_Virtual, 0, MEM_RELEASE);
}
return(TRUE);
}
//------------------------------------------------------------------------------------------------------------
// Function: PDD_AudioInitialize
//
// Purpose: Initialize Audio & DMA Hardware
//
// Returns: TRUE indicates success. FALSE indicates failure
//
//-------------------------------------------------------------------------------------------------------------
BOOL PDD_AudioInitialize(DWORD dwIndex)
{
int i;
BOOL retValue = FALSE;
DMA_ADAPTER_OBJECT Adapter;
PHYSICAL_ADDRESS PA;
HKEY hConfig = NULL;
LPWSTR lpRegPath = (LPWSTR)dwIndex;
DWORD dwDataSize = 0;
LONG regError;
DEBUGMSG(ZONE_ERROR, (TEXT("+Audio Initialize\r\n")));
g_fInPowerHandler = FALSE;
g_pfnReadAc97 = ReadAC97;
g_pfnWriteAc97 = WriteAC97;
// Get audio driver parameters from the registry.
//
hConfig = OpenDeviceKey(lpRegPath);
if(hConfig == NULL)
{
DEBUGMSG(ZONE_ERROR, (TEXT("ERROR: AudioInitialize: OpenDeviceKey('%s') failed.\r\n"), lpRegPath));
return(FALSE);
}
// Read the SYSINTR value from the registry.
//
dwDataSize = BULVERDE_REG_SYSINTR_VAL_LEN;
regError = RegQueryValueEx(hConfig, BULVERDE_REG_SYSINTR_VAL_NAME, NULL, NULL, (LPBYTE)&gIntrAudio, &dwDataSize);
if (regError != ERROR_SUCCESS)
{
DEBUGMSG(ZONE_ERROR, (TEXT("ERROR: AudioInitialize: Query registry Sysintr value failed.\r\n")));
RegCloseKey(hConfig);
return(FALSE);
}
// Close the registry handle.
//
RegCloseKey(hConfig);
//
// Map the DMAC descriptors.
//
if (!MapDMADescriptors())
{
DEBUGMSG(ZONE_ERROR, (TEXT("ERROR: AudioInitialize: failed to allocate DMA descriptor buffers.\r\n")));
return(FALSE);
}
//
// Map device registers.
//
if (!MapDeviceRegisters())
{
DEBUGMSG(ZONE_ERROR, (TEXT("ERROR: AudioInitialize: failed to map device register(s).\r\n")));
return(FALSE);
}
// Map both DMA pages into the local address space.
//
Adapter.ObjectSize = sizeof(DMA_ADAPTER_OBJECT);
Adapter.InterfaceType = Internal;
Adapter.BusNumber = 0;
dma_page[0] = (BYTE *) HalAllocateCommonBuffer(&Adapter, (AUDIO_BUFFER_SIZE * NUM_DMA_AUDIO_BUFFERS), &PA, FALSE);
if (!dma_page[0])
{
DEBUGMSG(ZONE_ERROR, (TEXT("ERROR: AudioInitialize: failed to allocate DMA buffer(s).\r\n")));
return(FALSE);
}
dma_page[1] = dma_page[0] + AUDIO_BUFFER_SIZE;
dma_page[2] = dma_page[1] + AUDIO_BUFFER_SIZE;
dma_page[3] = dma_page[2] + AUDIO_BUFFER_SIZE;
dma_page_physical[0] = (BYTE *)PA.LowPart;
dma_page_physical[1] = dma_page_physical[0] + AUDIO_BUFFER_SIZE;
dma_page_physical[2] = dma_page_physical[1] + AUDIO_BUFFER_SIZE;
dma_page_physical[3] = dma_page_physical[2] + AUDIO_BUFFER_SIZE;
DEBUGMSG(ZONE_ALLOC, (TEXT("INFO: AudioInitialize: dmap[0]=0x%x, dmap[1]=0x%x, dmap[2]=0x%x, dmap[3]=0x%x\r\n" ),
dma_page[0],dma_page[1],dma_page[2],dma_page[3]));
// Fill out the DMA descriptors.
// NOTE: this doesn't actually load the descriptors. We'll do that when asked to start DMA.
//
FillDescriptors();
// Dump the Descriptorx.
//
DEBUGMSG(ZONE_VERBOSE, (TEXT( "\r\n")));
DEBUGMSG(ZONE_VERBOSE, (TEXT( "v_pAudioXmitA->ddadr 0x%x \r\n" ),v_pAudioXmitA_Virtual->ddadr) );
DEBUGMSG(ZONE_VERBOSE, (TEXT( "v_pAudioXmitA->dsadr 0x%x \r\n" ),v_pAudioXmitA_Virtual->dsadr) );
DEBUGMSG(ZONE_VERBOSE, (TEXT( "v_pAudioXmitA->dtadr 0x%x \r\n" ),v_pAudioXmitA_Virtual->dtadr) );
DEBUGMSG(ZONE_VERBOSE, (TEXT( "v_pAudioXmitA->dcmd 0x%x \r\n" ),v_pAudioXmitA_Virtual->dcmd ) );
DEBUGMSG(ZONE_VERBOSE, (TEXT( "\r\n")));
DEBUGMSG(ZONE_VERBOSE, (TEXT( "v_pAudioXmitB->ddadr 0x%x \r\n" ),v_pAudioXmitB_Virtual->ddadr) );
DEBUGMSG(ZONE_VERBOSE, (TEXT( "v_pAudioXmitB->dsadr 0x%x \r\n" ),v_pAudioXmitB_Virtual->dsadr) );
DEBUGMSG(ZONE_VERBOSE, (TEXT( "v_pAudioXmitB->dtadr 0x%x \r\n" ),v_pAudioXmitB_Virtual->dtadr) );
DEBUGMSG(ZONE_VERBOSE, (TEXT( "v_pAudioXmitB->dcmd 0x%x \r\n" ),v_pAudioXmitB_Virtual->dcmd ) );
DEBUGMSG(ZONE_VERBOSE, (TEXT( "\r\n")));
DEBUGMSG(ZONE_VERBOSE, (TEXT( "v_pAudioRcvA->ddadr 0x%x \r\n" ),v_pAudioRcvA_Virtual->ddadr) );
DEBUGMSG(ZONE_VERBOSE, (TEXT( "v_pAudioRcvA->dsadr 0x%x \r\n" ),v_pAudioRcvA_Virtual->dsadr) );
DEBUGMSG(ZONE_VERBOSE, (TEXT( "v_pAudioRcvA->dtadr 0x%x \r\n" ),v_pAudioRcvA_Virtual->dtadr) );
DEBUGMSG(ZONE_VERBOSE, (TEXT( "v_pAudioRcvA->dcmd 0x%x \r\n" ),v_pAudioRcvA_Virtual->dcmd ) );
DEBUGMSG(ZONE_VERBOSE, (TEXT( "\r\n")));
DEBUGMSG(ZONE_VERBOSE, (TEXT( "v_pAudioRcvB->ddadr 0x%x \r\n" ),v_pAudioRcvB_Virtual->ddadr) );
DEBUGMSG(ZONE_VERBOSE, (TEXT( "v_pAudioRcvB->dsadr 0x%x \r\n" ),v_pAudioRcvB_Virtual->dsadr) );
DEBUGMSG(ZONE_VERBOSE, (TEXT( "v_pAudioRcvB->dtadr 0x%x \r\n" ),v_pAudioRcvB_Virtual->dtadr) );
DEBUGMSG(ZONE_VERBOSE, (TEXT( "v_pAudioRcvB->dcmd 0x%x \r\n" ),v_pAudioRcvB_Virtual->dcmd ) );
// Compress range of 3f - 0 to 1f - 0 this makes volume adjustment seem intuitive.
//
for (i=0; i < 64; i+=2)
{
g_VolMatrix[i] = (63 - i) >> 1;
g_VolMatrix[i+1] = (63 - i) >> 1;
}
// Customize lower volume settings to quickly rolloff to neg infinity.
g_VolMatrix[0] = 0x3f;
g_VolMatrix[1] = 0x3A;
g_VolMatrix[2] = 0x35;
g_VolMatrix[3] = 0x2F;
g_VolMatrix[4] = 0x2a;
g_VolMatrix[5] = 0x25;
g_VolMatrix[6] = 0x1f;
// Initialize the AClink.
//
if (InitializeACLink(FALSE, DEV_AUDIO))
{
// Power-on the audio controller.
if (AudioPowerOn())
{
retValue = TRUE;
}
}
//msWait(500);
DEBUGMSG(ZONE_ERROR, (TEXT("-Audio Initialize\r\n")));
return (retValue);
}
//------------------------------------------------------------------------------------------------------------
// Function: PDD_AudioPowerHandler
//
// Purpose: This function is responsible for managing the audio hardware during POWER_UP
// and POWER_DOWN notifications
//-------------------------------------------------------------------------------------------------------------
VOID
PDD_AudioPowerHandler(
BOOL power_down
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -