PDA

View Full Version : Teensy 3.1 + Audio Board polyphony - how many is too many?



thebigone
06-10-2015, 08:54 PM
Hello all,

I am hoping to make an electric drum kit based on the Teensy 3.1 + Audio board. This is rev 2 of a project I made a few years back: http://drummaster.digitalcave.ca/drummaster/. The original version ran on an Arduino and communicated with a computer for playback. Now, I want to make it completely self contained.

The analog stuff is easy and I have plans mostly completed for all that. What I am not sure about is the abilities of the teensy.

Basically, the workflow goes like this:
1) Hit a pad
2) Peak detection circuit to hold analog value; pass this value through to the teensy's ADC via an analog MUX
3) Teensy reads value, looks for the corresponding raw audio file (or wav file, but I think raw is faster), and starts to play it.

This is all simple enough... the issues start when you have multiple sounds playing at once.

Obviously some sounds are longer than others (a ride cymbal will play for easily 10+ seconds, whereas a snare drum will be less than a second).

In the computer-based implementation, I used multiple threads to play each sound, and kept track of how many sounds were currently active. If there were more simultaneous sounds than some limit (I think it was 16, but don't remember offhand). If there were more than this number of sounds playing, I would stop the one which has been playing the longest.

Now I realize that a teensy is not as powerful as a computer, so 16 sound polyphony is probably not feasible. However, how many samples *can* I expect to play back concurrently, when streaming off an SD card? (Assume for the sake of argument that I have the best SanDisk card that money can buy). Is 8 achievable? 6? I don't need 16, but I don't think that i can go lower than about 6 - 8 before you can audibly hear the sounds cutting out. More is obviously better.

I would be handling the task of stopping sounds manually if there are too many playing at once.

Anyway, I thought that I would get a feel for the hardware capabilities before I purchased anything... thanks for any advice that the community may have!

Cheers

Frank B
06-10-2015, 09:20 PM
With a winbond-flash on the audioboard, the Teensy can play more than 10 (..never tried it :-) 44 Khz mono samples simultanoulsy.
There's a library: https://github.com/FrankBoesing/Teensy-PlayRawFromSerialFlash

Pensive built an awesome device with it.
https://forum.pjrc.com/threads/26493-Build-Thread-Beatmaker

Perhaps ask him how many channels are possible :-)

PaulStoffregen
06-10-2015, 09:31 PM
Definitely put the short sounds into the internal program memory. Playing from program memory has very low overhead.

Playing from SD card has a lot of overhead. Even the best Sandisk cards have a pretty long lag from requesting the sector until they actually start sending the data. Currently the SD library only buffers 1 sector. There's a new experimental SD library in development with a multi-sector cache, but it still buffers only 1 sector per file. It'll give you better performance, but won't work any miracles (like a conventional operating system can cache gigabytes of data in RAM).

The Serial flash chips are the best off-chip storage. They have extremely low latency. Theoretically, such a chip ought to be able to support about 25 simultaneous streams. The practical limit is probably lower, but so far little testing has been done to figure out exactly where that limit really is.

thebigone
06-10-2015, 09:32 PM
Nice... it looks like he is getting "8 to 9 44Khz mono samples running at the same time", which is perfectly acceptable for my needs, when using the SPI memory add-on. I may have to make the jump... :-)

Thanks, Frank!

thebigone
06-10-2015, 09:35 PM
Thanks Paul. I will have to look at the samples I am using currently, but I am pretty sure that 16MB should be sufficient for a single set (e.g. acoustic, electric, whatever). When changing sets, you could read from a (slow) SD card onto the SPI flash; when playing the sounds they would be read directly from the SPI flash.

I'll definitely look into this further, but I think that it may be the answer... Thanks, Paul, for the comments and for helping the community at large.

Cheers

PaulStoffregen
06-10-2015, 09:40 PM
Eventually the audio library will use the SerialFlash library to access those chips. It supports the larger chips, which currently go up to 128 Mbyte/sec.

While the SPI flash chips have low latency and impressive read performance, they're fairly slow to erase and write. Fully erasing and rewriting a 16 Mbyte chip could take over a minute. It's certainly slow enough that you'd want to design some sort of progress indicator, so it doesn't seem like your board has crashed during the lengthy time needed to erase and write.

thebigone
06-10-2015, 09:49 PM
It would be OK for switching sets to take a bit of time... I am planning to have an HD44780 display on board, so showing a progress bar is no problem.

As far as size goes, it looks like this (http://www.digikey.ca/scripts/DkSearch/dksus.dll?Detail&itemSeq=173928924&uq=635695477608115856) is the largest chip that would be supported?

Cheers

PaulStoffregen
06-10-2015, 10:10 PM
That link seems to be dead.

I can tell you the largest chip that's been tested is Micron N25Q00AA. You can see the list of tested parts here:

https://github.com/PaulStoffregen/SerialFlash

Some time ago, Onehorse was talking about making a board with an even larger chip, when it becomes available.

thebigone
06-10-2015, 11:15 PM
OK cool. The chip I was trying to link to was the Winbond W25Q256FV, which is listed as supported.

The Micron N25Q00AA would be very nice (I would have more than enough room for anything that I wanted to put on it), but it would not fit on the audio breakout board. Although perhaps that is not a problem anyway, as I would be making my own PCB for the analog circuitry, and could put the larger chip on there. Hmmmm...

thebigone
06-10-2015, 11:18 PM
Do you have any rough idea how long until the audio library will work with Serial Flash? I do realize there are third party options available today, so there are ways around the current limitations, but it would be interesting to know if the planned timeframe was weeks vs months vs years.

onehorse
06-10-2015, 11:24 PM
Some time ago, Onehorse was talking about making a board with an even larger chip

I assembled a couple of the Micron N25Q00AA chips on the board I designed but wasn't able to get them to work. It's possible I need to solder headers onto the board instead of using clip on jumpers, but I sort of hit a wall there and stopped. I was hoping to get some Macronix SPI flash memory chips since they have the one CS an very large memories, 2 Gbits and maybe even 4 Gbits IIRC, but the rep who promised to get me samples never came through.

I hope to get back on this path soon...

PaulStoffregen
06-11-2015, 12:01 AM
Do you have any rough idea how long until the audio library will work with Serial Flash?

No, there's no reliable time estimate. But it ought to be within the next couple months....



I assembled a couple of the Micron N25Q00AA chips on the board I designed but wasn't able to get them to work. It's possible I need to solder headers onto the board instead of using clip on jumpers, but I sort of hit a wall there and stopped.


I tested that same chip with the 16 pin package. It definitely does work. I used a little adaptor PCB soldered on top of a Teensy, so the wire length was under 2 inches.



I was hoping to get some Macronix SPI flash memory chips since they have the one CS an very large memories, 2 Gbits and maybe even 4 Gbits IIRC, but the rep who promised to get me samples never came through.


I'd like to test those chips with the library, especially ones more than 1 Gbit... but not enough to go through the hassle of the Macronix rep.

thebigone
06-11-2015, 04:26 PM
Thanks all,

I have looked at my samples, and while I will have to reduce the number of samples slightly (for instance, currently I have different samples for different velocity strikes, and in some cases have upwards of 30 different samples for a single drum; this is obviously excessive, and most of the samples are indistinguishable from the others), it looks like I can quite easily fit a complete set into 16MB. For instance, a set of samples that I have for an acoustic set can fit in about 9MB, so I even have some room for picking more samples if needed.

(And yes there are larger chips, but they have a different footprint and are more expensive; if in the future I find that I need more space I can always expand the memory at that time).

It looks like I will be going ahead with the Teensy... I'll be sure to post my results back here when I have something to report.

Cheers

Frank B
06-11-2015, 10:34 PM
Eventually the audio library will use the SerialFlash library to access those chips. It supports the larger chips, which currently go up to 128 Mbyte/sec.

Paul , you're writing a new version ? I do not care , but it would be good to know , because in this case I would not upgrade my version (waste of time). There have been some demands .

The other option would be to tell me your plans/ideas and i could integrate them into my existing lib and do a pullrequest.

Pensive
06-14-2015, 02:02 PM
Using Frank B's code, I was at about 90% CPU while mashing 16 buttons all at once, each one playing a different sample @ 44.1Khz mono from flash, with envelopes on each button.

This was all while updating an LCD screen, and interfacing the buttons through a PS/2 Keyboard library.

So in practical terms, a polyphony of 10 is a good reserved design spec, which will be easily achieved even with some synth sounds running.

If you read from an SDCard instead of flash, even with a good card the polyphony will drop dramatically. Avoid where possible.


If you intend to add 808 or 909 sounds the original samples are tiny and will probably fit in sketch ram, but you'll need to code a bitdepth upscaler from the original 10 bit (or was it 9bit?) audio.

thebigone
06-23-2015, 06:14 PM
Well, I made the jump and ordered the Teensy + audio board, and will be making a Digikey order shortly with the memory chips and other components needed for my design. I'll post back once I start to make some progress (probably won't be for another month or so given the summer busy season).

