📄 wmwavepdd.c
字号:
pWMAudioData->moreData[WAPI_OUT] = FALSE;
/*
* Unlock access to the global data.
*/
ReleaseMutex( g_hGlobalDataDeviceMutex );
return retval;
}
/*-----------------------------------------------------------------------------
* Function: private_PddWaveInStop
*
* This function stops recording of data to a buffer pointed to by the wave
* header.
*
* Parameters:
* pWMAudioData pointer to the global audio data
*
* Returns: MMRESULT
* MMSYSERR_NOERROR indicates success
* MMSYSERR_ERROR indicates failure
*---------------------------------------------------------------------------*/
static MMRESULT private_PddWaveInStop( volatile WM_SHARED_AUDIO_DATA *pWMAudioData )
{
MMRESULT retval = MMSYSERR_ERROR;
WMSTATUS status = WMS_SUCCESS;
WM_POWERFLAG powerSections = WM_POWER_NONE;
DEBUGMSG( ZONE_FUNCTION, ( TEXT( "private_PddWaveInStop+\r\n" ) ) );
/*
* Lock our global data access
*/
retval = WaitForSingleObject( g_hGlobalDataDeviceMutex, WM_GLOBAL_TIME_OUT );
if ( WAIT_OBJECT_0 != retval )
{
ASSERT( 0 );
goto error;
}
/*
* Check to make sure that we have a valid running
* output stream.
*/
if ( !INPUTDMARUNNING( pWMAudioData ) )
{
DEBUGMSG( ZONE_ERROR,
( TEXT( "private_PddWaveInStop - Trying to stop a non-running stream\r\n") ) );
ASSERT( 0 );
goto error;
}
WMAudioStop( g_hAudioDevice, g_hInputStream );
pWMAudioData->moreData[WAPI_IN] = FALSE;
/*
* Disable the input paths.
*/
retval = private_PrepareInputPaths( WM_STREAM_DEFAULT_INPUT, pWMAudioData, FALSE );
if ( MMSYSERR_NOERROR != retval )
{
DEBUGMSG( ZONE_ERROR,
( TEXT( "private_PddWaveInStop - disabling input paths failed\r\n") ) );
goto error;
}
/*
* Unlock access to the global data.
*/
ReleaseMutex( g_hGlobalDataDeviceMutex );
DEBUGMSG( ZONE_FUNCTION, ( TEXT( "private_PddWaveInStop-\r\n" ) ) );
return MMSYSERR_NOERROR;
error:
pWMAudioData->moreData[WAPI_IN] = FALSE;
/*
* Unlock access to the global data.
*/
ReleaseMutex( g_hGlobalDataDeviceMutex );
return retval;
}
/*-----------------------------------------------------------------------------
* Function: private_PddWaveFillBuffer
*
* This function sends data until the buffer is full (padding with silence if
* necessary).
*
* Parameters:
* pwh pointer to a structure that defines the header used to
* identify a waveform-audio buffer.
*
* Returns: void
*---------------------------------------------------------------------------*/
static void private_PddWaveFillBuffer( PWAVEHDR pwh )
{
DWORD bytesLeft;
unsigned int bytesCopied = 0;
BOOL DMABufferFull = FALSE;
BOOL clearBuffer = TRUE;
/*
* Fill the buffer.
*/
while ( pwh )
{
if ( pwh->reserved >= pwh->dwBufferLength )
{
pwh = pwh->lpNext;
}
else
{
bytesLeft = pwh->dwBufferLength - pwh->reserved;
if ( 0 == bytesLeft )
{
continue;
}
DMABufferFull = WMAudioSendData( g_hAudioDevice,
g_hOutputStream,
pwh->lpData + pwh->reserved,
bytesLeft,
&bytesCopied
);
/*
* If we couldn't copy anything, finish.
*/
if ( 0 == bytesCopied )
{
break;
}
pwh->reserved += bytesCopied;
/*
* Set ClearCompleteBuffer flag to false as we have already
* filled some of the buffer with audio.
*/
clearBuffer = FALSE;
}
}
/*
* If the buffer is not full then finish it off by filling it
* with silence.
*/
if( ! DMABufferFull )
{
if( clearBuffer )
WMAudioClearBuffer( g_hAudioDevice, g_hOutputStream );
else
WMAudioFinishSample( g_hAudioDevice, g_hOutputStream );
}
}
/*-----------------------------------------------------------------------------
* Function: private_PddWaveComplete
*
* This function updates the queued wave headers with the number of bytes
* copied.
*
* Parameters:
* pwd pointer to a structure that defines the header used to
* identify a waveform-audio buffer.
*
* Returns: void
*---------------------------------------------------------------------------*/
static void private_PddWaveComplete( PWAVEHDR pwh, ULONG cbBytesCompleted )
{
/*
* We've just finished playing another cbDstBytes of data.
* update the queued headers accordingly.
*/
while ((pwh != NULL) && (cbBytesCompleted > 0))
{
if (pwh->dwBytesRecorded >= pwh->reserved)
{
pwh = pwh->lpNext;
}
else
{
ULONG cbBytesLeft = pwh->reserved - pwh->dwBytesRecorded;
ULONG cbAdvance = min(cbBytesCompleted, cbBytesLeft);
cbBytesCompleted -= cbAdvance;
pwh->dwBytesRecorded += cbAdvance;
}
}
}
/*-----------------------------------------------------------------------------
* Function: private_AudioGetBuffer
*
* This function gets the incoming data from DMA buffers and write it
* to the application buffers .
*
* Parameters:
* pwh pointer to the WAVEHDR.
*
* Returns: void
*---------------------------------------------------------------------------*/
static void private_PddWaveGetBuffer( PWAVEHDR pwh )
{
DWORD bytesLeft;
unsigned int bytesCopied = 0;
WM_BOOL DMABufferCopied = FALSE;
while ( pwh )
{
if ( pwh->dwBytesRecorded >= pwh->dwBufferLength )
{
pwh = pwh->lpNext;
}
else
{
bytesLeft = pwh->dwBufferLength - pwh->dwBytesRecorded;
DMABufferCopied = WMAudioReceiveData( g_hAudioDevice,
g_hInputStream,
pwh->lpData +
pwh->dwBytesRecorded,
bytesLeft,
&bytesCopied
);
pwh->dwBytesRecorded += bytesCopied;
/*
* If the DMA buffer has been copied we can finish.
*/
if ( DMABufferCopied )
{
break;
}
}
}
}
/*-----------------------------------------------------------------------------
* Function: private_PddWaveGetVolume
*
* Get the volume of the device.
* We convert to the windows volume which is 16 bits of Left and 16 bits of
* Right (0xRRRRLLLL) to the codecs understanding of volume.
*
* Parameters:
* none.
*
* Returns: ULONG The current volume.
*---------------------------------------------------------------------------*/
static ULONG private_PddWaveGetVolume( void )
{
return g_VolumeSettings.dwMasterVolume;
}
/*-----------------------------------------------------------------------------
* Function: private_PddWaveSetVolume
*
* Set the volume of the device.
* We convert the windows volume which is 16 bits of Left and 16 bits of Right
* (0xRRRRLLLL) to the codecs understanding of volume.
* NOTE: Any Wolfson library calls that are unsupported are not treated as error
* conditions. This procedure is generic so it will try to operate on all
* possible codecs, therefore it is only interested in facilities that are
* supported by the codec.
*
* Parameters:
* volume The volume to set the device to.
*
* Returns: MMRESULT
* MMSYSERR_NOERROR indicates success
* MMSYSERR_ERROR indicates failure
*---------------------------------------------------------------------------*/
static MMRESULT private_PddWaveSetVolume( ULONG volume )
{
DWORD retval = MMSYSERR_NOERROR;
WMSTATUS status = WMS_SUCCESS;
unsigned short volumeLeft;
unsigned short volumeRight;
unsigned short volumeMono;
DEBUGMSG( ZONE_FUNCTION, ( TEXT( "private_PddWaveSetVolume+\r\n" ) ) );
/* Windows Volume is 16 bits of Left and 16 bits of right (0xRRRRLLLL) */
g_VolumeSettings.dwMasterVolume = volume;
/*
* If we're not muted, set the output volumes.
* If we're muted, we'll set them when we unmute.
*/
if ( g_VolumeSettings.fMasterMute )
{
goto exit;
}
volumeRight = RIGHT_VOL( volume );
volumeLeft = LEFT_VOL( volume );
volumeMono = ( volumeLeft + volumeRight ) / 2 ;
/* SPEAKER */
status = WMAudioSetSignalVolumes( g_hAudioDevice,
WM_AUDIO_SPEAKER,
volumeLeft,
volumeRight
);
if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
{
DEBUGMSG( ZONE_ERROR,
( TEXT( "private_PddWaveSetVolume - WMAudioSetSignalVolumes(WM_AUDIO_SPEAKER) failed: %hs\r\n" ),
WMStatusText( status )
) );
goto exit;
}
/* HEADPHONE */
status = WMAudioSetSignalVolumes( g_hAudioDevice,
WM_AUDIO_HEADPHONE,
volumeLeft,
volumeRight
);
if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
{
DEBUGMSG( ZONE_ERROR,
( TEXT( "private_PddWaveSetVolume - WMAudioSetSignalVolumes(WM_AUDIO_HEADPHONE) failed: %hs\r\n" ),
WMStatusText( status )
) );
goto exit;
}
/* MONOOUT */
status = WMAudioSetSignalVolume( g_hAudioDevice,
WM_AUDIO_MONOOUT,
volumeMono,
WM_CHANNEL_ALL
);
if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
{
DEBUGMSG( ZONE_ERROR,
( TEXT( "private_PddWaveSetVolume - WMAudioSetSignalVolume(WM_AUDIO_MONOOUT) failed: %hs\r\n" ),
WMStatusText( status )
) );
goto exit;
}
/* OUT3 */
status = WMAudioSetSignalVolume( g_hAudioDevice,
WM_AUDIO_OUT3,
volumeMono,
WM_CHANNEL_ALL
);
if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
{
DEBUGMSG( ZONE_ERROR,
( TEXT( "private_PddWaveSetVolume - WMAudioSetSignalVolume(WM_AUDIO_OUT3) failed: %hs\r\n" ),
WMStatusText( status )
) );
goto exit;
}
/* OUT4 */
status = WMAudioSetSignalVolume( g_hAudioDevice,
WM_AUDIO_OUT4,
volumeMono,
WM_CHANNEL_ALL
);
if ( WM_ERROR( status ) && ( status != WMS_UNSUPPORTED ) )
{
DEBUGMSG( ZONE_ERROR,
( TEXT( "private_PddWaveSetVolume - WMAudioSetSignalVolume(WM_AUDIO_OUT4) failed: %hs\r\n" ),
WMStatusText( status )
) );
goto exit;
}
/* If volume is zero then mute the outputs for maximum attenuation */
if ( 0 == volume )
{
g_OutputMaxAtten = TRUE;
status = WMAudioIsSignalMuted( g_hAudioDevice, WM_AUDIO_STEREO_DAC );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -