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

Thread: How to Audio Library?

  1. #1
    Member Revalogics's Avatar
    Join Date
    Dec 2016
    Location
    Philippines
    Posts
    79

    How to Audio Library?

    Hi everyone! Is there any documentation on how to make an audio library object?
    I tried looking at Audio library files and I don't understand most of it, especially how audio data is processed.
    I'd like to develop new objects, and perhaps share them with everyone.
    Annotations (comments) on audio library files would be a great help.

    I have the following in my mind: (don't know if all of them are possible)
    • Additive synthesis - create exotic waveforms
    • Amplitude-modulated oscillator with different waveforms
    • Frequency-modulated oscillator with different waveforms
    • Phase-modulated oscillator with different waveforms
    • Soundfont player - use Teensy as wavetable synth
    • Vocoder object (unlike from my previous post (hardcoded vocoder))
    • Pitch Shifter
    • Oscillators with presettable waveform using float arrays or equations?
    • etcetera...

  2. #2

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,750
    Quote Originally Posted by Revalogics View Post
    Hi everyone! Is there any documentation on how to make an audio library object?
    Yes, here:

    https://www.pjrc.com/teensy/td_libs_...ewObjects.html


    • Amplitude-modulated oscillator with different waveforms
    Maybe use the multiply effect?

    https://www.pjrc.com/teensy/gui/?inf...EffectMultiply


    • Soundfont player - use Teensy as wavetable synth
    Take a look at this:

    https://github.com/TeensyAudio/Wavetable-Synthesis


    I'm sure a lot of people would love an implementation of those other features!

  4. #4
    Member Revalogics's Avatar
    Join Date
    Dec 2016
    Location
    Philippines
    Posts
    79
    Thanks guys for the help!
    I found THIS (anything about ARM Cortex M4 DSP instructions and stuff). I think this is compatible with my Teensy 3.6.
    Also, I found "dspinst.h" inside Audio Library and it explained everything about DSP algorithms.
    I'll be studying about these and probably create my very first Audio Library object.

  5. #5
    Member Revalogics's Avatar
    Join Date
    Dec 2016
    Location
    Philippines
    Posts
    79
    Paul, What does these do? It's in the "dspinst.h" header file.

    //get Q from PSR
    get_q_psr(void)
    //clear Q BIT in PSR
    clr_q_psr(void)

  6. #6
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,750
    Quote Originally Posted by Revalogics View Post
    What does these do?
    Those access the saturation status bit, which certain ARM instructions set if their math has a saturation condition.

    To learn more about the ARM registers and instruction set, you should get Joseph Yiu's book.

    https://www.amazon.com/dp/0124080820

    This info can also be found in the ARM documentation. The main one is ARM document number DDI0403E (useful for google search). But ARM's reference material is much harder to read than Yiu's book, and lacks a lot of useful tips on how to actually make use of the features which are scattered throughout the book.

  7. #7
    Member Revalogics's Avatar
    Join Date
    Dec 2016
    Location
    Philippines
    Posts
    79
    Thanks Paul for the help, but I don't know how to buy stuffs overseas (I bought my Teensy from a local electronics store that happens to be importing stuffs from Adafruit), I'm just a student .

    BTW, I have my first working Audio Library object with me, I don't know if this will be useful for anyone, it's an Envelope Follower.
    It takes an input, extracts its envelope, and outputs the envelope. It works much like by joining AudioAnalyzePeak and AudioSynthWaveformDc together, but with decay added.
    My Vocoder object is still in progress (it uses my Envelope Follower).

  8. #8
    Member Revalogics's Avatar
    Join Date
    Dec 2016
    Location
    Philippines
    Posts
    79
    I found this HERE. It says this function returns the free memory between stack and heap.
    It does not compile for Teensy (Teensy 3.6, in my case). Any ideas how to measure free memory in Teensy? I'm suspecting some memory leaks in my Envelope Follower object, although all used and allocated audio blocks by it is properly released.
    Code:
    int freeRam () 
    {
      extern int __heap_start, *__brkval; 
      int v; 
      return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 
    }

  9. #9
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,750
    The audio library uses its own memory pool, which you allocate with AudioMemory() at the beginning of your program. If your object is leaking audio memory, it will be in this fixed pre-allocated memory, not within the normal heap as that Adafruit tutorial describes.

    You can call AudioMemoryUsage() to find out how much of the memory is currently allocated. You'll get an integer from 0 to the amount you reserved with AudioMemory(). More details here:

    https://www.pjrc.com/teensy/td_libs_...onnection.html

  10. #10
    Member Revalogics's Avatar
    Join Date
    Dec 2016
    Location
    Philippines
    Posts
    79
    Thanks Paul for the help, that makes sense to me.

    However, I noticed that AudioMemoryUsageMax() (for me) retuns 255 as maximum value. I'm using Teensyduino 1.37 and Teensy 3.6 and a sketch with a delay object where I adjust the delay time frequently. Same case happens (255 max memory) in my faulty Envelope Follower object. Even I use AudioMemory(1000) or more, I'm still fixed at most 255. Is this a bug, or is it normal?
    Last edited by Revalogics; 08-06-2017 at 04:11 PM.

  11. #11
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,750
    Quote Originally Posted by Revalogics View Post
    I'm using Teensyduino 1.37
    ...
    Is this a bug, or is it normal?
    Yes, it's a bug, and it's been fixed in version 1.40. Please update.

Posting Permissions

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