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
|
$NetBSD: patch-ac,v 1.1 2007/01/09 23:36:45 wiz Exp $
--- flac123.c.orig 2005-05-09 04:25:20.000000000 +0000
+++ flac123.c
@@ -49,12 +49,17 @@ struct poptOption cli_options[] = {
static void play_file(const char *);
static void play_remote_file(void);
-void flac_error_hdl(const FLAC__FileDecoder *, FLAC__StreamDecoderErrorStatus,
- void *);
-void flac_metadata_hdl(const FLAC__FileDecoder *, const FLAC__StreamMetadata *,
- void *);
+#ifdef LEGACY_FLAC
+void flac_error_hdl(const FLAC__FileDecoder *, FLAC__StreamDecoderErrorStatus, void *);
+void flac_metadata_hdl(const FLAC__FileDecoder *, const FLAC__StreamMetadata *, void *);
FLAC__StreamDecoderWriteStatus flac_write_hdl(const FLAC__FileDecoder *,
const FLAC__Frame *, const FLAC__int32 * const buf[], void *);
+#else
+void flac_error_hdl(const FLAC__StreamDecoder *, FLAC__StreamDecoderErrorStatus, void *);
+void flac_metadata_hdl(const FLAC__StreamDecoder *, const FLAC__StreamMetadata *, void *);
+FLAC__StreamDecoderWriteStatus flac_write_hdl(const FLAC__StreamDecoder *,
+ const FLAC__Frame *, const FLAC__int32 * const buf[], void *);
+#endif
static void signal_handler(int);
static int quit_now = 0;
@@ -190,6 +195,7 @@ FLAC__bool decoder_constructor(const cha
file_info.year[VORBIS_YEAR_LEN] = '\0';
/* create and initialize flac decoder object */
+#ifdef LEGACY_FLAC
file_info.decoder = FLAC__file_decoder_new();
FLAC__file_decoder_set_md5_checking(file_info.decoder, true);
FLAC__file_decoder_set_filename(file_info.decoder, filename);
@@ -210,13 +216,29 @@ FLAC__bool decoder_constructor(const cha
FLAC__file_decoder_delete(file_info.decoder);
return false;
}
+#else
+ file_info.decoder = FLAC__stream_decoder_new();
+ FLAC__stream_decoder_set_md5_checking(file_info.decoder, true);
+
+ /* read metadata */
+ if ((FLAC__stream_decoder_init_file(file_info.decoder, filename, flac_write_hdl, flac_metadata_hdl, flac_error_hdl, (void *)&file_info) != FLAC__STREAM_DECODER_INIT_STATUS_OK)
+ || (!FLAC__stream_decoder_process_until_end_of_metadata(file_info.decoder)))
+ {
+ FLAC__stream_decoder_delete(file_info.decoder);
+ return false;
+ }
+#endif
/* open libao output device */
if (cli_args.wavfile) {
if (!(file_info.ao_dev = ao_open_file(ao_driver_id("wav"), cli_args.wavfile, /*overwrite*/ 1, &(file_info.ao_fmt), NULL)))
{
fprintf(stderr, "Error opening wav file %s\n", cli_args.wavfile);
+#ifdef LEGACY_FLAC
FLAC__file_decoder_delete(file_info.decoder);
+#else
+ FLAC__stream_decoder_delete(file_info.decoder);
+#endif
return false;
}
}
@@ -224,7 +246,11 @@ FLAC__bool decoder_constructor(const cha
if (!(file_info.ao_dev = ao_open_live(ao_output_id, &(file_info.ao_fmt), NULL)))
{
fprintf(stderr, "Error opening ao device %d\n", ao_output_id);
+#ifdef LEGACY_FLAC
FLAC__file_decoder_delete(file_info.decoder);
+#else
+ FLAC__stream_decoder_delete(file_info.decoder);
+#endif
return false;
}
}
@@ -237,7 +263,11 @@ FLAC__bool decoder_constructor(const cha
if (!(file_info.ao_dev = ao_open_live(ao_output_id, &(file_info.ao_fmt), NULL)))
{
fprintf(stderr, "Error opening ao device %d\n", ao_output_id);
+#ifdef LEGACY_FLAC
FLAC__file_decoder_delete(file_info.decoder);
+#else
+ FLAC__stream_decoder_delete(file_info.decoder);
+#endif
return false;
}
}
@@ -257,8 +287,13 @@ FLAC__bool decoder_constructor(const cha
void decoder_destructor(void)
{
+#ifdef LEGACY_FLAC
FLAC__file_decoder_finish(file_info.decoder);
FLAC__file_decoder_delete(file_info.decoder);
+#else
+ FLAC__stream_decoder_finish(file_info.decoder);
+ FLAC__stream_decoder_delete(file_info.decoder);
+#endif
file_info.is_loaded = false;
file_info.is_playing = false;
file_info.filename[0] = '\0';
@@ -272,9 +307,15 @@ static void play_file(const char *filena
return;
}
+#ifdef LEGACY_FLAC
while (FLAC__file_decoder_process_single(file_info.decoder) == true &&
FLAC__file_decoder_get_state(file_info.decoder) ==
FLAC__FILE_DECODER_OK && !interrupted)
+#else
+ while (FLAC__stream_decoder_process_single(file_info.decoder) == true &&
+ FLAC__stream_decoder_get_state(file_info.decoder) <
+ FLAC__STREAM_DECODER_END_OF_STREAM && !interrupted)
+#endif
{
}
interrupted = 0; /* more accurate feedback if placed after loop */
@@ -292,13 +333,22 @@ static void play_remote_file(void)
{
if (file_info.is_playing == true)
{
+#ifdef LEGACY_FLAC
if (FLAC__file_decoder_get_state(file_info.decoder) ==
FLAC__FILE_DECODER_END_OF_FILE)
+#else
+ if (FLAC__stream_decoder_get_state(file_info.decoder) ==
+ FLAC__STREAM_DECODER_END_OF_STREAM)
+#endif
{
decoder_destructor();
printf("@P 0\n");
}
+#ifdef LEGACY_FLAC
else if (!FLAC__file_decoder_process_single(file_info.decoder))
+#else
+ else if (!FLAC__stream_decoder_process_single(file_info.decoder))
+#endif
{
fprintf(stderr, "error decoding single frame!\n");
}
@@ -314,14 +364,24 @@ static void play_remote_file(void)
}
}
+#ifdef LEGACY_FLAC
void flac_error_hdl(const FLAC__FileDecoder *dec,
FLAC__StreamDecoderErrorStatus status, void *data)
+#else
+void flac_error_hdl(const FLAC__StreamDecoder *dec,
+ FLAC__StreamDecoderErrorStatus status, void *data)
+#endif
{
fprintf(stderr, "error handler called!\n");
}
+#ifdef LEGACY_FLAC
void flac_metadata_hdl(const FLAC__FileDecoder *dec,
const FLAC__StreamMetadata *meta, void *data)
+#else
+void flac_metadata_hdl(const FLAC__StreamDecoder *dec,
+ const FLAC__StreamMetadata *meta, void *data)
+#endif
{
file_info_struct *p = (file_info_struct *) data;
@@ -344,10 +404,17 @@ void flac_metadata_hdl(const FLAC__FileD
}
}
+#ifdef LEGACY_FLAC
FLAC__StreamDecoderWriteStatus flac_write_hdl(const FLAC__FileDecoder *dec,
const FLAC__Frame *frame,
const FLAC__int32 * const buf[],
void *data)
+#else
+FLAC__StreamDecoderWriteStatus flac_write_hdl(const FLAC__StreamDecoder *dec,
+ const FLAC__Frame *frame,
+ const FLAC__int32 * const buf[],
+ void *data)
+#endif
{
int sample, channel, i;
uint_32 samples = frame->header.blocksize;
|