diff --git a/src/audio/alsalayer.cpp b/src/audio/alsalayer.cpp index c8d735969d6f4d150464402ae5b218e4ef97837c..5d7e378837b6fda5bfd1b897e17160e78b27dbfa 100644 --- a/src/audio/alsalayer.cpp +++ b/src/audio/alsalayer.cpp @@ -658,3 +658,5 @@ AlsaLayer::adjustVolume( void* buffer , int len, int stream ) } return src ; } + +void AlsaLayer::setPlaybackVolume( double volume ){} diff --git a/src/audio/alsalayer.h b/src/audio/alsalayer.h index efa612574888c58eefb60c1e54d914e2913e7391..1b31eb2f03a2c6286e56310b87327341924f3164 100644 --- a/src/audio/alsalayer.h +++ b/src/audio/alsalayer.h @@ -201,6 +201,11 @@ class AlsaLayer : public AudioLayer { */ void restorePulseAppsVolume( void ); + /** + * UNUSED in ALSA layer + */ + void setPlaybackVolume( double volume ); + private: /** diff --git a/src/audio/audiolayer.h b/src/audio/audiolayer.h index f162ff6e505ac4927e1294f7ea0dbfec0cc51ae2..6e2b70879d2aed393ac3708ff6f8b13a9ae9951a 100644 --- a/src/audio/audiolayer.h +++ b/src/audio/audiolayer.h @@ -185,6 +185,8 @@ class AudioLayer { virtual void reducePulseAppsVolume( void ) = 0; virtual void restorePulseAppsVolume( void ) = 0; + + virtual void setPlaybackVolume( double volume ) = 0; /** * Write accessor to the error state diff --git a/src/audio/audiostream.cpp b/src/audio/audiostream.cpp index a9f6e7345a2ef2e41d5f7bd0a812fb659382e340..8b88009346f75726222af3597e2cd431fae04c11 100644 --- a/src/audio/audiostream.cpp +++ b/src/audio/audiostream.cpp @@ -30,7 +30,7 @@ AudioStream::AudioStream( pa_context* context, int type, std::string desc, doubl sample_spec.channels = 1; channel_map.channels = 1; flag = PA_STREAM_AUTO_TIMING_UPDATE ; - _volume = PA_VOLUME_NORM * vol / 100 ; + pa_cvolume_set( &_volume , 1 , PA_VOLUME_MUTED ) ; // * vol / 100 ; _audiostream = createStream( context ); } @@ -87,7 +87,8 @@ AudioStream::createStream( pa_context* c ) if( _streamType == PLAYBACK_STREAM ){ pa_stream_connect_playback( s , NULL , NULL , PA_STREAM_INTERPOLATE_TIMING, - pa_cvolume_set(&cv, sample_spec.channels , _volume) , NULL ); + &_volume, NULL); + //pa_cvolume_set(&cv, sample_spec.channels , _volume) , NULL ); } else if( _streamType == CAPTURE_STREAM ){ pa_stream_connect_record( s , NULL , NULL , PA_STREAM_START_CORKED ); diff --git a/src/audio/audiostream.h b/src/audio/audiostream.h index 16bab21ec41e510f8b6267fceb8d3e6bdf87bc14..8327805e983d3ecadb1201a1954d606babe1c483 100644 --- a/src/audio/audiostream.h +++ b/src/audio/audiostream.h @@ -85,8 +85,8 @@ class AudioStream { */ std::string getStreamName( void ) { return _streamDescription; } - void setVolume( double pc ); - pa_volume_t getVolume( void ) { return _volume; } + void setVolume( double pc ) { _volume.values[0] *= pc/100; } + pa_cvolume getVolume( void ) { return _volume; } private: /** @@ -131,7 +131,7 @@ class AudioStream { */ pa_stream_flags_t flag; pa_sample_spec sample_spec ; - pa_volume_t _volume; + pa_cvolume _volume; }; diff --git a/src/audio/pulselayer.cpp b/src/audio/pulselayer.cpp index a34f1f99c57d2dd812aee3c8554abb323f3c8a3e..862d74fbaf4c17e642524f7623356542ada46fc7 100644 --- a/src/audio/pulselayer.cpp +++ b/src/audio/pulselayer.cpp @@ -420,4 +420,13 @@ PulseLayer::restoreAppVolume( int index, int channels ) pa_context_set_sink_input_volume( context, index, &volume, on_success, this) ; } +void +PulseLayer::setPlaybackVolume( double volume ) +{ + //value between 0 and 100 + AudioStream* s = getPlaybackStream(); + s->setVolume( volume ); +} + + diff --git a/src/audio/pulselayer.h b/src/audio/pulselayer.h index 17fb909007db09f26cedad1f6f566c21b1a74cce..6265351f2e8bcbdf7559421a03b64bb7dd0398ae 100644 --- a/src/audio/pulselayer.h +++ b/src/audio/pulselayer.h @@ -165,6 +165,12 @@ class PulseLayer : public AudioLayer { */ AudioStream* getRecordStream(){ return record;} + /** + * Set the speaker volume to a new value ( between 0 and 100 ) + * @param volume The new value + */ + void setPlaybackVolume( double volume ); + private: /** * Drop the pending frames and close the capture device