mirror of
https://github.com/clangen/musikcube.git
synced 2024-11-19 11:10:52 +00:00
Added volume support; ALSA doesn't seem to support this natively so we do it in software.
This commit is contained in:
parent
a94f2e26fc
commit
2cfba1ff56
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user