From d8aebd601f70d207cb0fb5436b411fcf6a5161d6 Mon Sep 17 00:00:00 2001 From: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> Date: Mon, 2 Feb 2009 13:23:35 -0500 Subject: [PATCH] Restore mic adjust volume on ALSA layer --- src/audio/alsalayer.cpp | 21 +++++++++++++++++++++ src/audio/alsalayer.h | 6 +++++- src/audio/pulselayer.cpp | 1 - 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/audio/alsalayer.cpp b/src/audio/alsalayer.cpp index a340e35aac..24827d5249 100644 --- a/src/audio/alsalayer.cpp +++ b/src/audio/alsalayer.cpp @@ -143,6 +143,7 @@ AlsaLayer::getMic(void *buffer, int toCopy) if( _CaptureHandle ) { res = read( buffer, toCopy ); + adjustVolume( buffer , toCopy , SFL_PCM_CAPTURE ); } return res ; } @@ -651,3 +652,23 @@ void AlsaLayer::audioCallback (void) //_debug("AL: Nb sample: %d char, [0]=%f [1]=%f [2]=%f\n", toPut, in[0], in[1], in[2]); //_micRingBuffer.Put(in, toPut, micVolume); } + + +void* AlsaLayer::adjustVolume( void* buffer , int len, int stream ) +{ + int vol, i, size; + SFLDataFormat *src = NULL; + + (stream == SFL_PCM_PLAYBACK)? vol = _manager->getSpkrVolume() : vol = _manager->getMicVolume(); + + src = (SFLDataFormat*) buffer; + + if( vol != 100 ) + { + size = len / sizeof(SFLDataFormat); + for( i = 0 ; i < size ; i++ ){ + src[i] = src[i] * vol / 100 ; + } + } + return src ; +} diff --git a/src/audio/alsalayer.h b/src/audio/alsalayer.h index a36d423a1a..8f7bdbc426 100644 --- a/src/audio/alsalayer.h +++ b/src/audio/alsalayer.h @@ -220,6 +220,8 @@ class AlsaLayer : public AudioLayer { */ int read( void* buffer, int toCopy); + + /** * Recover from XRUN state for capture * ALSA Library API @@ -232,7 +234,9 @@ class AlsaLayer : public AudioLayer { */ void handle_xrun_playback( void ); - /** + void* adjustVolume( void* buffer , int len, int stream ); + +/** * Handles to manipulate playback stream * ALSA Library API */ diff --git a/src/audio/pulselayer.cpp b/src/audio/pulselayer.cpp index c2e02d21bf..45fb6edbae 100644 --- a/src/audio/pulselayer.cpp +++ b/src/audio/pulselayer.cpp @@ -142,7 +142,6 @@ PulseLayer::createStreams( pa_context* c ) record = new AudioStream(c, CAPTURE_STREAM, CAPTURE_STREAM_NAME , _manager->getMicVolume()); pa_stream_set_read_callback( record->pulseStream() , audioCallback, this); //pa_stream_set_underflow_callback( record->pulseStream() , underflow , this); - //cache = new AudioStream(c, UPLOAD_STREAM, "Cache samples", _manager->getSpkrVolume()); pa_threaded_mainloop_signal(m , 0); } -- GitLab