From a0e86733b4ddab6aa886a7cbb8fe9019f99a3459 Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Mon, 2 Jan 2017 12:58:55 +0100 Subject: Import from http://www.sharpmz.org/mzf2wav.htm --- mzf2wav/src/wav.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 mzf2wav/src/wav.c (limited to 'mzf2wav/src/wav.c') 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 +#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 -- cgit v1.2.1