31 bool is_volume_used =
false;
32 bool mono_downmix =
false;
34 int32_t volumeFactorMax;
38 volumeFactorMax = 0x1000;
41 virtual void update_audio_data(Frame* data, uint16_t frameCount) {
42 if (data!=
nullptr && frameCount>0 && ( mono_downmix || is_volume_used)) {
43 ESP_LOGD(
"VolumeControl",
"update_audio_data");
44 for (
int i=0;i<frameCount;i++){
45 int32_t pcmLeft = data[i].channel1;
46 int32_t pcmRight = data[i].channel2;
49 pcmRight = pcmLeft = (pcmLeft + pcmRight) / 2;
53 pcmLeft = pcmLeft * volumeFactor / volumeFactorMax;
54 pcmRight = pcmRight * volumeFactor / volumeFactorMax;
56 data[i].channel1 = pcmLeft;
57 data[i].channel2 = pcmRight;
63 int32_t get_volume_factor() {
68 int32_t get_volume_factor_max() {
69 return volumeFactorMax;
72 void set_enabled(
bool enabled) {
73 is_volume_used = enabled;
76 void set_mono_downmix(
bool enabled) {
77 mono_downmix = enabled;
80 virtual void set_volume(uint8_t volume) = 0;
90 virtual void set_volume(uint8_t volume)
override {
91 constexpr double base = 1.4;
92 constexpr double bits = 12;
93 constexpr double zero_ofs = pow(base, -bits);
94 constexpr double scale = pow(2.0, bits);
95 double volumeFactorFloat = (pow(base, volume * bits / 127.0 - bits) - zero_ofs) * scale / (1.0 - zero_ofs);
96 volumeFactor = volumeFactorFloat;
97 if (volumeFactor > 0x1000) {
98 volumeFactor = 0x1000;
108 virtual void set_volume(uint8_t volume)
override {
109 double volumeFactorFloat = volume;
110 volumeFactorFloat = pow(2.0, volumeFactorFloat * 12.0 / 127.0);
111 int32_t volumeFactor = volumeFactorFloat - 1.0;
112 if (volumeFactor > 0xfff) {
113 volumeFactor = 0xfff;
126 volumeFactorMax = 128;
129 virtual void set_volume(uint8_t volume)
override {
130 volumeFactor = volume;
141 virtual void update_audio_data(Frame* data, uint16_t frameCount)
override {
143 virtual void set_volume(uint8_t volume)
override {
Default implementation for handling of the volume of the audio data.
Definition: A2DPVolumeControl.h:88
The simplest possible implementation of a VolumeControl.
Definition: A2DPVolumeControl.h:123
Keeps the audio data as is -> no volume control!
Definition: A2DPVolumeControl.h:139
Exponentional volume control.
Definition: A2DPVolumeControl.h:107
Abstract class for handling of the volume of the audio data.
Definition: A2DPVolumeControl.h:28