📄 wmaudio.c
字号:
audioIF = WM_AUDIOIF_HIFI;
break;
case WM_STREAM_VOICE_OUT:
powerSections = WM_POWER_AUDIO_VOICE_DAC;
audioIF = WM_AUDIOIF_VOICE;
break;
case WM_STREAM_MONO_OUT:
powerSections = WM_POWER_AUDIO_MONO_DAC;
audioIF = (WM_AUDIO_INTERFACE) WM_AUDIOIF_MONO;
break;
default:
/* We checked we had a valid stream above */
WM_ASSERT( hDevice, WM_IS_VALID_STREAM( stream ) );
}
status = WMAudioPowerUp( hDevice, powerSections );
if ( WM_ERROR( status ) )
{
WM_TRACE( hDevice, ( "WMAudioEnableStream(%d): WMAudioPowerUp failed: %s",
ifStream,
WMStatusText( status )
)
);
goto error0;
}
/*
* Enable voice if necessary.
*/
if ( WM_IS_VOICE_STREAM( stream ) )
{
status = WMVoiceEnable( hDevice );
if ( WM_ERROR( status ) )
{
goto error0;
}
}
/*
* Look up our chipdef and see if we've got the function.
* If not (e.g. standard AC'97), we don't need to do anything extra.
*/
pChipDef = WMGetChipDef( hDevice );
WM_ASSERT( hDevice, pChipDef );
if ( !pChipDef )
{
status = WMS_NO_SUPPORTED_DEVICE;
WM_TRACE( hDevice, ( "WMAudioEnableStream(%d): Chip Def not found: %s",
ifStream,
WMStatusText( status )
)
);
goto error1;
}
if ( pChipDef->vtable.fnEnableStream )
{
status = pChipDef->vtable.fnEnableStream( hDevice, stream );
if ( WM_ERROR( status ) )
{
WM_TRACE( hDevice, ( "WMAudioEnableStream(%d): device-specific enable failed: %s",
ifStream,
WMStatusText( status )
)
);
goto error1;
}
}
/*
* If it's an I2S device, make sure the interface is configured
* - use default settings if not.
*
* Note we do this after the chip-specific initialisation in case there
* is special configuration needed by the chip (for example the WM8753
* output stream may be either HiFi or Voice depending on the other
* set-up).
*/
if ( WM_IS_I2S( hDevice ) )
{
WM_BOOL isMaster;
WM_AUDIOIF_FORMAT format;
WM_AUDIOIF_WIDTH width;
WM_AUDIOIF_FLAGS flags;
unsigned int configuredFlag;
if ( WM_AUDIOIF_HIFI == audioIF )
{
isMaster = WM_AUDIOIF_DEFAULT_HIFI_IS_MASTER;
format = WM_AUDIOIF_DEFAULT_HIFI_FORMAT;
width = WM_AUDIOIF_DEFAULT_HIFI_WIDTH;
flags = WM_AUDIOIF_DEFAULT_HIFI_FLAGS;
configuredFlag = WM_AUDIO_HIFI_CONFIGURED;
}
else
{
isMaster = WM_AUDIOIF_DEFAULT_VOICE_IS_MASTER;
format = WM_AUDIOIF_DEFAULT_VOICE_FORMAT;
width = WM_AUDIOIF_DEFAULT_VOICE_WIDTH;
flags = WM_AUDIOIF_DEFAULT_VOICE_FLAGS;
configuredFlag = WM_AUDIO_VOICE_CONFIGURED;
}
if ( !pDeviceContext->v_pWMData ||
!(pDeviceContext->v_pWMData->audioData.flags & configuredFlag)
)
{
status = WMAudioConfigureInterface( hDevice,
audioIF,
isMaster,
format,
width,
flags
);
if ( WM_ERROR( status ) )
{
WM_TRACE( hDevice,
( "WM8753EnableStream: WMAudioConfigureInterface failed: %s",
WMStatusText( status )
)
);
goto error2;
}
WM_ASSERT( hDevice,
WMS_RETURN_TRUE == WMAudioIsInterfaceConfigured( hDevice, audioIF )
);
}
}
/*
* Update our state.
*/
if ( pDeviceContext->v_pWMData )
{
/*
* Lock our global data.
*/
if ( WMLockGlobalData( hDevice ) )
{
pDeviceContext->v_pWMData->audioData.streams |= WM_STREAM_FLAG( stream );
/*
* Let other threads in.
*/
WMUnlockGlobalData( hDevice );
}
}
/*
* We're done.
*/
return WMS_SUCCESS;
error2:
if ( pChipDef->vtable.fnDisableStream )
{
status = pChipDef->vtable.fnDisableStream( hDevice, stream );
}
error1:
WMAudioPowerDown( hDevice, powerSections );
error0:
return status;
}
/*-----------------------------------------------------------------------------
* Function: WMAudioDisableStream
*
* Called to disable the given stream.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
* stream The stream to enable
*
* Returns: WMSTATUS
* See WMStatus.h.
*---------------------------------------------------------------------------*/
WMSTATUS WMAudioDisableStream( WM_DEVICE_HANDLE hDevice,
WM_STREAM_ID ifStream
)
{
WM_DEVICE_CONTEXT *pDeviceContext = WMHANDLE_TO_DEVICE( hDevice );
WMSTATUS status;
WM_POWERFLAG powerSections;
const WM_CHIPDEF *pChipDef;
WMSTATUS enabled;
WM_AUDIO_INTERFACE audioIF;
WM_STREAM_ID stream = _WMAudioGetRealStream( hDevice, ifStream );
WM_TRACE( hDevice, ("Disabling stream %d", ifStream));
/*
* Check our stream.
*/
if ( !WMAudioIsStreamSupported( hDevice, stream ) )
{
status = WMS_UNSUPPORTED;
goto error;
}
/*
* Power down.
*/
switch ( stream )
{
case WM_STREAM_HIFI_IN:
powerSections = WM_POWER_AUDIO_HIFI_ADC;
enabled = WMAudioIsStreamEnabled( hDevice, WM_STREAM_HIFI_OUT );
if ( WMS_RETURN_FALSE == enabled )
audioIF = WM_AUDIOIF_HIFI;
else
audioIF = WM_AUDIOIF_NONE;
break;
case WM_STREAM_HIFI_OUT:
powerSections = WM_POWER_AUDIO_HIFI_DAC;
enabled = WMAudioIsStreamEnabled( hDevice, WM_STREAM_HIFI_IN );
if ( WMS_RETURN_FALSE == enabled )
audioIF = WM_AUDIOIF_HIFI;
else
audioIF = WM_AUDIOIF_NONE;
break;
case WM_STREAM_VOICE_IN:
powerSections = WM_POWER_AUDIO_ADCS;
enabled = WMAudioIsStreamEnabled( hDevice, WM_STREAM_VOICE_OUT );
if ( WMS_RETURN_FALSE == enabled )
audioIF = WM_AUDIOIF_VOICE;
else
audioIF = WM_AUDIOIF_NONE;
break;
case WM_STREAM_VOICE_OUT:
powerSections = WM_POWER_AUDIO_VOICE_DAC;
enabled = WMAudioIsStreamEnabled( hDevice, WM_STREAM_VOICE_IN );
if ( WMS_RETURN_FALSE == enabled )
audioIF = WM_AUDIOIF_VOICE;
else
audioIF = WM_AUDIOIF_NONE;
break;
case WM_STREAM_MONO_OUT:
powerSections = WM_POWER_AUDIO_MONO_DAC;
audioIF = (WM_AUDIO_INTERFACE) WM_AUDIOIF_MONO;
break;
default:
/* We checked we had a valid stream above */
WM_ASSERT( hDevice, WM_IS_VALID_STREAM( stream ) );
}
/*
* Look up our chipdef and see if we've got the function.
* If not (e.g. standard AC'97), we don't need to do anything extra.
*/
pChipDef = WMGetChipDef( hDevice );
WM_ASSERT( hDevice, pChipDef );
if ( !pChipDef )
{
status = WMS_NO_SUPPORTED_DEVICE;
goto error;
}
if ( pChipDef->vtable.fnDisableStream )
{
status = pChipDef->vtable.fnDisableStream( hDevice, stream );
if ( WM_ERROR( status ) )
{
goto error;
}
}
if ( WM_IS_I2S( hDevice ) )
{
/*
* Unconfigure the interface, if it's not still in use.
*/
if ( ( WM_AUDIOIF_NONE != audioIF ) &&
( WMS_RETURN_TRUE == WMAudioIsInterfaceConfigured( hDevice, audioIF ) )
)
{
status = WMAudioUnconfigureInterface( hDevice, audioIF );
if ( WM_ERROR( status ) )
{
WM_TRACE( hDevice,
( "WMDisableStream: WMAudioUnconfigureInterface failed: %s",
WMStatusText( status )
)
);
goto error;
}
WM_ASSERT( hDevice,
WMS_RETURN_FALSE == WMAudioIsInterfaceConfigured( hDevice, audioIF )
);
}
}
/*
* Power down.
*/
status = WMAudioPowerDown( hDevice, powerSections );
if ( WM_ERROR( status ) )
{
goto error;
}
/*
* Disable voice if necessary.
*/
if ( WM_IS_VOICE_STREAM( stream ) )
{
WMVoiceDisable( hDevice );
}
/*
* Update our state.
*/
if ( pDeviceContext->v_pWMData )
{
/*
* Lock our global data.
*/
if ( WMLockGlobalData( hDevice ) )
{
pDeviceContext->v_pWMData->audioData.streams &= ~WM_STREAM_FLAG( stream );
/*
* Let other threads in.
*/
WMUnlockGlobalData( hDevice );
}
}
/*
* We're done.
*/
return WMS_SUCCESS;
error:
return status;
}
/*-----------------------------------------------------------------------------
* Function: WMAudioIsStreamEnabled
*
* Queries whether the given stream has been enabled.
* Note: this requires global data. If there is no global data, this
* function will return WMS_UNSUPPORTED.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
* stream The stream to enable
*
* Returns: WMSTATUS
* WMS_RETURN_TRUE - stream is enabled
* WMS_RETURN_FALSE - stream is disabled
* WMS_UNSUPPORTED - no global data
*---------------------------------------------------------------------------*/
WMSTATUS WMAudioIsStreamEnabled( WM_DEVICE_HANDLE hDevice,
WM_STREAM_ID ifStream
)
{
WM_DEVICE_CONTEXT *pDeviceContext = WMHANDLE_TO_DEVICE( hDevice );
WMSTATUS status;
WM_STREAM_ID stream = _WMAudioGetRealStream( hDevice, ifStream );
if ( WMAudioIsStreamSupported( hDevice, stream ) && pDeviceContext->v_pWMData )
{
/* Make sure we don't overrun the streams field */
WM_ASSERT( hDevice, stream <
( sizeof( pDeviceContext->v_pWMData->audioData.streams ) * 8 )
);
/* Now make the check */
if ( pDeviceContext->v_pWMData->audioData.streams & WM_STREAM_FLAG( stream ) )
{
status = WMS_RETURN_TRUE;
}
else
{
status = WMS_RETURN_FALSE;
}
}
else
{
status = WMS_UNSUPPORTED;
}
return status;
}
/*-----------------------------------------------------------------------------
* Function: WMAudioSetSampleRate
*
* Called to Set the sample Rate in the audio-specific sections of the chip.
*
* Parameters:
* hDevice handle to the device (from WMOpenDevice)
* stream The stream for which to set the sample rate
* sampleRate The requested sample rate.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -