protodomemusic / mmml

Micro Music Macro Language - An MML Implementation for 1-Bit Music on AVR Microcontrollers
GNU General Public License v3.0
96 stars 6 forks source link

WAV type output on mmml #5

Closed pdr0663 closed 1 year ago

pdr0663 commented 2 years ago

I noticed in your code, various percussion instruments which are hard-coded.

Ignoring tempo and volume, would it be possible to encode something like a piano, where each note is encoded separately? I'm interested in this for nice quality playback, with less of a Game-Boy sound.

How would you hard-code an individual sound?

Paul

protodomemusic commented 2 years ago

Sure it's possible but, if you're doing this on a microcontroller, you'll run out of space really fast. There are also much better, more efficient, solutions to playing back samples than this engine.

If you still want to try it out, it'll take a little bit of re-coding. You'll need to change the size of SAMPLE_LENGTH definition to the total size of the sample[] array, and update the sample_index[] array to index the start of each new sample. You'll also want to change sample_index[] to const unsigned int.

Also, only 12 samples total will be addressable, as the sample is set by the note value only (see lines 355 and 356 of mmml-avr-player.c). If you want more than that, you'll have to write something that takes the octave into account.

Now comes the sample generation. This is a bit more tricky, but I can point you to the simple python script I used. It only takes 16-bit mono files - also make sure to keep the sample rate low otherwise you'll end up with absolutely huge filesizes.

If you have another solution, you just need to turn a mono audio file into a pulse density modulation (best), or pulse width modulation (fine), bitstream.


You know, now I'm revisiting this and thinking about it, I might have messed up the endianness on the percussion samples. I think each byte needs to be inverted.

protodomemusic commented 1 year ago

I spent 15 minutes writing a response angrily disagreeing with this comment before I realised I had originally written it.

This is definitely a low point in my life.