I'm In Need of Help with Audio Crossfades (Teensy 4.0 Audio Shield Rev D)

Status
Not open for further replies.

isaacjacobson

Well-known member
I'm In Need of Help with Audio Crossfades (Teensy 4.0 with Audio Shield Rev D)

So I'm working on a project that would cue wav files (from SD card). I'm pretty stuck in figuring out how to even begin to accomplish this, so I don't have any source code to offer yet. Here's an explanation of my project:

  • When a wav file is first cued, it would fade in from silence. (ie. fade in "1.wav")
  • While that wav file is playing, if a new wav file is cued, it would then crossfade from the wav file that is currently playing to the next. (ie. crossfade from "1.wav" to "14.wav").
  • Then, if a new wav file is cued, it would again cross fade from the wav file that is currently playing to the next (ie. crossfade from "14.wav" to "50.wav").
  • Etc..
  • If the stop button is pressed, it will fade out whatever file is currently playing and stop it. (ie. fade out "50.wav" and stop).

Because my project would have 50+ wav files that could be cued and crossfaded, I'm having a very difficult time figuring out how to accomplish this without creating 50+ 'playSdWav' & 'fade' objects in the Audio System Design Tool.

Is there another way? Could anyone offer some advice as to how I can efficiently accomplish my goal for this project without needing to create a plethora of 'playSdWav' & 'fade' objects?

Thanks so much for your time!
 
The AudioEffectEnvelope object can be used to fade in/out the playsdwav. In its simplest, you just play a wav. If you want to switch to another one, you stop the first, wait for it to stop playing (which will fade it using the release setting of the object), then start the new one which will fade it in (using the attack setting).
If you want to fade one out at the same time as fading in another one, you'd need two playsdwav objects and alternate between them.

Pete
 
Hmm, so is the crossfading started by a user pressing a button or something? What should happen if the user presses the button too rapidly for the crossfading to complete on whatever is currently playing?
 
The AudioEffectEnvelope object can be used to fade in/out the playsdwav. In its simplest, you just play a wav. If you want to switch to another one, you stop the first, wait for it to stop playing (which will fade it using the release setting of the object), then start the new one which will fade it in (using the attack setting).
If you want to fade one out at the same time as fading in another one, you'd need two playsdwav objects and alternate between them.

Pete

Yes! Using the envelope object is a genius idea! In my application, the tracks will always fade in and fade out – so that's perfect.
I figured that was the case regarding needing multiple playSdWav objects... That's a good idea to just alternate between two of them.

Hmm, so is the crossfading started by a user pressing a button or something? What should happen if the user presses the button too rapidly for the crossfading to complete on whatever is currently playing?

The user would cue tracks via a button. That's a good thought there on the case of the button being pushed too rapidly. I suppose a delay or something could be set in place to prevent that. Thanks for thinking of that.




This is my first time posting on this forum. I'm amazed how quickly I got help on this. Thanks! This gets me to a good starting point, but other ideas and input is still welcome!
 
Status
Not open for further replies.
Back
Top