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

Thread: polyphonic audio sampler

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    11

    polyphonic audio sampler

    hello everyone
    I'd like to know if it is possible to do this with a teensy 3.1:
    - load wav files from the SD card and store them in RAM to access them faster
    - based on midi events received, play the wav files, more than 1 at time (more than 1 voice), using a DAC channel for each voice. So no software mixing involved.
    - the wav files would be pitch transposed according to the midi note event received, using interpolation to retain the original length.

    I would use external RAM chips to reduce latency (but maybe it's not necessary?).
    I'd like to use 16bit 44.1k wav files (mono or stereo, I don't mind), and a 16bit DAC (or codec).

    My questions are, how can I calculate the polyphony and latency I could get? Or maybe there are too many task and I should reduce bit depth/sample rate?

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,942
    The RAM isn't big enough to hold more than about half a second at full quality.

    However, you can probably play directly from the SD card. It's also possible to play from flash, but the files have to fixed when you upload. See the PlayFromSketch example.

    how can I calculate the polyphony and latency I could get?
    Use AudioProcessorUsage() to discover the worst case CPU usage as you try running more play objects concurrently. When you approach 80 to 90%, you're at the limit....

    Not all SD cards are created equal. The speed class is usually meaningless. Sandisk Ultra cards are often much better than cheap no-name ones, or the many counterfeits that claim to be Sandisk, but obviously aren't.... buyer beware.

    When you try this, please post here with your results and which cards you tried. I'm sure others will find it really helpful.

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    11
    thanks for the support
    yes indeed RAM is too little for this application, that's why I intended to use external RAM chips (pretty cheap) to store in them only the actual selected sound. But as you said, maybe the latency from quality SD cards is not bad. I should try.
    I still don't have a teensy (I'm saving money for it, I'm a student with no job :P), so I can't try right now..but now I'm only at the "requirement definition" stage.

    I assume I need to rewrite the audio library functions in order to get polyphony and pitch transposition.
    But is that doable?

    also, outputting each voice to a different DAC (or a different channel of the same DAC) would make the thing slower than mixing the voices in software? I would prefer separate outputs for each voice.

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,942
    Quote Originally Posted by Dimitree View Post
    .... why I intended to use external RAM chips (pretty cheap) to store in them only the actual selected sound.
    Unless you connect a RAM with a parallel bus, which is a lot of wires and trouble, it'll be no better than SPI bus for the SD card.

    But as you said, maybe the latency from quality SD cards is not bad. I should try.
    Yes, you should definitely try that first!

    I assume I need to rewrite the audio library functions in order to get polyphony and pitch transposition.
    But is that doable?
    You can absolutely get polyphony from the library as-is. Did you look at the PlayFromSketch example yet?

  5. #5
    Junior Member
    Join Date
    Nov 2012
    Posts
    11
    Quote Originally Posted by PaulStoffregen View Post
    You can absolutely get polyphony from the library as-is. Did you look at the PlayFromSketch example yet?
    well, not yet, since I don't have the teensy yet, as I said
    great then!

    my last question, would make problems if I use a separate DAC (or DAC channel) for each of the voices? I think I will need I2S DACs, since SPI DACs are too slow for that?

  6. #6
    Junior Member
    Join Date
    Nov 2012
    Posts
    11
    ah, I forgot to ask.. To do pitch shifting of a file I would need to read it slower or faster than normal.. Would that be possible (polyphonically over the same file) using the existing library?

  7. #7
    Senior Member
    Join Date
    Feb 2013
    Posts
    563
    Quote Originally Posted by Dimitree View Post
    ah, I forgot to ask.. To do pitch shifting of a file I would need to read it slower or faster than normal.. Would that be possible (polyphonically over the same file) using the existing library?
    i don't think. play_sd_wav.cpp only supports a few standard sample rates; you'd have to come up with a wav play/resampling class yourself. i don't know whether the teensy could pull that off polyphonically.

    also, "pitch shifting" (as in a "sampler") would be more intricate than that; if you wanted to alter the pitch w/o affecting the speed, that is.

  8. #8
    pitchshifting the hifi manner were used to these days, will not work anyway..
    but you can use this old trick:
    1) fill a circular buffer with speed x
    2) play the same buffer with speed y*x
    You will get artefacts and it will sound like a old digitech whammy pedal. If your looking for that sound, you should use this trick.
    I've used this trick on a 8 Mhz Amiga, nearly 25 years ago, worked very well!

  9. #9
    Junior Member
    Join Date
    Jan 2017
    Posts
    1
    Hello,
    This topic is almost 3yrs old but I am new here and have been searching for playable "sampler" like solution here.
    I ordered the Teensy 3.6 and the audio CODEC adapter.
    I found a similar thread here:
    https://forum.pjrc.com/threads/33551...hlight=sampler
    It refers the OP to another post related to granular synth for inspiration.

    I would like to make a sampler with a microphone, record a sound like say "ding" and play it using MIDI events at different pitch.
    I don't worry about the time stretching. Just play at different speeds.
    PaulD - your idea to "play the same buffer with speed y*x" sounds good but how do you change the playing speed.
    What method in the audio library would I use to speed up or slow down the replay would I use.
    Could polyphony be achieved in the same manner?

    Thank you,

    Mike S.

Posting Permissions

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