1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:57:35 +00:00

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%
This commit is contained in:
Andreas Kling 2019-07-29 19:06:58 +02:00
parent 2feddc58bb
commit 15afc88ffe
8 changed files with 72 additions and 0 deletions

View file

@ -60,6 +60,20 @@ bool ASClientConnection::handle_message(const ASAPI_ClientMessage& message, cons
post_message(reply);
break;
}
case ASAPI_ClientMessage::Type::GetMainMixVolume: {
ASAPI_ServerMessage reply;
reply.type = ASAPI_ServerMessage::Type::DidGetMainMixVolume;
reply.value = m_mixer.main_volume();
post_message(reply);
break;
}
case ASAPI_ClientMessage::Type::SetMainMixVolume: {
ASAPI_ServerMessage reply;
reply.type = ASAPI_ServerMessage::Type::DidSetMainMixVolume;
m_mixer.set_main_volume(message.value);
post_message(reply);
break;
}
case ASAPI_ClientMessage::Type::Invalid:
default:
dbgprintf("ASClientConnection: Unexpected message ID %d\n", int(message.type));

View file

@ -71,6 +71,8 @@ void ASMixer::mix()
for (int i = 0; i < mixed_buffer_length; ++i) {
auto& mixed_sample = mixed_buffer[i];
mixed_sample.scale(m_main_volume);
mixed_sample.clip();
i16 out_sample;

View file

@ -54,11 +54,16 @@ public:
NonnullRefPtr<ASBufferQueue> create_queue(ASClientConnection&);
int main_volume() const { return m_main_volume; }
void set_main_volume(int volume) { m_main_volume = volume; }
private:
Vector<NonnullRefPtr<ASBufferQueue>> m_pending_mixing;
CFile m_device;
CLock m_lock;
int m_main_volume { 100 };
void mix();
};