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

Thread: Envelope Object Stops I2S Input Sound

  1. #1
    Junior Member
    Join Date
    Dec 2020
    Location
    NYC
    Posts
    7

    Envelope Object Stops I2S Input Sound

    I'm not sure if that title makes total sense, but I also can't find the answer. I've tested the audio objects and my code a bunch of different ways back and forth and searched all over Google/Reddit/PJRC. That being said, I feel like I'm missing something very basic here.

    I am trying to take an old Yamaha Keyboard, plug it into a Teensy (I'm testing on a 3.2, but will likely upgrade to a 4.0 as I work out bugs). I like the sound of the old keyboard, so I'd like to preserve that while layering more effects on it using the teensy.

    Here is the code that "works" in the sense that I play a note on the keyboard and I hear it on my headphones.

    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    // GUItool: begin automatically generated code
    AudioInputI2S            i2s1;           //xy=63.75,106.25
    AudioMixer4              mixer1;         //xy=420.00000762939453,97.49999809265137
    AudioOutputI2S           i2s2;           //xy=877.5000076293945,112.50000190734863
    AudioConnection          patchCord1(i2s1, 0, mixer1, 0);
    AudioConnection          patchCord2(i2s1, 1, mixer1, 1);
    AudioConnection          patchCord3(mixer1, 0, i2s2, 0);
    AudioConnection          patchCord4(mixer1, 0, i2s2, 1);
    AudioControlSGTL5000     sgtl5000_1;     //xy=396.25000762939453,380.8333492279053
    // GUItool: end automatically generated code
    
    void setup() {
      Serial.begin(9600);
      AudioMemory(20);
      sgtl5000_1.enable();
      sgtl5000_1.volume(0.8);
      delay(500);
      mixer1.gain(0,1);
      mixer1.gain(1,1);
      mixer1.gain(2,0);
      mixer1.gain(3,0);
    }
    
    void loop() {
    }
    Very very basic. As soon as I introduce the envelope audio object, the sound goes away. I have tried using envelope before and after mixer1, but nothing changes. I tried adding a multiply between i2s1 and mixer1, but still nothing. Only when the envelope object is removed completely, does the sound come all the way through to the headphones. I've also tried replacing i2s1 with adc1, but that also does nothing.

    What am I missing?

    My current hunch is I need to add a noteOn() before engaging the filter, but also am not sure how to tell the teensy to listen for a signal to then start noteOn(). Likely something in the analyze list of objects, but I haven't started testing them out.

    If you have any insight, that would be super appreciated!

  2. #2
    Senior Member
    Join Date
    Apr 2020
    Location
    DFW area in Texas
    Posts
    229
    @normanras:

    Your hunch is generally correct: the envelope processing is typically initiated with a call to envelope.noteOn() & (optionally) terminated with a call to envelope.noteOff(). Does your Yamaha keyboard have a MIDI interface ?? If so, you could simply control your added envelope functionality in the chain by listening for the noteOn & noteOff messages over MIDI & making the corresponding calls to your envelope.

    Hope that helps !!

    Mark J Culross
    KD5RXT

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,965
    This is exactly what the envelope object does. It blocks all sound until you call noteOn(). Then when you call noteOff(), it fades the sound out and again blocks everything.

    Normally envelopes are used after synthesis objects which produce a continuous & steady sound. The envelope "shapes" the sound level into something like a musical note.


    My current hunch is I need to add a noteOn() before engaging the filter, but also am not sure how to tell the teensy to listen for a signal to then start noteOn(). Likely something in the analyze list of objects, but I haven't started testing them out.
    Maybe if you explain a bit more about what you're really trying to accomplish, we could recommend a way to use the envelope or other features to meet your needs. But from only this, I'm not getting a clear idea of what you're really trying to do. Difficult to recommend which way to use analysis objects without understanding the goal.

  4. #4
    Junior Member
    Join Date
    Dec 2020
    Location
    NYC
    Posts
    7
    Right, that's fair. I was trying to be as descriptive as possible without my usual novella-long descriptions. Currently, I have a Yamaha Portasound PSS-450 with an AUX out hooked into the line-in input on the Audio Shield. I want to preserve the preset sounds on the keyboard and use the teensy as an effects processor.

    I'm breaking the project into different sets of effects, so for this current leg of the project, I'd want to control ADSR+ with some pots.

    Ideally, I'd like get a wide range of effects incorporated: envelope, bit crusher, reverb and delay, wavetable, gradual, and combine. An even bigger aspiration is to include patch cables to turn off and on and layer the various effects. Which is all heavily inspired by Matt's PolyMod, however instead of the Teensy creating the waveforms and acting as a synth, I would like to have it just processing the sound.

    I've seen various projects doing an approximation of what I'd like, but they are often tutorials showing a certain effect (delay, freeverb, etc). Everything for ADSR I saw was using the Teensy as a synth, not using pumping in sounds and using the teensy to manipulate the waveform.

    I just looked through the analyze objects and am now wondering if I could use a conditional statement with <notefreq.available> or <tone.available> to trigger the envelope to enable.

    Quote Originally Posted by kd5rxt-mark View Post
    Does your Yamaha keyboard have a MIDI interface ?? If so, you could simply control your added envelope functionality in the chain by listening for the noteOn & noteOff messages over MIDI & making the corresponding calls to your envelope.
    This is very helpful, Mark, thank you! Unfortunately, no midi. I'll have to look down the road of getting the program to turn on the envelope without midi, maybe using some of the analyze objects.

  5. #5
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    23,965
    The envelope effect probably doesn't make much sense for this application. It's meant to turn a steady waveform into a note which starts & stops. But the sound you're processing already starts and stops. Even if you get the timing right, a best case scenario is you'll just attenuate or trim away some of the existing sound. Generally speaking, probably not a very satisfying effect.

    Likewise, the wavetable is about synthesis, not an effect. Probably not useful here.

    Reverb, echo (delay with mixer feedback), chorus are probably the most useful things. The new ladder filter might also be interesting with low frequency oscillators on its control inputs. There's also a spring reverb on a recent thread, which I'm going to merge this week. Tuned to the extreme range, it gives some rather unusual sound effects distinctly different from regular reverb. Maybe grab that code and give it a try.

    Oh, some of this new stuff needs a FPU which Teensy 3.2 doesn't have.

  6. #6
    Senior Member
    Join Date
    Apr 2020
    Location
    DFW area in Texas
    Posts
    229
    So, now that the simple solutions have been ruled out, how about another possibility: use an analog circuit (comparater, op-amp(s), etc.) to detect the presence of audio above some threshold, then provide that as an input to your Teensy. This would at least allow you to control the attack/hold/decay by calling envelope.noteOn() when triggered by the beginning of the note, as indicated by the analog circuit causing the input pin to transition from low-to-high.

    Mark J Culross
    KD5RXT

  7. #7
    Senior Member
    Join Date
    Jul 2020
    Posts
    901
    AudioAnalyzePeak would do a similar job without extra hardware

  8. #8
    Junior Member
    Join Date
    Dec 2020
    Location
    NYC
    Posts
    7
    Quote Originally Posted by PaulStoffregen View Post
    The new ladder filter might also be interesting with low frequency oscillators on its control inputs. There's also a spring reverb on a recent thread, which I'm going to merge this week. Tuned to the extreme range, it gives some rather unusual sound effects distinctly different from regular reverb. Maybe grab that code and give it a try.
    This is super helpful, Paul! Thank you. I'll grab those codes and give them a try. And thanks for the 3.2 heads-up; I was semi-aware this full project wouldn't work with the 3.2, it is just what I have hooked up on my testing breadboard. Looking forward to utilizing the 4.0/1 more!

    Quote Originally Posted by kd5rxt-mark View Post
    how about another possibility: use an analog circuit (comparater, op-amp(s), etc.) to detect the presence of audio above some threshold, then provide that as an input to your Teensy.
    Worth trying out! I think I have a couple op-amps laying around from other projects. Thanks for that. As to the other Mark's:
    Quote Originally Posted by MarkT View Post
    AudioAnalyzePeak would do a similar job without extra hardware
    Thank you! I plan on messing around with the analyze functions a bit more today. Although the more I thought about what Paul said about the envelope effect with this application, I suspect he's right that it may not produce very satisfying sounds. I'm going to mess around with it though and see if anything interesting happens.

Posting Permissions

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