📄 wmaudiosignals.c
字号:
* signal The signal to check.
*
* Returns: WM_BOOL
* TRUE - Left and Right gains are the different
* FALSE - Left and Right gains are the same
*---------------------------------------------------------------------------*/
WM_BOOL WMAudioIsSignalPanned( WM_DEVICE_HANDLE hDevice,
WM_AUDIO_SIGNAL signal
)
{
WMSTATUS status;
WM_BOOL retval = TRUE;
int gainLeft = 0;
int gainRight = 0;
status = WMAudioGetSignalVolumeAdv( hDevice,
signal,
&gainLeft,
WM_CHANNEL_LEFT
);
if ( WM_ERROR( status ) )
{
WM_ASSERT( hDevice, status );
goto done;
}
status = WMAudioGetSignalVolumeAdv( hDevice,
signal,
&gainRight,
WM_CHANNEL_RIGHT
);
if ( WM_ERROR( status ) )
{
WM_ASSERT( hDevice, status );
goto done;
}
if ( gainLeft == gainRight )
return FALSE;
done:
/*
* If there is an error reading the volumes
* assume that they are different and return
* TRUE.
*/
return retval;
}
/*-----------------------------------------------------------------------------
* Function: WMAudioIsSignalMono
*
* Check to see if the signal is supported and is a mono signal.
* Note this does not tell you that the signal is stereo - it might not be
* supported.
*
* Parameters:
* hDevice The handle to the device (from WMOpenDevice).
* signal The signal to check.
*
* Returns: WM_BOOL
* TRUE - signal is mono
* FALSE - signal is stereo or not supported
*---------------------------------------------------------------------------*/
WM_BOOL WMAudioIsSignalMono( WM_DEVICE_HANDLE hDevice,
WM_AUDIO_SIGNAL signal
)
{
WMSTATUS status;
WM_AUDIO_CHANNELS channels;
status = WMAudioGetSignalChannels( hDevice, signal, &channels );
if ( WM_SUCCESS( status ) )
{
if ( channels & WM_CHANNEL_MONO )
return TRUE;
}
return FALSE;
}
/*-----------------------------------------------------------------------------
* Function: WMAudioGetSignalChannels
*
* Returns the channels which this signal supports.
*
* Parameters:
* hDevice The handle to the device (from WMOpenDevice).
* signal The signal to check.
* pChannels Receives the channels.
*
* Returns: WMSTATUS
* WMS_SUCCESS - Succeeded.
* WMS_UNSUPPORTED - Signal not supported on this device.
* WMS_NO_SUPPORTED_DEVICE - Device support not present.
*---------------------------------------------------------------------------*/
WMSTATUS WMAudioGetSignalChannels( WM_DEVICE_HANDLE hDevice,
WM_AUDIO_SIGNAL signal,
WM_AUDIO_CHANNELS *pChannels
)
{
const WM_SIGNAL_DETAILS *pSignalDetails = NULL;
const WM_CHIPDEF *pChipDef;
WM_AUDIO_CHANNELS channels = 0;
WMSTATUS status;
unsigned int nSignal;
WM_BOOL found = FALSE;
/*
* Look up our chipdef.
*/
pChipDef = WMGetChipDef( hDevice );
if ( !pChipDef )
{
status = WMS_NO_SUPPORTED_DEVICE;
goto error;
}
/*
* Run through the signals, looking for ones which match. If we get
* both left and right, we've got a stereo signal.
*/
for ( nSignal = 0; nSignal < pChipDef->signalCount; nSignal++ )
{
pSignalDetails = &pChipDef->pSignalDetails[ nSignal ];
if ( pSignalDetails->signal == signal )
{
/* It matches. Remember the channel. */
channels |= ( pSignalDetails->flags & WM_SIG_CHANNEL_MASK );
found = TRUE;
}
}
if ( !found )
{
status = WMS_UNSUPPORTED;
goto error;
}
/*
* Success - return the channels we found.
*/
*pChannels = channels;
return WMS_SUCCESS;
error:
return status;
}
/*-----------------------------------------------------------------------------
* Function: WMAudioMuteSignal
*
* Called to mute or unmute the signal to all paths.
*
* Note: This function will set and clear all the mute bits for the signal.
* If WM_OUTPUT_GAIN_RAMP is defined as TRUE in WMConfig.h, it will
* also ramp the gain up from minimum to the current signals
* last known volume to prevent any pops or clicks on unmuting.
*
* Parameters:
* hDevice The handle to the device (from WMOpenDevice).
* signal The signal to mute.
* mute Mute if TRUE, unmute if FALSE.
*
* Returns: WMSTATUS
* See WMStatus.h.
*---------------------------------------------------------------------------*/
WMSTATUS WMAudioMuteSignal( WM_DEVICE_HANDLE hDevice,
WM_AUDIO_SIGNAL signal,
WM_BOOL mute
)
{
const WM_SIGNAL_DETAILS *pSignalDetails = NULL;
const WM_CHIPDEF *pChipDef;
WMSTATUS status = WMS_UNSUPPORTED;
unsigned int nSignal;
WM_REGTYPE reg = WM_REG_INVALID;
WM_REGVAL regval = 0;
WM_REGVAL update = 0;
WM_REGVAL mask = 0;
/*
* Look up our chipdef.
*/
pChipDef = WMGetChipDef( hDevice );
if ( !pChipDef )
{
status = WMS_NO_SUPPORTED_DEVICE;
goto error;
}
/*
* Run through the signals, looking for ones which match. Apply the
* mute to each. We have several scenarios here:
*
* - single field (one entry)
* - multiple fields in the same register (e.g. AC'97)
* - multiple fields in multiple registers (e.g. WM8753)
*/
for ( nSignal = 0; nSignal < pChipDef->signalCount; nSignal++ )
{
pSignalDetails = &pChipDef->pSignalDetails[ nSignal ];
if ( pSignalDetails->signal == signal &&
WM_REG_INVALID != pSignalDetails->muteReg
)
{
/*
* It matches. Do some checks.
*/
if ( !mute && pSignalDetails->flags & WM_SIG_VOLUME_MUTE )
{
/*
* This signal is muted by setting the volume value to a special
* value. This means we've lost the information about what the
* volume used to be, so the only way to unmute is to set the
* volume to a non-muted value.
*/
WM_TRACE( hDevice, (
"WMAudioMuteSignal: signal %s has a zero mute - to unmute set new volume",
WMSignalName( signal )
));
status = WMS_UNSUPPORTED;
goto error;
}
/*
* Check whether we need to setup for a new register.
*/
if ( pSignalDetails->muteReg != reg )
{
if ( WM_REG_INVALID != reg )
{
/*
* If we're adding to a previous signal, but it's a different
* register, write the previous one.
*/
status = WMSetField( hDevice, reg, regval, mask );
if ( WM_ERROR( status ) )
{
goto error;
}
}
/* Now initialise our working variables */
reg = pSignalDetails->muteReg;
regval = 0;
mask = 0;
if ( pSignalDetails->flags & WM_SIG_HAS_UPDATE )
{
update = pSignalDetails->special;
}
}
/* Now add this mute */
if ( mute )
regval |= pSignalDetails->mute;
mask |= pSignalDetails->muteMask;
/* Check whether we've got a "both" bit we can use */
if ( pSignalDetails->flags & WM_SIG_HAS_BOTH )
{
regval |= pSignalDetails->special;
mask |= pSignalDetails->special;
break;
}
}
}
/* Did we find it? */
if ( WM_REG_INVALID == reg )
{
status = WMS_UNSUPPORTED;
goto error;
}
#if WM_OUTPUT_GAIN_RAMP
/*
* If we are muting then we need to ramp the gain down to the signals
* minimum gain.
* If we are unmuting check that we have initalised the global output
* gain value. If we haven't, initalise it to the current gain value.
*/
if ( mute )
{
status = private_StepSignalVolume( hDevice, signal, FALSE );
if ( WM_ERROR( status ) && ( WMS_UNSUPPORTED != status ) )
{
goto error;
}
}
else
{
if ( ( WM_SIGNAL_IS_OUTPUT( signal ) ) &&
( ! ( private_IsOutputGainInitialised( hDevice, signal ) ) )
)
{
/*
* Get and save the current gain in the global registers.
*/
status = private_GetCurrentOutputGain( hDevice, signal );
if ( WM_ERROR( status ) )
{
goto error;
}
/*
* Set the gain to its minimum value before we
* unmute the signal.
*/
status = private_SetSignalVolumeMin( hDevice, signal );
if ( WM_ERROR( status ) )
{
goto error;
}
}
}
#endif /* WM_OUTPUT_GAIN_RAMP */
/* Now do our final write, setting the update bit if we have one */
if ( update )
{
regval |= update;
mask |= update;
}
/*
* And do the write.
*/
status = WMSetField( hDevice, reg, regval, mask );
if ( WM_ERROR( status ) )
{
goto error;
}
#if WM_OUTPUT_GAIN_RAMP
/*
* Now step the signal back up to it's original volume,
* if we are unmuting.
*/
if ( !mute )
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -