diff options
author | Yves Fischer <yvesf-git@xapek.org> | 2017-01-02 12:58:55 +0100 |
---|---|---|
committer | Yves Fischer <yvesf-git@xapek.org> | 2017-01-02 12:58:55 +0100 |
commit | a0e86733b4ddab6aa886a7cbb8fe9019f99a3459 (patch) | |
tree | d2f6fb78372cbb12a4123901383b0fe65795ca20 /mzf2wav/src/wav.c | |
download | sharp-mz-a0e86733b4ddab6aa886a7cbb8fe9019f99a3459.tar.gz sharp-mz-a0e86733b4ddab6aa886a7cbb8fe9019f99a3459.zip |
Import from http://www.sharpmz.org/mzf2wav.htm
Diffstat (limited to 'mzf2wav/src/wav.c')
-rw-r--r-- | mzf2wav/src/wav.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/mzf2wav/src/wav.c b/mzf2wav/src/wav.c new file mode 100644 index 0000000..ba0c3fa --- /dev/null +++ b/mzf2wav/src/wav.c @@ -0,0 +1,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 |