annotate wave.c @ 989:d70000fdff0b

Implemented IR and undefined bits of info word for address error exception frames
author Michael Pavone <pavone@retrodev.com>
date Wed, 27 Apr 2016 21:39:17 -0700
parents 6e9d1a8c1b08
children
rev   line source
pavone@467 1 /*
pavone@467 2 Copyright 2013 Michael Pavone
pavone@520 3 This file is part of BlastEm.
pavone@467 4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text.
pavone@467 5 */
pavone@407 6 #include "wave.h"
pavone@407 7 #include <stddef.h>
pavone@407 8 #include <string.h>
pavone@407 9
pavone@407 10 int wave_init(FILE * f, uint32_t sample_rate, uint16_t bits_per_sample, uint16_t num_channels)
pavone@407 11 {
pavone@407 12 wave_header header;
pavone@407 13 memcpy(header.chunk.id, "RIFF", 4);
pavone@407 14 memcpy(header.chunk.format, "WAVE", 4);
pavone@407 15 header.chunk.size = 0; //This will be filled in later
pavone@407 16 memcpy(header.format_header.id, "fmt ", 4);
pavone@407 17 header.format_header.size = sizeof(wave_header) - (sizeof(header.chunk) + sizeof(header.data_header) + sizeof(header.format_header));
pavone@407 18 header.audio_format = 1;
pavone@407 19 header.num_channels = num_channels;
pavone@407 20 header.sample_rate = sample_rate;
pavone@407 21 header.byte_rate = sample_rate * num_channels * (bits_per_sample/8);
pavone@407 22 header.block_align = num_channels * (bits_per_sample/8);
pavone@407 23 header.bits_per_sample = bits_per_sample;
pavone@407 24 memcpy(header.data_header.id, "data", 4);
pavone@407 25 header.data_header.size = 0;//This will be filled in later;
pavone@407 26 return fwrite(&header, 1, sizeof(header), f) == sizeof(header);
pavone@407 27 }
pavone@407 28
pavone@407 29 int wave_finalize(FILE * f)
pavone@407 30 {
pavone@407 31 uint32_t size = ftell(f);
pavone@407 32 fseek(f, offsetof(wave_header, chunk.size), SEEK_SET);
pavone@407 33 size -= 8;
pavone@520 34 if (fwrite(&size, sizeof(size), 1, f) != 1) {
pavone@407 35 fclose(f);
pavone@407 36 return 0;
pavone@407 37 }
pavone@407 38 fseek(f, offsetof(wave_header, data_header.size), SEEK_SET);
pavone@407 39 size -= 36;
pavone@520 40 if (fwrite(&size, sizeof(size), 1, f) != 1) {
pavone@407 41 fclose(f);
pavone@407 42 return 0;
pavone@407 43 }
pavone@407 44 fclose(f);
pavone@407 45 return 1;
pavone@407 46 }