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

Thread: Get the timer/timing information of the audio oscillator to trigger functions

  1. #1
    Junior Member
    Join Date
    Mar 2016
    Posts
    4

    Get the timer/timing information of the audio oscillator to trigger functions

    Hi there,

    I am relatively new to all this arduino/teensy stuff, but I enjoy it very much.
    Atm I am trying to get a sequencer up and running.
    Now first I thought the "intervaltimer" is a good candidate for all the counting, after I realized I need a ramp (reverse sawtooth) parallel running at the same speed and phase to the "intervaltimer". So I searched a little bit and found the audio library. Which to my luck has oscillators which can function as Lfo.
    Now the question I couldn't find in my searches. Is it possible to get the timing information of the audio oscillator to trigger other functions. Then the audio oscillator would be the master and I could do the counting stuff (which right now does the "intervaltimer") from that.
    I tried to run a function triggered by the intervaltimer at the same time with the same speed as the audio oscillator but they were not In sync.

    I hope this makes sense.

    Thanks for any help and insight.
    Christoph.

  2. #2
    Senior Member blackketter's Avatar
    Join Date
    May 2015
    Location
    San Francisco
    Posts
    318
    This is a good question. It's not clear to me how to access the timebase for the Audio subsystem. I don't think it's in sync with the clock provided by millis()/micros(), but I could be wrong. Seems like it should be possible to ask the output device how many samples it's generated and work from there.

  3. #3
    Junior Member
    Join Date
    Mar 2016
    Posts
    4
    Hi. The project did make a little pause but this problem is still on my list and I am not able to find a solution. Counting samples looks promising but I just donít know how to do it.
    Thanks christoph

  4. #4
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    7,976
    Depends on your goals.
    Normally, there is no reason to use a timer.
    All audio is buffered, and working on the samples normally should be done with the record-and play queue, or with a own, new effect/whatever by using the internal audio blocks.

    So.. so far no reason for a timer..or to access the output-timers .. but we don't know what you're trying to do.

  5. #5
    Junior Member
    Join Date
    Mar 2016
    Posts
    4
    Hi thanks for the reply.
    for example: get an output (Led) running (blinking) at the same speed as the waveform.frequency (dutycycle). Preferred going high when the waveform crosses zero.
    Or another example would be to send Midi(clk) in sync with the frequency to an output.
    Christoph

  6. #6
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    7,976
    The LED is not easy..
    Assuming I2S output: There are hardware Fifos involved. Maybe on the receiving chip, too. I think there is no way around and you'll need to modify the I2S code.

    What do want to do with the LED? You can not see any difference if it toggles on zero-cross or not..
    Or, Maybe using a comparator is the better way..?if it not just for a visible indicator.

    Midi is very slow. That will work with the queues. But you want the frequency - so the fft object is perfect.

  7. #7
    Senior Member
    Join Date
    Feb 2017
    Posts
    418
    I think the trouble is that the only synchronization timing available to you is the 128-sample Audio Library refresh period (~2.9 ms). The actual transmission of the individual samples through I2S, DAC, etc is handled via DMA of the 128-sample buffer. Thus, the exact instant when a specific sample (say the zero crossing) gets sent is unknowable to you.
    Last edited by gfvalvo; 03-04-2020 at 06:25 PM.

  8. #8
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    7,976
    Yeah.
    DMA and being "sample exact" just doesn't go together very well.
    But the main question is, where is this necessary? Not for LED visualization or MIDI, anyway.
    If it is really necessary, you just have to come up with something and program it yourself.

  9. #9
    i think i have an idea of what OP wants to achieve here. it's not about sample accuracy or gettingg into the low level hardware clocks, but there is a lot of use cases in audio where it would make sense to sync something as precisely as possible to lets say oscillator waves. a lot of times LFO waves are used as clock/trigger sources via simple threshold.

    one example is the low frequency oscillators that were described, where even for visualisation you wanna be as close in sync as possible, moreso for altering (syncing, shaping) the waveform. and if you start looking into oscillator sync or complex synthesis forms like fm, there's no way around knowing the zero crossings and/or phase of something. while of course most times this would be done at the synthesis stage where you actually calculate those zero crossings, it would help to have additional "trigger" outputs on some of the audio library objects. and/or a simple threshold/impulse trigger object maybe?
    i think in most (OPs ?) use cases you don't need an accurate frequency reading or anything FFT related, more like a general periodic trigger or phase information? easiest with a square wave LFO, but totallydoable with any somewhat clean periodic wave, right?

    look at the stuff that (insanely popular) modular synth CV-altering modules like maths or pamelas new workout are doing with control and/or audio signals.

    OP, another idea would be tolook at some midi libraries and midi clock generators which might make more sense in a sequencer use case anyways, later on.

  10. #10
    Senior Member
    Join Date
    Aug 2016
    Location
    Australia
    Posts
    170
    If the 2.9mS buffer rate is good enough for you as a basic heartbeat, then it is really easy to hook into one of the interrupts to create a global variable that toggles on/off, or counts.

    Just make sure you define it as volatile and make counters "long" (apologies for these hints if you have advanced C++ skills).

  11. #11
    Junior Member
    Join Date
    Mar 2016
    Posts
    4
    Quote Originally Posted by weasel View Post
    i think i have an idea of what OP wants to achieve here. it's not about sample accuracy or gettingg into the low level hardware clocks, but there is a lot of use cases in audio where it would make sense to sync something as precisely as possible to lets say oscillator waves. a lot of times LFO waves are used as clock/trigger sources via simple threshold.
    You absolutely nailed it. Thanks.
    Thatís a common procedure in the analog modular world. And itís more fun to modulate other things with saw/tri/sinewaves than pulses.

    Quote Originally Posted by weasel View Post
    while of course most times this would be done at the synthesis stage where you actually calculate those zero crossings, it would help to have additional "trigger" outputs on some of the audio library objects. and/or a simple threshold/impulse trigger object maybe?
    i think in most (OPs ?) use cases you don't need an accurate frequency reading or anything FFT related, more like a general periodic trigger or phase information? easiest with a square wave LFO, but totallydoable with any somewhat clean periodic wave, right?
    Such trigger outputs would be perfect.


    Quote Originally Posted by weasel View Post
    OP, another idea would be tolook at some midi libraries and midi clock generators which might make more sense in a sequencer use case anyways, later on.
    As stated above. The goal is to have a saw/tri/sine waveform lfo running parallel (same frequency) with the clock.

    If the 2.9mS buffer rate is good enough for you as a basic heartbeat, then it is really easy to hook into one of the interrupts to create a global variable that toggles on/off, or counts.

    Just make sure you define it as volatile and make counters "long" (apologies for these hints if you have advanced C++ skills)
    Sorry I just donít know enough about c++ to Ąhookď something up. I even donít know if the 2,9ms buffer has an effect or not. What about taking the waveform into an extern comparator and feed it back to an input which than fires an interrupt routine (ie. blinking led, counting....). What delay is to be expected? If the delay with this method is lower then the 2,9 ms I will try it that way. Unfortunately I only have an old analog oscilloscope where it hard to measure such thing precisely.

    Thanks all of you for your help. Maybe some day there will be trigger outputs...
    Christoph

  12. #12
    if you are serious about doing an audio project based on teensy boards there's no way around learning a little more c i think.

    alternatively you could look at the axoloti platform which will basically lets you lego together embedded standalone music devices with a GUI patcher much like maxmsp or puredata.
    this platform provides all the objects to make a sequencer, sync LFOs and what so not, by just clicking together a bunch of colorful cables. it's like the teensy audio design tool, just much more advanced and you don't have to look at code ever. but it still lets you hack into the low level c code at any time and place, which you could later translate to teensy projects.

    @Frank B i am sure youcame across axoloti before, another look at it might heelp you understand what OP was about. here's a website that shows an overview over the available "objects"
    http://www.privatepublic.de/public/f...bjectlist.html

    that being said. i think i just got to the misunderstanding in this thread. cj3000, for what you want to achieve you would simply have the LED cycle in the same frequency as you feed to the LFO. if you generate the signal yourself, you can use the same function to drive whatever else. to stay in a modular synth comparison which you seem to come from - you don't need to analyse the audio signal of an oscillator to get the frequency if you also have the 1V/oct CV avaliable that defines said frequency. you kind of got it backwards which again shows you should really try and learn somee more basic audio/programming/synthesis principles.
    Last edited by weasel; 03-07-2020 at 12:54 AM.

Posting Permissions

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