diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2014-03-09 16:07:01 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2014-03-09 16:07:01 +0100 |
commit | 9f0159f2327b29dda47735fd69aaf5ce2da20d91 (patch) | |
tree | 6eebe0cd2862dc502b501c07fda5e2127890b6f8 /src/AlsaInput.cpp | |
parent | 8e34d9a78752f3a7d8d49adbb219f51da4b2702e (diff) | |
download | ODR-AudioEnc-9f0159f2327b29dda47735fd69aaf5ce2da20d91.tar.gz ODR-AudioEnc-9f0159f2327b29dda47735fd69aaf5ce2da20d91.tar.bz2 ODR-AudioEnc-9f0159f2327b29dda47735fd69aaf5ce2da20d91.zip |
Split AlsaInput into two variants (Threaded/Direct)
Diffstat (limited to 'src/AlsaInput.cpp')
-rw-r--r-- | src/AlsaInput.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/AlsaInput.cpp b/src/AlsaInput.cpp index 8b6f790..14f4524 100644 --- a/src/AlsaInput.cpp +++ b/src/AlsaInput.cpp @@ -101,7 +101,7 @@ int AlsaInput::prepare() return 0; } -size_t AlsaInput::read(uint8_t* buf, snd_pcm_uframes_t length) +size_t AlsaInput::m_read(uint8_t* buf, snd_pcm_uframes_t length) { int i; int err; @@ -121,19 +121,30 @@ size_t AlsaInput::read(uint8_t* buf, snd_pcm_uframes_t length) return err; } -void AlsaInput::start() +void AlsaInputThreaded::start() { m_running = true; - m_thread = boost::thread(&AlsaInput::process, this); + m_thread = boost::thread(&AlsaInputThreaded::process, this); } -void AlsaInput::process() +void AlsaInputThreaded::process() { uint8_t samplebuf[NUM_SAMPLES_PER_CALL * BYTES_PER_SAMPLE * m_channels]; while (m_running) { - size_t n = read(samplebuf, NUM_SAMPLES_PER_CALL); + size_t n = m_read(samplebuf, NUM_SAMPLES_PER_CALL); m_queue.push(samplebuf, BYTES_PER_SAMPLE*m_channels*n); } } + +size_t AlsaInputDirect::read(uint8_t* buf, size_t length) +{ + int bytes_per_frame = m_channels * BYTES_PER_SAMPLE; + assert(length % bytes_per_frame == 0); + + size_t read = m_read(buf, length / bytes_per_frame); + + return read * bytes_per_frame; +} + |