x86 machine code (.COM file): 121 120 113113 109 bytes
00000000 b4 3e bb 01 00 cd 21 b4 3c 31 c9 ba 403e 01 cd 21 |.>....!.<1..@>..!|
00000010 424a b4 09 cd 21 be 5a56 01 818a fe0c 7146 01e8 0f0c 8400 e0b1 fe32 |B|J...!.Z.V..q.F....|2|
00000020 8a 0c 46 e8 07 00 b181 32fe 6d e801 0275 00 ebef ebc3 88 cb c0 e3 07 c1 |..F...m.2u........|
00000030 e3 07 c1 e1 04 30 d2 b4 02 00 da cd 21 e2 fa c3 2e 73 6e |.....0......!...|.sn|
00000040 61 2e 73 6e 64 00 00 00 18 ff ff ff ff 00 00 00 02 00 00 |a10 |d.snd..............|
00000050 02 00 00 10 00 00 00 00 01 24 33 33 99 99 99 66 99 99 99 99 |.....$33...f.$33...f||
00000060 99 99 99 99 99 66 33 99 99 99 99 66 33 33 33 33 |.....f3....f3333|
00000070 33 33 |3||.f3....f33333|
0000006d
Can be easily run under DosBox; the output is a .SND file.SND file named a.sndSND
. Here is a FLAC version of its output (and here the .COM file).
org 100h
start:
; close stdout
mov ah,3eh
mov bx,1
int 21h
; open a.snd
mov ah,3ch
xor cx,cx
mov dx,filename
int 21h
; write the header
inc dx
; we used the mov`snd` ah,9h
part of the header intas 21h
file name, back off movone si,data
.l:byte
; data readdec cycledx
; quit ifmov weah,9h
reached the end ofint data21h
cmpmov si,eofdata
.l:
je; 0data read cycle
; read the current byte in cl (zero-extending to 16-bit)
; notice that ch is already zero (at the first iteration it's 0 from the
; int 21h/3ch, then we are coming from gen, which leaves cx to zero)
mov cl,[si]
; move to next byte
inc si
; generate the tone
call gen
; generate the pause
mov cl,50
call gen
; rinserepeat anduntil repeatwe reach the end of data
jmpcmp si,eof
jne .l
; quit
ret
gen:
; generate a sawtooth wave at sampling frequency/2 Hz
; receives length (in samples>>4) in cx, with lowest bit indicating if
; it has to write a wave or a pause
mov bl,cl
; shift the rightmost bit all the way to the left; this kills the
; unrelated data and puts a 128 in bl (if cx & 1 != 0)
shl bl,7
; rescale the samples number
shl cx,4
; zero the starting signal
xor dl,dl
; prepare the stuff for int 21h
mov ah,2h
.l:
; increment the signal
add dl,bl
; write it
int 21h
; decrement iteration count and loop
loop .l
ret
; here be the data
; used for the file name; we recycle the .snd from the beginning
; of theSND file header, exploiting the fact that it comes just(8000 beforesamples, amono, zeroPCM)
filenameheader:
db "a"
header:"."
; .SNDwe filealso headeruse (8000"snd" samples,as mono,the PCM)file name
filename:
db ".snd""snd",0,0,0,24,0xff,0xff,0xff,0xff,0,0,0,2,0,0,0x10,0,0,0,0,1
; terminator for int 21h/ah=9h
db '$'
data:
; generated by gendata.py
incbin "data.dat"
eof: