19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*
29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    SDL - Simple DirectMedia Layer
39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Copyright (C) 1997-2012 Sam Lantinga
49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is SDL_free software; you can redistribute it and/or
69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    modify it under the terms of the GNU Lesser General Public
79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License as published by the Free Software Foundation; either
89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    version 2.1 of the License, or (at your option) any later version.
99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    This library is distributed in the hope that it will be useful,
119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    but WITHOUT ANY WARRANTY; without even the implied warranty of
129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Lesser General Public License for more details.
149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    You should have received a copy of the GNU Lesser General Public
169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    License along with this library; if not, write to the Free Software
179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    Sam Lantinga
209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall    slouken@libsdl.org
219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/
229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_config.h"
239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* WAVE files are little-endian */
259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*******************************************/
279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Define values for Microsoft WAVE format */
289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/*******************************************/
299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define RIFF		0x46464952		/* "RIFF" */
309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define WAVE		0x45564157		/* "WAVE" */
319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define FACT		0x74636166		/* "fact" */
329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define LIST		0x5453494c		/* "LIST" */
339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define FMT		0x20746D66		/* "fmt " */
349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define DATA		0x61746164		/* "data" */
359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define PCM_CODE	0x0001
369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define MS_ADPCM_CODE	0x0002
379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define IMA_ADPCM_CODE	0x0011
389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define MP3_CODE	0x0055
399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define WAVE_MONO	1
409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#define WAVE_STEREO	2
419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Normally, these three chunks come consecutively in a WAVE file */
439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Halltypedef struct WaveFMT {
449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Not saved in the chunk we read:
459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	Uint32	FMTchunk;
469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	Uint32	fmtlen;
479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/
489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	Uint16	encoding;
499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	Uint16	channels;		/* 1 = mono, 2 = stereo */
509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	Uint32	frequency;		/* One of 11025, 22050, or 44100 Hz */
519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	Uint32	byterate;		/* Average bytes per second */
529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	Uint16	blockalign;		/* Bytes per sample block */
539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	Uint16	bitspersample;		/* One of 8, 12, 16, or 4 for ADPCM */
549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} WaveFMT;
559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* The general chunk found in the WAVE file */
579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Halltypedef struct Chunk {
589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	Uint32 magic;
599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	Uint32 length;
609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall	Uint8 *data;
619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} Chunk;
629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall
63