Closed Dweaver309 closed 3 years ago
The generic method to set the volume is by multiplying the input data with a factor (between 0 and 1).
Have a look at the ConverterScaler class. This can be passed as argument to the copy method. The volume can then be controlled by calling setFactor(0.0) for mute or setFactor(1.0) to set the max volume. Tomorrow I might be able to make an example...
Thanks, I'm looking forward to seeing the example.
On Sat, Sep 18, 2021 at 12:31 PM Phil Schatzmann @.***> wrote:
Have a look at the ConverterScaler class. This can be passed as argument to the copy method. The volume can then be controlled by calling setFactor(0.0) for mute or setFactor(1.0) to set the max volume. Tomorrow I might be able to make an example...
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pschatzmann/arduino-audio-tools/issues/17#issuecomment-922343926, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD5AFHGCS6LMDHESXMQQJBTUCTEHDANCNFSM5EHTZBCA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
I am not sure I understand the example if you have time could you post an example using your file_mp3-a2dp.ino sketch. Thanks again.
Oh, I see you did not use the Stream API. But for file_mp3-a2dp.ino it is easy as well:
You just change the sketch to add
float volume = 1.0
// callback used by A2DP to provide the sound data
int32_t get_sound_data(Channels* data, int32_t len) {
// set volume
for (int j=0;j<len;j++){
data[j].channel1 = data[j].channel1 * volume;
data[j].channel2 = data[j].channel2 * volume;
}
return out == nullptr ? 0 : out->read(data, len);
}
Changing the volume is then just setting the volume variable to a value between 1.0 and 1.0
I set the volume to 0.0 and that to 1.0 using a float volume = 0.0 then float volume = 1.0. The loudness did not change. Do you think the two bluetooth devices I am using do not work with the call back?
Thanks for all the help
On Mon, Sep 20, 2021 at 1:37 PM Phil Schatzmann @.***> wrote:
Oh, I see you did not use the Stream API. But for file_mp3-a2dp.ino it is easy as well:
You just change the sketch to add
float volume = 1.0
// callback used by A2DP to provide the sound data int32_t get_sound_data(Channels data, int32_t len) { // set volume for (int j=0;j<len;j++){ data[j].channel1 = data[j].channel1 volume; data[j].channel2 = data[j].channel2 * volume; } return out == nullptr ? 0 : out->read(data, len); }
Changing the volume is then just setting the volume variable to a value between 1.0 and 1.0
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pschatzmann/arduino-audio-tools/issues/17#issuecomment-923179704, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD5AFHGQKUMNIGUXB6KSTULUC55NZANCNFSM5EHTZBCA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
I hope the following works:
volatile float volume = 1.0
// callback used by A2DP to provide the sound data
int32_t get_sound_data(Channels* data, int32_t len) {
// get data
if out == 0 return 0;
int32_t result = out->read(data, len)
// set volume
for (int j=0;j<len;j++){
data[j].channel1 = data[j].channel1 * volume;
data[j].channel2 = data[j].channel2 * volume;
}
return result;
}
Tried volatile ... Serial.print(volume) returns the correct change?
On Tue, Sep 21, 2021 at 2:09 AM Phil Schatzmann @.***> wrote:
Does it help if you use volatile float volume = 1.0 ? If not try to to check with Serial.print(volume) that the values are really updated
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pschatzmann/arduino-audio-tools/issues/17#issuecomment-923701773, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD5AFHAOWZRC5JV5PGRW2L3UDAVSLANCNFSM5EHTZBCA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
Did you use the corrected version of get_sound_data() ?
I will update all my libs now and try. Thanks
On Tue, Sep 21, 2021 at 8:53 AM Phil Schatzmann @.***> wrote:
Did you use the corrected version of get_sound_data() ?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pschatzmann/arduino-audio-tools/issues/17#issuecomment-924012233, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD5AFHBJXA4GMPWE36ILVV3UDCE5XANCNFSM5EHTZBCA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
I just updated my arduino-audio-tools lib This is my get_sound_data:
// callback used by A2DP to provide the sound data int32_t get_sound_data(Channels data, int32_t len) { // set volume for (int j = 0; j < len; j++) { data[j].channel1 = data[j].channel1 volume; data[j].channel2 = data[j].channel2 * volume; }
return out == nullptr ? 0 : out->read(data, len); }
On Tue, Sep 21, 2021 at 8:54 AM david weaver @.***> wrote:
I will update all my libs now and try. Thanks
On Tue, Sep 21, 2021 at 8:53 AM Phil Schatzmann @.***> wrote:
Did you use the corrected version of get_sound_data() ?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pschatzmann/arduino-audio-tools/issues/17#issuecomment-924012233, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD5AFHBJXA4GMPWE36ILVV3UDCE5XANCNFSM5EHTZBCA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
I just updated my arduino-audio-tools lib This is my get_sound_data: // callback used by A2DP to provide the sound data int32_t get_sound_data(Channels data, int32_t len) { // set volume for (int j = 0; j < len; j++) { data[j].channel1 = data[j].channel1 volume; data[j].channel2 = data[j].channel2 * volume; }
return out == nullptr ? 0 : out->read(data, len); }
Nop that won't work.... I suggest that you use the version from 7 hours ago
The version posted 7 hours ago works great!
Thanks for all your help
Your libs are great I am using them in my new "Jukebox" music play biased on your file_mp3-a2dp.ino sketch. Is it possible to control the volume to the Bluetooth device? If it can be done please post an example. Thanks for the great work.