summaryrefslogtreecommitdiff
blob: e7f9d4bc55bb794266b2335b3ec61ee043293788 (plain)
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
Index: TiMidity++-2.13.2/timidity/flac_a.c
===================================================================
--- TiMidity++-2.13.2.orig/timidity/flac_a.c
+++ TiMidity++-2.13.2/timidity/flac_a.c
@@ -45,6 +45,11 @@
 #endif
 
 #include <FLAC/all.h>
+#if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT < 8
+#define LEGACY_FLAC
+#else
+#undef LEGACY_FLAC
+#endif
 #ifdef AU_OGGFLAC
 #include <OggFLAC/stream_encoder.h>
 #endif
@@ -100,7 +105,11 @@ typedef struct {
   unsigned long out_bytes;
   union {
     FLAC__StreamEncoderState flac;
+#ifdef LEGACY_FLAC
     FLAC__SeekableStreamEncoderState s_flac;
+#else
+    FLAC__StreamEncoderState s_flac;
+#endif
 #ifdef AU_OGGFLAC
     OggFLAC__StreamEncoderState ogg;
 #endif
@@ -108,7 +117,11 @@ typedef struct {
   union {
     union {
       FLAC__StreamEncoder *stream;
+#ifdef LEGACY_FLAC
       FLAC__SeekableStreamEncoder *s_stream;
+#else
+      FLAC__StreamEncoder *s_stream;
+#endif
     } flac;
 #ifdef AU_OGGFLAC
     union {
@@ -174,11 +187,19 @@ static void flac_stream_encoder_metadata
 						  const FLAC__StreamMetadata *metadata,
 						  void *client_data);
 static FLAC__StreamEncoderWriteStatus
+#ifdef LEGACY_FLAC
 flac_seekable_stream_encoder_write_callback(const FLAC__SeekableStreamEncoder *encoder,
+#else
+flac_seekable_stream_encoder_write_callback(const FLAC__StreamEncoder *encoder,
+#endif
 				   const FLAC__byte buffer[],
 				   unsigned bytes, unsigned samples,
 				   unsigned current_frame, void *client_data);
+#ifdef LEGACY_FLAC
 static void flac_seekable_stream_encoder_metadata_callback(const FLAC__SeekableStreamEncoder *encoder,
+#else
+static void flac_seekable_stream_encoder_metadata_callback(const FLAC__StreamEncoder *encoder,
+#endif
 						  const FLAC__StreamMetadata *metadata,
 						  void *client_data);
 
@@ -306,8 +327,13 @@ static int flac_session_close()
 #endif /* AU_OGGFLAC */
     if (flac_options.seekable) {
       if (ctx->encoder.flac.s_stream) {
+#ifdef LEGACY_FLAC
 	FLAC__seekable_stream_encoder_finish(ctx->encoder.flac.s_stream);
 	FLAC__seekable_stream_encoder_delete(ctx->encoder.flac.s_stream);
+#else
+	FLAC__stream_encoder_finish(ctx->encoder.flac.s_stream);
+	FLAC__stream_encoder_delete(ctx->encoder.flac.s_stream);
+#endif
       }
     }
     else
@@ -435,17 +461,29 @@ static int flac_output_open(const char *
   else
 #endif /* AU_OGGFLAC */
   if (flac_options.seekable) {
+#ifdef LEGACY_FLAC
     if ((ctx->encoder.flac.s_stream = FLAC__seekable_stream_encoder_new()) == NULL) {
+#else
+    if ((ctx->encoder.flac.s_stream = FLAC__stream_encoder_new()) == NULL) {
+#endif
       ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "cannot create FLAC stream");
       flac_session_close();
       return -1;
     }
 
+#ifdef LEGACY_FLAC
     FLAC__seekable_stream_encoder_set_channels(ctx->encoder.flac.s_stream, nch);
     /* 16bps only */
     FLAC__seekable_stream_encoder_set_bits_per_sample(ctx->encoder.flac.s_stream, 16);
 
     FLAC__seekable_stream_encoder_set_verify(ctx->encoder.flac.s_stream, flac_options.verify);
+#else
+    FLAC__stream_encoder_set_channels(ctx->encoder.flac.s_stream, nch);
+    /* 16bps only */
+    FLAC__stream_encoder_set_bits_per_sample(ctx->encoder.flac.s_stream, 16);
+
+    FLAC__stream_encoder_set_verify(ctx->encoder.flac.s_stream, flac_options.verify);
+#endif
 
     if (!FLAC__format_sample_rate_is_valid(dpm.rate)) {
       ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "invalid sampling rate %d",
@@ -453,27 +491,54 @@ static int flac_output_open(const char *
       flac_session_close();
       return -1;
     }
+#ifdef LEGACY_FLAC
     FLAC__seekable_stream_encoder_set_sample_rate(ctx->encoder.flac.s_stream, dpm.rate);
 
     FLAC__seekable_stream_encoder_set_qlp_coeff_precision(ctx->encoder.flac.s_stream, flac_options.qlp_coeff_precision);
     /* expensive! */
     FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search(ctx->encoder.flac.s_stream, flac_options.qlp_coeff_precision_search);
+#else
+    FLAC__stream_encoder_set_sample_rate(ctx->encoder.flac.s_stream, dpm.rate);
+
+    FLAC__stream_encoder_set_qlp_coeff_precision(ctx->encoder.flac.s_stream, flac_options.qlp_coeff_precision);
+    /* expensive! */
+    FLAC__stream_encoder_set_do_qlp_coeff_prec_search(ctx->encoder.flac.s_stream, flac_options.qlp_coeff_precision_search);
+#endif
+
 
     if (nch == 2) {
+#ifdef LEGACY_FLAC
       FLAC__seekable_stream_encoder_set_do_mid_side_stereo(ctx->encoder.flac.s_stream, flac_options.mid_side);
       FLAC__seekable_stream_encoder_set_loose_mid_side_stereo(ctx->encoder.flac.s_stream, flac_options.adaptive_mid_side);
+#else
+      FLAC__stream_encoder_set_do_mid_side_stereo(ctx->encoder.flac.s_stream, flac_options.mid_side);
+      FLAC__stream_encoder_set_loose_mid_side_stereo(ctx->encoder.flac.s_stream, flac_options.adaptive_mid_side);
+#endif
     }
 
+#ifdef LEGACY_FLAC
     FLAC__seekable_stream_encoder_set_max_lpc_order(ctx->encoder.flac.s_stream, flac_options.max_lpc_order);
     FLAC__seekable_stream_encoder_set_min_residual_partition_order(ctx->encoder.flac.s_stream, flac_options.min_residual_partition_order);
     FLAC__seekable_stream_encoder_set_max_residual_partition_order(ctx->encoder.flac.s_stream, flac_options.max_residual_partition_order);
 
     FLAC__seekable_stream_encoder_set_blocksize(ctx->encoder.flac.s_stream, flac_options.blocksize);
     FLAC__seekable_stream_encoder_set_client_data(ctx->encoder.flac.s_stream, ctx);
+#else
+    FLAC__stream_encoder_set_max_lpc_order(ctx->encoder.flac.s_stream, flac_options.max_lpc_order);
+    FLAC__stream_encoder_set_min_residual_partition_order(ctx->encoder.flac.s_stream, flac_options.min_residual_partition_order);
+    FLAC__stream_encoder_set_max_residual_partition_order(ctx->encoder.flac.s_stream, flac_options.max_residual_partition_order);
+
+    FLAC__stream_encoder_set_blocksize(ctx->encoder.flac.s_stream, flac_options.blocksize);
+#endif
 
     if (0 < num_metadata)
+#ifdef LEGACY_FLAC
       FLAC__seekable_stream_encoder_set_metadata(ctx->encoder.flac.s_stream, metadata, num_metadata);
+#else
+      FLAC__stream_encoder_set_metadata(ctx->encoder.flac.s_stream, metadata, num_metadata);
+#endif
 
+#ifdef LEGACY_FLAC
     /* set callback */
 /*    FLAC__seekable_stream_encoder_set_metadata_callback(ctx->encoder.flac.s_stream, flac_seekable_stream_encoder_metadata_callback); /* */
 #ifndef __BORLANDC__
@@ -483,8 +548,17 @@ static int flac_output_open(const char *
 
     ctx->state.s_flac = FLAC__seekable_stream_encoder_init(ctx->encoder.flac.s_stream);
     if (ctx->state.s_flac != FLAC__SEEKABLE_STREAM_ENCODER_OK) {
+#else
+
+    ctx->state.s_flac = FLAC__stream_encoder_init_stream(ctx->encoder.flac.s_stream, flac_seekable_stream_encoder_write_callback, NULL, NULL, flac_seekable_stream_encoder_metadata_callback,  ctx);
+    if (ctx->state.s_flac != FLAC__STREAM_ENCODER_OK) {
+#endif
       ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "cannot create FLAC state (%s)",
+#ifdef LEGACY_FLAC
 		FLAC__SeekableStreamEncoderStateString[ctx->state.s_flac]);
+#else
+		FLAC__StreamEncoderStateString[ctx->state.s_flac]);
+#endif
       flac_session_close();
       return -1;
     }
@@ -525,16 +599,22 @@ static int flac_output_open(const char *
     FLAC__stream_encoder_set_max_residual_partition_order(ctx->encoder.flac.stream, flac_options.max_residual_partition_order);
 
     FLAC__stream_encoder_set_blocksize(ctx->encoder.flac.stream, flac_options.blocksize);
+#ifdef LEGACY_FLAC
     FLAC__stream_encoder_set_client_data(ctx->encoder.flac.stream, ctx);
+#endif
 
     if (0 < num_metadata)
       FLAC__stream_encoder_set_metadata(ctx->encoder.flac.stream, metadata, num_metadata);
 
+#ifdef LEGACY_FLAC
     /* set callback */
     FLAC__stream_encoder_set_metadata_callback(ctx->encoder.flac.stream, flac_stream_encoder_metadata_callback);
     FLAC__stream_encoder_set_write_callback(ctx->encoder.flac.stream, flac_stream_encoder_write_callback);
 
     ctx->state.flac = FLAC__stream_encoder_init(ctx->encoder.flac.stream);
+#else
+    ctx->state.flac = FLAC__stream_encoder_init_stream(ctx->encoder.flac.stream, flac_stream_encoder_write_callback, NULL, NULL,  flac_stream_encoder_metadata_callback, ctx);
+#endif
     if (ctx->state.flac != FLAC__STREAM_ENCODER_OK) {
       ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "cannot create FLAC state (%s)",
 		FLAC__StreamEncoderStateString[ctx->state.flac]);
@@ -676,7 +756,11 @@ static void flac_stream_encoder_metadata
 {
 }
 static FLAC__StreamEncoderWriteStatus
+#ifdef LEGACY_FLAC
 flac_seekable_stream_encoder_write_callback(const FLAC__SeekableStreamEncoder *encoder,
+#else
+flac_seekable_stream_encoder_write_callback(const FLAC__StreamEncoder *encoder,
+#endif
 				   const FLAC__byte buffer[],
 				   unsigned bytes, unsigned samples,
 				   unsigned current_frame, void *client_data)
@@ -690,7 +774,11 @@ flac_seekable_stream_encoder_write_callb
   else
     return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
 }
+#ifdef LEGACY_FLAC
 static void flac_seekable_stream_encoder_metadata_callback(const FLAC__SeekableStreamEncoder *encoder,
+#else
+static void flac_seekable_stream_encoder_metadata_callback(const FLAC__StreamEncoder *encoder,
+#endif
 						  const FLAC__StreamMetadata *metadata,
 						  void *client_data)
 {
@@ -747,22 +835,38 @@ static int output_data(char *buf, int32 
   else
 #endif /* AU_OGGFLAC */
 	if (flac_options.seekable) {
+#ifdef LEGACY_FLAC
     ctx->state.s_flac = FLAC__seekable_stream_encoder_get_state(ctx->encoder.flac.s_stream);
+#else
+    ctx->state.s_flac = FLAC__stream_encoder_get_state(ctx->encoder.flac.s_stream);
+#endif
     if (ctx->state.s_flac != FLAC__STREAM_ENCODER_OK) {
       if (ctx->state.s_flac == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR |
 	  FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA) {
 	ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "FLAC stream verify error (%s)",
+#ifdef LEGACY_FLAC
 		  FLAC__SeekableStreamDecoderStateString[FLAC__seekable_stream_encoder_get_verify_decoder_state(ctx->encoder.flac.s_stream)]);
+#else
+		  FLAC__StreamDecoderStateString[FLAC__stream_encoder_get_verify_decoder_state(ctx->encoder.flac.s_stream)]);
+#endif
       }
       else {
 	ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "cannot encode FLAC stream (%s)",
+#ifdef LEGACY_FLAC
 		  FLAC__SeekableStreamEncoderStateString[ctx->state.s_flac]);
+#else
+		  FLAC__StreamEncoderStateString[ctx->state.s_flac]);
+#endif
       }
       flac_session_close();
       return -1;
     }
 
+#ifdef LEGACY_FLAC
     if (!FLAC__seekable_stream_encoder_process_interleaved(ctx->encoder.flac.s_stream, oggbuf,
+#else
+    if (!FLAC__stream_encoder_process_interleaved(ctx->encoder.flac.s_stream, oggbuf,
+#endif
 						  nbytes / nch / 2 )) {
       ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "cannot encode FLAC stream");
       flac_session_close();
@@ -823,9 +927,17 @@ static void close_output(void)
   else
 #endif /* AU_OGGFLAC */
   if (flac_options.seekable) {
+#ifdef LEGACY_FLAC
     if ((ctx->state.s_flac = FLAC__seekable_stream_encoder_get_state(ctx->encoder.flac.s_stream)) != FLAC__SEEKABLE_STREAM_ENCODER_OK) {
+#else
+    if ((ctx->state.s_flac = FLAC__stream_encoder_get_state(ctx->encoder.flac.s_stream)) != FLAC__STREAM_ENCODER_OK) {
+#endif
       ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "FLAC stream encoder is invalid (%s)",
+#ifdef LEGACY_FLAC
 		FLAC__SeekableStreamEncoderStateString[ctx->state.s_flac]);
+#else
+		FLAC__StreamEncoderStateString[ctx->state.s_flac]);
+#endif
       /* fall through */
     }
 	}