From d7394a5c57def97aeffaf39eaa42025a5a1e9be9 Mon Sep 17 00:00:00 2001 From: Chris Greening Date: Fri, 18 Oct 2024 22:34:04 +0100 Subject: [PATCH] Enabled volume control for PDM and PWM --- player/src/AudioOutput/PDMTimerOuput.cpp | 4 +++- player/src/AudioOutput/PWMTimerOuput.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/player/src/AudioOutput/PDMTimerOuput.cpp b/player/src/AudioOutput/PDMTimerOuput.cpp index 84d6a1b..699aec4 100644 --- a/player/src/AudioOutput/PDMTimerOuput.cpp +++ b/player/src/AudioOutput/PDMTimerOuput.cpp @@ -96,7 +96,9 @@ void PDMTimerOutput::write(int8_t *samples, int count) // make sure there's enough room for the samples mSecondBuffer = (int8_t *)realloc(mSecondBuffer, count); // copy them into the second buffer - memcpy(mSecondBuffer, samples, count); + for(int i = 0; i < count; i++) { + mSecondBuffer[i] = samples[i] * mVolume / 10; + } // second buffer is now full of samples mSecondBufferLength = count; // unlock the mutext and return diff --git a/player/src/AudioOutput/PWMTimerOuput.cpp b/player/src/AudioOutput/PWMTimerOuput.cpp index f1ebf3b..9bec4b7 100644 --- a/player/src/AudioOutput/PWMTimerOuput.cpp +++ b/player/src/AudioOutput/PWMTimerOuput.cpp @@ -80,7 +80,9 @@ void PWMTimerOutput::write(int8_t *samples, int count) // make sure there's enough room for the samples mSecondBuffer = (int8_t *)realloc(mSecondBuffer, count); // copy them into the second buffer - memcpy(mSecondBuffer, samples, count); + for(int i = 0; i < count; i++) { + mSecondBuffer[i] = samples[i] * mVolume / 10; + } // second buffer is now full of samples mSecondBufferLength = count; // unlock the mutext and return