diff --git a/src/cpp/ALSA_support.cpp b/src/cpp/ALSA_support.cpp index a5bd7fe83e4d45fa90a259dec02b5768cd2a3124..ffe5ac9a3aab73f9f0a53d87503740894dd66fad 100644 --- a/src/cpp/ALSA_support.cpp +++ b/src/cpp/ALSA_support.cpp @@ -904,69 +904,69 @@ bool DSP::ALSA_object_t::get_wave_in_raw_buffer(DSP::e::SampleType &InSampleType snd_pcm_sframes_t rc; + wave_in_raw_buffer.resize(capture_buffer.size()); + for (unsigned int ind = 0; ind < pcm_buffer.size(); ind++) - { - while (pcm_buffer_size_in_frames[ind]) - { - + { + while (pcm_buffer_size_in_frames[ind]) + { rc = snd_pcm_readi(alsa_handle, pcm_buffer[ind], pcm_buffer_size_in_frames[ind]); - switch (-rc) - { - case EPIPE: + switch (-rc) + { + case EPIPE: + + #ifdef AUDIO_DEBUG_MESSAGES_ON + // EPIPE means underrun + DSP::log << "Underrun occurred" << endl; + #endif // AUDIO_DEBUG_MESSAGES_ON + snd_pcm_prepare(alsa_handle); + break; + + case EAGAIN: + + #ifdef AUDIO_DEBUG_MESSAGES_ON + DSP::log << "EAGAIN occurred. Waiting for a free buffer." << endl; + #endif // AUDIO_DEBUG_MESSAGES_ON + + DSP::f::Sleep(0); + break; + + default: + if (rc > 0) + { + pcm_buffer_size_in_frames[ind] -= rc; + pcm_buffer[ind] += rc * no_of_channels_alsa * no_of_bytes_in_channel; + #ifdef AUDIO_DEBUG_MESSAGES_ON - // EPIPE means underrun - DSP::log << "Underrun occurred" << endl; + DSP::log << "Short read. Current rc = " << rc << "." << endl; #endif // AUDIO_DEBUG_MESSAGES_ON - - snd_pcm_prepare(alsa_handle); - break; - case EAGAIN: + if (pcm_buffer_size_in_frames[ind] == 0) + { + std::swap(wave_in_raw_buffer, capture_buffer); + DSP::log << "Inbuffer is full." << endl; + return true; + } + } + + else + { #ifdef AUDIO_DEBUG_MESSAGES_ON - DSP::log << "EAGAIN occurred. Waiting for a free buffer." << endl; + // EPIPE means underrun + DSP::log << "Unsupported error." << endl; + DSP::log << "Error from readi: " << snd_strerror(rc) << endl; #endif // AUDIO_DEBUG_MESSAGES_ON - - DSP::f::Sleep(0); - break; - - default: - if (rc > 0) - { - pcm_buffer_size_in_frames[ind] -= rc; - pcm_buffer[ind] += rc * no_of_channels_alsa * no_of_bytes_in_channel; - - #ifdef AUDIO_DEBUG_MESSAGES_ON - DSP::log << "Short read. Current rc = " << rc << "." << endl; - #endif // AUDIO_DEBUG_MESSAGES_ON - - if (pcm_buffer_size_in_frames[ind] == 0) - { - std::swap(wave_in_raw_buffer, capture_buffer); - DSP::log << "Inbuffer is full." << endl; - - return true; - } - - } - - else - { - #ifdef AUDIO_DEBUG_MESSAGES_ON - // EPIPE means underrun - DSP::log << "Unsupported error." << endl; - DSP::log << "Error from readi: " << snd_strerror(rc) << endl; - #endif // AUDIO_DEBUG_MESSAGES_ON - - pcm_buffer_size_in_frames[ind] = 0; - return false; - } - break; - } + + pcm_buffer_size_in_frames[ind] = 0; + return false; + } + break; } } + } } snd_pcm_sframes_t DSP::ALSA_object_t::pcm_writei(const void *buffer, const snd_pcm_uframes_t &frames) diff --git a/src/include/ALSA_support.h b/src/include/ALSA_support.h index e7be18197b468caab367d3952f47eddc15002d0a..e06cc1e469561570fdd11d470847843da517bea8 100644 --- a/src/include/ALSA_support.h +++ b/src/include/ALSA_support.h @@ -56,7 +56,7 @@ namespace DSP { std::vector<std::vector<double>> buffers_64bit; //! inbuffer - std::vector<uint8_t> capture_buffer; + std::vector<char> capture_buffer; //! samples are integers rather than float values bool IsHigherQualityMode;