meditationatae

Just another WordPress.com site

Checking headers of new *wav file, and source code

I used the TV tuner of an old analog TV to generate 434 megabytes of white noise, in stereo audio, recorded with Audacity on Windows.
I used Winzip to zip this, and burn it to a CD using Toshiba Disc Creator. Toshibiba disc creator complained at the end (this is Windows 10) that “this was not possible and Toshiba disc creator would be terminated”, or somesuch; all indicates that this is a bogus warning (from Toshiba or Windows, whatever).
I expected this *.wav file to be in stereo which means Left and Right channels, at 16 bits for each sample on each channel, and sample 44100 times per second: this is something like uncompressed CD stereo quality (or Red Book standard).
The verification on Linux through the 44-byte Headers:

[david@localhost noise]$ ./decode01a.out

1: 82 R
2: 73 I
3: 70 F
4: 70 F

5: 36
6: 212
7: 223
8: 25

9: 87 W
10: 65 A
11: 86 V
12: 69 E

13: 102 f
14: 109 m
15: 116 t
16: 32 Space

17: 16
18: 0
19: 0
20: 0

21: 1 PCM = Pulse coded modulation = normal
22: 0

23: 2 2 channels (as expected)
24: 0

25: 68
26: 172 172*256 + 68 = 44100 = Sample Rate per second, each channel . Ok.
27: 0
28: 0

29: 16
30: 177
31: 2 2*256^2 + 177*256 + 16 = 176400 bytes/second
32: 0

33: 4 (BitsPerSample * Channels) / 8 = (16*2)/8 = 4 bytes per time-slot, Ok.
34: 0

35: 16 16 bits per sample, on each channel = Normal, Ok.
36: 0

37: 100 d
38: 97 a
39: 116 t
40: 97 a

41: 0 25*256^3 + 223*256^2 + 212*256 + 0 =
42: 212 = 434099200 bytes data
43: 223 = 434099244 – 44 bytes of data, all Ok.
44: 25

=== END of HEADERS ===============

45: 18 // now, 4 first bytes or 32 bits of data, setereo,
46: 216 // 16 bits per sample, per channel…
47: 9
48: 216 // self-consistency PASSED.

N.B. I consulted topherlee dot com for this:
http://www.topherlee.com/software/pcm-tut-wavformat.html
( Highly recommended for *wav headers ).

I wrote a program in the C programming language to read the *wav file, and display the first 100 bytes of the file as decimal numbers in the range 0 to 255 (no characters, bits or hex digits…).

Source code of decode01a.c :

#include

int main(void)
{
int j;
unsigned char car;
FILE *in;

in = fopen(“/home/david/ZIPfiles/Jan_14_2016/noise/test14JAN2017.wav”, “r”);

for(j=0; j<100; j++)
{
fscanf(in, "%c", &car);
printf("%3d: ", j+1);
printf("%3d\n", car);
}

fclose(in);
return 0;
}

Further in the data section we have 32 bit values per time-slot of:

117: 38 // Least significant byte, left channel
118: 2 // Most significant byte, left channel
119: 36 // Least significant byte, right channel
120: 2 // Most significant byte, right channel

121: 77 // Least significant byte, left channel
122: 3 // Most significant byte, left channel
123: 68 // Least significant byte, right channel
124: 3 // Most significant byte, right channel

125: 82 // Least significant byte, left channel
126: 1 // Most significant byte, left channel
127: 96 // Least significant byte, right channel
128: 1 // Most significant byte, right channel

The Left and Right channel numbers are quite similar,
the laptop used has two microphones, and the samples from
left and right will be correlated. Therefore, for random numbers,
I discard the right channel (second group of two bytes).
Among the Most significant byte and the Least significant byte
for a channel, the Most significant byte varies little from one
sample to the next. So for random numbers, I discard
all Most significant bytes. This leaves us with
the Least significant byte(s) of left channel,
which vary somewhat. 38, 77, 82 from above.
The rule of thumb I use is to use only the
least significant bit of this byte, or the parity, so
38, 77, 82 yields: 0, 1, 0. [ parity bit, least significant bit].

Advertisements

Written by meditationatae

January 14, 2017 at 4:43 pm

Posted in History

%d bloggers like this: