From 2cfba1ff56314ccb7caffa56316a18bcf19c7fce Mon Sep 17 00:00:00 2001 From: clangen Date: Thu, 9 Jun 2016 01:01:47 -0700 Subject: [PATCH] Added volume support; ALSA doesn't seem to support this natively so we do it in software. --- src/contrib/alsaout/AlsaOut.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/contrib/alsaout/AlsaOut.cpp b/src/contrib/alsaout/AlsaOut.cpp index 1f5ead2a0..70b950f64 100755 --- a/src/contrib/alsaout/AlsaOut.cpp +++ b/src/contrib/alsaout/AlsaOut.cpp @@ -188,7 +188,8 @@ void AlsaOut::Resume() { } void AlsaOut::SetVolume(double volume) { - + LOCK("set volume"); + this->volume = volume; } void AlsaOut::WriteLoop() { @@ -219,6 +220,17 @@ void AlsaOut::WriteLoop() { if (next) { size_t samples = next->buffer->Samples(); + size_t channels = next->buffer->Channels(); + + float volume = (float) this->volume; + + /* software volume; alsa doesn't support this internally. this is about + as terrible as an algorithm can be -- it's just a linear ramp. */ + float *buffer = next->buffer->BufferPointer(); + for (size_t i = 0; i < samples * channels; i++) { + (*buffer) *= volume; + ++buffer; + } err = snd_pcm_writei( this->pcmHandle,