Thanks to all for your help, and I look forward to getting into the wonderful world of Teensy :-)

thebigone
01-04-2016, 06:20 PM
In case anyone finds this thread later on, I have (more or less) finished the project. Details, videos, schematics, source code, etc can be found at https://hackaday.io/project/6881-drum-master (and eventually a distilled version with just the best information will be at http://drummaster.digitalcave.ca, although this is still a WIP as of the time of this writing). In short, the Teensy has worked beautifully. Thanks to Paul and the rest of you for all the help and direction!

Cheers

Pensive
01-04-2016, 06:52 PM
Cracking project! Probably the best use of the audio board I've seen to date.

It's amazing what one person can build with a bit of ingenuity and a quality software/hardware stack as a foundation.

Well played sir :)

I will need to take a closer look at your peak detection solution for the piezo :) sounds neat.

dpharris
01-04-2016, 07:55 PM
Very nicely done! It sounds good, too! Congrats.

Pensive
01-11-2016, 08:24 PM
I will need to take a closer look at your peak detection solution for the piezo :) sounds neat.

I have seen and noted your non-commercial license and will not utilise your solution.

thebigone
01-11-2016, 08:29 PM
I have seen and noted your non-commercial license and will not utilise your solution.

Sorry, where are you looking? I generally pick non restrictive licenses for my work unless modifying an existing (restrictively licensed) design. If I have listed a non commercial license on work I had created from scratch, that is incorrect and I will fix it.

thebigone
01-11-2016, 08:33 PM
Sorry, where are you looking? I generally pick non restrictive licenses for my work unless modifying an existing (restrictively licensed) design. If I have listed a non commercial license on work I had created from scratch, that is incorrect and I will fix it.

Ahh, I think I found it - on the drummaster.digitalcave.ca website. That site is old and is in the process of undergoing major changes, but I missed the license text; it is now changed to attribution / share alike. Hope this works better for you :-)

Cheers

Pensive
01-11-2016, 08:57 PM
Ahh, I think I found it - on the drummaster.digitalcave.ca website. That site is old and is in the process of undergoing major changes, but I missed the license text; it is now changed to attribution / share alike. Hope this works better for you :-)

Cheers

Thank you! I don't want to be inspired by something i'm not allowed to be inspired by!!! :)

I need to get a piezo working - I've not connected it up yet, but i also can't afford too many clock ticks doing software fudges.

I'm sure my dad will understand your schematics better than I do. :) I can follow it and build it but I don't have a _feel_ for the electronics logic behind it, if you will. It will come with time, I'm sure.

is the second amplification stage still required if you plug straight into a teensy pin? how low is the signal?

Pensive
01-11-2016, 09:08 PM
I'm using this one:
https://www.sparkfun.com/products/9196

Apparently i need to bring the voltage down from a peak of 30 instead; Still AC, though I believe? It doesn't say but the nature of the vibration leads me to believe so.


I'm not so sure this piezo is similiar enough to yours for your circuit to work out of the box.

thebigone
01-11-2016, 09:11 PM
Thank you! I don't want to be inspired by something i'm not allowed to be inspired by!!! :)

I need to get a piezo working - I've not connected it up yet, but i also can't afford too many clock ticks doing software fudges.

I'm sure my dad will understand your schematics better than I do. :) I can follow it and build it but I don't have a _feel_ for the electronics logic behind it, if you will. It will come with time, I'm sure.

is the second amplification stage still required if you plug straight into a teensy pin? how low is the signal?

If not amplification, you will probably want some sort of impedance matching there. If you look at the schematic http://drummaster.digitalcave.ca/drummaster/img/schematic_rev2.pdf, the output of the peak detection bit is at the *_D labels, e.g. HP_D. If you were to attach an ADC pin directly at that point, you may get a faster falloff from peak voltage (since the ADC pin would be draining a (very small) amount of current). By buffering it with another op amp (either at unity gain or with some amplification), you are providing the ADC a low impedance output to read from.

