Audio Library

Status
Not open for further replies.
@Paul:
I might as well make my current flash code available to you and everyone.
It has been in this state for a couple of weeks because I've got a new toy to play
with that has seriously distracted me from this.
The basic library code in flash_spi.cpp is just a collection of C functions rather
than a proper library object but perhaps it would work for you as the basis of a proper library.

I've uploaded the current version of my library for flash and some examples to:
http://members.shaw.ca/el_supremo/flash_distrib.zip

It works with the most recent version of Audiomaster on Paul's github site.
https://github.com/PaulStoffregen/Audio

There is a "samples" directory in the archive which contains the list of WAV
files that I've been using. The files which have _11 in them are sampled at
11025Hz instead of 44100Hz and won't play (haven't figured out why
yet) but they are included just in case I figure them out. All of them were
downloaded from free websites.
Copy them to the root directory of a uSD card.

The example sketches, in the order that you should try them, are:

flash_test
- this just tests access to the chip through the library. If this fails, you've got
problems

flash_wav_write_file_list
- this ERASES the entire chip and then writes a list of named WAV files from
the uSD card to the flash chip. The list of files in this example are all in
the root directory of the uSD but they don't have to be.
Each file is written to the flash and then one more block containing only the
file's name is added on the end. This is how flash_wav_play_file finds the files
by name.

flash_wav_play_file
- this plays one named file from the flash. At the moment it must be a stereo
file recorded at 44100Hz (so the files with _11 in them won't play)

flash_wav_dump_flash_header
- dumps a list of the files in flash that were written by flash_wav_write_file_list
with their start and ending page numbers

record_flash_linein
- records the line input in stereo as a WAV file for a specified period of time and writes the
given file name at the end so that it can be played by name with flash_wav_play_file

Gimme a yell if you have any questions.

Pete
 
Hi Pete

Thought I'd start with the flash_test.ino sketch... but there's an #include <flash_spi.h> - and the .h file isn't in the flash_distrib folder...

I can see it's required for the flash_wav_dump_flash_header.ino sketch too... haven't looked further.

Prodical
 
I don't know what's wrong there. I've downloaded it twice here and both winzip and windows explorer unzip it just fine. Can you try the original file again?
http://members.shaw.ca/el_supremo/flash_distrib.zip

I'm on OS X... sorry... should have mentioned that...

I'm getting that error on two machines... and the original file is still fine... but I managed to extract it on a Windows 7 virtual machine... though even then it had issues with extracting the audio files which I was able to skip. So I have the missing file now... will try it and let you know. Thanks Pete...

Prodical
 
I don't know what's wrong there. I've downloaded it twice here and both winzip and windows explorer unzip it just fine. Can you try the original file again?
http://members.shaw.ca/el_supremo/flash_distrib.zip

Getting a different compile error now:
"In file included from /Users/Shared/AllUsers/Arduino/Sketchbook/libraries/flash_distrib/record_flash_wav.cpp:23:0:
/Users/Shared/AllUsers/Arduino/Sketchbook/libraries/flash_distrib/record_flash_wav.h:28:22: fatal error: soundhdr.h: No such file or directory
compilation terminated."
 
Dear all,

i need a USB(or SPI) to I2S slave converter, what can do 192kS/24bit. Can i use the Teensy 3.1 for that? The conversion USB(or SPI) to I2S should mainly work with DMA, best would be a DMA from USB to a ring buffer, and a DMA from the ring buffer to the I2S hardware. If using USB as host interface, is there an UAE2 USB host available in Teensy? That would remove the need for me to write a Linux device driver. Has anybody a similar setup running?

Thanks,
Iwan
 
i need a USB(or SPI) to I2S slave converter, what can do 192kS/24bit. Can i use the Teensy 3.1 for that?

In theory, maybe. In practice, this would requires a lot of difficult software development.

There is a DMA-based audio library in public beta testing, using 44100 Hz 16 bit sampling, so at least that part is started. There's some initial work (elsewhere on this forum) at USB audio (acting as a USB device, not host), but not anything usable yet.
 
@prodical
Were the missing includes in Audio.h?

I have modified record_flash_line so that it writes the filename on the end and then it writes the recording to the uSD card. I'll update the zip sometime today and post a new version.
But, I've run into a problem with recording. When I first wrote the record sketch, I am sure I was able to record glitch-free for 90 seconds (filled the flash). But now even short recordings have lots of glitches in them. I can't figure out if the previous recordings were a statistical fluke or I've since changed something for the worse.

Pete
 
I have deleted the flash zip files from my web page because last night I tracked down where I got the audio samples from and my memory is faulty. They are free for personal use but redistribution is not allowed. If you have downloaded my flash code, please delete the samples directory. You can download the samples yourself, although what I distributed was a modified version of the original, usually increasing the amplitude and sometimes cropping part of the sample out:
beep1 http://www.mediacollege.com/downloads/sound-effects/beep/
lasers 1 and 3 http://www.mediacollege.com/downloads/sound-effects/alien/
bomb6 http://www.mediacollege.com/downloads/sound-effects/explosion/
phone http://www.mediacollege.com/downloads/sound-effects/electronics/phone/
alien144 http://www.mediacollege.com/downloads/sound-effects/alien/
I can't find the doorbell sample on mediacollege but please delete it anyway until I am sure of its status.

I'll post a new version of the flash zip file later today and if/when I find "really free" replacement samples I'll add them to the archive.

Pete
 
I've uploaded a new version of my flash code. The samples directory has been removed and I've added a Flash_README_FIRST.txt file which shows the four #includes that you must add to Audio.h
http://members.shaw.ca/el_supremo/flash.zip
Only other change is an updated version of record_flash_linein which now writes the recorded file to the uSD card.
BTW: this sketch can also record and save in mono. See the define of MIX_TO_MONO.

Pete
 
I've uploaded a new version of my flash code. The samples directory has been removed and I've added a Flash_README_FIRST.txt file which shows the four #includes that you must add to Audio.h
http://members.shaw.ca/el_supremo/flash.zip
Only other change is an updated version of record_flash_linein which now writes the recorded file to the uSD card.
BTW: this sketch can also record and save in mono. See the define of MIX_TO_MONO.

Pete

I can confirm the record_flsh_linein.ino sketch is working fine for me. Not actually reading the Flash_README_FIRST.txt file I added the following includes to the top of the sketch. ;-)

