Error Using Audio Library Envelope Object

grinch

Well-known member
Hi, I am working on a project using the Teensy audio library and am running into a strange error when trying to use the envelope object:

Code:
MTG_Tomb_081122_FullHeartbeat:95: error: call of overloaded 'release(int)' is ambiguous
   env1.release(0);
                 ^
In file included from /private/var/folders/j0/_sxbhppj1b9bmytyldk9lt600000gp/T/AppTranslocation/1AE95969-E134-4286-9B52-BCFDC8FF82AD/d/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/Audio_T3_I2C/Audio.h:79:0,
                 from /Users/emmettpalaima/Desktop/ArduinoProjects/MTG_Tomb_081122_FullHeartbeat/MTG_Tomb_081122_FullHeartbeat.ino:4:
/private/var/folders/j0/_sxbhppj1b9bmytyldk9lt600000gp/T/AppTranslocation/1AE95969-E134-4286-9B52-BCFDC8FF82AD/d/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/Audio_T3_I2C/effect_envelope.h:69:7: note: candidate: void AudioEffectEnvelope::release(float)
  void release(float milliseconds) {
       ^
In file included from /private/var/folders/j0/_sxbhppj1b9bmytyldk9lt600000gp/T/AppTranslocation/1AE95969-E134-4286-9B52-BCFDC8FF82AD/d/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/Audio_T3_I2C/analyze_fft256.h:31:0,
                 from /private/var/folders/j0/_sxbhppj1b9bmytyldk9lt600000gp/T/AppTranslocation/1AE95969-E134-4286-9B52-BCFDC8FF82AD/d/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/Audio_T3_I2C/Audio.h:61,
                 from /Users/emmettpalaima/Desktop/ArduinoProjects/MTG_Tomb_081122_FullHeartbeat/MTG_Tomb_081122_FullHeartbeat.ino:4:
/private/var/folders/j0/_sxbhppj1b9bmytyldk9lt600000gp/T/AppTranslocation/1AE95969-E134-4286-9B52-BCFDC8FF82AD/d/Teensyduino.app/Contents/Java/hardware/teensy/avr/cores/teensy3/AudioStream.h:169:14: note: candidate: static void AudioStream::release(audio_block_t*)
  static void release(audio_block_t * block);
              ^
MTG_Tomb_081122_FullHeartbeat:102: error: call of overloaded 'release(int)' is ambiguous
   env2.release(0);

This is from the following piece of code. Basically just trying to set the release value with a number:

Code:
  env1.attack(atk);
  env1.hold(10);
  env1.decay(dec);
  env1.sustain(1);
  env1.release(0);
  env1.releaseNoteOn(0);

It appears that naming the function release is conflicting with the release audio block function elsewhere in the audio library, which doesn't make much sense. Any idea what is going on here and how I can get this to stop happening?
 
Hi, I am working on a project using the Teensy audio library and am running into a strange error when trying to use the envelope object:

Code:
MTG_Tomb_081122_FullHeartbeat:95: error: call of overloaded 'release(int)' is ambiguous
   env1.release(0);
                 ^
In file included from /private/var/folders/j0/_sxbhppj1b9bmytyldk9lt600000gp/T/AppTranslocation/1AE95969-E134-4286-9B52-BCFDC8FF82AD/d/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/Audio_T3_I2C/Audio.h:79:0,
                 from /Users/emmettpalaima/Desktop/ArduinoProjects/MTG_Tomb_081122_FullHeartbeat/MTG_Tomb_081122_FullHeartbeat.ino:4:
/private/var/folders/j0/_sxbhppj1b9bmytyldk9lt600000gp/T/AppTranslocation/1AE95969-E134-4286-9B52-BCFDC8FF82AD/d/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/Audio_T3_I2C/effect_envelope.h:69:7: note: candidate: void AudioEffectEnvelope::release(float)
  void release(float milliseconds) {
       ^
In file included from /private/var/folders/j0/_sxbhppj1b9bmytyldk9lt600000gp/T/AppTranslocation/1AE95969-E134-4286-9B52-BCFDC8FF82AD/d/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/Audio_T3_I2C/analyze_fft256.h:31:0,
                 from /private/var/folders/j0/_sxbhppj1b9bmytyldk9lt600000gp/T/AppTranslocation/1AE95969-E134-4286-9B52-BCFDC8FF82AD/d/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/Audio_T3_I2C/Audio.h:61,
                 from /Users/emmettpalaima/Desktop/ArduinoProjects/MTG_Tomb_081122_FullHeartbeat/MTG_Tomb_081122_FullHeartbeat.ino:4:
/private/var/folders/j0/_sxbhppj1b9bmytyldk9lt600000gp/T/AppTranslocation/1AE95969-E134-4286-9B52-BCFDC8FF82AD/d/Teensyduino.app/Contents/Java/hardware/teensy/avr/cores/teensy3/AudioStream.h:169:14: note: candidate: static void AudioStream::release(audio_block_t*)
  static void release(audio_block_t * block);
              ^
MTG_Tomb_081122_FullHeartbeat:102: error: call of overloaded 'release(int)' is ambiguous
   env2.release(0);

This is from the following piece of code. Basically just trying to set the release value with a number:

Code:
  env1.attack(atk);
  env1.hold(10);
  env1.decay(dec);
  env1.sustain(1);
  env1.release(0);
  env1.releaseNoteOn(0);

It appears that naming the function release is conflicting with the release audio block function elsewhere in the audio library, which doesn't make much sense. Any idea what is going on here and how I can get this to stop happening?
Yup ... change your calls to AudioEffectEnvelope functions to use float values for the parameters, so for example env2.release(0.0f).

You've passed an integer to the function, and as the error messages are saying, the compiler can't tell whether you meant a call to AudioStream::release(), coercing the integer 0 to a NULL pointer (which would cause mayhem, as it happens...), or AudioEffectEnvelope::release(), coercing integer 0 to float 0.0. Quite rightly, it gives up with an error, rather than making a wild guess.

[the AudioEffectEnvelope class is based on the AudioStream class, so it inherits all of its functions, and overloads the release(audio_block_t*) function with its own release(float)]
 
Wouldn’t the fact that this function is directly attached to an instance of the envelope class make it pretty obvious which one is being called? Unless audio stream is inherited by the envelope class, is that the problem?

Maybe this should be mentioned in the documentation, because right now there’s nothing that indicates this will happen or how to fix it.
 
Wouldn’t the fact that this function is directly attached to an instance of the envelope class make it pretty obvious which one is being called? Unless audio stream is inherited by the envelope class, is that the problem?

Maybe this should be mentioned in the documentation, because right now there’s nothing that indicates this will happen or how to fix it.
As noted in #2 above that's exactly the problem - AudioEffectEnvelope (and pretty much all audio library classes) inherits from AudioStream.

The documentation already specifies that AudioEffectEnvelope::release() takes a float parameter - you've just managed to hit on one of the few occasions where you can't get away with ignoring that requirement and passing an integer. And "how to fix it" can be determined by understanding the compiler error messages:
Code:
[COLOR="#FF0000"][B]MTG_Tomb_081122_FullHeartbeat:95: error: call of overloaded 'release(int)' is ambiguous
   env1.release(0);
                 ^[/B][/COLOR]
In file included from /private/var/folders/j0/_sxbhppj1b9bmytyldk9lt600000gp/T/AppTranslocation/1AE95969-E134-4286-9B52-BCFDC8FF82AD/d/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/Audio_T3_I2C/Audio.h:79:0,
                 from /Users/emmettpalaima/Desktop/ArduinoProjects/MTG_Tomb_081122_FullHeartbeat/MTG_Tomb_081122_FullHeartbeat.ino:4:
/private/var/folders/j0/_sxbhppj1b9bmytyldk9lt600000gp/T/AppTranslocation/1AE95969-E134-4286-9B52-BCFDC8FF82AD/d/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/Audio_T3_I2C/effect_envelope.h:69:7: 
[B][COLOR="#FF0000"]note: candidate: void AudioEffectEnvelope::release(float)
  void release(float milliseconds) {
       ^[/COLOR][/B]
In file included from /private/var/folders/j0/_sxbhppj1b9bmytyldk9lt600000gp/T/AppTranslocation/1AE95969-E134-4286-9B52-BCFDC8FF82AD/d/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/Audio_T3_I2C/analyze_fft256.h:31:0,
                 from /private/var/folders/j0/_sxbhppj1b9bmytyldk9lt600000gp/T/AppTranslocation/1AE95969-E134-4286-9B52-BCFDC8FF82AD/d/Teensyduino.app/Contents/Java/hardware/teensy/avr/libraries/Audio_T3_I2C/Audio.h:61,
                 from /Users/emmettpalaima/Desktop/ArduinoProjects/MTG_Tomb_081122_FullHeartbeat/MTG_Tomb_081122_FullHeartbeat.ino:4:
/private/var/folders/j0/_sxbhppj1b9bmytyldk9lt600000gp/T/AppTranslocation/1AE95969-E134-4286-9B52-BCFDC8FF82AD/d/Teensyduino.app/Contents/Java/hardware/teensy/avr/cores/teensy3/AudioStream.h:169:14: 
[COLOR="#FF0000"][B]note: candidate: static void AudioStream::release(audio_block_t*)
  static void release(audio_block_t * block);
              ^[/B][/COLOR]
MTG_Tomb_081122_FullHeartbeat:102: [COLOR="#FF0000"][B]error: call of overloaded 'release(int)' is ambiguous
   env2.release(0);[/B][/COLOR]
I've taken the liberty of doing some minor re-formatting, and highlighted the really important elements of the error report, but as a programmer you do kind of have to get used to puzzling these things out! It's admittedly not helped by the massively long path names which get in your way...

Basically the compiler is telling you release() is overloaded, so there are two "candidates" which might apply to your env1.release(0) call, and that it can't reliably tell which one you meant, so it refuses to guess. You then read this, decide you want the one that sets the envelope release time, note that it's expecting a float, and give it what it wants - env1.release(0.0f)

As it happens, there is a way of preventing this, by making a minor change to the library - I've submitted PR#442, though it may take a while to get into a formal Teensyduino release. I suspect the reasons it's not previously been reported (as far as I'm aware) are (a) people use a float for the parameter, and (b) a release time of 0 sounds terrible.
 
Back
Top