From c4fd8fc35553fa3dc716a05428f9fe8923219366 Mon Sep 17 00:00:00 2001 From: bruceperens Date: Thu, 20 Mar 2014 00:02:51 +0000 Subject: [PATCH] More tuning so that more devices work correctly. git-svn-id: https://svn.code.sf.net/p/freetel/code@1457 01035d8c-6547-0410-b346-abe4f91aad63 --- freedv-server/source/platform/linux/alsa.cpp | 11 ++++++----- .../source/platform/linux/audio_in_alsa.cpp | 6 +++--- .../source/platform/linux/audio_out_alsa.cpp | 16 ++++++++-------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/freedv-server/source/platform/linux/alsa.cpp b/freedv-server/source/platform/linux/alsa.cpp index dc910654..8dd56e1a 100644 --- a/freedv-server/source/platform/linux/alsa.cpp +++ b/freedv-server/source/platform/linux/alsa.cpp @@ -85,7 +85,8 @@ namespace FreeDV { 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; @@ -100,8 +101,8 @@ namespace FreeDV { 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); } } } @@ -148,13 +149,13 @@ namespace FreeDV { 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; diff --git a/freedv-server/source/platform/linux/audio_in_alsa.cpp b/freedv-server/source/platform/linux/audio_in_alsa.cpp index ab43998b..26d7fad9 100644 --- a/freedv-server/source/platform/linux/audio_in_alsa.cpp +++ b/freedv-server/source/platform/linux/audio_in_alsa.cpp @@ -14,7 +14,7 @@ namespace FreeDV { /// 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; @@ -66,8 +66,8 @@ namespace FreeDV { SND_PCM_ACCESS_RW_INTERLEAVED, 1, SampleRate, - AudioFrameSamples / 2, - AudioFrameSamples); + AudioFrameSamples, + AudioFrameSamples * 2); if ( handle == 0 ) do_throw(-ENODEV); diff --git a/freedv-server/source/platform/linux/audio_out_alsa.cpp b/freedv-server/source/platform/linux/audio_out_alsa.cpp index d9e30c35..556ca6b9 100644 --- a/freedv-server/source/platform/linux/audio_out_alsa.cpp +++ b/freedv-server/source/platform/linux/audio_out_alsa.cpp @@ -66,8 +66,8 @@ namespace FreeDV { SND_PCM_ACCESS_RW_INTERLEAVED, 1, SampleRate, - AudioFrameSamples / 2, - AudioFrameSamples); + AudioFrameSamples, + AudioFrameSamples * 2); if ( handle == 0 ) do_throw(-ENODEV); @@ -85,10 +85,10 @@ namespace FreeDV { 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 @@ -96,7 +96,7 @@ namespace FreeDV { // 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)); } @@ -153,7 +153,7 @@ namespace FreeDV { 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 -- 2.25.1