Skip to content

Latest commit

 

History

History
83 lines (58 loc) · 8.92 KB

README.md

File metadata and controls

83 lines (58 loc) · 8.92 KB

blip

Small C library for sound synthesis of MML (Music Macro Language) strings. MML is a simple language for describing music, often used in old video games.

blip implements a subset of MML and is good enough to play simple tunes. It is designed to be small and portable, so it can be used in embedded systems. There are no external dependencies, dynamic allocations or floating point operations.

However, it is not an audio library. It does not provide any means of playing the generated sound. You only get a stream of samples. It is up to you to play them using whatever audio API you have available.

MML syntax

Following is a list of supported MML commands. All commands are case-insensitive, whitespace is ignored.

cdefgab - notes C, D, E, F, G, A, B. Appending + or # makes the note sharp, appending - makes it flat. Note duration can be specified by a number (1-255) following the note. The number represents a fraction of a whole note. For example, c4 is a quarter note, c8 is an eighth note, c16 is a sixteenth note, etc. Note commanfa h is interpreted as b.

o - octave, followed by a number (0-7). Sets the default octave for all upcoming notes.

p or r - pause or rest. Pauses are treated as notes with zero frequency.

l - length, followed by a number (1-255). Sets the default note length for all upcoming notes.

t - tempo, followed by a number (32-255). Sets the tempo in beats per minute. Default is 120.

v - volume, followed by a number (0-15). Sets the volume for all upcoming notes. Default is 15.

< or > - step down or step up the octave. Changes the default octave for all upcoming notes.

& - tie. Makes the previous note last longer. For example, c8 & c8 plays a single quarter note.

. - extend length by half of the previous length. For example, c8. is same length as c8 & c16. If used multiple times, c8... is same as c8 & c16 & c32 & c64.

Examples

George Michael – Careless Whisper MP3

t100l32aa+>cdl8ed16<af>e.d16<af.b+a+16fdb+.a+16f3a+a16fd<a+2aa+>cdefga

Für Elise MP3

t100l16>ed+ed+ec-dc<a8rceab8reg+bb+8re>ed+ed+ec-dc<a8rceab8rdb+ba8rb>cde8.<g>fed8.<f>edc8.<e>dc<br8r>er8r>er8<d+er8d+ed+ed+ec-dc<a8rceab8reg+bb+8re>ed+ed+ec-dc<a8rceab8rdb+ba8,
r2l16<<a>ear8&r16<e>eg+r8&r16<a>ear2r<a>ear8&r16<e>eg+r8&r16<a>ear8&r16cgb+r8&r16<g>gbr8&r16<a>ear8&r16<e>e>eere>eerd+er8d+er2r<<<a>ear8&r16<e>eg+r8&r16<a>ear2r<a>ear8&r16<e>eg+r8&r16<a8

Mungo Jerry – In The Summertime MP3

t110l16b>c+e8.ee8c-c+c+<bgg+e8b>c+e8.ee8c-c+c+<bgg+e8ef+f+8.e8f+ec+f+ec+f+ec+b>c+e8.ee8c-c+c+<bgg+e8f+g+b8.bb8f+g+f+ec+f+ec+ff+e8.ee8c+c-c+<bgg+e8,r8<e8r8<b8r8>e8r8<b16r16>c+16r16e8r8<b8r8>e8r8e16r16f+16r16a8r8e8r8<a8r8a16r16>c+16r16e8r8<b8r8>e8r8<b16r16>e16r16<b8r8>f+8r8<a8r8>e16r16<b16r16>e8r8<b8r8>e8<b8e8

Game Of Thrones MP3

v120o5r1r1r1r4r8l32cdd+fg4&g16.rc4&c16.rd+16f16g8.&grc8.&crl16d+fd2&d8.r2r4rf4&f.r32<a+4&a+.r32>d+df8.&f32r32<a+4&a+.r32>d+dc2&cr2r8r16l32cdd+fg4&g16.rc4&c16.rd+16f16g8.&grc8.&crl16d+fd2&d8.r2r4rf4&f.r32<a+4&a+.r32>d+df8.&f32r32<a+4&a+.r32>d+dc4.&cr2r4r8r16>d+4&d+.r32<g4&g.r32>cdd+8.l32&d+r<g8.&grl16>cd<a+4.&a+r8r16l32dd+dcd8g8&grl16aa+8>c8d8d4&d.r32<f4&f.r32b+a+>d8.&d32r32<f4&f.r32b+a+g+2&g+r2r4r>d+4&d+.r32<g4&g.r32>cdd+8.l32&d+r<g8.&grl16>cd<a+4.&a+r8r16a8g4.&gr8r16a+>d+d4&d.r32<f4&f.l32ra+8.&a+rb+8a+8.&a+rf8g4.&l16gr1rb+8d+8g+a+b+8d+8g+b+a+8d+8gg+a+d+8g8a+g+8c8fgg+8c8fg+g8>c8d+fg8c8d+f<g+8.&g+32r32>cdd+8<g+8>dd+d+4&d+.r32f4&f.r32g4.&gr1rc8<d+8g+a+b+8d+8g+b+a+8d+8gg+a+8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ra+rd+r<ar>d+ra+rd+r<ar>d+ra+rd+r<ar>d+ra+rd+r<ar>d+ra+rd+r<ar>d+ra+rd+r<ar>d+r8.<ar8.>d+r8.<ar8.>d+r8.<ar8.>d+r8.<ar8.>d+r8.<ar8.>d+r8.<ar8.>d+r8.<ar8.>d+r8.<ar8.>d+4<g4a4>c4>c+8frfr<g8r8>frfrfrc+8frfr<g8>fr<g8>fr<g8c+4.gr2rc+4.gr8.gr4rc+8c+8c+8c+8,
l1rrrrrrrrrrrrrrl16r2r8<arar4rararar8.arar8.ar8.al1rrrrrrrrrrrrrrrrl16r4rf+rf+r4rf+rf+rf+r8.f+rf+r8.f+r8.f+

License

Unlicense / public domain / I do't care. Do whatever you want with it.

https://unlicense.org

Misc.

Frequency table

blip uses 5.27 fixed-point frequency table of the 0th octave (notes C0 to B0) to calculate frequencies of all notes. Here is the Python script used to generate it:

import math

freqs = []
for i in range(0, 12):
    f = 440 * math.pow(math.pow(2, 1.0/12.0), i - 57)
    freqs.append(int(f * (1 << 27) + 0.5 / 27))

print(", ".join("0x{:08x}".format(f) for f in freqs))