Alsa9Buf::Alsa9Buf( hw hardware, int channels_ ) { GetSoundCardDebugInfo(); InitializeErrorHandler(); channels = channels_; samplerate = 44100; samplebits = 16; last_cursor_pos = 0; samplerate_set_explicitly = false; preferred_writeahead = 8192; preferred_chunksize = 1024; /* Open the device. */ int err; err = dsnd_pcm_open( &pcm, DeviceName(), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK ); if (err < 0) RageException::ThrowNonfatal("dsnd_pcm_open(%s): %s", DeviceName().c_str(), dsnd_strerror(err)); if( !SetHWParams() ) { CHECKPOINT; dsnd_pcm_close(pcm); CHECKPOINT; RageException::ThrowNonfatal( "SetHWParams failed" ); } SetSWParams(); }
RString Alsa9Buf::Init( int channels_, int iWriteahead, int iChunkSize, int iSampleRate ) { channels = channels_; preferred_writeahead = iWriteahead; preferred_chunksize = iChunkSize; if( iSampleRate == 0 ) samplerate = 44100; else samplerate = iSampleRate; GetSoundCardDebugInfo(); InitializeErrorHandler(); /* Open the device. */ int err; err = dsnd_pcm_open( &pcm, DeviceName(), SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK ); if( err < 0 ) return ssprintf( "dsnd_pcm_open(%s): %s", DeviceName().c_str(), dsnd_strerror(err) ); if( !SetHWParams() ) { CHECKPOINT; return "SetHWParams failed"; } SetSWParams(); LOG->Info( "ALSA: Mixing at %ihz", samplerate ); if( preferred_writeahead != writeahead ) LOG->Info( "ALSA: writeahead adjusted from %u to %u", (unsigned) preferred_writeahead, (unsigned) writeahead ); if( preferred_chunksize != chunksize ) LOG->Info( "ALSA: chunksize adjusted from %u to %u", (unsigned) preferred_chunksize, (unsigned) chunksize ); return ""; }
RString Alsa9Buf::GetHardwareID( RString name ) { InitializeErrorHandler(); if( name.empty() ) name = DeviceName(); snd_ctl_t *handle; int err; err = dsnd_ctl_open( &handle, name, 0 ); if ( err < 0 ) { LOG->Info( "Couldn't open card \"%s\" to get ID: %s", name.c_str(), dsnd_strerror(err) ); return "???"; } snd_ctl_card_info_t *info; dsnd_ctl_card_info_alloca(&info); err = dsnd_ctl_card_info( handle, info ); RString ret = dsnd_ctl_card_info_get_id( info ); dsnd_ctl_close(handle); return ret; }
void Alsa9Buf::GetSoundCardDebugInfo() { static bool done = false; if( done ) return; done = true; if( DoesFileExist("/rootfs/proc/asound/version") ) { RString sVersion; GetFileContents( "/rootfs/proc/asound/version", sVersion, true ); LOG->Info( "ALSA: %s", sVersion.c_str() ); } InitializeErrorHandler(); int card = -1; while( dsnd_card_next( &card ) >= 0 && card >= 0 ) { const RString id = ssprintf( "hw:%d", card ); snd_ctl_t *handle; int err; err = dsnd_ctl_open( &handle, id, 0 ); if ( err < 0 ) { LOG->Info( "Couldn't open card #%i (\"%s\") to probe: %s", card, id.c_str(), dsnd_strerror(err) ); continue; } snd_ctl_card_info_t *info; dsnd_ctl_card_info_alloca(&info); err = dsnd_ctl_card_info( handle, info ); if ( err < 0 ) { LOG->Info( "Couldn't get card info for card #%i (\"%s\"): %s", card, id.c_str(), dsnd_strerror(err) ); dsnd_ctl_close( handle ); continue; } int dev = -1; while ( dsnd_ctl_pcm_next_device( handle, &dev ) >= 0 && dev >= 0 ) { snd_pcm_info_t *pcminfo; dsnd_pcm_info_alloca(&pcminfo); dsnd_pcm_info_set_device(pcminfo, dev); dsnd_pcm_info_set_stream(pcminfo, SND_PCM_STREAM_PLAYBACK); err = dsnd_ctl_pcm_info(handle, pcminfo); if ( err < 0 ) { if (err != -ENOENT) LOG->Info("dsnd_ctl_pcm_info(%i) (%s) failed: %s", card, id.c_str(), dsnd_strerror(err)); continue; } LOG->Info( "ALSA Driver: %i: %s [%s], device %i: %s [%s], %i/%i subdevices avail", card, dsnd_ctl_card_info_get_name(info), dsnd_ctl_card_info_get_id(info), dev, dsnd_pcm_info_get_id(pcminfo), dsnd_pcm_info_get_name(pcminfo), dsnd_pcm_info_get_subdevices_avail(pcminfo), dsnd_pcm_info_get_subdevices_count(pcminfo) ); } dsnd_ctl_close(handle); } if( card == 0 ) LOG->Info( "No ALSA sound cards were found."); if( !PREFSMAN->m_iSoundDevice.Get().empty() ) LOG->Info( "ALSA device overridden to \"%s\"", PREFSMAN->m_iSoundDevice.Get().c_str() ); }