As far as the voltage level is concerned, the voltage at point HP_D will be the actual peak voltage, up to the op amp rail voltage minus the voltage drop of the diode. So in my system, I am using rail to rail op amps at 3.3v, with a standard diode which has a voltage drop of about 0.6V, so I have a peak value of about 2.7V at that point. I seem to recall that in practice it is a bit less than that. The amplification after that is nice (especially for calibration; I find that some of my pads are more sensitive than others; this allows me to normalize them), but not strictly needed.

If you have not already done so, give Falstad's circuit simulator a shot. It is not perfect as far as simulators go (I understand that Spice, etc are more accurate), but the simplicity of Falstad's sim makes it perfect for throwing quick things together and seeing what happens. When designing the peak detection circuit, I used this simulator heavily (and in fact there is a peak detection sample in the examples folder somewhere).

thebigone
01-11-2016, 09:16 PM
I'm using this one:
https://www.sparkfun.com/products/9196

Apparently i need to bring the voltage down from a peak of 30 instead; Still AC, though I believe? It doesn't say but the nature of the vibration leads me to believe so.


I'm not so sure this piezo is similiar enough to yours for your circuit to work out of the box.

I've not seen a piezo looking like that, but I assume the theory is the same. Yes, with my piezos there is potentially high voltage AC (with incredibly low current) being output from a piezo. In my design I use a voltage divider to reduce the input voltage. Originally I was using a 10k / 1k to reduce it by a factor of around 1/10, but found that this was too much. Now I am using 1k/1k for about 1/2, and that works much better.

When figuring out how much to drop the signal, you also need to know about your pad design. I find that pad design is just as important as circuit design if you want consistent signals. After a lot of trial and error I arrived at the pad design documented at https://hackaday.io/project/6881-drum-master/log/29084. By doing things like this, you won't get the full 30V-ish max output on the piezos.

Pensive
01-11-2016, 09:24 PM
mine is being attached to a midi device full of arcade buttons.

When I detect a button being pressed, I need the peak from the last XXms. I will apply this as a velocity to the midi note.


This sounds complex, but achievable. Not something I want to do twice though.
Since I will ultimately need a PCB mounted solution, I will wait until i'm developing the PCB to selct a suitable SMD shock sensor / accelerometer.

I'm prototyping at the moment, so I dont want to go down to the Nth degree on a component I almost certainly won't use on the final PCB.

Thanks for your help! :)

Addendum: It looks like an accelerometer could be used as a vibration sensor, and they tend to be able to talk i2c. This might well be a preferable solution for the less electronically minded of us - IE me.

Pensive
01-11-2016, 09:52 PM
Or my last option - i wont clog your thread anymore!

https://www.adafruit.com/index.php?q=vibration%20sensor%20switch&main_page=adasearch

The top 3 items are 3 sensitivities of shock sensor. I could just query the three digital pins when a button is pressed to get velocity of 33%, 66% and 100% and map those to suitbale midi velocities - it would give the feel of velocity detection. Far from ideal though.

This one is the easy way out, but it would work after a fashion. No way of calibrating though!!

It wouldn't be hard to build an arcade button with velostat mounted inside affording velocity and aftertouch.......hmmmm.....

thebigone
01-11-2016, 10:03 PM
Or my last option - i wont clog your thread anymore!


Not clogging at all, but if you would rather start a new thread let me know what the link is and I can start replying there. Or feel free to just email me directly.



https://www.adafruit.com/index.php?q=vibration%20sensor%20switch&main_page=adasearch

The top 3 items are 3 sensitivities of shock sensor. I could just query the three digital pins when a button is pressed to get velocity of 33%, 66% and 100% and map those to suitbale midi velocities - it would give the feel of velocity detection. Far from ideal though.

This one is the easy way out, but it would work after a fashion. No way of calibrating though!!

It wouldn't be hard to build an arcade button with velostat mounted inside affording velocity and aftertouch.......hmmmm.....

Do your arcade buttons return some sort of pressure value? Or would you be mounting a piezo on / underneath / touching each button to use for the velocity value? The electronics part seems easy, but I can't wrap my head around your physical build.

As far as prototyping is concerned, it would be very easy to prototype the peak detection (I know cuz that's what I did!) ;-) A normal 4x op amp chip with two caps and two diodes will give you two channels with peak detection and buffering. Add a couple more potentiometers if you want amplification / calibration, but that is not required. If you want to get all 16 buttons prototyped, you could probably fit it all on 2 breadboard panels, or just leave the prototype at 2 channels. (That's what I did... if it works for one it will work for a million, right? ;-) )

