Permalink
Browse files

init white noise

  • Loading branch information...
jfo committed Oct 10, 2016
1 parent eac2040 commit cf20c195d94a01b0edf70ef21d10118d39e977a2
Showing with 68 additions and 1 deletion.
  1. +23 −0 Cargo.lock
  2. +1 −0 Cargo.toml
  3. +44 −1 src/main.rs

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -4,3 +4,4 @@ version = "0.1.0"
authors = ["Jeff Fowler <jeffowler@gmail.com>"]

[dependencies]
rand = "*"
@@ -1,6 +1,49 @@
use std::io::{ stdout, Write };
extern crate rand;

#[allow(unused_must_use)]
fn main() {
stdout().write(b"hi mom");

// ChunkId
stdout().write(b"RIFF");

// ChunkSize = 36 + subchunk size 2
stdout().write(&[ 0x68, 0xac, 0x00, 0x00 ]);

// Format
stdout().write(b"WAVE");

// Subchunk1ID
stdout().write(b"fmt ");

// Subchunk1size
stdout().write(&[16, 0, 0, 0 ]);

// AudioFormat
stdout().write(&[ 1, 0 ]);

// Numchannels
stdout().write(&[ 1, 0 ]);

// Samplerate
stdout().write(&[ 0x44, 0xac, 0x00, 0x00 ]);

// Byterate samplerate + num of channels * bits per sample /8
stdout().write(&[ 0x44, 0xac, 0x00, 0x00 ]);

// blockalign
stdout().write(&[ 1, 0 ]);

// bitspersample
stdout().write(&[ 8, 0 ]);

// subchunk2 id
stdout().write(b"data");

// subchunk2size == numsamples * numchannels * bitspersample / 8
stdout().write(&[ 0x44, 0xac, 0x00, 0x00 ]);

for x in 0..44100 {
stdout().write(&[ rand::random::<u8>() ]);
}
}

0 comments on commit cf20c19

Please sign in to comment.