Inconsistency/confusion about when setNotifyAudioChange() is needed #925
-
Hi, arduino-audio-tools/src/AudioTools/VolumeStream.h Lines 54 to 59 in af3e2c5 For example, for EncodedAudioStream you have to manually call AudioStream::setNotifyAudioChange(), as p_notify is not set in its constructors: arduino-audio-tools/src/AudioCodecs/AudioEncoded.h Lines 421 to 425 in af3e2c5 And VolumeStream does NOT automatically change p_notify when you change its output using setTarget(): arduino-audio-tools/src/AudioTools/VolumeStream.h Lines 67 to 70 in af3e2c5 Is there a reason for this? And another question: // setup I2S based on sampling rate provided by decoder
dec.setNotifyAudioChange(i2s);
dec.begin();
// set initial volume
volume.begin(config); // we need to provide the bits_per_sample and channels
volume.setVolume(0.3); I think that this would be better, because then both I2S and VolumeStream would get notified about any changes: // setup VolumeStream based on sampling rate provided by decoder
dec.setNotifyAudioChange(volume);
dec.begin();
//VolumeStream will automatically notify I2S about any changes to the AudioConfig Or is that not needed because the VolumeStream doesn't care about sampling rate and in this example the bits per sample and channels will never change? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
Actually as far as I can see the API seems to be quite consistent for both the VolumeStream and EncodedAudioStream. If you give an AudioStream or AudioPrint in the constructor it gets automatically notified and you do not need to call setNotifyAudioChange(). I have corrected the example by removing the setNotifyAudioChange. ps. I rarely had the case when the sampling rate or the channels or the bits per sample were changing and it is good practice to set things up to the correct expected values. |
Beta Was this translation helpful? Give feedback.
-
Maybe when this was written, this functionality was not in place, and it never got updated. I did not have this in place in the beginning and just later found that it would make sense to do this automatically. You might also still find other examples where setNotifyAudioChange() is still called. |
Beta Was this translation helpful? Give feedback.
-
You are right. The notification flow got broken in the example. However the most likely thing to change is the sampling rate and the VolumeStream does not care about this... |
Beta Was this translation helpful? Give feedback.
Maybe when this was written, this functionality was not in place, and it never got updated. I did not have this in place in the beginning and just later found that it would make sense to do this automatically. You might also still find other examples where setNotifyAudioChange() is still called.