open_by_longname(
snd_pcm_t * * handle,
const char * name,
- snd_pcm_stream_t stream)
+ snd_pcm_stream_t stream,
+ int mode)
{
const int length = strlen(name);
int card_index = -1;
if ( snd_card_get_longname(card_index, &longname) == 0 ) {
if ( strncmp(name, longname, length) == 0 ) {
- sprintf(device_name, "hw:%d", card_index);
- return snd_pcm_open(handle, device_name, stream, 0);
+ sprintf(device_name, "plughw:%d", card_index);
+ return snd_pcm_open(handle, device_name, stream, mode);
}
}
}
snd_pcm_t * handle = 0;
snd_pcm_hw_params_t * hw_params = 0;
- error = open_by_longname(&handle, name, stream);
+ error = open_by_longname(&handle, name, stream, mode);
if ( error < 0 ) {
error = snd_pcm_open(
&handle,
name,
stream,
- 0);
+ mode);
if ( error < 0 )
return 0;
/// Audio input "ALSA", Uses the Linux ALSA Audio API.
class AudioInALSA : public AudioInput {
private:
- static const int overlong_delay = AudioFrameSamples * 2;
+ static const int overlong_delay = AudioFrameSamples * 10;
char * const parameters;
snd_pcm_t * handle;
SND_PCM_ACCESS_RW_INTERLEAVED,
1,
SampleRate,
- AudioFrameSamples / 2,
- AudioFrameSamples);
+ AudioFrameSamples,
+ AudioFrameSamples * 2);
if ( handle == 0 )
do_throw(-ENODEV);
SND_PCM_ACCESS_RW_INTERLEAVED,
1,
SampleRate,
- AudioFrameSamples / 2,
- AudioFrameSamples);
+ AudioFrameSamples,
+ AudioFrameSamples * 2);
if ( handle == 0 )
do_throw(-ENODEV);
AudioOutALSA::write16(const std::int16_t * array, std::size_t length)
{
if ( !started ) {
- // Preload the audio output queue with one frame of silence. This makes
- // underruns less likely. This delays the output by one frame from where
- // we would otherwise have started it. Otherwise we tend to underrun
- // repeatedly at startup time.
+ // Preload the audio output queue with two frames of silence. This makes
+ // underruns less likely. This delays the output from where we would
+ // otherwise have started it. Otherwise we tend to underrun repeatedly
+ // at startup time.
//
// Note that all inputs and outputs of the typical user do not run on
// a shared clock. There is the potential for overruns or underruns
// a shared clock, and the more expensive equipment that supports it,
// to avoid this problem.
//
- int16_t buf[AudioFrameSamples];
+ int16_t buf[AudioFrameSamples * 2];
memset(buf, 0, sizeof(buf));
snd_pcm_writei(handle, buf, sizeof(buf) / sizeof(*buf));
}
return AudioFrameSamples;
error = snd_pcm_avail_delay(handle, &available, &delay);
- if ( delay > (AudioFrameSamples * 3) ) {
+ if ( delay > (AudioFrameSamples * 10) ) {
const double seconds = (double)delay / (double)SampleRate;
std::cerr << "ALSA output \"" << parameters