H Pyle's I2S library settings help!

Status
Not open for further replies.

mattomatto

Well-known member
Hi,

I am using Hugh Pyle's (amazing) I2S library with the WM8731 codec, using the MikroE proto board. In Hugh's example sketch there are settings for both the MikroE board and the OML board:

Code:
#if 0

// Settings for MikroE prototype board
#define clock_per_sec               48000
#define CLOCK_TYPE                  (I2S_CLOCK_EXTERNAL)
#define CODEC_INTERFACE_FLAGS       (WM8731_INTERFACE_FORMAT(I2S) | WM8731_INTERFACE_WORDLEN(bits16) | WM8731_INTERFACE_MASTER)
#define CODEC_BITRATE               (WM8731_SAMPLING_RATE(hz48000))

#else

// Settings for OML audio codec shield
#define clock_per_sec               44100
#define CLOCK_TYPE                  (I2S_CLOCK_44K_INTERNAL)
#define CODEC_INTERFACE_FLAGS       (WM8731_INTERFACE_FORMAT(I2S) | WM8731_INTERFACE_WORDLEN(bits16) )
#define CODEC_BITRATE               (WM8731_SAMPLING_RATE(hz44100))

#endif

If I use the MikroE settings, I only get audio through the right channel. If I use the OML settings, it works fine. This is the case for both the DMA and non-DMA examples. Do I need to feed the samples to the buffer in a different way for the MikroE?


Thanks for your time!
 
Generating pure tones in a variety of ways, I also find the output really quite noisy at anything less than 96K, especially at higher frequencies. Anyone else have experience with this?
Thanks
 
Yes, there are some bugs in that code, I believe in manipulating the WM8731 chip.

I'm planning to release the official audio library and audio board within the next couple days. That should help.....
 
Next couple of days?! Wooop!

Except I haven't made even one line of progress today. I blew off answering forum questions and even most email for the last few days, so today has been catching up on questions.

I'm currently working on the test fixture. It's almost done, but the signal tests have a difficult timing bug. The tester causes the audio board to output 4 sine waves, one at a time on each of the 4 outputs (stereo headphone, stereo lineout) and checks for a correct waveform on each output while having silence on the other 3.

If I'm sluggish to answer questions over the next couple days, well, you now know why......
 
Really keen to see the board since I was planning on making my own amalgamation of the teensy and the mikroe proto. I'll keep my gob shut and let you get on! ;)
 
Really keen to see the board

audio1.jpg

The codec chip is SGTL5000.
 
Here's some text I wrote up recently describing the library.....



It uses raw 16 bit, 44.1 kHz PCM/wave data.

The library is a toolkit of objects which you can connect together in almost any way, to create nearly all types of sophisticated audio processing applications (within the CPU limitations). There are 2 types of objects: components and connections. Components can have any number of input and outputs. For example, the 4 channel mixer object has inputs 0 to 3, and output 0. The .wav file player has outputs 0 and 1. A sine wave generator has only output #0. Filters have input 0 and output 0. The stereo DAC object has inputs 0 and 1, and no outputs. A mono ADC object has only output 0.

Connection objects move audio data from one output to one input. The mental model is much like hooking up real audio gear. You create instances of the libraries objects for each audio component you want. Then you create instances of the connection object that work like audio cables between the objects. This is all done at the beginning of your Arduino sketch, just creating instances of objects.

Then in setup() and loop(), your sketch can call the objects' functions to trigger changes or change parameters, much like pushing buttons and turning knobs on real audio gear.

Internally, the library moves all audio on/off chip using efficient DMA. An interrupt runs at 344 Hz (every 128 audio samples) to compute/update all audio data. Casual Arduino users are never exposed to the high speed, real-time audio processing. It's all done automatically and very efficiently (DMA & shared copy-on-write memory management) by the library running in the background. The background processing plays nicely with other Arduino libraries using interrupts, thanks to the ARM NVIC interrupt priority system. The library also provides functions to query current and worst case CPU usage for individual objects and the entire system. Each object uses some CPU power, like 3% for the DDS waveform generator, a couple percent for a mixer, about 40% for .wav file playing from the SD card (due to slowness in the SD library....), etc. Some of the objects use the Cortex-M4 DSP instructions, and over time I'll optimize more of them.

The initial release will have high quality stereo in/out from the audio board, and lower quality mono in/out using the on-chip ADC and PWM (all can work simultaneously). It also has a minimal collection of other objects, mixers, a sine wave generator, wav file playback, a sort-of working FFT analysis, etc. Future versions will add many more objects: filters, effects like flangers & reverb, modulators, envelopes, wavetable synthesis, and an object for Teensy 3.1's built in 12 bit DAC. The infrastructure is designed with an API to allow intermediate level programmers to easily contribute data processing libraries without having to learn how the rest of the library works, especially the thorny DMA and memory management stuff.
 
The audio board will be $14.25. As soon as I get the test fixture fully checking all 4 output connections, we'll be selling them. Should be sometime this week.

The library will be released within 24 hours of the first sale. The first release will have a pretty basic collection of objects. More will be added in the coming weeks....
 
I look forward to seeing this and contributing. The component/connection design is the backbone of the Max/MSP, PD and related languages which were derived from the unit generator idea
that Max Mathews pioneered at the beginning of computer music. Amar Chaudhary did a wonderful C++ implementation of this a few years ago called OSW. It has too many
dependencies to port to teensy but you might find some useful code for the algorithms in the middle of it: http://osw.sourceforge.net.

In anticipation of good audio on the Teensy 3.0, I have been studying what it takes to port some of our floating-point music DSP code to integers.
Cortex M4 has a nice multiply/add architecture with support for wide
accumulation (64-bit) so if you are careful you can actually do better than single precision floating point for recursive filters. However it can be really challenging
to feed the operands to the ALU at the rate it can do the math. Here is a survey of useful techniques: http://www.arm.com/files/pdf/dspconceptsm4presentation.pdf
In my experience, one technique in particular, loop unrolling (and the related loop inversion), can lead to dramatic performance gains.
I am used to writing the code so the compiler can do unrolling for me. I tried turning that optimization switch on and got an error. I will eventually file
a bug report on this when I have a simpler test case. I mention it to encourage people to be a little wary of the compiler optimizer as code correctness sometimes suffers.
If you experience something unusual, recompile without optimization!
 
Wow, not what I expected, and very cool! I hope I can contribute what I've learnt over the past few years! MaxMSP for hardware :D I'm in the UK so I might have to wait a while longer... Is the schematic very similar to the one on the SGTL5000 datasheet?
 
Well, shit.

As soon as the Teensy 3.1 came out I snapped one up immediately because I saw it had a built in DAC. My intention was to design a board for it with an SD card, a line out, and a spot to connect an electret mic preamp module. That's why I've been asking questions about what analog reference the DAC uses and how to adjust that. I haven't even powered the board up yet because I've been working for a week on the PCB layout:



Since I'd already designed an arduino variant that integrated an SD card, DAC and line out, with a customized version of WaveHC for playing audio, this was gonna be a piece of cake, and I had my breadboard with a 3.5mm jack and SD card all ready to go.

I saw you were working on a sound board shortly after I began, but the prototype looked rather large and didn't appear to be designed to sit under the teensy, so I figured my much smaller board, which wasn't going to play mp3s or have an amp would find its own niche. And I needed a very small board anyway, since I want to put these things in handheld devices. Primarily I was designing it for my own use. Being able to sell it was just a bonus.

Oh well. I'm not complaining. Saves me a ton of work. I just wish I hadn't just spent $90 on a couple gravitech mp3 modules and a nano for another project that I could not delay for a month while I finished up my own daughterboard, cause it sounds like I have a new favorite sound module.
 
Anyway, as soon as you put those up for sale, I'll definitely grab one. I assume it can seamlessly transition from one sound to the next?

Also, I see mention of a "mixer". Can you play multiple sounds at the same time? If so, that's fantastic.
 
My intention was to design a board for it with an SD card, a line out, and a spot to connect an electret mic preamp module.

You certainly still can. A smaller, very low cost board might be quite nice for some uses.

Also, I see mention of a "mixer". Can you play multiple sounds at the same time? If so, that's fantastic.

Yes, multiple sounds can be played simultaneously, of course with the caveat that your SD card must be able to keep up. Most cards probably can. The SD library also has some slowness. I spliced in the newest sdfat SPI code to the SD lib, which helps speed things up. But there's nothing Teensy can do about really crappy SD cards with high latency for non-sequential reads. Genuine Sandisk cards seem to be among the best.

The library is capable of so much more than just playing files from SD cards....
 
Just wanted to chip in and say that this board is *exactly* what I was looking for. Just got the Teensy 3.1 in the mail yesterday, very quickly got it to play some MIDI notes over the internal DAC (literally 60 minutes of work, awesome) and went looking for a nice stereo I2C DAC. Then found this and the original thread. Hurray!
 
I assume the 3.5mm jack can be used as a line out to an amplifier? The datasheet seems to indicate that it can be.
 
Posted an update on the main audio thread.

You can use the headphone output as a line out if you AC couple the signals, or Teensy's power+ground are isolated. The headphone "ground" is actually 1.575 volts DC relative to Teensy3's ground.

The 9 pins at the top of the board have actual line level input and output.
 
Did you design the pins at the top for the line out with a particular 3.5mm jack in mind? I can see from the PCB layout that the two pins near the edge aren't connected to anything, which suggests strain relief, but I can't seem to find a jack on Digikey which will fit.

I must say I'm a bit perplexed at the decision to include a jack for headphones instead of one for line out. A line out jack would probably be used far more often than a headphone jack will.
 
Last edited:
Did you design the pins at the top for the line out with a particular 3.5mm jack in mind?

They're meant to sort-of follow the AC97 or HD-Audio connector pinout used on PC motherboards. 4 pins are signals: line in L/R and line out L/R, 3 pins are ground, and 2 are no connection.

I must say I'm a bit perplexed at the decision to include a jack for headphones instead of one for line out. A line out jack would probably be used far more often than a headphone jack will.

So many trade-offs.

I really wanted a headphone jack to make it easy to use casually. Pretty much everyone has headphones, which you can just plug in to listen to the sound and hear if the board is working.

Feedback from several people indicated line in/out would usually involve soldering wires to a front panel or some other board. I really did consider adding more jacks, RCA or headphones, but ultimately small size and lower cost won over convenient jacks.

Certainly other designs are possible. I'll almost certainly try an "audiophile" board (very high quality DAC & output filters) at some point, but odds are it will be only a published design and OSH Park shared board. If you've got other ideas, I'd like to encourage you to give them a try. PCB prototypes are so easy and cheap now with OSH Park. In the next several days I'll be updating the website with info about the audio board and library. The I2S interface is just a few pins and it runs in MCLK-master, 256Fs mode which is by far the most widely supported by virtually all audio DACs.


BTW: I posted an update on the other main audio thread. The boards are now in stock. We'll begin shipping either today or Monday (depending on a number of non-technical details that are in Robin & Erin's hands at this point).
 
Status
Not open for further replies.
Back
Top