Skip to content

Commit c9b93e8

Browse files
committed
VolumeControl allow_boost bug
1 parent 6800808 commit c9b93e8

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

src/AudioTools/AudioStreams.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -943,8 +943,17 @@ class VolumeStream : public AudioStreamX {
943943
if (info.channels>max_channels){
944944
max_channels = info.channels;
945945
}
946+
947+
// usually we use a exponential volume control - except if we allow values > 1.0
948+
if (cfg.allow_boost){
949+
setVolumeControl(linear_vc);
950+
} else {
951+
setVolumeControl(pot_vc);
952+
}
953+
946954
// set start volume
947955
setVolume(cfg.volume);
956+
948957
return true;
949958
}
950959

@@ -955,7 +964,7 @@ class VolumeStream : public AudioStreamX {
955964

956965
/// Resets the volume control to use the standard logic
957966
void resetVolumeControl(){
958-
cached_volume.setVolumeControl(default_volume);
967+
cached_volume.setVolumeControl(pot_vc);
959968
}
960969

961970
/// Read raw PCM audio data, which will be the input for the volume control
@@ -1033,8 +1042,9 @@ class VolumeStream : public AudioStreamX {
10331042
Print *p_out=nullptr;
10341043
Stream *p_in=nullptr;
10351044
VolumeStreamConfig info;
1036-
SimulatedAudioPot default_volume;
1037-
CachedVolumeControl cached_volume = CachedVolumeControl(default_volume);
1045+
LinearVolumeControl linear_vc{true};
1046+
SimulatedAudioPot pot_vc;
1047+
CachedVolumeControl cached_volume{pot_vc};
10381048
float *volume_values = nullptr;
10391049
float *factor_for_channel = nullptr;
10401050
bool is_active = false;
@@ -1102,7 +1112,7 @@ class VolumeStream : public AudioStreamX {
11021112
void applyVolume16(int16_t* data, size_t size){
11031113
for (size_t j=0;j<size;j++){
11041114
float result = factorForChannel(j%info.channels) * data[j];
1105-
if (info.allow_boost){
1115+
if (!info.allow_boost){
11061116
if (result>max_value) result = max_value;
11071117
if (result<-max_value) result = -max_value;
11081118
}
@@ -1113,7 +1123,7 @@ class VolumeStream : public AudioStreamX {
11131123
void applyVolume24(int24_t* data, size_t size) {
11141124
for (size_t j=0;j<size;j++){
11151125
float result = factorForChannel(j%info.channels) * data[j];
1116-
if (info.allow_boost){
1126+
if (!info.allow_boost){
11171127
if (result>max_value) result = max_value;
11181128
if (result<-max_value) result = -max_value;
11191129
}
@@ -1125,7 +1135,7 @@ class VolumeStream : public AudioStreamX {
11251135
void applyVolume32(int32_t* data, size_t size) {
11261136
for (size_t j=0;j<size;j++){
11271137
float result = factorForChannel(j%info.channels) * data[j];
1128-
if (info.allow_boost){
1138+
if (!info.allow_boost){
11291139
if (result>max_value) result = max_value;
11301140
if (result<-max_value) result = -max_value;
11311141
}

src/AudioTools/AudioTypes.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,17 @@ struct AudioBaseInfo {
3333
bool operator!=(AudioBaseInfo alt){
3434
return !(*this == alt);
3535
}
36+
3637
void setAudioInfo(AudioBaseInfo info){
3738
sample_rate = info.sample_rate;
3839
channels = info.channels;
3940
bits_per_sample = info.bits_per_sample;
4041
}
4142

43+
void copyFrom(AudioBaseInfo info){
44+
setAudioInfo(info);
45+
}
46+
4247
AudioBaseInfo& operator= (const AudioBaseInfo& info){
4348
setAudioInfo(info);
4449
return *this;

src/AudioTools/Converter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class NumberConverter {
3737

3838
/// provides the biggest number for the indicated number of bits
3939
static int64_t maxValue(int value_bits_per_sample){
40-
switch(value_bits_per_sample/8){
40+
switch(value_bits_per_sample){
4141
case 8:
4242
return 127;
4343
case 16:

src/AudioTools/VolumeControl.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,15 @@ class SimulatedAudioPot : public VolumeControl {
142142
*/
143143
class LinearVolumeControl : public VolumeControl {
144144
public:
145+
LinearVolumeControl(bool allowBoost=false){
146+
is_limited = !allowBoost;
147+
}
145148
// provides a factor in the range of 0.0 to 1.0
146149
virtual float getVolumeFactor(float volume) {
147-
return limit(volume);
150+
return is_limited ? limit(volume) : volume;
148151
}
152+
protected:
153+
bool is_limited;
149154
};
150155

151156

0 commit comments

Comments
 (0)