1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#include <stdio.h>
#include "wav.h"
#include "physical.h"
// Externs.
extern FILE *OUT;
// Global variables.
dword fs = 0;
// Numbers are little endian.
byte header[44] = { 'R', 'I', 'F', 'F', // File description header.
0x0, 0x0, 0x0, 0x0, // Filesize - 8.
'W', 'A', 'V', 'E', // "WAVE" Description header.
'f', 'm', 't', ' ', // "fmt " Description header.
0x10, 0x0, 0x0, 0x0, // Size of WAVE section chunck.
0x1, 0x0, // Wave type format.
0x1, 0x0, // Mono or stereo.
0x44, 0xac, 0x0, 0x0, // Sample rate.
0x44, 0xac, 0x0, 0x0, // Bytes per second.
0x1, 0x0, // Block alignment.
0x8, 0x0, // Bits per sample.
'd', 'a', 't', 'a', // "data" Description header.
0x0, 0x0, 0x0, 0x0 }; // Size of data chunk.
// Public functions.
void outb(int value, int port) {
fprintf(OUT, "%c", value);
}//outb
// Write the WAV header.
void writewavheader(void) {
int i = 0;
for (i = 0; i < 44; i++)
fprintf(OUT, "%c", header[i]);
}//writewavheader
// Set the filesizes in the WAV header.
void setheader(void) {
dword temp = fs;
int i = 0;
fseek(OUT, 4, SEEK_SET);
fprintf(OUT, "%c", (temp & 0xff) + 36);
fseek(OUT, 40, SEEK_SET);
fprintf(OUT, "%c", temp & 0xff);
temp >>= 8;
for (i = 1; i < 4; i++) {
fseek(OUT, 4 + i, SEEK_SET);
fprintf(OUT, "%c", temp & 0xff);
fseek(OUT, 40 + i, SEEK_SET);
fprintf(OUT, "%c", temp & 0xff);
temp >>= 8;
}//for
}//setheader
|