Skip to content

Instantly share code, notes, and snippets.

@thewestwind
Created February 20, 2015 02:15
Show Gist options
  • Save thewestwind/11af4db4e040f663278a to your computer and use it in GitHub Desktop.
Save thewestwind/11af4db4e040f663278a to your computer and use it in GitHub Desktop.
Creates a WAVE file which contains just silence. Woo.
;; -*- asm -*-
;;
;; Some ugly cruft:
%ifndef HZ
%define HZ DEFAULT_HZ
%warning No -DHZ=
%endif
%ifndef CHANNELS
%define CHANNELS DEFAULT_CHANNELS
%warning No -DCHANNELS=
%endif
%ifndef BITSPERSAMPLE
%define BITSPERSAMPLE DEFAULT_BITSPERSAMPLE
%warning No -DBITSPERSAMPLE=
%endif
%if BITSPERSAMPLE == 8 || BITSPERSAMPLE == 16
%define BYTESPERSAMPLE BITSPERSAMPLE / 8
%else
%error FIXME: Strange -DBITSPERSAMPLE=, is BITSPERSAMPLE (use 8 or 16)
%define BYTESPERSAMPLE 0
%endif
%ifndef DURATION
%define DURATION DEFAULT_DURATION
%warning No -DDURATION=
%endif
%if DURATION < 500
%define UNIT seconds
%else
%define UNIT milliseconds
%endif
%warning Settings: HZ Hz, CHANNELS Channel(s), BITSPERSAMPLE Bits/Sample, DURATION UNIT
%undef UNIT
%if DURATION < 500
%define NUMERATOR_DURATION DURATION
%define DENOMINATOR_DURATION 1
%else
%define NUMERATOR_DURATION DURATION
%define DENOMINATOR_DURATION 1000
%endif
%if CHANNELS > 2
%fatal FIXME: #Channels: CHANNELS > 2, needs some mapping
%endif
;; Creates a WAVE file which contains just silence. Woo.
;;
;; Command line:
;;
;; nasm -f bin -o SILENCE.wav Gensilence.asm
%define DEFAULT_HZ 48000
%define DEFAULT_CHANNELS 2
%define DEFAULT_BITSPERSAMPLE 16
%define DEFAULT_DURATION 5 ;seconds
%include "config.inc"
%macro crlf 0
db 13, 10
%endmacro
;; WRITE THE RIFF HEADER:
riff_header:
db 'RIFF'
dd _end - _start
_start:
db 'WAVE'
;; WRITE THE FORMAT CHUNK:
fmt_chunk:
db 'fmt '
dd .end - .start
.start:
dw 1 ;wFormatTag, 1=PCM
dw CHANNELS ;wChannels
dd HZ ;dwSamplesPerSec
dd HZ*CHANNELS*BYTESPERSAMPLE ;dwAvgBytesPerSec
dw CHANNELS*BYTESPERSAMPLE ;wBlockAlign, i.e. the frame size
dw BITSPERSAMPLE ;wBitsPerSample
.end:
;; WRITE SOME JOKE JUNK CHUNK:
dave_chunk:
db 'DAVE'
dd .end - .start
.start:
crlf
crlf
db 'In deinem Haus cruist ein Creeper herum, '
db 'ich glaub er sucht dich :)'
crlf
db '-- brought to you by Dirty Dave/thewestwind'
crlf
crlf
align 2, db 0
.end:
;; WRITE THE ACTUAL SAMPLES:
data_chunk:
db 'data'
dd .end - .start
.start:
times NUMERATOR_DURATION * (HZ * CHANNELS * BYTESPERSAMPLE) / DENOMINATOR_DURATION db 0
.end:
_end:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment