Added volume support; ALSA doesn't seem to support this natively so we do it in software.

This commit is contained in:
clangen 2016-06-09 01:01:47 -07:00
parent a94f2e26fc
commit 2cfba1ff56

View File

@ -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,