📄 audlinux_esound.cpp
字号:
}
return retCode;
}
//XXXgfw, since we have to open the audio device in ESD with
//all the format information (no way to change it once open)
//we will just return OK here and do the actual open in
//SetDeviceConfig() call. In this call we will just open
//our connectin to the ESD server that we use for changing
//the volume of our stream (panning).
HX_RESULT CAudioOutESound::_OpenAudio()
{
HX_RESULT retCode = RA_AOE_NOERR;
//Set the tick count to zero
m_ulTickCount = 0;
m_ulPausePosition = 0;
// create DLLAccess object
m_pESDLib = new DLLAccess();
if((DLLAccess::DLL_OK==m_pESDLib->open("libesd.so", DLLTYPE_NOT_DEFINED))||
(DLLAccess::DLL_OK==m_pESDLib->open("libesd.so.0", DLLTYPE_NOT_DEFINED)))
{
m_fpESDPlayStream = (ESDPlayStreamType)m_pESDLib->getSymbol("esd_play_stream");
if( dlerror() != NULL )
retCode = RA_AOE_DEVNOTOPEN;
m_fpESDGetAllInfo = (ESDGetAllInfoType)m_pESDLib->getSymbol("esd_get_all_info");
if( dlerror() != NULL )
retCode = RA_AOE_DEVNOTOPEN;
m_fpESDFreeAllInfo = (ESDFreeAllInfoType)m_pESDLib->getSymbol("esd_free_all_info");
if( dlerror() != NULL )
retCode = RA_AOE_DEVNOTOPEN;
m_fpESDClose = (ESDCloseType)m_pESDLib->getSymbol("esd_close");
if( dlerror() != NULL )
retCode = RA_AOE_DEVNOTOPEN;
m_fpESDSetStreamPan = (ESDSetStreamPanType)m_pESDLib->getSymbol("esd_set_stream_pan");
if( dlerror() != NULL )
retCode = RA_AOE_DEVNOTOPEN;
m_fpESDAudioFlush = (ESDAudioFlushType)m_pESDLib->getSymbol("esd_audio_flush");
if( dlerror() != NULL )
retCode = RA_AOE_DEVNOTOPEN;
m_fpESDOpenSound = (ESDOpenSoundType)m_pESDLib->getSymbol("esd_open_sound");
if( dlerror() != NULL )
retCode = RA_AOE_DEVNOTOPEN;
}
else
{
#ifdef _DEBUG
//Can't load the ESD shared lib. Tell the user.
fprintf( stderr, "The ESD library, libesd.so, could not be loaded.\n");
fprintf( stderr, "Please install ESD, disable ESD support or locate\n" );
fprintf( stderr, "the missing library.\n");
#endif
retCode = RA_AOE_DEVNOTOPEN;
}
//Open the ESD server on the localhost.
if( RA_AOE_NOERR == retCode )
{
m_nESoundServerID = m_fpESDOpenSound( NULL );
if( m_nESoundServerID == -1 )
{
#ifdef _DEBUG
fprintf( stderr, "The ESD server could not be located on localhost.\n");
fprintf( stderr, "Either disable ESD support or start the esd daemon.\n");
#endif
retCode = RA_AOE_DEVNOTOPEN;
}
}
m_wLastError = retCode;
return m_wLastError;
}
HX_RESULT CAudioOutESound::_CloseAudio()
{
HX_RESULT retCode = RA_AOE_NOERR;
if( m_nDevID >= 0 )
{
//close the esd server
m_fpESDClose( m_nESoundServerID );
m_nESoundServerID = NO_FILE_DESCRIPTOR;
//Close the esd player FD.
::close( m_nDevID );
m_nDevID = NO_FILE_DESCRIPTOR;
}
else
{
retCode = RA_AOE_DEVNOTOPEN;
}
m_ulPausePosition = 0;
m_ulTickCount = 0;
m_wLastError = retCode;
return m_wLastError;
}
HX_RESULT CAudioOutESound::_OpenMixer()
{
HX_RESULT retCode = RA_AOE_NOERR;
//ESD always has volume support.
m_bMixerPresent = 1;
_Imp_GetVolume();
m_wLastError = retCode;
return m_wLastError;
}
//Do nothing under ESD.
HX_RESULT CAudioOutESound::_CloseMixer()
{
HX_RESULT retCode = RA_AOE_NOERR;
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.
//Can't really do anything here under ESD.
HX_RESULT CAudioOutESound::_Reset()
{
HX_RESULT retCode = RA_AOE_NOERR;
if ( m_nDevID < 0 )
{
retCode = RA_AOE_DEVNOTOPEN;
}
m_ulPausePosition = 0;
m_wLastError = retCode;
return m_wLastError;
}
//Device specific method to get/set the devices current volume.
UINT16 CAudioOutESound::_GetVolume() const
{
int nRetVolume = 0;
if( m_nESoundPlayerID > 0 )
{
//We have been added to the esd server list and can report
//volume.
esd_player_info_t *pPlayer = _GetPlayerInfo();
if( NULL != pPlayer )
{
//Choose either the left or right?
nRetVolume = pPlayer->left_vol_scale;
HX_DELETE( pPlayer );
}
}
else
{
//ESD always starts out an app at 256. ESD_VOLUME_BASE.
nRetVolume = ESD_VOLUME_BASE;
}
//Map device specific volume levels to [0,100].
nRetVolume = (int) ((float)nRetVolume/256.0*100.0+0.5);
return nRetVolume;
}
HX_RESULT CAudioOutESound::_SetVolume(UINT16 unVolume)
{
HX_RESULT retCode = RA_AOE_NOERR;
//Map incoming [0..100] volume to ESD_VOLUME_BASE.
unVolume = (int)((float)unVolume/100.0 * (float)ESD_VOLUME_BASE + 0.5 );
if( m_nESoundPlayerID > 0 )
{
//We have been added to the esd server list and can set
//volumes.
m_fpESDSetStreamPan( m_nESoundServerID, m_nESoundPlayerID, unVolume, unVolume);
}
else
{
//Just do nothing here for now....
}
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 CAudioOutESound::_Drain()
{
HX_RESULT retCode = RA_AOE_NOERR;
if ( m_nDevID < 0 )
{
retCode = RA_AOE_DEVNOTOPEN;
}
m_fpESDAudioFlush();
m_wLastError = retCode;
return m_wLastError;
}
UINT64 CAudioOutESound::_GetBytesActualyPlayed(void) const
{
UINT64 ulBytes2 = 0;
if( m_ulTotalWritten > 0 )
{
ulBytes2 = ((double)((GetTickCount()-m_ulTickCount)*m_unNumChannels)/(double)1000*m_unSampleRate*m_uSampFrameSize);
ulBytes2 += m_ulPausePosition;
}
return ulBytes2;
}
//this must return the number of bytes that can be written without blocking.
//Don't use SNDCTL_DSP_GETODELAY here as it can't compute that amount
//correctly.
HX_RESULT CAudioOutESound::_GetRoomOnDevice(ULONG32& ulBytes) const
{
HX_RESULT retCode = RA_AOE_NOERR;
//XXXgfw :-( This is going to suck if they don't use threads...
ulBytes = m_wBlockSize;
// ulBytes = m_ulDeviceBufferSize-(m_ulTotalWritten-_GetBytesActualyPlayed() );
m_wLastError = retCode;
return m_wLastError;
}
HX_RESULT CAudioOutESound::_CheckFormat( const HXAudioFormat* pFormat )
{
m_wLastError = RA_AOE_NOERR;
return m_wLastError;
}
HX_RESULT CAudioOutESound::_CheckSampleRate( ULONG32 ulSampleRate )
{
//ESD supposidly converts any format to one the matches the
//installed hardware the best. ESD does the conversion for
//us. So, Just return OK.
m_wLastError = RA_AOE_NOERR;
return m_wLastError;
}
HX_RESULT CAudioOutESound::_Pause()
{
m_wLastError = HXR_OK;
m_ulPausePosition = m_ulTotalWritten;
m_ulTickCount = 0;
return m_wLastError;
}
HX_RESULT CAudioOutESound::_Resume()
{
m_wLastError = HXR_OK;
if( m_ulTotalWritten > 0 )
m_ulTickCount = GetTickCount();
return m_wLastError;
}
BOOL CAudioOutESound::_IsSelectable() const
{
return TRUE;
}
BOOL CAudioOutESound::_HardwarePauseSupported() const
{
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -