Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

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

  1. #1

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

    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!

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,528
    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

  3. #3
    Senior Member
    Join Date
    Feb 2015
    Posts
    217
    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?

  4. #4
    Quote Originally Posted by el_supremo View Post
    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.

    Quote Originally Posted by wcalvert View Post
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •