Audio Library

Status
Not open for further replies.
Also I'm getting a consistent error with examples that use the AudioSynthWaveform - I get an "'AudioWaveformSine' was not declared in this scope" message in the console. Any ideas why?

I changed the way that AudioSynthWaveform works. I've written some (small) documentation files for the classes I wrote or modified. This is the one for AudioSynthWaveform:
Code:
synth_waveform 140404
	This synthesizes a waveform of the specified type with a given amplitude
	and frequency. There are currently four types of waveform:
	#define TONE_TYPE_SINE     0
	#define TONE_TYPE_SAWTOOTH 1
	#define TONE_TYPE_SQUARE   2
	#define TONE_TYPE_TRIANGLE 3
	Sine wave generation uses the arm library's arm_sin_q15 function. This function uses
	a table lookup and cubic interpolation.
	The other three waveforms are generated directly without using table lookup.
	
boolean begin(float t_amp,float t_freq,short t_type)
	This starts generation of a waveform of given type, amplitude and frequency
	Example: begin(0.8,440.0,TONE_TYPE_SINE)
	
void set_ramp_length(int16_t r_length)
	When a tone starts, or ends, playing it can generate an audible "thump" which can
	be very distracting, especially when playing musical notes. This function specifies
	a "ramp" length (in number of samples) and the beginning of the generated waveform
	will be ramped up in volume from zero to t_amp over the course of r_length samples.
	When the tone is switched off, by changing its volume to zero, instead of ending
	abruptly it will be ramped down to zero over the next r_length samples. 
	For example, if r_length is 44, the beginning and end of the wave will have a ramp
	of approximately one millisecond.
	
void frequency(int t_freq)
	Changes the frequency of the wave to the specified t_freq. This is done in a phase-
	continuous manner which should allow generation of audio frequency shift keying and
	other effects requiring a changing frequency.
	
void amplitude(float n)
	Changes the amplitude to 'n'. If 'n' is zero the wave is turned off and any further
	audio output will be zero.

Pete
 
I've tried recording to SD from line-in (which would be same as from the mic) but haven't been able to get it to record without glitching. Maybe I'm not doing it right.

How long do you want to record?

Pete
 
I've tried recording to SD from line-in (which would be same as from the mic) but haven't been able to get it to record without glitching. Maybe I'm not doing it right.

How long do you want to record?

Pete

Maximum 10 seconds...

The device I'm making has a single button which you hold to start recording and release to stop... it also plays a random file from the SD on button press... it's quite straightforward.

I'd appreciate seeing any example code Pete - even if the result is a bit glitchy...

Prodical
 
Also does the Audio Adaptor interfere with Teensy 3.1 reset button in any way?

I seem to have lost the ability to "Please press the RESET BUTTON on your Teensy to upload your sketch. Auto-reboot only works if the Teensy is running a previous sketch."

Any advice appreciated...

Prodical
 
Maximum 10 seconds...
I'd appreciate seeing any example code Pete - even if the result is a bit glitchy...

The code I wrote/played with could not record mono for 10 seconds to the uSD card without a lot of glitches. It really isn't worth trying.
I believe there's a way to write to a uSD/SD card by just writing raw blocks directly to the card - no file system at all. It allows you to write to it faster and should allow recording glitch-free mono and perhaps stereo too. But I haven't tried it and I'm not sure it can be done on a Teensy3.x because it uses sdfatlib which I haven't been able to get working on Teensy3.x. Maybe someone else has got it working.

As I mentioned in post #493 on page 20, I have installed a W25Q128FV 16Mbyte flash chip on my audio board and have written some library code and sketches for it - some of which I have since improved. You can record up to 1.5 minutes of stereo at 44100Hz to the chip without glitching at all. The chip costs around $3.50. Before I got that chip, I played around with a M25P16 2Mbyte chip which is mostly command compatible with the W25Q128FV. The M25P16 has enough capacity for about 11 seconds of 44100Hz stereo and costs around $1.
Either chip can be breadboarded rather than soldered onto the audio board if you wish.

If you are comfortable soldering surface mount chips, I think the flash chip might be a better way to go.

Pete
 
The code I wrote/played with could not record mono for 10 seconds to the uSD card without a lot of glitches. It really isn't worth trying.

Fair enough... I understand enough to realise there'll be significant issues with managing sufficient numbers and sizes of audio buffers along with the copy speed to the uSD with the limitations of the Teensy 3.1s RAM, the access times of the uSD and switching back and forth between SPI devices...

The W25Q128FV looks the way to go... I'll order one and fit it.

Are your library code and sketches publicly available Pete? May I ask you for them once I'm ready?

Thanks for the advice.

Best

Prodical
 
They (or something else/better) will eventually make their way into the Audio library. I'll make them available to you before that if necessary.

Pete
 
I would like to see an audioEffectDelay. The ability to modulate playback frequency of tails would be desirable. I am curious as to the potential of the ram in the Teensy3.1 to support this. I am also looking at datasheets for i2c and spi ram that can take the read/write cycles in the event that the ram in the Teensy3.1 isn't enough...and to offer a solution for 3.0 users.

I apologize if there is a better way to bring this up, I'm neck deep in the learning curve.
 
A suggestion for the library:

I have an application (software defined radio) that requires separate FIR filters for left and right channels. I have it working but it looks like when you call AudioFilterFIR it automatically creates left and right filter pairs. It doesn't look like it processes both channels unless you include them both in the audio chain but its probably wasting some memory and CPU cycles. A mono filter function would be a bit more efficient in this case.