#include <flash_spi.h>
#include <record_flash_wav.h>

Just a note that for one or two of the other examples - I can't quite remember which sorry... I also had to add #include <soundhdr.h> - and that isn't mentioned in your text file...

Saving to SD card was something I really wanted... so many thanks for adding that.

Is it actually necessary to bulk erase the chip before each recording? Could you do this during startup, start each successive recording from an empty 'page' and then occasionally bulk erase as a background task? I'm just trying to minimise the time it takes to record for user interaction purposes...

Prodical
 
Dear all,

i need a USB(or SPI) to I2S slave converter, what can do 192kS/24bit. Can i use the Teensy 3.1 for that? The conversion USB(or SPI) to I2S should mainly work with DMA, best would be a DMA from USB to a ring buffer, and a DMA from the ring buffer to the I2S hardware. If using USB as host interface, is there an UAE2 USB host available in Teensy? That would remove the need for me to write a Linux device driver. Has anybody a similar setup running?

Thanks,
Iwan

I'm fairly sure that, when I can find the time, I can make (the control_sgtl5000 member of the) library Paul mentioned basically allow end users to use all of the sampling rates the SGTL5000 is capable of;
SGTL5000.pdf said:
The device supports 8.0kHz, 11.025kHz, 16kHz, 22.05kHz, 24kHz, 32kHz, 44.1kHz, 48kHz, 96kHz sampling frequencies.
But the SGTL5000 itself isn't capable of 192Ksps and there is little likelihood of me trying to make any of the changes necessary to make it do 24 bit samples instead of 16 bits. Making the whole library work at all the sample rates might be uglier than I have time for.

The TLV320AIC3254 (and others in its series) is capable of 192Ksps; trick Paul into making an Audio Adapter Mark II using that one (or similar) and there is an OK chance I can help support it because my employer is making me do some closed source stuff for it for them atm.
 
Is it actually necessary to bulk erase the chip before each recording? Could you do this during startup, start each successive recording from an empty 'page' and then occasionally bulk erase as a background task? I'm just trying to minimise the time it takes to record for user interaction purposes...

I've checked the sketch... it does only happen during startup... my bad. More haste... less speed...
 
The record flash sketch, like the rest of the code, is still in development phase.
It always erases the chip before recording. I will look at changing it to append to the existing files in the flash. That would require a separate sketch which only erases the chip.
If you add the includes to Audio as described in the readme, you should not need to include soundhdr.h. Let me know if they are still required and I'll try to figure out why.

Pete
 
The record flash sketch, like the rest of the code, is still in development phase.
It always erases the chip before recording. I will look at changing it to append to the existing files in the flash. That would require a separate sketch which only erases the chip.

I do understand the code is in development...

If you could look into 'appending to the existing files in the flash' and saving each new file to the uSD that would be much appreciated... it's the functionality I'm aiming for...

I'll add the includes as you suggest.

Prodical
 
But the SGTL5000 itself isn't capable of 192Ksps and there is little likelihood of me trying to make any of the changes necessary to make it do 24 bit samples instead of 16 bits. Making the whole library work at all the sample rates might be uglier than I have time for.

Requests for 24 bits and fast sample rates are something I've expected to start hearing more and more as this library becomes more widely known and used.

I'm certainly not going to touch 24 bits until after a 1.0 release, but I have put a little thought into it. Here's my current thinking on 24 bit support... which could be subject to change, so don't take this as a iron-clad technical requirements spec.

Internally, I'm imagining objects that support 24 bits will provide a pair of inputs or outputs for each audio channel, one for the upper 16 bits and the other for a lower 16 bits. It's up to the object if it wants to process 24 or all 32 bits, but the library would retain all of its current structure, but just pass two 16 bit streams for the cases where higher resolution is used. Any 32 bit object would just consider the lower 16 bits to be all zero if nothing is connected to the 2nd input. Any 32 bit output could feed into any 16 bit object by simply not making a connection to it's 2nd output port. This approach requires no structural changes to the library, so it's "easy" (except for the part of actually writing those higher res objects).

I believe a 24 bit version of the I2S objects should be relatively straightforward. Of course, this may be a case of "the devil is in the details", but the hardware claims to support it and my understanding is a slightly different config and double size buffers and 32 bit DMA should do the job. The SGTL5000 can be used for testing, even though it's pointless to send more than 16 bits to it (but most of this 24 bit stuff is pointless anyway, other than the fact it makes people happy, which is really all that matters....)

How many non-I/O objects ever get created for 32 bit resolution is a good question. The most I see myself ever doing would be WAV player, fader and mixer. Well, an insanely pure sine wave might get created too, but mostly for testing, since the lookup table will probably fill most of Teensy 3.1's program space. Or course, contributions are welcome, if anyone wants to create high res objects.

For I2S master mode, or any use involving the on-chip DAC, ADC and PWM, we're very tightly locked into 44.1 kHz. Or 48 MHz divided by 1088 to be precise. Any other sample rate will need to use I2S slave mode, and will be incompatible with the on-chip I/O objects. If any audiophiles are reading this, designing a PCB (shared at OSH Park) with a high-end DAC and 24.576 crystal oscillator (no PLL, direct from a crystal+amplifier) for MCLK would a necessary step if we're ever going to even try to support such sample rates. A DAC with 120 dB SINAD would also be encouraging, so at least 4 of those extra bits might mean something....

My hope is anyone asking about 24 bit support and high sample rates will find this message. Maybe it should become its own thread? I'm certainly not planning work on any of this soon, and certainly not at all before a 1.0 release. But I did want to take a moment to share my thoughts on how this can eventually happen, especially for anyone who might want to actually work on 24 bit support and submit a pull request (hint, hint...)
 
Status
Not open for further replies.
Back
Top