| 1 | /* |
|---|
| 2 | * wavfile.h WAV fileé¢é£ |
|---|
| 3 | * |
|---|
| 4 | * Copyright: wavfile.c (c) Erik de Castro Lopo erikd@zip.com.au |
|---|
| 5 | * |
|---|
| 6 | * Modified : 1997-1998 Masaki Chikama (Wren) <chikama@kasumi.ipl.mech.nagoya-u.ac.jp> |
|---|
| 7 | * 1998- <masaki-c@is.aist-nara.ac.jp> |
|---|
| 8 | * |
|---|
| 9 | * This program is free software; you can redistribute it and/or modify |
|---|
| 10 | * it under the terms of the GNU General Public License as published by |
|---|
| 11 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 12 | * (at your option) any later version. |
|---|
| 13 | * |
|---|
| 14 | * This program is distributed in the hope that it will be useful, |
|---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 | * GNU General Public License for more details. |
|---|
| 18 | * |
|---|
| 19 | * You should have received a copy of the GNU General Public License along |
|---|
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., |
|---|
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
|---|
| 22 | * |
|---|
| 23 | */ |
|---|
| 24 | #ifndef __WAVEFILE__ |
|---|
| 25 | #define __WAVEFILE__ |
|---|
| 26 | |
|---|
| 27 | #define WW_BADOUTPUTFILE 1 |
|---|
| 28 | #define WW_BADWRITEHEADER 2 |
|---|
| 29 | |
|---|
| 30 | #define WR_BADALLOC 3 |
|---|
| 31 | #define WR_BADSEEK 4 |
|---|
| 32 | #define WR_BADRIFF 5 |
|---|
| 33 | #define WR_BADWAVE 6 |
|---|
| 34 | #define WR_BADFORMAT 7 |
|---|
| 35 | #define WR_BADFORMATSIZE 8 |
|---|
| 36 | |
|---|
| 37 | #define WR_NOTPCMFORMAT 9 |
|---|
| 38 | #define WR_NODATACHUNK 10 |
|---|
| 39 | #define WR_BADFORMATDATA 11 |
|---|
| 40 | |
|---|
| 41 | /* |
|---|
| 42 | * These values represent values found in/or destined for a |
|---|
| 43 | * WAV file. |
|---|
| 44 | */ |
|---|
| 45 | typedef struct { |
|---|
| 46 | unsigned int SamplingRate; /* Sampling rate in Hz */ |
|---|
| 47 | int Channels; /* Mono or Stereo */ |
|---|
| 48 | unsigned short DataBits; /* Sample bit size (8/12/16) */ |
|---|
| 49 | } WAVINF; |
|---|
| 50 | |
|---|
| 51 | struct WAVFILE{ |
|---|
| 52 | WAVINF wavinfo; /* WAV file hdr info */ |
|---|
| 53 | WAVFILE(void); |
|---|
| 54 | static int freq; |
|---|
| 55 | static int format; |
|---|
| 56 | static int channels; |
|---|
| 57 | virtual ~WAVFILE() {}; |
|---|
| 58 | virtual int Read(char* buf, int blksize, int blklen) = 0; |
|---|
| 59 | virtual void Seek(int count) = 0; |
|---|
| 60 | static WAVFILE* MakeConverter(WAVFILE* new_reader); |
|---|
| 61 | }; |
|---|
| 62 | |
|---|
| 63 | struct WAVFILE_Converter : WAVFILE { |
|---|
| 64 | WAVFILE* original; |
|---|
| 65 | struct SDL_AudioCVT* cvt; |
|---|
| 66 | int datasize; |
|---|
| 67 | char* tmpbuf; |
|---|
| 68 | int Read(char* buf, int blksize, int blklen); |
|---|
| 69 | void Seek(int count) { original->Seek(count);} |
|---|
| 70 | WAVFILE_Converter(WAVFILE* orig, struct SDL_AudioCVT* cvt); |
|---|
| 71 | ~WAVFILE_Converter(); |
|---|
| 72 | }; |
|---|
| 73 | |
|---|
| 74 | struct WAVFILE_Stream : WAVFILE{ |
|---|
| 75 | char *data; /* real data */ |
|---|
| 76 | char *data_orig; |
|---|
| 77 | int data_length; |
|---|
| 78 | FILE* stream; |
|---|
| 79 | int stream_length; |
|---|
| 80 | int stream_length_orig; |
|---|
| 81 | int stream_top; |
|---|
| 82 | int Read(char* buf, int blksize, int blklen); |
|---|
| 83 | void Seek(int count); |
|---|
| 84 | WAVFILE_Stream(FILE* stream, int length); |
|---|
| 85 | ~WAVFILE_Stream(); |
|---|
| 86 | }; |
|---|
| 87 | |
|---|
| 88 | struct NWAFILE : WAVFILE { |
|---|
| 89 | int skip_count; |
|---|
| 90 | FILE* stream; |
|---|
| 91 | struct NWAData* nwa; |
|---|
| 92 | char* data; |
|---|
| 93 | int block_size; |
|---|
| 94 | int data_len; |
|---|
| 95 | |
|---|
| 96 | NWAFILE(FILE* stream); |
|---|
| 97 | ~NWAFILE(); |
|---|
| 98 | void Seek(int count); |
|---|
| 99 | int Read(char* buf, int blksize, int blklen); |
|---|
| 100 | static char* ReadAll(FILE* stream, int& size); |
|---|
| 101 | }; |
|---|
| 102 | |
|---|
| 103 | struct OggFILE : WAVFILE { |
|---|
| 104 | struct OggFILE_impl* pimpl; |
|---|
| 105 | |
|---|
| 106 | OggFILE(FILE* stream, int size); |
|---|
| 107 | ~OggFILE(); |
|---|
| 108 | void Seek(int count); |
|---|
| 109 | int Read(char* buf, int blksize, int blklen); |
|---|
| 110 | }; |
|---|
| 111 | |
|---|
| 112 | struct MP3FILE : WAVFILE { |
|---|
| 113 | struct MP3FILE_impl* pimpl; |
|---|
| 114 | |
|---|
| 115 | MP3FILE(FILE* stream, int size); |
|---|
| 116 | ~MP3FILE(); |
|---|
| 117 | void Seek(int count); |
|---|
| 118 | int Read(char* buf, int blksize, int blklen); |
|---|
| 119 | }; |
|---|
| 120 | |
|---|
| 121 | #endif /* !__WAVEFILE__ */ |
|---|