1 /* WaveGain - Filename: AUDIO.H
2  *
3  *   Copyright (c) 2002 - 2005 John Edwards <john.edwards33@ntlworld.com>
4  *
5  *   This library is free software; you can redistribute it and/or
6  *   modify it under the terms of the GNU Library General Public
7  *   License as published by the Free Software Foundation; either
8  *   version 2 of the License, or (at your option) any later version.
9  *
10  *   This library is distributed in the hope that it will be useful,
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  *   Library General Public License for more details.
14  *
15  *   You should have received a copy of the GNU Library General Public
16  *   License along with this library; if not, write to the Free Software
17  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  * Portions Copyright 2000-2002, Michael Smith <msmith@labyrinth.net.au>
20  *
21  * AIFF/AIFC support from OggSquish, (c) 1994-1996 Monty <xiphmont@xiph.org>
22  */
23 
24 
25 #ifndef AUDIO_H_INCLUDED
26 #define AUDIO_H_INCLUDED
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include <stdio.h>
33 #include "misc.h"
34 
35 typedef long (*audio_read_func)(void *src,
36                                 double **buffer,
37                                 int samples,
38                                 int fast,
39                                 int chunk);
40 
41 typedef struct
42 {
43 	audio_read_func read_samples;
44 
45 	void *readdata;
46 
47 	unsigned long total_samples_per_channel;
48 	int channels;
49 	long rate;
50 	int samplesize;
51 	int endianness;
52 	int format;
53 	int gain_chunk;
54 	double gain_scale;
55 	int std_in;
56 	int std_out;
57 	int apply_gain;
58 	int write_chunk;
59 	int force;
60 	int undo;
61 	int header_size;
62 	unsigned char *header;
63 
64 	FILE *out;
65 	char *filename;
66 } wavegain_opt;
67 
68 typedef struct
69 {
70 	int  (*id_func)(unsigned char *buf, int len); /* Returns true if can load file */
71 	int  id_data_len; /* Amount of data needed to id whether this can load the file */
72 	int  (*open_func)(FILE *in, wavegain_opt *opt, unsigned char *buf, int buflen);
73 	void (*close_func)(void *);
74 	char *format;
75 	char *description;
76 } input_format;
77 
78 
79 typedef struct {
80 	short format;
81 	short channels;
82 	int   samplerate;
83 	int   bytespersec;
84 	short align;
85 	short samplesize;
86 } wav_fmt;
87 
88 typedef struct {
89 	short channels;
90 	short samplesize;
91 	unsigned long  totalsamples;
92 	unsigned long  samplesread;
93 	FILE  *f;
94 	short bigendian;
95 } wavfile;
96 
97 typedef struct {
98 	short channels;
99 	unsigned long   totalframes;
100 	short samplesize;
101 	int   rate;
102 	int   offset;
103 	int   blocksize;
104 } aiff_fmt;
105 
106 typedef wavfile aifffile; /* They're the same */
107 
108 input_format *open_audio_file(FILE *in, wavegain_opt *opt);
109 
110 int raw_open(FILE *in, wavegain_opt *opt);
111 int wav_open(FILE *in, wavegain_opt *opt, unsigned char *buf, int buflen);
112 int aiff_open(FILE *in, wavegain_opt *opt, unsigned char *buf, int buflen);
113 int wav_id(unsigned char *buf, int len);
114 int aiff_id(unsigned char *buf, int len);
115 void wav_close(void *);
116 void raw_close(void *);
117 
118 long wav_read(void *, double **buffer, int samples, int fast, int chunk);
119 long wav_ieee_read(void *, double **buffer, int samples, int fast, int chunk);
120 
121 typedef enum {
122 	WAV_NO_FMT = 0,
123 	WAV_FMT_8BIT,
124 	WAV_FMT_16BIT,
125 	WAV_FMT_24BIT,
126 	WAV_FMT_32BIT,
127 	WAV_FMT_FLOAT,
128 	WAV_FMT_AIFF,
129 	WAV_FMT_AIFC8,
130 	WAV_FMT_AIFC16
131 } file_formats;
132 
133 typedef struct
134 {
135 	int           outputFormat;
136 	FILE          *sndfile;
137 	unsigned long samplerate;
138 	unsigned long bits_per_sample;
139 	unsigned long channels;
140 	unsigned long samples;
141 	int           endianness;
142 	int           format;
143 } audio_file;
144 
145 audio_file *open_output_audio_file(char *infile, wavegain_opt *opt);
146 int write_audio_file(audio_file *aufile, void *sample_buffer, int samples);
147 void close_audio_file(FILE *in, audio_file *aufile, wavegain_opt *opt);
148 static int write_wav_header(audio_file *aufile, wavegain_opt *opt, Int64_t file_size);
149 static int write_aiff_header(audio_file *aufile);
150 static int write_audio_8bit(audio_file *aufile, void *sample_buffer, unsigned int samples);
151 static int write_audio_16bit(audio_file *aufile, void *sample_buffer, unsigned int samples);
152 static int write_audio_24bit(audio_file *aufile, void *sample_buffer, unsigned int samples);
153 static int write_audio_32bit(audio_file *aufile, void *sample_buffer, unsigned int samples);
154 static int write_audio_float(audio_file *aufile, void *sample_buffer, unsigned int samples);
155 void* output_to_PCM(double **input, void *samplebuffer, int channels, int samples, int format);
156 
157 #ifdef __cplusplus
158 }
159 #endif
160 #endif /* AUDIO_H_INCLUDED */
161