mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:17:45 +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:
parent
2feddc58bb
commit
15afc88ffe
8 changed files with 72 additions and 0 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -12,4 +12,7 @@ public:
|
|||
|
||||
virtual void handshake() override;
|
||||
void enqueue(const ABuffer&);
|
||||
|
||||
int get_main_mix_volume();
|
||||
void set_main_mix_volume(int);
|
||||
};
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue