diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-07-29 19:06:58 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-07-29 19:06:58 +0200 |
commit | 15afc88ffefa5b9641107834c87b8674c7fa3fa9 (patch) | |
tree | 776ccd065e303ed831231568ccca4df4556a6b42 /Libraries | |
parent | 2feddc58bbecd8da5cfb175082cc3dd1b72ef455 (diff) | |
download | serenity-15afc88ffefa5b9641107834c87b8674c7fa3fa9.zip |
AudioServer: Add a "main mix volume" and a simple program to get/set it
Give the mixer a main volume value (percent) that we scale all the
outgoing samples by (before clipping.)
Also add a simple "avol" program for querying and setting the volume:
- "avol" prints the current volume.
- "avol 200" sets the main mix volume to 200%
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibAudio/ABuffer.h | 7 | ||||
-rw-r--r-- | Libraries/LibAudio/AClientConnection.cpp | 16 | ||||
-rw-r--r-- | Libraries/LibAudio/AClientConnection.h | 3 | ||||
-rw-r--r-- | Libraries/LibAudio/ASAPI.h | 6 |
4 files changed, 32 insertions, 0 deletions
diff --git a/Libraries/LibAudio/ABuffer.h b/Libraries/LibAudio/ABuffer.h index a8a7d2a580..287c0a738f 100644 --- a/Libraries/LibAudio/ABuffer.h +++ b/Libraries/LibAudio/ABuffer.h @@ -39,6 +39,13 @@ struct ASample { right = -1; } + void scale(int percent) + { + float pct = (float)percent / 100.0; + left *= pct; + right *= pct; + } + ASample& operator+=(const ASample& other) { left += other.left; diff --git a/Libraries/LibAudio/AClientConnection.cpp b/Libraries/LibAudio/AClientConnection.cpp index d77a455c51..bc0eecaa7f 100644 --- a/Libraries/LibAudio/AClientConnection.cpp +++ b/Libraries/LibAudio/AClientConnection.cpp @@ -30,3 +30,19 @@ void AClientConnection::enqueue(const ABuffer& buffer) sleep(1); } } + +int AClientConnection::get_main_mix_volume() +{ + ASAPI_ClientMessage request; + request.type = ASAPI_ClientMessage::Type::GetMainMixVolume; + auto response = sync_request(request, ASAPI_ServerMessage::Type::DidGetMainMixVolume); + return response.value; +} + +void AClientConnection::set_main_mix_volume(int volume) +{ + ASAPI_ClientMessage request; + request.type = ASAPI_ClientMessage::Type::SetMainMixVolume; + request.value = volume; + sync_request(request, ASAPI_ServerMessage::Type::DidSetMainMixVolume); +} diff --git a/Libraries/LibAudio/AClientConnection.h b/Libraries/LibAudio/AClientConnection.h index 1a6c00abac..7f7047b99c 100644 --- a/Libraries/LibAudio/AClientConnection.h +++ b/Libraries/LibAudio/AClientConnection.h @@ -12,4 +12,7 @@ public: virtual void handshake() override; void enqueue(const ABuffer&); + + int get_main_mix_volume(); + void set_main_mix_volume(int); }; diff --git a/Libraries/LibAudio/ASAPI.h b/Libraries/LibAudio/ASAPI.h index 47da165de6..2915360ff3 100644 --- a/Libraries/LibAudio/ASAPI.h +++ b/Libraries/LibAudio/ASAPI.h @@ -7,11 +7,14 @@ struct ASAPI_ServerMessage { PlayingBuffer, FinishedPlayingBuffer, EnqueueBufferResponse, + DidGetMainMixVolume, + DidSetMainMixVolume, }; Type type { Type::Invalid }; unsigned extra_size { 0 }; bool success { true }; + int value { 0 }; union { struct { @@ -29,10 +32,13 @@ struct ASAPI_ClientMessage { Invalid, Greeting, EnqueueBuffer, + GetMainMixVolume, + SetMainMixVolume, }; Type type { Type::Invalid }; unsigned extra_size { 0 }; + int value { 0 }; union { struct { |