What is a really simple audio file format?

Leros

Lifer
Jul 11, 2004
21,867
7
81
I'm making a really simple audio device for a lab. The extra credit is to make it play music, but I only have around 10KB of room to store data for the song. I'd like to find some pre-existing files so I can have a more complex song, but I don't want to have create it myself for sake of my sanity. Right now my program basically takes in a series of notes and outputs the correct frequencies, but I can make some changes.

What is a good simple file format? I almost want something that could easily be converted to sheet music.

 

Leros

Lifer
Jul 11, 2004
21,867
7
81
Is there anything simpler than that?

I'm reading the specs for it and it still seems to have way too many options.
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Midis are pretty basic and are fairly standard too. There are two different kinds of audio files really, ones that actually store waveform data(uncompressed like a .wav, or compressed like .mp3) and ones that store instructions on how to create the waveforms(like midis).

So given that, midis won't be able to reproduce music anywhere near the capacity of what a waveform file can store. It's also obvious from the file size. A typical mp3 file of an average song from a CD could be anywhere from 3-10MB, depending on quality settings. Midis are usually 2 orders of magnitude smaller, which is needed given your constraint size.

All that being said, I'd suggest a simple custom file format. All you need in order to play music is a sequence of frequencies and durations, assuming you only have instrument playing and only need 1 tone played at the same time. You've already stated that you have a working device based on that, so the next step would be to allow multiple instruments to be played at the same time. Depending on your device(assuming it's hardware based) you would be limited to whatever the audio processor on the board can do. You can see where I'm going here, it quickly gets complex. In the end, coding a midi file interpreter will be complex, but so will writing a custom format.

My final advice would be to lay out exactly what features you want from the player, and determine whether or not it will be easier to write something from scratch or whether or not it will be easier to write a simple midi file parser.

Another note is that most older phones, and still most newer phones use midi files for their ringtones.

 

SonicIce

Diamond Member
Apr 12, 2004
4,771
0
76
Individual midi files are around 5-50KB. You need more than that to make sound, though. The total size of the wave samples on the sound card can be between 2-8MB. Thats for wavetable synthesis. I'm not sure how much space FM synthesis takes up, but my guess is alot less.

I have no idea how you could make a device to play music, though. Maybe like find some sort of chip that makes a song out of beeps like those greeting cards with music. Go buy one and take it apart and see how it works.
 

Leros

Lifer
Jul 11, 2004
21,867
7
81
Thanks for the advice Crusty. This is a pretty primitive device. All I have is a 4-bit DAC to play with. My plan is to create table of frequencies and durations, then step through that. I know I'm not gonna be making any great sounds, but I was hoping to get a table a bit more precise than what I could make from sheet music.

One of my thoughts was to write some really simple recording software that reads from my ADC at 44.1kHz and use that to build up my own table from that, but I'd rather use pre-existing data if possible.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
You don't want simple, you want small :). In audio that means low-resultion. So either a combination of Crusty's idea with very low-res samples, or some low-res PCM data in .wav format. I don't know what you can actually fit into 10k, but when I say low-res I mean really low res. Problem is that the smallest sample supported by modern formats is 8-bits. Even at 5.5 khz (the lowest sample rate most of them support) that's 115k or so for 30 seconds worth. If you could gin up a teeny codec to play 4-bit samples at 5.5 khz then you could get it down to maybe 50k.

http://www.site4sound.com/encyclopedia/lr.html

You ought to hunt around for code to play music through the onboard PC speaker. Tricks like that were popular fifteen years or so ago.
 

Leros

Lifer
Jul 11, 2004
21,867
7
81
I think I have more space than I thought I did. I'm not entirely sure what my limitations on this processor are, but I have about 48,000 bytes to play with. Thats 96,000 4 bit samples. That would be roughly 17 seconds of 5.5kHz audio. Now I just need to see if I can find an easy way to convert some kind of file into the data form I need.

 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Just a warning is that if you plan on loading waveforms onto the chip, music on a very low resolution will sounds horrible so be very careful on the type of music you pick.
 

Leros

Lifer
Jul 11, 2004
21,867
7
81
Originally posted by: Crusty
Just a warning is that if you plan on loading waveforms onto the chip, music on a very low resolution will sounds horrible so be very careful on the type of music you pick.

Is a 4-bit dac even worthy of trying to do pcm/wav style data?

I guess it won't be too hard to write the code to find out. The hard will be making the 4-bit data. I have to write a conversion program.
 

Crusty

Lifer
Sep 30, 2001
12,684
2
81
Check out Audacity, it should be able to do the conversion simply and it's free :)
 

degibson

Golden Member
Mar 21, 2008
1,389
0
0
This sounds like an awesome project. It looks like you're on the right track with the table-of-frequencies-and-durations approach. Alas, I've never heard a 4-bit DAC used in this way, so I cannot comment on the end sound quality. I did once hear a 1-bit DAC that was playing an MP3 -- singing could be heard, though the white noise was terrible. I think if you stick to pure tones you should be OK.
 

Leros

Lifer
Jul 11, 2004
21,867
7
81
I ended up writing a program in java that takes an 8-bit stereo 44.1kHz wav file and outputts my own homebrewed 4-bit mono 5500Hz wav form. It discards every other sample to make it mono, then it only read every 8th of the remaining samples to get it down to 5500Hz. I took the 8-bit sample and discarded the lower 4-bits. I then packed two 4-bit samples in every byte to double my storage capacity. I had it output in a list of assembly code byte allocations so I could copy and paste it into my assembly file.

My program to play it back is very simple. Every 1/5500 seconds, it reads in a sample and oututs it to the DAC. I was able to fit 15 seconds of audio in the 46,000 bytes i had to play with. It doesn't sound great, but it sounds ok. The song I converted was originaly midi, so it wasn't too complicated. I'll try it out later with some more complex sounds, but now I need to go turn it in.

I know a pure wav form is a bad way to do this. I really wanted to convert a midi file into a list of frequencies and durations but I don't have time to figure out how to write that conversion. Plus my playback is more complicated because I would need to figure out how to combine multiple frequencies at runtime.