📄 hwctxt.cpp.bak
字号:
RETAILMSG(1,(TEXT("sound increase volume event Error2\r\n")));
}
}
HANDLE hIncrease=CreateThread((LPSECURITY_ATTRIBUTES)NULL,
0,
(LPTHREAD_START_ROUTINE)CallInterruptThreadIncreaseVolume,
this,//this,
0,
NULL);
if (!hIncrease)
{
return FALSE;
}
CeSetThreadPriority(hIncrease, 30);
//reduce volume!
if (m_hVolumeReduEvent == NULL)
{
// allocate the interrupt event
m_hVolumeReduEvent = CreateEvent(NULL, FALSE, FALSE,NULL);
if (NULL == m_hVolumeIncrEvent)
{
RETAILMSG(1,(TEXT("sound reduce volume event Error1\r\n")));
}
// initialize interrupt event
if (!InterruptInitialize (SYSINTR_REDVOLUME, m_hVolumeReduEvent, NULL, 0))
{
RETAILMSG(1,(TEXT("sound reduce volume event Error2\r\n")));
}
}
HANDLE hReduce=CreateThread((LPSECURITY_ATTRIBUTES)NULL,
0,
(LPTHREAD_START_ROUTINE)CallInterruptThreadReduceVolume,
this,//this,
0,
NULL);
if (!hReduce)
{
return FALSE;
}
CeSetThreadPriority(hReduce, 31);
// control volume!!!
RETAILMSG(1,(TEXT("------------------volume interrupt init finish!----------------\r\n")));
///################################################
m_hBKLightEvent=CreateEvent(NULL, TRUE, FALSE,NULL);//manu ,intinial nosignal
if (NULL == m_hBKLightEvent)
RETAILMSG(1,(TEXT("sound reduce volume event Error1\r\n")));
HANDLE hBKLight=CreateThread((LPSECURITY_ATTRIBUTES)NULL,
0,
(LPTHREAD_START_ROUTINE)CallBKLight,
NULL,//this,
0,
NULL);
if (!hBKLight)
return FALSE;
CeSetThreadPriority(hBKLight, 102);*/
return TRUE;
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: PowerUp()
Description: Powers up the audio codec chip.
Notes: Currently, this function is unimplemented because
the audio codec chip is ONLY powered up when the
user wishes to play or record. The AudioMute() function
handles the powerup sequence.
Returns: Boolean indicating success
-------------------------------------------------------------------*/
void HardwareContext::PowerUp()
{
I2S_Init();
//AudioMute(IIC_INPUT_CHANNEl|IIC_OUTPUT_CHANNEl,FALSE); // 030711
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: PowerDown()
Description: Powers down the audio codec chip.
Notes: Even if the input/output channels are muted, this
function powers down the audio codec chip in order
to conserve battery power.
Returns: Boolean indicating success
-------------------------------------------------------------------*/
void HardwareContext::PowerDown()
{
//StopOutputDMA();
//AudioMute(IIC_OUTPUT_CHANNEl|IIC_INPUT_CHANNEl,TRUE);
}
//############################################ Helper Functions #############################################
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: TransferOutputBuffer()
Description: Retrieves the next "mixed" audio buffer of data to
DMA into the output channel.
Returns: Number of bytes needing to be transferred.
-------------------------------------------------------------------*/
ULONG HardwareContext::TransferOutputBuffer(ULONG NumBuf)
{
ULONG BytesTransferred = 0;
PBYTE pBufferStart = m_Output_pbDMA_PAGES[NumBuf];
PBYTE pBufferEnd = pBufferStart + AUDIO_DMA_PAGE_SIZE;
PBYTE pBufferLast;
__try
{
pBufferLast = m_OutputDeviceContext.TransferBuffer(pBufferStart, pBufferEnd,NULL);
BytesTransferred = m_OutBytes[NumBuf] = pBufferLast-pBufferStart;
// Enable if you need to clear the rest of the DMA buffer
StreamContext::ClearBuffer(pBufferLast,pBufferEnd);
if(NumBuf == OUT_BUFFER_A) // Output Buffer A
{
m_OutputDMAStatus &= ~DMA_DONEA;
m_OutputDMAStatus |= DMA_STRTA;
}
else // Output Buffer B
{
m_OutputDMAStatus &= ~DMA_DONEB;
m_OutputDMAStatus |= DMA_STRTB;
}
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DEBUGMSG(ZONE_ERROR, (TEXT("WAVDEV2.DLL:TransferOutputBuffer() - EXCEPTION: %d"), GetExceptionCode()));
}
return BytesTransferred;
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: TransferOutputBuffers()
Description: Determines which output buffer (A or B) needs to
be filled with sound data. The correct buffer is
then populated with data and ready to DMA to the
output channel.
Returns: Boolean indicating success
-------------------------------------------------------------------*/
ULONG HardwareContext::TransferOutputBuffers(DWORD dwDCSR)
{
//RETAILMSG(1,(TEXT(" ---------------TransferOutputBuffers---------------------\r\n")));
ULONG BytesTransferred = 0;
ULONG BytesTotal;
//3 5 7
DWORD Bits = dwDCSR & (DMA_DONEA|DMA_DONEB|DMA_BIU);
DEBUGMSG(1,(TEXT("%x\n"),Bits));
switch (Bits)
{
case 0:
case DMA_BIU: //7
// No done bits set- must not be my interrupt
return 0;
case DMA_DONEA|DMA_DONEB|DMA_BIU: //3 5 7
// Load B, then A
BytesTransferred = TransferOutputBuffer(OUT_BUFFER_B);
// fall through
case DMA_DONEA: // This should never happen!
case DMA_DONEA|DMA_BIU: //3 /3 7
BytesTransferred += TransferOutputBuffer(OUT_BUFFER_A); // charlie, A => B
break;
case DMA_DONEA|DMA_DONEB: //3 5
// Load A, then B
BytesTransferred = TransferOutputBuffer(OUT_BUFFER_A);
// charlie
BytesTransferred += TransferOutputBuffer(OUT_BUFFER_B);
break; // charlie
// fall through
case DMA_DONEB|DMA_BIU: // This should never happen!
case DMA_DONEB: //5 7 / 5
// Load B
BytesTransferred += TransferOutputBuffer(OUT_BUFFER_B); // charlie, B => A
break;
}
// If it was our interrupt, but we weren't able to transfer any bytes
// (e.g. no full buffers ready to be emptied)
// and all the output DMA buffers are now empty, then stop the output DMA
BytesTotal = m_OutBytes[OUT_BUFFER_A]+m_OutBytes[OUT_BUFFER_B];
if (BytesTotal==0)
{
StopOutputDMA();
}
//RETAILMSG(1,(TEXT(" ---------------TransferOutputBuffers---------------------\r\n")));
return BytesTransferred;
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: TransferInputBuffer()
Description: Retrieves the chunk of recorded sound data and inputs
it into an audio buffer for potential "mixing".
Returns: Number of bytes needing to be transferred.
-------------------------------------------------------------------*/
ULONG HardwareContext::TransferInputBuffer(ULONG NumBuf)
{
//int tmp;
ULONG BytesTransferred = 0;
PBYTE pBufferStart = m_Input_pbDMA_PAGES[NumBuf];
PBYTE pBufferEnd = pBufferStart + AUDIO_DMA_PAGE_SIZE;
PBYTE pBufferLast;
__try
{
pBufferLast = m_InputDeviceContext.TransferBuffer(pBufferStart, pBufferEnd,NULL);
BytesTransferred = m_InBytes[NumBuf] = pBufferLast-pBufferStart;
if(NumBuf == IN_BUFFER_A) // Input Buffer A
{
m_InputDMAStatus &= ~DMA_DONEA;
m_InputDMAStatus |= DMA_STRTA;
}
else // Input Buffer B
{
m_InputDMAStatus &= ~DMA_DONEB;
m_InputDMAStatus |= DMA_STRTB;
}
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
DEBUGMSG(ZONE_ERROR, (TEXT("WAVDEV2.DLL:TransferInputBuffer() - EXCEPTION: %d"), GetExceptionCode()));
}
return BytesTransferred;
}
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Function: TransferInputBuffers()
Description: Determines which input buffer (A or B) needs to
be filled with recorded sound data. The correct
buffer is then populated with recorded sound data
from the input channel.
Returns: Boolean indicating success
-------------------------------------------------------------------*/
ULONG HardwareContext::TransferInputBuffers(DWORD dwDCSR)
{
ULONG BytesTransferred=0;
DWORD Bits = dwDCSR & (DMA_DONEA|DMA_DONEB|DMA_BIU);
//int tmp;
switch (Bits)
{
case 0:
case DMA_BIU:
// No done bits set- must not be my interrupt
return 0;
case DMA_DONEA|DMA_DONEB|DMA_BIU:
// Load B, then A
BytesTransferred = TransferInputBuffer(IN_BUFFER_B);
// fall through
case DMA_DONEA: // This should never happen!
case DMA_DONEA|DMA_BIU:
// Load A
BytesTransferred += TransferInputBuffer(IN_BUFFER_A);
break;
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
case DMA_DONEA|DMA_DONEB: //haha ! it is!
// Load A, then B
BytesTransferred = TransferInputBuffer(IN_BUFFER_A);
BytesTransferred += TransferInputBuffer(IN_BUFFER_B);
break;
//@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// fall through
case DMA_DONEB|DMA_BIU: // This should never happen!
case DMA_DONEB:
// Load B
BytesTransferred += TransferInputBuffer(IN_BUFFER_B);
break;
}
// If it was our interrupt, but we weren't able to transfer any bytes
// (e.g. no empty buffers ready to be filled)
// Then stop the input DMA
if (BytesTransferred==0)
{
StopInputDMA();
}
return BytesTransferred;
}
void HardwareContext::InterruptThread() //DMA interrupt!
{
ULONG InputTransferred, OutputTransferred;
//int tmp;
BOOL dmaInterruptSource = 0;
// Fast way to access embedded pointers in wave headers in other processes.
SetProcPermissions((DWORD)-1);
while(TRUE)
{
WaitForSingleObject(m_hAudioInterrupt, INFINITE);
//RETAILMSG(1,(TEXT("***************AudioInterrupt**************!\r\n")));
//DEBUGMSG(1,(TEXT("0x%x\n"),s2440INT->rINTMSK));
//DEBUGMSG(1,(TEXT("start\n")));
dmaInterruptSource = 0;
//----- 1. Grab the lock -----
Lock();
//MAX_AudioMuted(IIC_OUTPUT_CHANNEl,false);
/*if((v_pIOPregs->rGPFDAT)&0x02)//HP
{
b_nowlevel=true;
//b_nowlevel
gHP_flag=true;
}else
{
b_nowlevel=false;
//RETAILMSG(1,(TEXT(" -----------------no HP!--------------------\r\n")));
gHP_flag=false;
}
//if(b_nowlevel==b_prolevel)
//gb_changed=true;
if(b_nowlevel!=b_prolevel)
{
if(gHP_flag)
{
//MAX_HeadphoneMuted(false);
MAX_AudioMuted(IIC_OUTPUT_CHANNEl,true);
}else
{
//MAX_HeadphoneMuted(true);
MAX_AudioMuted(IIC_OUTPUT_CHANNEl,false);
}
}
b_prolevel= b_nowlevel;*/
__try
{
//DEBUGMSG(1,(TEXT("try\n")));
//----- 3. Determine the interrupt source (input DMA operation or output DMA operation?) -----
//----- NOTE: Often, platforms use two separate DMA channels for input/output operations but
// have the OAL return SYSINTR_AUDIO as the interrupt source. If this is the case,
// then the interrupt source (input or output DMA channel) must be determined in
// this step.
// charlie, determine the interrupt source
if( s2440INT->rINTMSK & BIT_DMA1 ){
dmaInterruptSource |= DMA_CH_MIC; //input! // Input DMA is supported...
}
if( s2440INT->rINTMSK & BIT_DMA2 ){
dmaInterruptSource |= DMA_CH_OUT; // Output DMA is supported...
}
// For determine the interrupt source
//----- 2. Acknowledge the DMA interrupt -----
InterruptDone(m_IntrAudio);
if ( m_Dx != D0 ) continue;
//----- 4. Handle any interrupts on the input source -----
// NOTE: The InterruptDone() call below automatically clears the interrupt.
// if((m_InputDMARunning) && (dmaInterruptSource == DMA_CH_MIC))
if((dmaInterruptSource == DMA_CH_MIC))
{
//----- Determine which buffer just completed the DMA transfer -----
if(m_InputDMAStatus & DMA_BIU)
{
m_InputDMAStatus &= ~DMA_STRTB; // Buffer B just completed...
m_InputDMAStatus |= DMA_DONEB;
m_InputDMAStatus &= ~DMA_BIU; // Buffer A is in use
//SELECT_AUDIO_DMA_INPUT_BUFFER_B();
v_pDMAregs->rDIDST1 = (int)(AUDIO_DMA_BUFFER_PHYS+3*AUDIO_DMA_PAGE_SIZE);
DEBUGMSG(1,(TEXT("1\n")));
}else
{
m_InputDMAStatus &= ~DMA_STRTA; // Buffer A just completed...
m_InputDMAStatus |= DMA_DONEA;
m_InputDMAStatus |= DMA_BIU; // Buffer B is in use
//SELECT_AUDIO_DMA_INPUT_BUFFER_A();
v_pDMAregs->rDIDST1 = (int)(AUDIO_DMA_BUFFER_PHYS+2*AUDIO_DMA_PAGE_SIZE);
DEBUGMSG(1,(TEXT("2\n")));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -