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

Thread: Printing a wave amplitude to the code.

  1. #1

    Printing a wave amplitude to the code.

    Is it possible to print the amplitude of a wave (from the audio library) to the code as a value?
    I don't want to waste pins on it
    I just want to add LFO and Envelope pitch Cotrol capability to my AudioLibrary synthesizer and I don't how to program a wave or an envelope from scratch

    Thanks a head

  2. #2
    Senior Member
    Join Date
    Nov 2013
    Posts
    719
    Quote Originally Posted by alonstudi@ View Post
    Is it possible to print the amplitude of a wave (from the audio library) to the code as a value?
    Yes: http://www.pjrc.com/teensy/gui/?info=AudioAnalyzePeak (Not what you meant?)

    Quote Originally Posted by alonstudi@ View Post
    I just want to add LFO and Envelope pitch Cotrol capability to my AudioLibrary synthesizer and I don't how to program a wave or an envelope from scratch
    As far as a wave goes - Sine: http://www.pjrc.com/teensy/gui/?info...thWaveformSine or other shapes http://www.pjrc.com/teensy/gui/?info=AudioSynthWaveform

    Regarding envelopes and pitch shifting, and staying in the theme I seem to have followed for this post, these have properties within a bulls roar of what you want but are not actually the animal(s) you describe: http://www.pjrc.com/teensy/gui/?info...mSineModulated and http://www.pjrc.com/teensy/gui/?info...EffectEnvelope - I point these out because finding and reading the source code to them may help you make a start in (near enough) the right direction. ( https://github.com/PaulStoffregen/Audio )

  3. #3
    Quote Originally Posted by robsoles View Post
    Yes: http://www.pjrc.com/teensy/gui/?info=AudioAnalyzePeak (Not what you meant?)

    As far as a wave goes - Sine: http://www.pjrc.com/teensy/gui/?info...thWaveformSine or other shapes http://www.pjrc.com/teensy/gui/?info=AudioSynthWaveform

    Regarding envelopes and pitch shifting, and staying in the theme I seem to have followed for this post, these have properties within a bulls roar of what you want but are not actually the animal(s) you describe: http://www.pjrc.com/teensy/gui/?info...mSineModulated and http://www.pjrc.com/teensy/gui/?info...EffectEnvelope - I point these out because finding and reading the source code to them may help you make a start in (near enough) the right direction. ( https://github.com/PaulStoffregen/Audio )
    Hey, I think the best options for me is to do so-
    For the LFO- send the waveform object to a PWM object, and attach a diode (to have a feedback on the LFO state on the panel) and connect the other side of the LED to an analog pin to read the value and than map it to the wanted scales and multiply it by the wanted object frequency
    Might work?

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,849
    I don't understand what you're trying to accomplish, so the best I can do is some very generic advice.

    Every waveform synthesis object can be a LFO. They all support very low frequencies, so there aren't objects for only LFO signals.

    There's a dedicated envelope object, meant for applying short-duration attack-hold-decay-sustain-release envelopes (signal level change) to any signal. It's very efficient, so if you just want to shape signals on the time scale of common envelopes used for musical notes, use this.

    For longer durations or very special applications, you can use the multiplier object. Feed the signal you want to modify into one input, and a waveform from 0 to 1.0 as the other input. There's a DC level object, which actually implement gradual linear ramps between DC levels. You can use that to create the other signal, like a slow ramp. Or you can use a mixer to add it to an oscillator or other signal, if you want a strange envelope. You can also use the mixer if you just want to amplify or attenuate a signal (just like using a real analog mixer with gain knobs).

    Currently the library has only the peak object for measuring the amplitude of a signal. But if the signals are something you're synthesizing, why would you need to measure it? You should already know its amplitude, since it's entirely the product of synthesis objects you're controlling.

    Eventually the library needs to get more analysis objects for RMS and probably 300 ms average/volume numbers. These are meant for making projects that react and respond to live audio input signals. You could of course use them to measure signals you're creating, but they will simply tell you things you already should know, since you control the amplitude of synthesized signals.

    But maybe there's some subtle point I've missed. You asked for specific technical things without explaining why you need them or what you're ultimately trying to accomplish, so it's hard to give an answer better than the specific technical capabilities.

  5. #5
    Quote Originally Posted by PaulStoffregen View Post
    I don't understand what you're trying to accomplish, so the best I can do is some very generic advice.

    Every waveform synthesis object can be a LFO. They all support very low frequencies, so there aren't objects for only LFO signals.

    There's a dedicated envelope object, meant for applying short-duration attack-hold-decay-sustain-release envelopes (signal level change) to any signal. It's very efficient, so if you just want to shape signals on the time scale of common envelopes used for musical notes, use this.

    For longer durations or very special applications, you can use the multiplier object. Feed the signal you want to modify into one input, and a waveform from 0 to 1.0 as the other input. There's a DC level object, which actually implement gradual linear ramps between DC levels. You can use that to create the other signal, like a slow ramp. Or you can use a mixer to add it to an oscillator or other signal, if you want a strange envelope. You can also use the mixer if you just want to amplify or attenuate a signal (just like using a real analog mixer with gain knobs).

    Currently the library has only the peak object for measuring the amplitude of a signal. But if the signals are something you're synthesizing, why would you need to measure it? You should already know its amplitude, since it's entirely the product of synthesis objects you're controlling.

    Eventually the library needs to get more analysis objects for RMS and probably 300 ms average/volume numbers. These are meant for making projects that react and respond to live audio input signals. You could of course use them to measure signals you're creating, but they will simply tell you things you already should know, since you control the amplitude of synthesized signals.

    But maybe there's some subtle point I've missed. You asked for specific technical things without explaining why you need them or what you're ultimately trying to accomplish, so it's hard to give an answer better than the specific technical capabilities.
    Hey Paul, I know the WaveForm object can act as a LFO, that's what I want to measure...
    since the Waveform object does not have a modulation Input (except the FMSine), I wanted to measure the amplitude of a the LFO (waveform object I use to modulate the filter and the amplitude of my synthesizer) and multiply it by the frequency (inside the WaveForm.frequency(); object) to apply frequency modulation to my synthesizer and not only filter modulation and amplitude modulation.
    Same with the an Envelope object,

    BTW, do I need to connect a DC object to an Envelope object if I want to attach it to the filter frequency modulation input? Or by connecting it with nothing in is ok ?

    Thanks

    Oh and one more thing does the Sharp P900v chip is ok to use for midi Input?

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,849
    Oh, I see, you're trying to make the non-sine waveform frequency modulated.

    First, you need to understand the audio library works in 128 sample blocks. The non-FM waveform synth has code that's designed to create the same frequency. Even if you change the frequency, it will always use the same setting for 128 samples.

    All audio library code generates the next 128 samples all at once. The FM sine object has special FM code that varies the frequency during those 128 samples, on a sample-by-sample basis.

    Because the frequency is fixed for every 128 samples, the best you could hope to achieve on the non-FM waveforms is a new frequency every 128 samples. You can achieve that from your Arduino sketch. Just call the waveform's frequency() function every 2.9 ms. Of you can call it every 1 ms if you like... but when the audio library generates another 128 samples, it will use only the most recent setting you've given, for all 128 samples.

  7. #7
    Quote Originally Posted by PaulStoffregen View Post
    Oh, I see, you're trying to make the non-sine waveform frequency modulated.

    First, you need to understand the audio library works in 128 sample blocks. The non-FM waveform synth has code that's designed to create the same frequency. Even if you change the frequency, it will always use the same setting for 128 samples.


    All audio library code generates the next 128 samples all at once. The FM sine object has special FM code that varies the frequency during those 128 samples, on a sample-by-sample basis.

    Because the frequency is fixed for every 128 samples, the best you could hope to achieve on the non-FM waveforms is a new frequency every 128 samples. You can achieve that from your Arduino sketch. Just call the waveform's frequency() function every 2.9 ms. Of you can call it every 1 ms if you like... but when the audio library generates another 128 samples, it will use only the most recent setting you've given, for all 128 samples.
    I'm not sure what you mean,
    But Im trying to achieve a non Sine FM synth, I want to modulate the input frequency (waveform.frequency() to be modulated by the amplitude of the LFO waveform

    But I'll write my point of thinking on how I thought it will work

    1.measure the amplitude of the LFO
    2.multiply it by the frequency mentioned in the function waveform.frequency();
    3. Add it to the frequency inside the function waveform.frequency();

    Example:
    1st- let's say the frequency mentioned is waveform.frequency(440.000);.
    2nd- let's say that in that hypotatic point of time the LFO waveform.amplitude(); value is 0.38 (a made up number for the example).

    1. The measured amplitude is 0.38.
    2. Multiplied by the frequency of the oscillator (440.00*0.38) = most updated added frequency (167.2).
    3. Waveform.frequency(440.000); is now waveform.frequency(440.000+most current added freq); (waveform.frequency(567.2).
    Last edited by alonstudi@; 07-27-2015 at 04:36 PM.

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,849
    Quote Originally Posted by alonstudi@ View Post
    But Im trying to achieve a non Sine FM synth, I want to modulate the input frequency (waveform.frequency() to be modulated by the amplitude of the LFO waveform
    Well, that's exactly what the AudioSynthWaveformSineModulated object does. It synthesizes a sine wave, where the amplitude of another waveform changes the frequency.

    Click image for larger version. 

Name:	sine.png 
Views:	107 
Size:	7.6 KB 
ID:	4796

    Just create a waveform object to act as your LFO, and connect its output to the input of the FM sine object.

  9. #9
    Quote Originally Posted by PaulStoffregen View Post
    Well, that's exactly what the AudioSynthWaveformSineModulated object does. It synthesizes a sine wave, where the amplitude of another waveform changes the frequency.

    Click image for larger version. 

Name:	sine.png 
Views:	107 
Size:	7.6 KB 
ID:	4796




    Just create a waveform object to act as your LFO, and connect its output to the input of the FM sine object.
    We'll, I would like it to be another kind of wave form.
    So I think Ill do as we'll:

    For the LFO- send the waveform object to a PWM object, and attach a LED (to have a feedback on the LFO state on the panel) and connect the other side of the LED to an analog pin to read the value and than map it to the wanted scales and multiply it by the wanted object frequency (or any other of my synthesizer parameters).

    Would it work? How many PWM output modules can I use?

  10. #10
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,849
    Quote Originally Posted by alonstudi@ View Post
    Would it work?
    Well, if "connect the other side of the LED to an analog pin to read the value" means you're going to use a LED as a diode in the signal path, then I'd say the odds are slim it'll work in any useful way. Even regular diodes are problematic, due to their forward voltage drop. LEDs have far greater forward voltage, and some have terribly slow specs like reverse recovery time, which would probably cause all sorts of other trouble.

    An analog circuit which tracks the envelope of a signal would normally use a opamp-based precision rectifier circuit driving a high quality capacitor (eg, a NP0 or plastic film type), plus either a resistor to drain the capacitor slowly, or a switch to reset the measurement.

    Of course, you're probably looking to track the envelope of the LFO, not the actual PWM waveform, so before you can even try to feed it into a diode+capacitor circuit to capture the signal's envelope, you'll need to low pass filter the PWM to get the LFO waveform. If you look at the waveforms on the PWM page, you can see the trade-offs in speed versus the smoothness of the filtered output. Obviously any saw-tooth like ripple left on the signal is going to play havoc with the results from a diode-based envelope follower circuit.

    If you over come all these analog circuit design issues, a diode-based signal amplitude circuit is essentially a peak detector, which is the same as the audio library's peak detect, except with analog noise and distortion added. Presumably you wish to go to all this extra effort for some reason... which I don't understand, but whatever you're hoping to accomplish, you'll need to design your analog circuit to do.


    How many PWM output modules can I use?
    Teensy 3.1 has 12 PWM pins. If you're controlling them with analogWrite, you could use all 12. If you're using the audio shield, 3 of those 12 pins are required to communicate with the SGTL5000 chip, leaving 9 available. If you're using the SD card portion, one more of those pins is needed to control the SD card.

    If you use the audio library to automatically send the signal to PWM, only a single signal is supported.

  11. #11
    Quote Originally Posted by PaulStoffregen View Post
    Well, if "connect the other side of the LED to an analog pin to read the value" means you're going to use a LED as a diode in the signal path, then I'd say the odds are slim it'll work in any useful way. Even regular diodes are problematic, due to their forward voltage drop. LEDs have far greater forward voltage, and some have terribly slow specs like reverse recovery time, which would probably cause all sorts of other trouble.

    An analog circuit which tracks the envelope of a signal would normally use a opamp-based precision rectifier circuit driving a high quality capacitor (eg, a NP0 or plastic film type), plus either a resistor to drain the capacitor slowly, or a switch to reset the measurement.

    Of course, you're probably looking to track the envelope of the LFO, not the actual PWM waveform, so before you can even try to feed it into a diode+capacitor circuit to capture the signal's envelope, you'll need to low pass filter the PWM to get the LFO waveform. If you look at the waveforms on the PWM page, you can see the trade-offs in speed versus the smoothness of the filtered output. Obviously any saw-tooth like ripple left on the signal is going to play havoc with the results from a diode-based envelope follower circuit.

    If you over come all these analog circuit design issues, a diode-based signal amplitude circuit is essentially a peak detector, which is the same as the audio library's peak detect, except with analog noise and distortion added. Presumably you wish to go to all this extra effort for some reason... which I don't understand, but whatever you're hoping to accomplish, you'll need to design your analog circuit to do.




    Teensy 3.1 has 12 PWM pins. If you're controlling them with analogWrite, you could use all 12. If you're using the audio shield, 3 of those 12 pins are required to communicate with the SGTL5000 chip, leaving 9 available. If you're using the SD card portion, one more of those pins is needed to control the SD card.

    If you use the audio library to automatically send the signal to PWM, only a single signal is supported.
    another point of thinking:
    would the one of the next objects would work to print the amplitude to the sketch?
    1. analyze- print.
    2 analyze - tone.

    and can I use the P900V chip to midi read ?

  12. #12
    Senior Member
    Join Date
    Nov 2013
    Posts
    719
    OK, what do you mean by amplitude? Or, if you mean amplitude for real then what scale do you want it in?

    Actually, a better question might be: What do you mean by "print the amplitude to the sketch"? Because that is the bit which makes the absolute least sense I guess.

    Edit: I take this tack because AudioAnalyzePrint will print sample values to monitor where an external process could find peak amplitude per period, AudioAnalyzeTone cannot be used to determine amplitude and the first thing I pointed out is the object (in the library) which can tell you the Amplitude of the signal at any given time: AudioAnalyzePeak - it gives the result in the scale of 'power of this system' (pretty sure this terminology isn't too far off technically correct) and that scale is convert-able to any scale which is defined well enough to determine the appropriate formula (or values for ratio to determine dBm or dBu).
    Last edited by robsoles; 07-28-2015 at 11:09 PM.

  13. #13
    Member
    Join Date
    Aug 2016
    Location
    Santiago, Chile
    Posts
    22
    Quote Originally Posted by PaulStoffregen View Post
    Oh, I see, you're trying to make the non-sine waveform frequency modulated.

    Because the frequency is fixed for every 128 samples, the best you could hope to achieve on the non-FM waveforms is a new frequency every 128 samples. You can achieve that from your Arduino sketch. Just call the waveform's frequency() function every 2.9 ms. Of you can call it every 1 ms if you like... but when the audio library generates another 128 samples, it will use only the most recent setting you've given, for all 128 samples.
    Paul, even if it's not that accurate, is it possible to do this? i'm just trying to build a simple LFO(to pitch) for a waveform osc. I just don't know where to start i would really appreciate some help.
    Thanks

  14. #14
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,889
    Maybe try wavetable-synthesis?

  15. #15
    Member
    Join Date
    Aug 2016
    Location
    Santiago, Chile
    Posts
    22
    Quote Originally Posted by Frank B View Post
    Maybe try wavetable-synthesis?
    So, i need to generate a wavetable of a sine or square ...put it into an array ...and then?
    Where do i get the values for these wavetables? can i just download this data from other examples?
    And also, after i have the wavetable , how do i connect the oscillator freq to the lfo?
    Many questions

  16. #16
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,889
    Uh..i'm sure, google can explain that far better than me.. and in better English
    Well, if you have such a simple waveform like square or sine, you can generate it yourself (or, the teensy .. )

    For sine, you don't even need a wavetable - just use the sine-object. It has a function to set the frequency.

    For working with wavetables.. hm, ask the internet.. or perhaps an other user can explain it (i've still problems with english)

    Over the last few weeks, there were several questions re: wavetable. Might be the time to develop such an object for the library.. (argh-... i have way too much projects at the moment..)


    https://en.wikipedia.org/wiki/Wavetable_synthesis
    Last edited by Frank B; 10-30-2016 at 08:13 PM.

  17. #17
    Member
    Join Date
    Jun 2016
    Location
    rural West Virginia
    Posts
    62
    BTW, do I need to connect a DC object to an Envelope object if I want to attach it to the filter frequency modulation input? Or by connecting it with nothing in is ok ?
    Yes. DC object set to an amplitude of 1 goes into envelope, then envelope goes into filter frequency mod in. I also have a mixer object between the envelope and the filter so control the sweep range. Other inputs for the mixer are a sine object (the LFO) and an A/D (Analog read pin) for a pedal (zero to 3 volts).

    If you are looking to frequency modulate a waveform object read this thread. I have this working in my synth. Maybe it updates every 2.9 mS as Paul states, but it works OK with reasonable sine LFO rates and a pitch bend wheel. Haven't tried odd waveform LFO's yet. I am essentially running my entire bank of VCO's (17 of them) as modulated objects all driven from A/D pins mapped as 1V/oct inputs. I switched to a T3.6 because a 3.2 couldn't keep up with 17 VCO's and a bunch of other stuff like reading 49 pots and 4 rotary encoders. No unusual sounds noted when playing live from a keyboard.....MIDI mapping still being developed.

    https://forum.pjrc.com/threads/32917...(Audiolibrary)

  18. #18
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,849
    Quote Originally Posted by Frank B View Post
    Over the last few weeks, there were several questions re: wavetable. Might be the time to develop such an object for the library.. (argh-... i have way too much projects at the moment..)

    https://en.wikipedia.org/wiki/Wavetable_synthesis
    There's a student project at a local university (here in Portland, Oregon) that will taking on this project.

Posting Permissions

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