18 #include "SoundData.h"
29 virtual void update_audio_data(Frame* data, uint16_t frameCount, uint8_t volume,
bool mono_downmix,
bool is_volume_used) {
30 if (data!=
nullptr && frameCount>0 && ( mono_downmix || is_volume_used)) {
31 ESP_LOGD(
"VolumeControl",
"update_audio_data");
32 int32_t volumeFactor = get_volume_factor(volume);
33 int32_t max = get_volume_factor_max();
34 for (
int i=0;i<frameCount;i++){
35 int32_t pcmLeft = data[i].channel1;
36 int32_t pcmRight = data[i].channel2;
39 pcmRight = pcmLeft = (pcmLeft + pcmRight) / 2;
43 pcmLeft = pcmLeft * volumeFactor / max;
44 pcmRight = pcmRight * volumeFactor / max;
46 data[i].channel1 = pcmLeft;
47 data[i].channel2 = pcmRight;
53 virtual int32_t get_volume_factor(uint8_t volume) = 0;
56 virtual int32_t get_volume_factor_max() {
68 virtual int32_t get_volume_factor(uint8_t volume) {
69 constexpr
double base = 1.4;
70 constexpr
double bits = 12;
71 constexpr
double zero_ofs = pow(base, -bits);
72 constexpr
double scale = pow(2.0, bits);
73 double volumeFactorFloat = (pow(base, volume * bits / 127.0 - bits) - zero_ofs) * scale / (1.0 - zero_ofs);
74 int32_t volumeFactor = volumeFactorFloat;
75 if (volumeFactor > 0x1000) {
76 volumeFactor = 0x1000;
89 virtual int32_t get_volume_factor(uint8_t volume) {
90 double volumeFactorFloat = volume;
91 volumeFactorFloat = pow(2.0, volumeFactorFloat * 12.0 / 127.0);
92 int32_t volumeFactor = volumeFactorFloat - 1.0;
93 if (volumeFactor > 0xfff) {
108 virtual int32_t get_volume_factor(uint8_t volume) {
111 virtual int32_t get_volume_factor_max() {
123 virtual void update_audio_data(Frame* data, uint16_t frameCount, uint8_t volume,
bool mono_downmix,
bool ivolume_used) {
Default implementation for handling of the volume of the audio data.
Definition: VolumeControl.h:66
The simplest possible implementation of a VolumeControl.
Definition: VolumeControl.h:106
Keeps the audio data as is -> no volume control!
Definition: VolumeControl.h:121
Definition: VolumeControl.h:87
Abstract class for handling of the volume of the audio data.
Definition: VolumeControl.h:27