Registration Notice

Due to increased spam, forum registration must be manually approved by a moderator! Please see this post for instructions.

*

Offline LukeZ

  • 1254
    • View Profile
  • France
Open Source Sound using Teensy 3.2 and PJRC Audio Library
« on: January 15, 2017, 03:09:42 PM »
This thread will follow my attempts to create an open source sound card based on a Teensy 3.2 microcontroller featuring a 32 bit ARM processor (72 MHz Cortex-M4). It costs about $20 so represents a lot of power for very little money, and it's also very small.

All Teensy devices (there are several versions) are Arduino compatible and can be programmed using the Arduino IDE if you install the free Teensyduino add-on. Development can proceed rapidly because all the standard Arduino libraries can be used, and there are lots of Teensy-specific libraries available as well.

The greatest thing about this board is that it runs the Teensy Audio Library. This is an entire toolkit for building audio projects using a Teensy processor. They have a workshop you can go through that will probably blow your mind. I attended one of these in person last year for the express purpose of learning how we could leverage these resources for an Open Panzer sound card.

The workshop examples use a Teensy 3.2 mated to the PJRC Audio Adapter board. This board outputs CD quality stereo sound (16 bits, 44.1 kHz) and basically just consists of an SD card slot and an SGTL5000 codec chip. This chip takes I2S audio data from the Teensy (not to be confused with I2C) and with the onboard DAC converts it to analog audio. It has a built in headphone amp so you can listen on headphones without any extra hardware. But if you want to drive a speaker you have to add an amplifier circuit to the line-outputs. The SGTL5000 also has a lot of audio processing and signal conditioning features that can be manipulated through convenient functions in the Audio Library.

The Audio Adapter board is a bit overkill for our purposes. We don't need headphone outputs, we don't need stereo sound, and we probably don't need the majority of the signal processing capabilities. We do need however to drive a speaker and that requires yet another chip. However it would not be hard to create our own board with the SGTL5000, SD card, and a small Class D IC.

We do however have other options...

NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline LukeZ

  • 1254
    • View Profile
  • France
Re: Open Source Sound using Teensy 3.2 and PJRC Audio Library
« Reply #1 on: January 15, 2017, 03:33:28 PM »
Let's take a step back and look at our options. The Audio Library enables the Teensy to stream sound data from two possible sources - an SD card or flash memory. It can then perform various tasks with the sound (mixing, adjusting, etc) and output to one of two outputs - mono analog using its single onboard DAC, or digital I2S data out.

If we use the onboard DAC, all we need to add to the Teensy (on the output side) is an amplifier IC. This is easy to do and there are lots to choose from. PJRC sells what they call a Prop Shield (not for propellers, for props) that uses a Texas Instrument LM48310; I have been using this for experimentation. Adafruit has an inexpensive breakout using a Diodes Inc PAM8302A. I'm sure there are a million other options as well. Both these listed operate at up 2.5 watts on a 4-ohm speaker which is probably more than enough for most 1/16 scale models and is equivalent to the Benedini TBS Mini.

In other words, in terms of hardware using the Teensy's DAC out is about as simple as it gets.

We could also use I2S out into a codec chip like the afore-mentioned SGTL5000 and then into an amp. This adds another IC but gives us some audio processing abilities we may not need.

I also recently discovered this fascinating combination I2S-DAC/Class-D amp chip that Adafruit sells a breakout for: MAX98357A. Feed it I2S digital audio and it will convert to analog and give you a hefty 3.2 watt amplified mono output you can connect directly to a speaker. I have ordered one to experiment with but don't have it yet.

All these options involve relatively inexpensive chips we can easily incorporate into our own board design. The final result I am shooting for is a small carrier board with a socket to plug in a Teensy 3.2. The carrier board will "carry" all the extra audio components we need such as the amplifier, plus the SD card slot, standard headers to attach HengLong/Taigen speakers and volume control knobs, and serial and power connections for hookup to the TCB.

So the question at this point is what hardware route to take. But we have some more things to consider first.
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline LukeZ

  • 1254
    • View Profile
  • France
Re: Open Source Sound using Teensy 3.2 and PJRC Audio Library
« Reply #2 on: January 15, 2017, 04:07:10 PM »
Now we need to think about the audio source, SD card or flash memory. From an end-user perspective, an SD card is to be preferred by far. Put your files on it, stick it in your sound card, bam, you're done. SD cards are cheap and can provide gigabytes more storage space than we'd ever need.

Here is the big downside to SD cards - they are optimized for reading serial data, not parallel. This means you can stream a song off it no problem, but try to stream two sounds, or three, or more simultaneously and the card quickly croaks. The processor on the Teensy is more than capable of managing probably even a dozen simultaneous audio streams, but the SD card will not be able to keep up.

This is why the RC Tanks Australia Asp2 board uses two SD cards to play two sounds simultaneously. There is nothing special about the sound cards, they are off-the-shelf Chinese mini MP3 modules that are awash on eBay. On the first MP3 player he has engine sounds running, on the second auxiliary sounds like cannon fire. This works (if you don't need more than 2 sounds) but is bulky, inflexible, unsophisticated and not the way I want to go.

Putting sounds on flash memory solves the polyphony problem, but creates many more. Small flash chips don't have great capacity, in 8-SOIC packages I think the limit now is about 16 Mbytes. Considering the Audio Library only plays 16 bit, 44.1 kHz WAV files, this isn't much. Getting flies on to the flash chip is also a royal pain. The user can't simply drag and drop files the way they can with an SD card. We need to add functionality to a PC application (OP Config) to convert and load them, and bother with a bunch of extra hassle on the controller as well.

When you realize the complexity of this approach you really start to appreciate the genius of the Benedini TBS which runs on a ridiculously humble 8-bit ATmega168 processor with only 3/4 MB of flash memory to store sounds!! This is the extreme opposite approach to the Asp2 board. Thomas makes up completely what he lacks in hardware with pure brain power and sophistication typical of the Germanic race.

However I am no Thomas. It would be great to have him design a board for us but then he'd put himself out of business. So we shall have to muddle ahead ourselves (or myself).

In the end I think there is no avoiding the use of an SD card, the benefits are just too great. We actually can play more than one sound at a time from SD, but we have to be careful how we do it. And there is no guarantee I won't run into some pitfalls that make all this effort a waste of time eventually.
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline LukeZ

  • 1254
    • View Profile
  • France
Re: Open Source Sound using Teensy 3.2 and PJRC Audio Library
« Reply #3 on: January 15, 2017, 04:16:15 PM »
What I need to do next is determine if using the Teensy's onboard DAC in any way causes more problems with simultaneous SD card reads than outputting I2S only. I don't think it will but I have not gotten far enough in my experiments to be sure. If there is no real difference, then I think I will design a board that uses the Teensy's onboard DAC fed into a Class D amp and that should be all we need for hardware. If I find I2S somehow appears to give us a bit more wiggle room, then the hardware will probably use the MAX98357A listed before.

One thing I need is a quality set of sound files for testing. The Benedini comes with good sounds but they are in proprietary format. I've assembled a small set of my own for playing around with but I put no effort into them and they sound awful to begin with, so they will continue to sound awful no matter how wonderful this sound card may or may not become. I know there are a couple guys on RCU who have have really gone all in creating quality sets for their models, I may ask over there if anyone wants to share.

NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline vonTirpitz

  • 30
  • Panzer, vorwärts!
    • View Profile
  • Wilmington NC
Re: Open Source Sound using Teensy 3.2 and PJRC Audio Library
« Reply #4 on: January 15, 2017, 07:32:58 PM »
The Audio Adapter board is a bit overkill for our purposes. We don't need headphone outputs, we don't need stereo sound, and we probably don't need the majority of the signal processing capabilities. We do need however to drive a speaker and that requires yet another chip. However it would not be hard to create our own board with the SGTL5000, SD card, and a small Class D IC.

While I am still very "green" and a long way from catching up to you on this project in terms of overall understanding a thought does occur to me.  Given the flexibility that you are striving for with the project I might suggest not discarding the stereo option out of hand.

For instance, you can actually use a stereo system to play "split tracks" that could be used to play two different sounds (in terms of a left and right speaker).  So, in the case of our tanks, I could perceive one speaker playing an engine sound channel (with everything from idle to acceleration/deceleration) and the other channel playing overlap audio for brakes, gun fire, track sounds, etc.

One thing I notice with my tanks is that each sound plays exclusive of the other sounds (so the engine sounds are suspended when the gun fires, etc).  Using the Stereo channels to seamlessly interlace audio would allow for a much richer sound experience.  From a hardware standpoint, unless looking to use bridged mono, this approach would also require the second speaker and enough energy to drive both.  However even this it isn't a zero sum option.  The stereo logic circuitry provide some interesting capabilities whether using one or more speakers (as long as we know what the capabilities of the speakers are).

Of course, less elegant options are out there but they would require much more sound data (thus more memory) to provide a "smoothness" to overlapped audio. 

Once again, it has been a very long time since I did any serious work in audio so forgive me if anyone finds myself rambling.  If such is the case all I can do is apologize.  I've discovered that many of my thoughts end up being casualties of a tired mind.   :P

"The two most powerful warriors are patience and time."

                                                                 -LT

*

Offline LukeZ

  • 1254
    • View Profile
  • France
Re: Open Source Sound using Teensy 3.2 and PJRC Audio Library
« Reply #5 on: January 16, 2017, 02:26:31 PM »
Those are some good thoughts vonT and no suggestion is a dumb one! At least if it gets us thinking. It may have been a long time since you did work in audio, but for me it is all completely new. So I know very little but have learned enough to realize this is an extremely complicated subject, which probably explains why a good sound system for models is so hard to find.

But my design philosophy generally is not to add a feature that would be useful for the 10 percent if it inconveniences the 90 percent. If it can be added without inconvenience to those who don't use, then ok. But in the case of a sound card with stereo outputs, users would then have to use two speakers or a special stereo speaker, which I imagine is hard to find in the small sizes we typically require (at least in 1/16 scale). It may be possible to design the board with two amps, each fed stereo but one that converts to mono and one to stereo. This increases board size and cost. I suppose another option would be to proceed with an amplified mono output but have stereo line-outs available for those who want it, and they would need to supply their own amplifier.

Using each individual channel for overlapping sounds is a good idea, but so far as I can think ahead, doesn't solve any technical issues regarding read limitations on SD cards. We can't start or stop reading the left and right channels of a given audio file at different times, they have to be streamed simultaneously - but we don't know for example when the user is going to want to fire the cannon relative to the position of any engine sound, so pre-mixing overlaid tracks is not going to help us much.

Maybe there are some other benefits I'm not seeing or comprehending...

I think with the correct SD card we should be able to play three sounds simultaneously - or at the very least two. This is not as great as it seems since we will need at least two just for engine sounds (the engine being dynamic we will constantly be fading from one sound to the next, which requires two tracks to overlap each other for at least a portion of time). But if we can reliably get three I think we are out of the woods.

It may also be possible to put short sounds like cannon and machine gun fire, squeaks, etc... in flash memory. If there is space to pre-load all the variants likely to be required, these could be static and therefore wouldn't require the complicated end-user hassle needed to get those files onto the flash, but would still let us stream more sounds simultaneously.

Anyway, these are my random thoughts for now...
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline LukeZ

  • 1254
    • View Profile
  • France
Re: Open Source Sound using Teensy 3.2 and PJRC Audio Library
« Reply #6 on: January 18, 2017, 11:29:44 PM »
I was able to do some testing. Using the optimized Teensyduino SD library for reading SD cards instead of the Arduino library, and using a SanDisk Ultra card which has "higher non sequential speed" according to PJRC, I was able to stream 4 stereo WAV files simultaneously without problem. Perhaps I could do even more but that's as far as I tried, and it should be plenty for what we need.

Using a slower card (Kingston brand) I could only reliably get 2 stereo sounds simultaneously, so the card definitely makes a difference. However even the Kingston was able to stream 4 mono files.

I could detect no difference in performance between audio out via I2S or DAC, which is what I expected. To keep the hardware simple I'm going to proceed with DAC out to a mono amp for now. We can always change the hardware later if we need a stereo version, the firmware is going to be the valuable part, not the board.

I've attached a picture of the hardware I'm using now: on the bottom is a simple carrier board, followed by a Prop Shield, then a Teensy 3.2, then an SD card shield. It's kind of a hot mess.

Feeling comfortable this setup will give us the technical capabilities we need, I will next design a better carrier board to eliminate everything but the Teensy. It will consist of the SD card slot, amplifier, speaker and volume connections, RC and TCB connections, etc...  I might throw on a small flash chip as well.

Of course the firmware is the most important part. I'll try to have some code in good enough shape to start a GitHub repo within a few weeks. Perhaps ninety percent of the functionality will not be difficult other than putting in the time. The challenging part will be realistic engine speed routines. That is the part I expect the more people involved, the better the outcome.
Components.jpg
Open Source Sound using Teensy 3.2 and PJRC Audio Library Components.jpg
Views: 15941
EarlyPrototype.jpg
Open Source Sound using Teensy 3.2 and PJRC Audio Library EarlyPrototype.jpg
Views: 10826
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline vonTirpitz

  • 30
  • Panzer, vorwärts!
    • View Profile
  • Wilmington NC
Re: Open Source Sound using Teensy 3.2 and PJRC Audio Library
« Reply #7 on: January 19, 2017, 09:48:07 PM »
The challenging part will be realistic engine speed routines. That is the part I expect the more people involved, the better the outcome.

I will try to remember to spend some time looking through code examples of dynamic sound manipulation.  I like the idea of dynamically manipulating baseline audio to produce desired output.  It greatly expands the uses of recordings and I would not expect the additional program logic to overwhelm the hardware so it might be a good path to pursue. 

An example can be found here (In the Flight Sounds section).
"The two most powerful warriors are patience and time."

                                                                 -LT

*

Offline LukeZ

  • 1254
    • View Profile
  • France
Re: Open Source Sound using Teensy 3.2 and PJRC Audio Library
« Reply #8 on: July 08, 2017, 03:14:35 PM »
Been a while since I posted an update on this project but development has been on-going. Using the Teensy 3.2 as a processor works great and I can play 5 sounds simultaneously no problem straight from the SD. In fact it could do more but I haven't found a need and anyway when you have five things going at once it already starts to sound like cacophony.

Right now the firmware assigns two sound slots to the engine - this is so that as engine speed increases, or any other engine sound transition occurs, we can fade from one file to the next (which requires two sounds to play at once), rather than to cut abruptly from one file to the next.

The other three sounds are for effects, so for example you could have the MG firing, the turret moving, and music playing - all while the engine is going. I think this should be plenty.

I've simplified the ridiculous 4-stack test model shown earlier. There is now a single "carrier" board into which an off-the-shelf Teensy plugs in to. The carrier board provides connections for the speaker, volume pot (HL/Taigen pots are plug-n-play), as well as connections to the TCB and optional RC inputs if used without the TCB in a standard RC model.

There isn't much to it hardware-wise so the cost is relatively low. Even in single quantities you can build one for less than $40, including the Teensy. If you do decide to build one, note that OSH Park sells Teensy 3.2s at checkout when you get your boards.

I've created a project page on GitHub with firmware source code as well as instructions, see it here.

When used with the TCB there isn't much setup. You assemble your sound files, give them the correct names as shown in the instructions, and put them on the Micro-SD card. That's pretty much it. Sound files must be 16 bit 44,100 Hz WAV files (this is CD quality).

SD cards up to 32 Gb in size are supported. That equates to about 100 hours of sound. As mentioned before though, a high quality memory card must be used or else it will have problems playing multiple sounds at once. SanDisk Ultra are recommended.

The sound card can also be used with standard RC gear and has 5 channels of input. However flexibility is really limited in this mode. Right now RC mode works like this:
Channel 1 - Engine on/off
Channel 2 - Throttle
Channel 3 - Cannon/MG
Channel 4 - Two user sounds
Channel 5 - Volume control

But much more could be accomplished for the RC mode if a configuration program were created (similar to Benedini's TBS Flash), or if we just used some kind of "Settings.txt" file placed on the SD card. Since none of this is really relevant for use with the TCB, I'm not planning to spend a lot of time developing the RC aspect right now. However I can see it might be very popular, and maybe more people would want this device for general RC usage than for use in tanks, because there is definitely no other good option available today that doesn't cost an arm and a leg.
OPSound_Components.jpg
Open Source Sound using Teensy 3.2 and PJRC Audio Library OPSound_Components.jpg
Views: 10076
OPSound.jpg
Open Source Sound using Teensy 3.2 and PJRC Audio Library OPSound.jpg
Views: 10233
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline LukeZ

  • 1254
    • View Profile
  • France
Re: Open Source Sound using Teensy 3.2 and PJRC Audio Library
« Reply #9 on: July 08, 2017, 03:19:29 PM »
The sound card has pass-through plugs on both ends so it can be used with the TCB alone or it can go in-between the TCB and the Scout ESC.

The photo below shows a prototype version of the TCB with slightly different connectors than on the final version you will buy. The final version has a 3-pin communication plug to the sound card instead of the 2-pin shown here (the sound card and Scout both use 3-pin), and the final version of the TCB also has a standard JST plug for power instead of the screw terminals shown here.
OPSound_wTCB.jpg
Open Source Sound using Teensy 3.2 and PJRC Audio Library OPSound_wTCB.jpg
Views: 9331
OPSound_TCB_Scout.jpg
Open Source Sound using Teensy 3.2 and PJRC Audio Library OPSound_TCB_Scout.jpg
Views: 3540
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline LukeZ

  • 1254
    • View Profile
  • France
Re: Open Source Sound using Teensy 3.2 and PJRC Audio Library
« Reply #10 on: July 08, 2017, 03:27:01 PM »
Here is a brief video showing that basically it works. The card has many more sounds than are played here, stuff like receiving hits from cannons or machine guns, repair, braking, etc... plus of course you can always add your own custom sounds.

Two somewhat special things are illustrated:
  • Listen carefully, the machine gun is comprised of two sounds - a repeating portion, and an ending portion. You can play the repeating portion for as short or as long as you like, when you are done the ending portion will play automatically. In fact the MG sound can be made up of up to 3 sounds (you can insert a beginning sound). The barrel elevation and turret rotation sound can also be made up of up to 3 sounds (but if you only have 1 sound that's fine too, the sound card will use whatever you give it).
  • Volume can be controlled physically with any standard pot, or directly via the transmitter. You can go back and forth between both sources, as shown.

The sound files I'm using in this demo are very simple, in fact there is only 1 engine running speed (but you can have up to 10). It doesn't sound half bad due to the interesting acceleration and deceleration sounds. But of course someone with more ingenuity with sound file manipulation could make something even better.

NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline LukeZ

  • 1254
    • View Profile
  • France
Re: Open Source Sound using Teensy 3.2 and PJRC Audio Library
« Reply #11 on: July 08, 2017, 03:51:53 PM »
You can download the sound set I'm using in this test:
   Click here,
      select the file named OPSound_TestSet_2017_07_08.zip,
         then download.
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline LukeZ

  • 1254
    • View Profile
  • France
What's Next?
« Reply #12 on: July 08, 2017, 04:00:21 PM »
Ok, this is all very interesting, but before anyone gets too excited, please remember this thing only exists in prototype form and there is no way to buy it right now.

Right now the board needs two important things before it is ready for production: testing by end users, and quality sound sets. Testing will certainly uncover firmware improvements that need to be made, and it may even lead to a further hardware revisions as well.

That's where we're at now. This next stage is going to take time, so again, please don't expect to obtain one of these yourself anytime soon (unless you want to build your own, but note, the amplifier IC requires reflow soldering).

Even when the testing/development stage is complete, then we still have to find some company who wants to make these at their own expense. That has proven difficult (no luck with the Scout), and it will no doubt prove difficult here again as well.

Bottom line, please don't ask me every other day if you can buy one! Don't expect to see one in the wild for the next very long time! As I have updates I will post them here and in the FAQ.
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

*

Offline johnnyvd

  • 170
    • View Profile
  • Netherlands
Re: Open Source Sound using Teensy 3.2 and PJRC Audio Library
« Reply #13 on: July 13, 2017, 04:48:20 AM »
I will try solder one together and start testing.. I really like the way the Scout, Sound and TCB are connected.. What type of volume control are you using in the pictures Luke?
* E-75 / E-100 PAK44 "monster" - in progress
* Sturmjagdtiger PAK44 - in progress
* pz.kpfw KV-2 754(r) - in progress
* T-34 88mm "Kurland Tiger" - in progress

*

Offline LukeZ

  • 1254
    • View Profile
  • France
Re: Open Source Sound using Teensy 3.2 and PJRC Audio Library
« Reply #14 on: July 13, 2017, 11:31:25 AM »
You can use any standard potentiometer, the ones that come with Taigen / Heng-Long boards will plug in directly.

The pot you see in the photo is one I got from eBay from Keyestudio, you can find it here. It's the same thing, just a little nicer. You'll have to make a cable for it. You'll also have to get the knob separately, anything that fits the common 6mm shaft will work well, such as these or these.

Keyestudio has all kinds of goodies. Some of their items (like that same pot, or their relays) will work on the General Purpose I/O ports on the TCB. Worth browsing around their store.
NO SUPPORT THROUGH PM - Read why
Need a forum account? Read here
Open Panzer FAQs

 

bomber-explosion