Cheers

Mat13
10-28-2018, 04:44 PM
Do you have any rough idea how long until the audio library will work with Serial Flash?


No, there's no reliable time estimate. But it ought to be within the next couple months....

Hi Paul,
I'm interested in playing music and sound simultaneously:
I was quite stuck with Arduino... as far as I understand the system described here, I could use Teensy + SPI flash chip + Audio board? or it still requires some evolution of the library quoted above?
Thanks :)

Pensive
10-28-2018, 05:25 PM
Hi Paul,
I'm interested in playing music and sound simultaneously:
I was quite stuck with Arduino... as far as I understand the system described here, I could use Teensy + SPI flash chip + Audio board? or it still requires some evolution of the library quoted above?
Thanks :)

That’s all long since working fine.

With a teensy 3.6 you’d be able to use an sdcard at the same time as “music” if by music you mean synth sounds.

If by music you mean mp3 decoding....you’ll only be able to do that on a teensy 3.6.

3.2 is only just man enough to play mp3s back ;) although Frank might have optimised it further - not sure.

Can you define “music” and “sound” by file format and bitrate/bitdepth please?

Mat13
10-28-2018, 10:00 PM
Sorry for the lack of details :p
I meant reading several .wav files at the same time...

Not sure about quality: 16 bit - 44 kHz would be nice but something equivalent to a mp3 quality of 196 kb/s is fine.

Frank B
10-28-2018, 10:06 PM
You're comparing apples to pears. The MP3-bitrate (by the way- AAC is way better) has nothing to do with samplerate or bit-depth (but it has to be encoded with 44.1kHz for Teensy 3.x)
You can play a MP3 with 196kb/s with any Teensy 3.x - with 16Bit/44.1 kHz. MP3 decoding needs lot of RAM,so the decoder allows only one file a time.
Playing RAW from Serial Flash works best. Don't remember exactly, too long ago that I tried it, but I think more than 10 files simultanously were possible - on a Teensy 3.2

PaulStoffregen
10-29-2018, 12:17 AM
When playing WAV files from the SD card, the Arduino SD library is only capable of reading about 3 files simultaneously.

Someday we'll have a better library, but for now the SD library is limited to a 1-sector-at-a-time approach which is far from optimal for modern SD cards.

Mat13
10-29-2018, 10:17 AM
Many thanks for your fast answers ;)

I'll try to rephrase my question (sorry english is not my native language):
► my need: playing multiple audio wav files (up to 4 simultaneously) in 16 bit - 44 kHz quality

I've read here https://hackaday.io/project/6881-drum-master/log/27665-extra-flash-memory-working from @thebigone
that reading from SD card is not a viable option but that flash chip is the way

► my question: what hardware setup would do? and with which library please?
- Teensy LC
+ Audio board
+ SPI flash chip (like W25Q128FVSIG 128Mbit 16M x 8bit 7ns Serial-SPI 3V/3.3V) flash chip is 3,3V like Teensy LC

thanks for your expertise,
Mat

Pensive
10-29-2018, 11:42 AM
I’d recommend a teensy 3.2 absolute minimum but for the price - a teensy 3.6 is so much more powerful. I like sledgehammer engineering. Hit it with much more than you need!

Mat13
10-30-2018, 03:00 PM
I've found 2 posts about this memory chip used in conjunction with Teensy, so I guess I could have a try
https://forum.pjrc.com/threads/33189-Trouble-with-W25Q128FV-on-Audio-adapter
https://forum.pjrc.com/threads/52486-W25Q128FV-SPI-Memory-Chip-Discontinued-Should-This-Direct-Replacement-Work-Fine
I've just ordered some chips at aliexpress

sledgehammer engineering ?! :p
"when you only have a hammer, every screws look like nails!"

Does Teensy LC have enough horsepower?

Theremingenieur
10-30-2018, 05:25 PM
The Teensy LC has a Cortex M0+ core which does not support all the DSP instructions used by the audio library and the audio board. Thus, you absolutely should have a Cortex M4 processor as in the Teensy 3.2, 3.5 and 3.6 boards which offer full audio library and audio board support.

Mat13
10-30-2018, 05:52 PM
Thanks @Theremingenieur for your clear explanation! :cool:

merci
Mat