Rich
 
FIR filter optimization

Just noticed something of interest in the FIR filter processing block. There is an arm_fir_fast_q15 function in the ARM CMSIS DSP library that uses 32 bit accumulator instead of the 64 bit accumulation used in the arm_fir_q15 function that's used in the audio library now. The 32 bit accumulator means you have to pay more attention to signal levels to avoid overflows.

My test results:
two 100 tap FIR filters with the slower 64 bit version: 84% CPU utilization
same sketch with the fast 32 bit version: 18% CPU utilization

I'm going to use the 32 bit version! A quick test shows no overflow issues with the filters I'm using at fairly high input signal levels.

Perhaps some #ifdefs in Audio.h to optimize for speed vs precision ?

Rich
 
Thanks for that info Rich. I've made a mono version of the filter code. I'll look at changing it so that you can specify whether you want arm_fir_q15 or arm_fir_fast_q15.

Pete
 
Something strange happening with the FIR filter. I have set up a Hilbert Filter pair to generate a 90 degree phase difference between the two audio channels. I have confirmed that it works, and yet sometimes the filters behave as tho they are in passthru mode - no phase change. I can compile, load, and have it work, recompile with zero changes, reload and have it not work. A power cycle seems to make it work. Its behaving like there is an uninitialized variable which flips around somewhat randomly.

Thought it might be an intervening interrupt causing issues so I turned off interrupts before the filter.begin() calls and back on after - still flakey.

I haven't dug into the code yet but something looks fishy...

Rich
 
Pete - I'll PM you the Hilbert filter code. I've been trying it this morning and it works every time. Maybe something is flakey in the hardware or some code corruption in the loader? Its pretty weird.

Rich
BTW - I have a working I/Q version of the SDR RX. It uses the same Hilbert filter code but theres more stuff in the audio chain.
 
They (or something else/better) will eventually make their way into the Audio library. I'll make them available to you before that if necessary.

Pete

Hi Pete

I struggled to find a UK supplier for W25Q128FV IC - Digi-Key sold them cheaply enough but with £12 postage :-(

But I found a SPI Flash Winbond W25Q128FVSIG. (128Mbit, SOIC8) same as W25Q128FVSG on eBay from Hong Kong... and that's now mounted on my Audio Shield.

Your library code and sketches would be appreciated.

Should I PM you my email?

Best

Prodical
 
I'll package them in a zip and then PM you the URL.
This won't be the version that I upload for the library though. I am, eventually, going to fix it up a bit so that it is constructed more like the other library code. But, it should get you on your way.

Pete
 
Never found them. I would throw arbitrary files names in there, but my head infers short with the S suffix'd one and medium length with the M.

Hey Doc, my guess was 'S'tereo and 'M'ono but your guess is as valid as mine until Paul sets us straight :)

Sorry about those files: 01_16S.WAV and 01_16M.WAV. They were just some random song I had laying around. It's copyrighted music that can't be legally shared.

I started a new issue about this on github.

https://github.com/PaulStoffregen/Audio/issues/29

Does anyone know of any reasonably pleasing, good quality music files that are definitely public domain or creative commons allowing commercial use. Almost everything I've seen forbids any commercial use, which probably means PJRC can't put the on the website.

A couple years ago I learned a painful lesson about creative commons music. I made a Youtube video of projects people brought to a DorkbotPDX meetup, and I used a music file from a creative commons music site. About a year later, the video got a takedown notice. Fortunately, I still had the MP3 file and it had the URL on that website in the ID3 comment. But the link was dead. The "author" deleted his account and all record of the file being creative commons was gone. It certainly seems like it was actually a commercial file someone had uploaded and mislabeled.

I do want to find a good file to be the benchmark standard. I just want to be really sure it truly is legal for sharing and not something someone uploaded illegally.
 
I see in SD2Card.cpp that the SPI speed is initialized to its lowest value - spiInit(6) on line 430. Is that required because of some interaction in the audio library? Can it be increased without blowing something up?

The SD library configures a slow speed while initializing the card. Then it changes to a fast speed after the card it set up.

I believe this is due to some ancient recommendation to auto-detect SD vs MMC cards, where the MMC needs a slow clock during initialization. It doesn't case any harm though, other than making the SD library code a bit more confusing.
 
This is the way that i am wiring the teensy to the Pot. I am showing in a picture what is the value of the A6 in the DVM and the values with Serial Monitor.

Reading 1023 from analogRead() with 1.9987 volts means the ADC is probably configured for the internal reference. The full scale range in that mode is 0 to 1.2V.
 
This won't be the version that I upload for the library though. I am, eventually, going to fix it up a bit so that it is constructed more like the other library code.

After a delay of the last 3-4 weeks, I'm _finally_ back to work on the audio library. :)

Just send a pull request when you're ready and I'll merge it.

I'm also going to take a look at SD card recording. Maybe it's glitching when the SD library needs to allocate new FAT sectors? Maybe pre-allocating the entire file would help?
 
This won't be the version that I upload for the library though. I am, eventually, going to fix it up a bit so that it is constructed more like the other library code. But, it should get you on your way.

That's fine... will expect your PM.

Thanks so much...

Prodical
 
@Paul:
How large were those WAV files?
The speed test doesn't seem to depend upon the test files being WAV. Can you just use a pair of binary or text files for the standard test?

Pete
 
Status
Not open for further replies.
Back
Top