📄 audsolaris.cpp
字号:
else
{
retCode = RA_AOE_DEVNOTOPEN;
}
m_wLastError = retCode;
return m_wLastError;
}
HX_RESULT CAudioOutSolaris::_OpenMixer()
{
HX_RESULT retCode = RA_AOE_NOERR;
if(!m_bMixerPresent)
{
//Let user override default device with environ variable.
char *pszOverrideName = getenv( "MIXER" ); /* Flawfinder: ignore */
char szDevCtlName[MAX_DEV_NAME]; /* Flawfinder: ignore */
if (pszOverrideName && strlen(pszOverrideName)>0 )
{
SafeStrCpy( szDevCtlName , pszOverrideName, MAX_DEV_NAME );
}
else
{
SafeStrCpy( szDevCtlName, "/dev/audioctl", MAX_DEV_NAME); // default for volume
}
m_nMixerID = ::open( szDevCtlName, O_RDWR );
if (m_nMixerID > 0)
{
m_bMixerPresent = 1;
_Imp_GetVolume();
}
else
{
m_nMixerID = NO_FILE_DESCRIPTOR;
m_bMixerPresent = 0;
}
}
m_wLastError = retCode;
return m_wLastError;
}
HX_RESULT CAudioOutSolaris::_CloseMixer()
{
HX_RESULT retCode = RA_AOE_NOERR;
if( m_nMixerID >= 0 )
{
::close( m_nMixerID );
m_nMixerID = NO_FILE_DESCRIPTOR;
}
m_wLastError = retCode;
return m_wLastError;
}
//Device specific method to reset device and return it to a state that it
//can accept new sample rates, num channels, etc.
HX_RESULT CAudioOutSolaris::_Reset()
{
HX_RESULT retCode = RA_AOE_NOERR;
if ( m_nDevID < 0 )
{
retCode = RA_AOE_DEVNOTOPEN;
}
else if( ::ioctl(m_nDevID, I_FLUSH, FLUSHW) == -1 )
{
retCode = RA_AOE_GENERAL;
}
//Now, m_ulTotalWritten is going to go to Zero in CAudioOutUNIX.
//So, we must reset the EOF marker.
audio_info stAudioInfo;
AUDIO_INITINFO( &stAudioInfo );
//Fill in the structure with current settings.
if (::ioctl(m_nDevID, AUDIO_GETINFO, &stAudioInfo) < 0)
{
#ifdef _DEBUG
fprintf( stderr, "CAudioOutSolaris: Just trying to reset EOF in _Reset.\n");
#endif
}
//Just change the gain setting. Must map incoming [0,100]-->[0,255]
stAudioInfo.play.eof = 0;
stAudioInfo.play.samples = 0;
//Now store the new settings.
if( ::ioctl(m_nMixerID, AUDIO_SETINFO, &stAudioInfo)<0 )
{
#ifdef _DEBUG
fprintf( stderr, "CAudioOutSolaris: just trying to reset EOF\n");
#endif
}
m_wLastError = retCode;
return m_wLastError;
}
//Device specific method to get/set the devices current volume.
UINT16 CAudioOutSolaris::_GetVolume() const
{
UINT16 unVolume = 0;
audio_info stAudioInfo;
if (::ioctl( m_nMixerID, AUDIO_GETINFO, &stAudioInfo) < 0)
{
//What to do here? Should we close the mixer and pretend
//we don't have one anymore?
unVolume = m_uCurVolume;
}
else
{
//Map device specific volume levels to [0,100].
unVolume = (UINT16) (((float)(stAudioInfo.play.gain-AUDIO_MIN_GAIN))*100.0 / (float)(AUDIO_MAX_GAIN-AUDIO_MIN_GAIN) + 0.5);
}
return unVolume;
}
HX_RESULT CAudioOutSolaris::_SetVolume(UINT16 unVolume)
{
HX_RESULT retCode = RA_AOE_NOERR;
audio_info stAudioInfo;
//Fill in the structure with current settings.
if (::ioctl(m_nMixerID, AUDIO_GETINFO, &stAudioInfo) < 0)
{
#ifdef _DEBUG
fprintf( stderr, "CAudioOutSolaris: Can't get the audio configuration\n");
#endif
retCode = RA_AOE_NOTSUPPORTED;
}
//Just change the gain setting. Must map incoming [0,100]-->[0,255]
stAudioInfo.play.gain = (UINT16)((float)unVolume/100.0 *(float)(AUDIO_MAX_GAIN-AUDIO_MIN_GAIN) + AUDIO_MIN_GAIN + 0.5);
//Now store the new settings.
if( ::ioctl(m_nMixerID, AUDIO_SETINFO, &stAudioInfo)<0 )
{
#ifdef _DEBUG
fprintf( stderr, "CAudioOutSolaris: Can't set the audio configuration.\n");
#endif
retCode = RA_AOE_NOTSUPPORTED;
}
m_wLastError = retCode;
return m_wLastError;
}
//Device specific method to drain a device. This should play the remaining
//bytes in the devices buffer and then return.
HX_RESULT CAudioOutSolaris::_Drain()
{
HX_RESULT retCode = RA_AOE_NOERR;
if ( m_nDevID < 0 )
{
retCode = RA_AOE_DEVNOTOPEN;
}
//XXXgfw We don't use _Drain anywhere right now. The problem
//XXXgfw is that drain will block the proc until the buffers
//XXXgfw are all drained. We don't want that. Just let it
//XXXgfw play.
// else if( ::ioctl (m_nDevID, AUDIO_DRAIN, 0) == -1 )
// {
// retCode = RA_AOE_GENERAL;
// }
m_wLastError = retCode;
return m_wLastError;
}
UINT64 CAudioOutSolaris::_GetBytesActualyPlayed(void) const
{
UINT64 ulTheAnswer = 0;
audio_info stAudioInfo;
//Fill in the structure with current settings.
AUDIO_INITINFO( &stAudioInfo );
if (::ioctl(m_nDevID, AUDIO_GETINFO, &stAudioInfo) < 0)
{
#ifdef _DEBUG
fprintf( stderr, "CAudioOutSolaris::_GetBytesActualyPlayed: Failure.\n");
#endif
HX_ASSERT( "_GetBytesActualyPlayed: Error reading audio device"==NULL );
ulTheAnswer = 0;
}
if( stAudioInfo.play.error )
{
//Underflow has occured.
HX_ASSERT( "_GetBytesActualyPlayed: underflow in audio device"==NULL);
}
//We *always* right full blocks to the device. Well, in the
//case of solaris, we don't use the rewind mechinism of CAudioOutUNIX
//so this is true.
ulTheAnswer = stAudioInfo.play.eof*m_wBlockSize/m_nBlockDivisions;
//XXXgfw It would be so cool of we could count on the samples field.
// ulTheAnswer = (ULONG32)stAudioInfo.play.samples*m_unNumChannels*m_uSampFrameSize;
// fprintf( stderr, "m_ulTotalWritten: %lu Bytesplayed:%lu eof: %d samples: %d \n",
// m_ulTotalWritten, ulTheAnswer, stAudioInfo.play.eof, stAudioInfo.play.samples );
return ulTheAnswer;
}
HX_RESULT CAudioOutSolaris::_GetRoomOnDevice(ULONG32& ulBytes) const
{
HX_RESULT retCode = RA_AOE_NOERR;
ulBytes = m_ulDeviceBufferSize-(m_ulTotalWritten-_GetBytesActualyPlayed());
m_wLastError = retCode;
return m_wLastError;
}
HX_RESULT CAudioOutSolaris::_CheckFormat( const HXAudioFormat* pFormat )
{
m_wLastError = RA_AOE_NOERR;
return m_wLastError;
}
HX_RESULT CAudioOutSolaris::_CheckSampleRate( ULONG32 ulSampleRate )
{
m_wLastError = RA_AOE_NOERR;
//XXXgfw For now, just assume that it is supported.
return m_wLastError;
}
HX_RESULT CAudioOutSolaris::_Pause()
{
audio_info_t stAudioInfo;
m_wLastError = HXR_OK;
AUDIO_INITINFO(&stAudioInfo);
stAudioInfo.play.pause = 1;
if( ::ioctl(m_nDevID, AUDIO_SETINFO, &stAudioInfo) < 0 )
{
m_wLastError = RA_AOE_NOTSUPPORTED;
}
return m_wLastError;
}
HX_RESULT CAudioOutSolaris::_Resume()
{
audio_info_t stAudioInfo;
m_wLastError = HXR_OK;
AUDIO_INITINFO(&stAudioInfo);
stAudioInfo.play.pause = 0;
if( ::ioctl(m_nDevID, AUDIO_SETINFO, &stAudioInfo) < 0 )
{
m_wLastError = RA_AOE_NOTSUPPORTED;
}
return m_wLastError;
}
BOOL CAudioOutSolaris::_IsSelectable() const
{
return FALSE;
}
BOOL CAudioOutSolaris::_HardwarePauseSupported() const
{
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -