Audio Format For Trellis M4

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
randomhacksdrc
 
Posts: 41
Joined: Thu Feb 11, 2016 11:51 am

Audio Format For Trellis M4

Post by randomhacksdrc »

The Trellis M4 shipped with a nice little demo with 4 voices (wav format) and a nice little function called parse_wav

When you run voice01.wav through the parse_wave function you get the following output. Note I added a ton of print statements.

Reading file voice01.wav
('chunk_id = ', 'RIFF')
('format = ', 'WAVE')
('subchunk1_id = ', 'fmt ')
('subchunk1 size = ', 16)
('audio_format = ', 1)
('num_channels = ', 2)
('sample_rate = ', 22050)
('bits_per_sample = ', 16)
('subchunk2_id = ', 'data')
{'channels': 2, 'sample_rate': 22050, 'data_size': 61316, 'num_samples': 30658}

I'm trying to make my own little beat box machine so I downloaded a bunch of .ogg files. I scoured the ffmpeg documentation and arrive at this command to convert an ogg to wav in the required format that the trellis requires. You'll notice I have the channels set to 2, with 16 bit uncompressed at 22050 Hz.

ffmpeg -i 'Future_Beat/Drums Hey.ogg' -acodec pcm_s16le -ac 2 -ar 22050 'Future_Beat/Drums_Hey.wav'

Problem is when I run this converted wav file through the parse_wav function I get the following output

('chunk_id = ', 'RIFF')
('format = ', 'WAVE')
('subchunk1_id = ', 'fmt ')
('subchunk1 size = ', 16)
('audio_format = ', 1)
('num_channels = ', 2)
('sample_rate = ', 22050)
('bits_per_sample = ', 16)
('subchunk2_id = ', 'LIST')

The code breaks at that point because the subchunk2_id is LIST not data. I looked at some documentation for WAV RIFF files and I'm in way over my head. Does anyone know how to make the proper wav files to play on the Trellis??

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Audio Format For Trellis M4

Post by adafruit_support_mike »

We have a tutorial on doing file conversions here:

https://learn.adafruit.com/microcontrol ... conversion

User avatar
randomhacksdrc
 
Posts: 41
Joined: Thu Feb 11, 2016 11:51 am

Re: Audio Format For Trellis M4

Post by randomhacksdrc »

Awesome so it definitely works using Audacity the problem is you have to open up one file at a time. To get around that you can create a Chain by going into File>Chains>Edit Chains...

From there you can have the Chain be to just convert the audio files to WAV. The default conversion in Audacity is 16 Bit PCM 44100 Hz. So I used python and a for loop to convert all my ogg files to 22050 Hz using the command below. Looping this in python is pretty simple and it makes an entire folder of wav files in almost the right format but it's at least at the right bitrate.

ffmpeg -i 'Future_Beat/Voice Days.ogg' -ar 22050 'Future_Beat/FFMPEG/Voice Days.wav'

Once you have a folder of all these files you can open up Audacity and click File>Chains>Apply Chains.... Then you just select every single file you want and it will do a batch conversion and create a folder called 'cleaned/'. The files in here open up just fine.

Thanks for the help! Hopefully something finds this instead of manually converting over 50 audio files. Batch scripts ftw!

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: Audio Format For Trellis M4

Post by adafruit_support_mike »

Glad to hear you got things working, and thanks for the info about batch-processing files. I'm sure someone will find that useful!

Locked
Please be positive and constructive with your questions and comments.

Return to “AdaBox! Show us what you made!”