Link Here
|
75 |
/************** |
75 |
/************** |
76 |
* Prototypes * |
76 |
* Prototypes * |
77 |
**************/ |
77 |
**************/ |
|
|
78 |
#endif /* ENABLE_FLAC */ |
79 |
|
80 |
#ifdef ENABLE_FLAC_8 |
81 |
static FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data); |
82 |
static void metadata_callback_ (const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data); |
83 |
static void error_callback_ (const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data); |
84 |
#elif ENABLE_FLAC_7 |
78 |
static FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data); |
85 |
static FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data); |
79 |
static void metadata_callback_(const FLAC__FileDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data); |
86 |
static void metadata_callback_ (const FLAC__FileDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data); |
80 |
static void error_callback_ (const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data); |
87 |
static void error_callback_ (const FLAC__FileDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data); |
81 |
|
88 |
#endif /* ENABLE_FLAC_8 */ |
82 |
|
|
|
83 |
|
89 |
|
84 |
/************* |
90 |
/************* |
85 |
* Functions * |
91 |
* Functions * |
Link Here
|
88 |
/**************************** |
94 |
/**************************** |
89 |
* Header info of FLAC file * |
95 |
* Header info of FLAC file * |
90 |
****************************/ |
96 |
****************************/ |
|
|
97 |
#ifdef ENABLE_FLAC_8 |
91 |
|
98 |
|
92 |
gboolean Flac_Header_Read_File_Info (gchar *filename, ET_File_Info *ETFileInfo) |
99 |
gboolean Flac_Header_Read_File_Info (gchar *filename, ET_File_Info *ETFileInfo) |
93 |
{ |
100 |
{ |
94 |
FILE *file; |
101 |
FILE *file; |
95 |
gdouble duration = 0; |
102 |
gdouble duration = 0; |
96 |
gulong filesize; |
103 |
gulong filesize; |
|
|
104 |
|
105 |
|
106 |
|
107 |
FLAC__StreamDecoder *tmp_decoder; |
108 |
|
109 |
file_info_struct tmp_file_info; |
110 |
|
111 |
|
112 |
if (!filename || !ETFileInfo) |
113 |
return FALSE; |
114 |
|
115 |
if ( (file=fopen(filename,"r"))==NULL ) |
116 |
{ |
117 |
gchar *filename_utf8 = filename_to_display(filename); |
118 |
g_print(_("ERROR while opening file: '%s' (%s)\n\a"),filename_utf8,g_strerror(errno)); |
119 |
g_free(filename_utf8); |
120 |
return FALSE; |
121 |
} |
122 |
fclose(file); |
123 |
|
124 |
/* Decoding FLAC file */ |
125 |
tmp_decoder = FLAC__stream_decoder_new(); |
126 |
if (tmp_decoder == 0) |
127 |
{ |
128 |
return FALSE; |
129 |
} |
130 |
|
131 |
tmp_file_info.abort_flag = false; |
132 |
|
133 |
FLAC__stream_decoder_set_md5_checking(tmp_decoder, false); |
134 |
|
135 |
if(FLAC__stream_decoder_init_file( |
136 |
tmp_decoder, |
137 |
filename, |
138 |
write_callback_, |
139 |
metadata_callback_, |
140 |
error_callback_, |
141 |
&tmp_file_info |
142 |
) != FLAC__STREAM_DECODER_INIT_STATUS_OK) { |
143 |
return FALSE; |
144 |
} |
145 |
|
146 |
if (!FLAC__stream_decoder_process_until_end_of_metadata(tmp_decoder)) { |
147 |
return FALSE; |
148 |
} |
97 |
|
149 |
|
|
|
150 |
FLAC__stream_decoder_finish(tmp_decoder); |
151 |
FLAC__stream_decoder_delete(tmp_decoder); |
152 |
/* End of decoding FLAC file */ |
153 |
|
154 |
|
155 |
filesize = Get_File_Size(filename); |
156 |
duration = (gint)tmp_file_info.length_in_msec/1000; |
157 |
|
158 |
ETFileInfo->version = 0; // Not defined in FLAC file |
159 |
if (duration > 0) |
160 |
ETFileInfo->bitrate = filesize*8/duration/1000; // FIXME : Approximation!! Needs to remove tag size! |
161 |
ETFileInfo->samplerate = tmp_file_info.sample_rate; |
162 |
ETFileInfo->mode = tmp_file_info.channels; |
163 |
ETFileInfo->size = filesize; |
164 |
ETFileInfo->duration = duration; |
165 |
|
166 |
return TRUE; |
167 |
} |
168 |
|
169 |
#elif ENABLE_FLAC_7 |
170 |
|
171 |
gboolean Flac_Header_Read_File_Info (gchar *filename, ET_File_Info *ETFileInfo) |
172 |
{ |
173 |
FILE *file; |
174 |
gdouble duration = 0; |
175 |
gulong filesize; |
176 |
|
177 |
|
178 |
|
98 |
FLAC__FileDecoder *tmp_decoder; |
179 |
FLAC__FileDecoder *tmp_decoder; |
|
|
180 |
|
99 |
file_info_struct tmp_file_info; |
181 |
file_info_struct tmp_file_info; |
100 |
|
182 |
|
|
|
183 |
|
101 |
if (!filename || !ETFileInfo) |
184 |
if (!filename || !ETFileInfo) |
102 |
return FALSE; |
185 |
return FALSE; |
103 |
|
186 |
|
Link Here
|
159 |
return TRUE; |
242 |
return TRUE; |
160 |
} |
243 |
} |
161 |
|
244 |
|
|
|
245 |
#endif /* ENABLE_FLAC_8 */ |
162 |
|
246 |
|
|
|
247 |
#ifdef ENABLE_FLAC_8 |
248 |
|
249 |
FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data) |
250 |
{ |
251 |
file_info_struct *file_info = (file_info_struct *)client_data; |
252 |
const unsigned bps = file_info->bits_per_sample, channels = file_info->channels, wide_samples = frame->header.blocksize; |
253 |
unsigned wide_sample, sample, channel; |
254 |
FLAC__int8 *scbuffer = (FLAC__int8*)reservoir_; |
255 |
FLAC__int16 *ssbuffer = (FLAC__int16*)reservoir_; |
256 |
|
257 |
(void)decoder; |
258 |
|
259 |
if (file_info->abort_flag) |
260 |
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; |
261 |
|
262 |
if (bps == 8) { |
263 |
for(sample = reservoir_samples_*channels, wide_sample = 0; wide_sample < wide_samples; wide_sample++) |
264 |
for(channel = 0; channel < channels; channel++, sample++) |
265 |
scbuffer[sample] = (FLAC__int8)buffer[channel][wide_sample]; |
266 |
} |
267 |
else if (bps == 16) { |
268 |
for(sample = reservoir_samples_*channels, wide_sample = 0; wide_sample < wide_samples; wide_sample++) |
269 |
for(channel = 0; channel < channels; channel++, sample++) |
270 |
ssbuffer[sample] = (FLAC__int16)buffer[channel][wide_sample]; |
271 |
} |
272 |
else { |
273 |
file_info->abort_flag = true; |
274 |
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; |
275 |
} |
276 |
|
277 |
reservoir_samples_ += wide_samples; |
278 |
|
279 |
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE; |
280 |
} |
281 |
|
282 |
void metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) |
283 |
{ |
284 |
file_info_struct *file_info = (file_info_struct *)client_data; |
285 |
(void)decoder; |
286 |
if (metadata->type == FLAC__METADATA_TYPE_STREAMINFO) { |
287 |
FLAC__ASSERT(metadata->data.stream_info.total_samples < 0x100000000); /* this plugin can only handle < 4 gigasamples */ |
288 |
file_info->total_samples = (unsigned)(metadata->data.stream_info.total_samples&0xffffffff); |
289 |
file_info->bits_per_sample = metadata->data.stream_info.bits_per_sample; |
290 |
file_info->channels = metadata->data.stream_info.channels; |
291 |
file_info->sample_rate = metadata->data.stream_info.sample_rate; |
292 |
|
293 |
if (file_info->bits_per_sample == 8) { |
294 |
file_info->sample_format = FMT_S8; |
295 |
} |
296 |
else if (file_info->bits_per_sample == 16) { |
297 |
file_info->sample_format = FMT_S16_NE; |
298 |
} |
299 |
else { |
300 |
file_info->abort_flag = true; |
301 |
return; |
302 |
} |
303 |
file_info->length_in_msec = file_info->total_samples * 10 / (file_info->sample_rate / 100); |
304 |
} |
305 |
} |
306 |
|
307 |
void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data) |
308 |
{ |
309 |
file_info_struct *file_info = (file_info_struct *)client_data; |
310 |
(void)decoder; |
311 |
if (status != FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC) |
312 |
file_info->abort_flag = true; |
313 |
} |
314 |
|
315 |
#elif ENABLE_FLAC_7 |
163 |
|
316 |
|
164 |
FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data) |
317 |
FLAC__StreamDecoderWriteStatus write_callback_(const FLAC__FileDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data) |
165 |
{ |
318 |
{ |
Link Here
|
227 |
file_info->abort_flag = true; |
380 |
file_info->abort_flag = true; |
228 |
} |
381 |
} |
229 |
|
382 |
|
|
|
383 |
#endif /* FLAC_ENABLE_8 */ |
230 |
|
384 |
|
231 |
|
385 |
#ifdef ENABLE_FLAC |
232 |
|
386 |
|
233 |
gboolean Flac_Header_Display_File_Info_To_UI (gchar *filename_utf8, ET_File_Info *ETFileInfo) |
387 |
gboolean Flac_Header_Display_File_Info_To_UI (gchar *filename_utf8, ET_File_Info *ETFileInfo) |
234 |
{ |
388 |
{ |