diff --git a/src/audio/alsalayer.cpp b/src/audio/alsalayer.cpp index a340e35aac7f01b45f6a137d7b6822fbf833e396..24827d524930b1eb40a03350e3fd1e73c91936b9 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 a36d423a1add9306396a1d98d6784d3c5f6806ad..8f7bdbc426cad80a84849eb8d90bc74c5e9f7f6e 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 c2e02d21bf8253eda251228ca152ef2535594e86..45fb6edbae5810fec4c1b66935583532857327cf 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); }