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