1 /* libFLAC - Free Lossless Audio Codec library
2 * Copyright (C) 2000,2001 Josh Coalson
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
22 #include <stdlib.h> /* for malloc() */
23 #include "FLAC/stream_decoder.h"
24 #include "private/bitbuffer.h"
25 #include "private/crc.h"
26 #include "private/fixed.h"
27 #include "private/lpc.h"
29 typedef struct FLAC__StreamDecoderPrivate {
30 FLAC__StreamDecoderReadStatus (*read_callback)(const FLAC__StreamDecoder *decoder, byte buffer[], unsigned *bytes, void *client_data);
31 FLAC__StreamDecoderWriteStatus (*write_callback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const int32 *buffer[], void *client_data);
32 void (*metadata_callback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetaData *metadata, void *client_data);
33 void (*error_callback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
35 FLAC__BitBuffer input;
36 int32 *output[FLAC__MAX_CHANNELS];
37 int32 *residual[FLAC__MAX_CHANNELS];
38 unsigned output_capacity;
39 uint32 last_frame_number;
40 uint64 samples_decoded;
41 bool has_stream_header;
42 FLAC__StreamMetaData stream_header;
44 } FLAC__StreamDecoderPrivate;
46 static byte ID3V2_TAG_[3] = { 'I', 'D', '3' };
48 static bool stream_decoder_allocate_output_(FLAC__StreamDecoder *decoder, unsigned size);
49 static bool stream_decoder_find_metadata_(FLAC__StreamDecoder *decoder);
50 static bool stream_decoder_read_metadata_(FLAC__StreamDecoder *decoder);
51 static bool stream_decoder_skip_id3v2_tag_(FLAC__StreamDecoder *decoder);
52 static bool stream_decoder_frame_sync_(FLAC__StreamDecoder *decoder);
53 static bool stream_decoder_read_frame_(FLAC__StreamDecoder *decoder, bool *got_a_frame);
54 static bool stream_decoder_read_frame_header_(FLAC__StreamDecoder *decoder);
55 static bool stream_decoder_read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps);
56 static bool stream_decoder_read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps);
57 static bool stream_decoder_read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order);
58 static bool stream_decoder_read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order);
59 static bool stream_decoder_read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps);
60 static bool stream_decoder_read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, unsigned predictor_order, unsigned partition_order, int32 *residual);
61 static bool stream_decoder_read_zero_padding_(FLAC__StreamDecoder *decoder);
62 static bool read_callback_(byte buffer[], unsigned *bytes, void *client_data);
64 const char *FLAC__StreamDecoderStateString[] = {
65 "FLAC__STREAM_DECODER_SEARCH_FOR_METADATA",
66 "FLAC__STREAM_DECODER_READ_METADATA",
67 "FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC",
68 "FLAC__STREAM_DECODER_READ_FRAME",
69 "FLAC__STREAM_DECODER_RESYNC_IN_HEADER",
70 "FLAC__STREAM_DECODER_END_OF_STREAM",
71 "FLAC__STREAM_DECODER_ABORTED",
72 "FLAC__STREAM_DECODER_UNPARSEABLE_STREAM",
73 "FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR",
74 "FLAC__STREAM_DECODER_UNINITIALIZED"
77 const char *FLAC__StreamDecoderReadStatusString[] = {
78 "FLAC__STREAM_DECODER_READ_CONTINUE",
79 "FLAC__STREAM_DECODER_READ_END_OF_STREAM",
80 "FLAC__STREAM_DECODER_READ_ABORT"
83 const char *FLAC__StreamDecoderWriteStatusString[] = {
84 "FLAC__STREAM_DECODER_WRITE_CONTINUE",
85 "FLAC__STREAM_DECODER_WRITE_ABORT"
88 const char *FLAC__StreamDecoderErrorStatusString[] = {
89 "FLAC__STREAM_DECODER_ERROR_LOST_SYNC"
92 FLAC__StreamDecoder *FLAC__stream_decoder_get_new_instance()
94 FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder*)malloc(sizeof(FLAC__StreamDecoder));
96 decoder->state = FLAC__STREAM_DECODER_UNINITIALIZED;
102 void FLAC__stream_decoder_free_instance(FLAC__StreamDecoder *decoder)
107 FLAC__StreamDecoderState FLAC__stream_decoder_init(
108 FLAC__StreamDecoder *decoder,
109 FLAC__StreamDecoderReadStatus (*read_callback)(const FLAC__StreamDecoder *decoder, byte buffer[], unsigned *bytes, void *client_data),
110 FLAC__StreamDecoderWriteStatus (*write_callback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const int32 *buffer[], void *client_data),
111 void (*metadata_callback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetaData *metadata, void *client_data),
112 void (*error_callback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data),
118 assert(sizeof(int) >= 4); /* we want to die right away if this is not true */
119 assert(decoder != 0);
120 assert(read_callback != 0);
121 assert(write_callback != 0);
122 assert(metadata_callback != 0);
123 assert(error_callback != 0);
124 assert(decoder->state == FLAC__STREAM_DECODER_UNINITIALIZED);
125 assert(decoder->guts == 0);
127 decoder->state = FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
129 decoder->guts = (FLAC__StreamDecoderPrivate*)malloc(sizeof(FLAC__StreamDecoderPrivate));
130 if(decoder->guts == 0)
131 return decoder->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
133 decoder->guts->read_callback = read_callback;
134 decoder->guts->write_callback = write_callback;
135 decoder->guts->metadata_callback = metadata_callback;
136 decoder->guts->error_callback = error_callback;
137 decoder->guts->client_data = client_data;
139 FLAC__bitbuffer_init(&decoder->guts->input);
141 for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
142 decoder->guts->output[i] = 0;
143 decoder->guts->residual[i] = 0;
146 decoder->guts->output_capacity = 0;
147 decoder->guts->last_frame_number = 0;
148 decoder->guts->samples_decoded = 0;
149 decoder->guts->has_stream_header = false;
151 return decoder->state;
154 void FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
157 assert(decoder != 0);
158 if(decoder->state == FLAC__STREAM_DECODER_UNINITIALIZED)
160 if(decoder->guts != 0) {
161 FLAC__bitbuffer_free(&decoder->guts->input);
162 for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
163 if(decoder->guts->output[i] != 0) {
164 free(decoder->guts->output[i]);
165 decoder->guts->output[i] = 0;
167 if(decoder->guts->residual[i] != 0) {
168 free(decoder->guts->residual[i]);
169 decoder->guts->residual[i] = 0;
175 decoder->state = FLAC__STREAM_DECODER_UNINITIALIZED;
178 bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder)
180 assert(decoder != 0);
182 if(!FLAC__bitbuffer_clear(&decoder->guts->input)) {
183 decoder->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
190 bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder)
192 assert(decoder != 0);
194 if(!FLAC__stream_decoder_flush(decoder)) {
195 decoder->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
198 decoder->state = FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
203 bool FLAC__stream_decoder_process_whole_stream(FLAC__StreamDecoder *decoder)
206 assert(decoder != 0);
208 if(decoder->state == FLAC__STREAM_DECODER_END_OF_STREAM)
211 assert(decoder->state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA);
213 if(!FLAC__stream_decoder_reset(decoder)) {
214 decoder->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
219 switch(decoder->state) {
220 case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
221 if(!stream_decoder_find_metadata_(decoder))
222 return false; /* above function sets the status for us */
224 case FLAC__STREAM_DECODER_READ_METADATA:
225 if(!stream_decoder_read_metadata_(decoder))
226 return false; /* above function sets the status for us */
228 case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
229 if(!stream_decoder_frame_sync_(decoder))
230 return true; /* above function sets the status for us */
232 case FLAC__STREAM_DECODER_READ_FRAME:
233 if(!stream_decoder_read_frame_(decoder, &dummy))
234 return false; /* above function sets the status for us */
236 case FLAC__STREAM_DECODER_END_OF_STREAM:
244 bool FLAC__stream_decoder_process_metadata(FLAC__StreamDecoder *decoder)
246 assert(decoder != 0);
248 if(decoder->state == FLAC__STREAM_DECODER_END_OF_STREAM)
251 assert(decoder->state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA);
253 if(!FLAC__stream_decoder_reset(decoder)) {
254 decoder->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
259 switch(decoder->state) {
260 case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
261 if(!stream_decoder_find_metadata_(decoder))
262 return false; /* above function sets the status for us */
264 case FLAC__STREAM_DECODER_READ_METADATA:
265 if(!stream_decoder_read_metadata_(decoder))
266 return false; /* above function sets the status for us */
268 case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
271 case FLAC__STREAM_DECODER_END_OF_STREAM:
279 bool FLAC__stream_decoder_process_one_frame(FLAC__StreamDecoder *decoder)
282 assert(decoder != 0);
284 if(decoder->state == FLAC__STREAM_DECODER_END_OF_STREAM)
287 assert(decoder->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC);
290 switch(decoder->state) {
291 case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
292 if(!stream_decoder_frame_sync_(decoder))
293 return true; /* above function sets the status for us */
295 case FLAC__STREAM_DECODER_READ_FRAME:
296 if(!stream_decoder_read_frame_(decoder, &got_a_frame))
297 return false; /* above function sets the status for us */
299 return true; /* above function sets the status for us */
301 case FLAC__STREAM_DECODER_END_OF_STREAM:
309 bool FLAC__stream_decoder_process_remaining_frames(FLAC__StreamDecoder *decoder)
312 assert(decoder != 0);
314 if(decoder->state == FLAC__STREAM_DECODER_END_OF_STREAM)
317 assert(decoder->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC);
320 switch(decoder->state) {
321 case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
322 if(!stream_decoder_frame_sync_(decoder))
323 return true; /* above function sets the status for us */
325 case FLAC__STREAM_DECODER_READ_FRAME:
326 if(!stream_decoder_read_frame_(decoder, &dummy))
327 return false; /* above function sets the status for us */
329 case FLAC__STREAM_DECODER_END_OF_STREAM:
337 unsigned FLAC__stream_decoder_input_bytes_unconsumed(FLAC__StreamDecoder *decoder)
339 assert(decoder != 0);
340 return decoder->guts->input.bytes - decoder->guts->input.consumed_bytes;
343 bool stream_decoder_allocate_output_(FLAC__StreamDecoder *decoder, unsigned size)
348 if(size <= decoder->guts->output_capacity)
351 /* @@@ should change to use realloc() */
353 for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
354 if(decoder->guts->output[i] != 0) {
355 free(decoder->guts->output[i]);
356 decoder->guts->output[i] = 0;
358 if(decoder->guts->residual[i] != 0) {
359 free(decoder->guts->residual[i]);
360 decoder->guts->residual[i] = 0;
364 for(i = 0; i < decoder->guts->frame.header.channels; i++) {
365 tmp = (int32*)malloc(sizeof(int32)*size);
367 decoder->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
370 decoder->guts->output[i] = tmp;
372 tmp = (int32*)malloc(sizeof(int32)*size);
374 decoder->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
377 decoder->guts->residual[i] = tmp;
380 decoder->guts->output_capacity = size;
385 bool stream_decoder_find_metadata_(FLAC__StreamDecoder *decoder)
391 assert(decoder->guts->input.consumed_bits == 0); /* make sure we're byte aligned */
393 for(i = id = 0; i < 4; ) {
394 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, 8, read_callback_, decoder))
395 return false; /* the read_callback_ sets the state for us */
396 if(x == FLAC__STREAM_SYNC_STRING[i]) {
402 if(x == ID3V2_TAG_[id]) {
406 if(!stream_decoder_skip_id3v2_tag_(decoder))
407 return false; /* the read_callback_ sets the state for us */
411 if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
413 if(!FLAC__bitbuffer_peek_bit(&decoder->guts->input, &y, read_callback_, decoder))
414 return false; /* the read_callback_ sets the state for us */
415 if(!y) { /* MAGIC NUMBER for the last sync bit */
416 decoder->state = FLAC__STREAM_DECODER_READ_FRAME;
422 decoder->guts->error_callback(decoder, FLAC__STREAM_DECODER_ERROR_LOST_SYNC, decoder->guts->client_data);
427 decoder->state = FLAC__STREAM_DECODER_READ_METADATA;
431 bool stream_decoder_read_metadata_(FLAC__StreamDecoder *decoder)
433 uint32 i, x, last_block, type, length;
435 assert(decoder->guts->input.consumed_bits == 0); /* make sure we're byte aligned */
437 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &last_block, FLAC__STREAM_METADATA_IS_LAST_LEN, read_callback_, decoder))
438 return false; /* the read_callback_ sets the state for us */
439 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &type, FLAC__STREAM_METADATA_TYPE_LEN, read_callback_, decoder))
440 return false; /* the read_callback_ sets the state for us */
441 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &length, FLAC__STREAM_METADATA_LENGTH_LEN, read_callback_, decoder))
442 return false; /* the read_callback_ sets the state for us */
443 if(type == FLAC__METADATA_TYPE_ENCODING) {
444 unsigned used_bits = 0;
445 decoder->guts->stream_header.type = type;
446 decoder->guts->stream_header.is_last = last_block;
447 decoder->guts->stream_header.length = length;
449 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, FLAC__STREAM_METADATA_ENCODING_MIN_BLOCK_SIZE_LEN, read_callback_, decoder))
450 return false; /* the read_callback_ sets the state for us */
451 decoder->guts->stream_header.data.encoding.min_blocksize = x;
452 used_bits += FLAC__STREAM_METADATA_ENCODING_MIN_BLOCK_SIZE_LEN;
454 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, FLAC__STREAM_METADATA_ENCODING_MAX_BLOCK_SIZE_LEN, read_callback_, decoder))
455 return false; /* the read_callback_ sets the state for us */
456 decoder->guts->stream_header.data.encoding.max_blocksize = x;
457 used_bits += FLAC__STREAM_METADATA_ENCODING_MAX_BLOCK_SIZE_LEN;
459 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, FLAC__STREAM_METADATA_ENCODING_MIN_FRAME_SIZE_LEN, read_callback_, decoder))
460 return false; /* the read_callback_ sets the state for us */
461 decoder->guts->stream_header.data.encoding.min_framesize = x;
462 used_bits += FLAC__STREAM_METADATA_ENCODING_MIN_FRAME_SIZE_LEN;
464 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, FLAC__STREAM_METADATA_ENCODING_MAX_FRAME_SIZE_LEN, read_callback_, decoder))
465 return false; /* the read_callback_ sets the state for us */
466 decoder->guts->stream_header.data.encoding.max_framesize = x;
467 used_bits += FLAC__STREAM_METADATA_ENCODING_MAX_FRAME_SIZE_LEN;
469 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, FLAC__STREAM_METADATA_ENCODING_SAMPLE_RATE_LEN, read_callback_, decoder))
470 return false; /* the read_callback_ sets the state for us */
471 decoder->guts->stream_header.data.encoding.sample_rate = x;
472 used_bits += FLAC__STREAM_METADATA_ENCODING_SAMPLE_RATE_LEN;
474 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, FLAC__STREAM_METADATA_ENCODING_CHANNELS_LEN, read_callback_, decoder))
475 return false; /* the read_callback_ sets the state for us */
476 decoder->guts->stream_header.data.encoding.channels = x+1;
477 used_bits += FLAC__STREAM_METADATA_ENCODING_CHANNELS_LEN;
479 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, FLAC__STREAM_METADATA_ENCODING_BITS_PER_SAMPLE_LEN, read_callback_, decoder))
480 return false; /* the read_callback_ sets the state for us */
481 decoder->guts->stream_header.data.encoding.bits_per_sample = x+1;
482 used_bits += FLAC__STREAM_METADATA_ENCODING_BITS_PER_SAMPLE_LEN;
484 if(!FLAC__bitbuffer_read_raw_uint64(&decoder->guts->input, &decoder->guts->stream_header.data.encoding.total_samples, FLAC__STREAM_METADATA_ENCODING_TOTAL_SAMPLES_LEN, read_callback_, decoder))
485 return false; /* the read_callback_ sets the state for us */
486 used_bits += FLAC__STREAM_METADATA_ENCODING_TOTAL_SAMPLES_LEN;
488 for(i = 0; i < 16; i++) {
489 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, 8, read_callback_, decoder))
490 return false; /* the read_callback_ sets the state for us */
491 decoder->guts->stream_header.data.encoding.md5sum[i] = (byte)x;
495 /* skip the rest of the block */
496 assert(used_bits % 8 == 0);
497 length -= (used_bits / 8);
498 for(i = 0; i < length; i++) {
499 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, 8, read_callback_, decoder))
500 return false; /* the read_callback_ sets the state for us */
503 decoder->guts->has_stream_header = true;
504 decoder->guts->metadata_callback(decoder, &decoder->guts->stream_header, decoder->guts->client_data);
507 /* skip other metadata blocks */
508 for(i = 0; i < length; i++) {
509 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, 8, read_callback_, decoder))
510 return false; /* the read_callback_ sets the state for us */
515 decoder->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
520 bool stream_decoder_skip_id3v2_tag_(FLAC__StreamDecoder *decoder)
525 /* skip the version and flags bytes */
526 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, 24, read_callback_, decoder))
527 return false; /* the read_callback_ sets the state for us */
528 /* get the size (in bytes) to skip */
530 for(i = 0; i < 4; i++) {
531 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, 8, read_callback_, decoder))
532 return false; /* the read_callback_ sets the state for us */
536 /* skip the rest of the tag */
537 for(i = 0; i < skip; i++) {
538 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, 8, read_callback_, decoder))
539 return false; /* the read_callback_ sets the state for us */
544 bool stream_decoder_frame_sync_(FLAC__StreamDecoder *decoder)
549 /* If we know the total number of samples in the stream, stop if we've read that many. */
550 /* This will stop us, for example, from wasting time trying to sync on an ID3V1 tag. */
551 if(decoder->guts->has_stream_header && decoder->guts->stream_header.data.encoding.total_samples) {
552 if(decoder->guts->samples_decoded >= decoder->guts->stream_header.data.encoding.total_samples) {
553 decoder->state = FLAC__STREAM_DECODER_END_OF_STREAM;
558 /* make sure we're byte aligned */
559 if(decoder->guts->input.consumed_bits != 0) {
560 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, 8-decoder->guts->input.consumed_bits, read_callback_, decoder))
561 return false; /* the read_callback_ sets the state for us */
565 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, 8, read_callback_, decoder))
566 return false; /* the read_callback_ sets the state for us */
567 if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
569 if(!FLAC__bitbuffer_peek_bit(&decoder->guts->input, &y, read_callback_, decoder))
570 return false; /* the read_callback_ sets the state for us */
571 if(!y) { /* MAGIC NUMBER for the last sync bit */
572 decoder->state = FLAC__STREAM_DECODER_READ_FRAME;
577 decoder->guts->error_callback(decoder, FLAC__STREAM_DECODER_ERROR_LOST_SYNC, decoder->guts->client_data);
585 bool stream_decoder_read_frame_(FLAC__StreamDecoder *decoder, bool *got_a_frame)
589 int32 mid, side, left, right;
591 *got_a_frame = false;
593 if(!stream_decoder_read_frame_header_(decoder))
595 if(decoder->state != FLAC__STREAM_DECODER_READ_FRAME) {
596 if(decoder->state == FLAC__STREAM_DECODER_RESYNC_IN_HEADER)
597 decoder->state = FLAC__STREAM_DECODER_READ_FRAME;
599 decoder->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
602 if(!stream_decoder_allocate_output_(decoder, decoder->guts->frame.header.blocksize))
604 for(channel = 0; channel < decoder->guts->frame.header.channels; channel++) {
606 * first figure the correct bits-per-sample of the subframe
608 unsigned bps = decoder->guts->frame.header.bits_per_sample;
609 switch(decoder->guts->frame.header.channel_assignment) {
610 case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
611 /* no adjustment needed */
613 case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
617 case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
621 case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
631 if(!stream_decoder_read_subframe_(decoder, channel, bps))
633 if(decoder->state != FLAC__STREAM_DECODER_READ_FRAME) {
634 decoder->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
638 if(!stream_decoder_read_zero_padding_(decoder))
641 /* Undo any special channel coding */
642 switch(decoder->guts->frame.header.channel_assignment) {
643 case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
646 case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
647 assert(decoder->guts->frame.header.channels == 2);
648 for(i = 0; i < decoder->guts->frame.header.blocksize; i++)
649 decoder->guts->output[1][i] = decoder->guts->output[0][i] - decoder->guts->output[1][i];
651 case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
652 assert(decoder->guts->frame.header.channels == 2);
653 for(i = 0; i < decoder->guts->frame.header.blocksize; i++)
654 decoder->guts->output[0][i] += decoder->guts->output[1][i];
656 case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
657 assert(decoder->guts->frame.header.channels == 2);
658 for(i = 0; i < decoder->guts->frame.header.blocksize; i++) {
659 mid = decoder->guts->output[0][i];
660 side = decoder->guts->output[1][i];
662 if(side & 1) /* i.e. if 'side' is odd... */
666 decoder->guts->output[0][i] = left >> 1;
667 decoder->guts->output[1][i] = right >> 1;
677 /* put the latest values into the public section of the decoder instance */
678 decoder->channels = decoder->guts->frame.header.channels;
679 decoder->channel_assignment = decoder->guts->frame.header.channel_assignment;
680 decoder->bits_per_sample = decoder->guts->frame.header.bits_per_sample;
681 decoder->sample_rate = decoder->guts->frame.header.sample_rate;
682 decoder->blocksize = decoder->guts->frame.header.blocksize;
684 decoder->guts->samples_decoded += decoder->guts->frame.header.blocksize;
687 if(decoder->guts->write_callback(decoder, &decoder->guts->frame, decoder->guts->output, decoder->guts->client_data) != FLAC__STREAM_DECODER_WRITE_CONTINUE)
690 decoder->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
694 bool stream_decoder_read_frame_header_(FLAC__StreamDecoder *decoder)
698 unsigned i, blocksize_hint = 0, sample_rate_hint = 0;
699 byte crc, raw_header[15]; /* MAGIC NUMBER based on the maximum frame header size, including CRC */
700 unsigned raw_header_len;
701 bool is_unparseable = false;
703 assert(decoder->guts->input.consumed_bits == 0); /* make sure we're byte aligned */
705 /* init the raw header with the first 8 bits of the sync code */
706 raw_header[0] = 0xff; /* MAGIC NUMBER for the first 8 frame sync bits */
710 * read in the raw header as bytes so we can CRC it, and parse it on the way
712 for(i = 0; i < 2; i++) {
713 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, 8, read_callback_, decoder))
714 return false; /* the read_callback_ sets the state for us */
715 else if(x == 0xff) { /* MAGIC NUMBER for the first part of the sync code */
716 /* if we get here it means our original sync was erroneous since the sync code cannot appear in the header */
718 if(!FLAC__bitbuffer_peek_bit(&decoder->guts->input, &y, read_callback_, decoder))
719 return false; /* the read_callback_ sets the state for us */
720 if(!y) { /* MAGIC NUMBER for the last sync bit */
721 decoder->state = FLAC__STREAM_DECODER_RESYNC_IN_HEADER;
725 decoder->guts->error_callback(decoder, FLAC__STREAM_DECODER_ERROR_LOST_SYNC, decoder->guts->client_data);
726 decoder->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
730 raw_header[raw_header_len++] = (byte)x;
732 assert(!(raw_header[1] & 0x80)); /* last sync bit should be confirmed zero before we get here */
734 switch(x = raw_header[1] >> 4) {
736 if(decoder->guts->has_stream_header && decoder->guts->stream_header.data.encoding.min_blocksize == decoder->guts->stream_header.data.encoding.max_blocksize) /* i.e. it's a fixed-blocksize stream */
737 decoder->guts->frame.header.blocksize = decoder->guts->stream_header.data.encoding.min_blocksize;
739 is_unparseable = true;
742 decoder->guts->frame.header.blocksize = 192;
748 decoder->guts->frame.header.blocksize = 576 << (x-2);
759 switch(x = raw_header[1] & 0x0f) {
761 if(decoder->guts->has_stream_header)
762 decoder->guts->frame.header.sample_rate = decoder->guts->stream_header.data.encoding.sample_rate;
764 is_unparseable = true;
769 is_unparseable = true;
772 decoder->guts->frame.header.sample_rate = 8000;
775 decoder->guts->frame.header.sample_rate = 16000;
778 decoder->guts->frame.header.sample_rate = 22050;
781 decoder->guts->frame.header.sample_rate = 24000;
784 decoder->guts->frame.header.sample_rate = 32000;
787 decoder->guts->frame.header.sample_rate = 44100;
790 decoder->guts->frame.header.sample_rate = 48000;
793 decoder->guts->frame.header.sample_rate = 96000;
798 sample_rate_hint = x;
801 decoder->guts->error_callback(decoder, FLAC__STREAM_DECODER_ERROR_LOST_SYNC, decoder->guts->client_data);
802 decoder->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
808 x = (unsigned)(raw_header[2] >> 4);
810 decoder->guts->frame.header.channels = 2;
813 decoder->guts->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE;
816 decoder->guts->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE;
819 decoder->guts->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_MID_SIDE;
822 is_unparseable = true;
827 decoder->guts->frame.header.channels = (unsigned)x + 1;
828 decoder->guts->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
831 switch(x = (unsigned)(raw_header[2] & 0x0e) >> 1) {
833 if(decoder->guts->has_stream_header)
834 decoder->guts->frame.header.bits_per_sample = decoder->guts->stream_header.data.encoding.bits_per_sample;
836 is_unparseable = true;
839 decoder->guts->frame.header.bits_per_sample = 8;
842 decoder->guts->frame.header.bits_per_sample = 12;
845 decoder->guts->frame.header.bits_per_sample = 16;
848 decoder->guts->frame.header.bits_per_sample = 20;
851 decoder->guts->frame.header.bits_per_sample = 24;
855 is_unparseable = true;
862 if(raw_header[2] & 0x01) { /* this should be a zero padding bit */
863 decoder->guts->error_callback(decoder, FLAC__STREAM_DECODER_ERROR_LOST_SYNC, decoder->guts->client_data);
864 decoder->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
869 if(!FLAC__bitbuffer_read_utf8_uint64(&decoder->guts->input, &xx, read_callback_, decoder, raw_header, &raw_header_len))
870 return false; /* the read_callback_ sets the state for us */
871 if(xx == 0xffffffffffffffff) {
872 if(raw_header[raw_header_len-1] == 0xff) { /* MAGIC NUMBER for sync code */
874 if(!FLAC__bitbuffer_peek_bit(&decoder->guts->input, &y, read_callback_, decoder))
875 return false; /* the read_callback_ sets the state for us */
876 if(!y) { /* MAGIC NUMBER for the last sync bit */
877 decoder->state = FLAC__STREAM_DECODER_RESYNC_IN_HEADER;
881 decoder->guts->error_callback(decoder, FLAC__STREAM_DECODER_ERROR_LOST_SYNC, decoder->guts->client_data);
882 decoder->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
887 decoder->guts->error_callback(decoder, FLAC__STREAM_DECODER_ERROR_LOST_SYNC, decoder->guts->client_data);
888 decoder->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
892 if(decoder->guts->has_stream_header && decoder->guts->stream_header.data.encoding.min_blocksize == decoder->guts->stream_header.data.encoding.max_blocksize) /* i.e. it's a fixed-blocksize stream */
893 decoder->guts->frame.header.number.sample_number = (uint64)decoder->guts->last_frame_number * (int64)decoder->guts->stream_header.data.encoding.min_blocksize + xx;
895 decoder->guts->frame.header.number.sample_number = xx;
898 if(!FLAC__bitbuffer_read_utf8_uint32(&decoder->guts->input, &x, read_callback_, decoder, raw_header, &raw_header_len))
899 return false; /* the read_callback_ sets the state for us */
900 if(x == 0xffffffff) {
901 if(raw_header[raw_header_len-1] == 0xff) { /* MAGIC NUMBER for sync code */
903 if(!FLAC__bitbuffer_peek_bit(&decoder->guts->input, &y, read_callback_, decoder))
904 return false; /* the read_callback_ sets the state for us */
905 if(!y) { /* MAGIC NUMBER for the last sync bit */
906 decoder->state = FLAC__STREAM_DECODER_RESYNC_IN_HEADER;
910 decoder->guts->error_callback(decoder, FLAC__STREAM_DECODER_ERROR_LOST_SYNC, decoder->guts->client_data);
911 decoder->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
916 decoder->guts->error_callback(decoder, FLAC__STREAM_DECODER_ERROR_LOST_SYNC, decoder->guts->client_data);
917 decoder->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
921 decoder->guts->last_frame_number = x;
922 if(decoder->guts->has_stream_header) {
923 decoder->guts->frame.header.number.sample_number = (int64)decoder->guts->stream_header.data.encoding.min_blocksize * (int64)x;
926 is_unparseable = true;
931 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, 8, read_callback_, decoder))
932 return false; /* the read_callback_ sets the state for us */
933 raw_header[raw_header_len++] = (byte)x;
934 if(blocksize_hint == 7) {
936 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &_x, 8, read_callback_, decoder))
937 return false; /* the read_callback_ sets the state for us */
938 raw_header[raw_header_len++] = (byte)_x;
941 decoder->guts->frame.header.blocksize = x+1;
944 if(sample_rate_hint) {
945 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, 8, read_callback_, decoder))
946 return false; /* the read_callback_ sets the state for us */
947 raw_header[raw_header_len++] = (byte)x;
948 if(sample_rate_hint != 12) {
950 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &_x, 8, read_callback_, decoder))
951 return false; /* the read_callback_ sets the state for us */
952 raw_header[raw_header_len++] = (byte)_x;
955 if(sample_rate_hint == 12)
956 decoder->guts->frame.header.sample_rate = x*1000;
957 else if(sample_rate_hint == 13)
958 decoder->guts->frame.header.sample_rate = x;
960 decoder->guts->frame.header.sample_rate = x*10;
963 /* read the crc byte */
964 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, 8, read_callback_, decoder))
965 return false; /* the read_callback_ sets the state for us */
968 if(FLAC__crc8(raw_header, raw_header_len) != crc) {
969 decoder->guts->error_callback(decoder, FLAC__STREAM_DECODER_ERROR_LOST_SYNC, decoder->guts->client_data);
970 decoder->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
975 decoder->state = FLAC__STREAM_DECODER_UNPARSEABLE_STREAM;
982 bool stream_decoder_read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps)
986 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &x, FLAC__SUBFRAME_TYPE_LEN, read_callback_, decoder))
987 return false; /* the read_callback_ sets the state for us */
988 if(x & 0x01 || x & 0x80) {
989 decoder->guts->error_callback(decoder, FLAC__STREAM_DECODER_ERROR_LOST_SYNC, decoder->guts->client_data);
990 decoder->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
994 return stream_decoder_read_subframe_constant_(decoder, channel, bps);
997 return stream_decoder_read_subframe_verbatim_(decoder, channel, bps);
1000 decoder->state = FLAC__STREAM_DECODER_UNPARSEABLE_STREAM;
1004 return stream_decoder_read_subframe_fixed_(decoder, channel, bps, (x>>1)&7);
1007 decoder->state = FLAC__STREAM_DECODER_UNPARSEABLE_STREAM;
1011 return stream_decoder_read_subframe_lpc_(decoder, channel, bps, ((x>>1)&31)+1);
1015 bool stream_decoder_read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps)
1017 FLAC__Subframe_Constant *subframe = &decoder->guts->frame.subframes[channel].data.constant;
1020 int32 *output = decoder->guts->output[channel];
1022 decoder->guts->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_CONSTANT;
1024 if(!FLAC__bitbuffer_read_raw_int32(&decoder->guts->input, &x, bps, read_callback_, decoder))
1025 return false; /* the read_callback_ sets the state for us */
1027 subframe->value = x;
1029 /* decode the subframe */
1030 for(i = 0; i < decoder->guts->frame.header.blocksize; i++)
1036 bool stream_decoder_read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order)
1038 FLAC__Subframe_Fixed *subframe = &decoder->guts->frame.subframes[channel].data.fixed;
1043 decoder->guts->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_FIXED;
1045 subframe->residual = decoder->guts->residual[channel];
1046 subframe->order = order;
1048 /* read warm-up samples */
1049 for(u = 0; u < order; u++) {
1050 if(!FLAC__bitbuffer_read_raw_int32(&decoder->guts->input, &i32, bps, read_callback_, decoder))
1051 return false; /* the read_callback_ sets the state for us */
1052 subframe->warmup[u] = i32;
1055 /* read entropy coding method info */
1056 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN, read_callback_, decoder))
1057 return false; /* the read_callback_ sets the state for us */
1058 subframe->entropy_coding_method.type = u32;
1059 switch(subframe->entropy_coding_method.type) {
1060 case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
1061 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN, read_callback_, decoder))
1062 return false; /* the read_callback_ sets the state for us */
1063 subframe->entropy_coding_method.data.partitioned_rice.order = u32;
1066 decoder->state = FLAC__STREAM_DECODER_UNPARSEABLE_STREAM;
1071 switch(subframe->entropy_coding_method.type) {
1072 case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
1073 if(!stream_decoder_read_residual_partitioned_rice_(decoder, order, subframe->entropy_coding_method.data.partitioned_rice.order, decoder->guts->residual[channel]))
1080 /* decode the subframe */
1081 memcpy(decoder->guts->output[channel], subframe->warmup, sizeof(int32) * order);
1082 FLAC__fixed_restore_signal(decoder->guts->residual[channel], decoder->guts->frame.header.blocksize-order, order, decoder->guts->output[channel]+order);
1087 bool stream_decoder_read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order)
1089 FLAC__Subframe_LPC *subframe = &decoder->guts->frame.subframes[channel].data.lpc;
1094 decoder->guts->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_LPC;
1096 subframe->residual = decoder->guts->residual[channel];
1097 subframe->order = order;
1099 /* read warm-up samples */
1100 for(u = 0; u < order; u++) {
1101 if(!FLAC__bitbuffer_read_raw_int32(&decoder->guts->input, &i32, bps, read_callback_, decoder))
1102 return false; /* the read_callback_ sets the state for us */
1103 subframe->warmup[u] = i32;
1106 /* read qlp coeff precision */
1107 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &u32, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN, read_callback_, decoder))
1108 return false; /* the read_callback_ sets the state for us */
1110 decoder->guts->error_callback(decoder, FLAC__STREAM_DECODER_ERROR_LOST_SYNC, decoder->guts->client_data);
1111 decoder->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
1114 subframe->qlp_coeff_precision = u32+1;
1116 /* read qlp shift */
1117 if(!FLAC__bitbuffer_read_raw_int32(&decoder->guts->input, &i32, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN, read_callback_, decoder))
1118 return false; /* the read_callback_ sets the state for us */
1119 subframe->quantization_level = i32;
1121 /* read quantized lp coefficiencts */
1122 for(u = 0; u < order; u++) {
1123 if(!FLAC__bitbuffer_read_raw_int32(&decoder->guts->input, &i32, subframe->qlp_coeff_precision, read_callback_, decoder))
1124 return false; /* the read_callback_ sets the state for us */
1125 subframe->qlp_coeff[u] = i32;
1128 /* read entropy coding method info */
1129 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN, read_callback_, decoder))
1130 return false; /* the read_callback_ sets the state for us */
1131 subframe->entropy_coding_method.type = u32;
1132 switch(subframe->entropy_coding_method.type) {
1133 case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
1134 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN, read_callback_, decoder))
1135 return false; /* the read_callback_ sets the state for us */
1136 subframe->entropy_coding_method.data.partitioned_rice.order = u32;
1139 decoder->state = FLAC__STREAM_DECODER_UNPARSEABLE_STREAM;
1144 switch(subframe->entropy_coding_method.type) {
1145 case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
1146 if(!stream_decoder_read_residual_partitioned_rice_(decoder, order, subframe->entropy_coding_method.data.partitioned_rice.order, decoder->guts->residual[channel]))
1153 /* decode the subframe */
1154 memcpy(decoder->guts->output[channel], subframe->warmup, sizeof(int32) * order);
1155 FLAC__lpc_restore_signal(decoder->guts->residual[channel], decoder->guts->frame.header.blocksize-order, subframe->qlp_coeff, order, subframe->quantization_level, decoder->guts->output[channel]+order);
1160 bool stream_decoder_read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps)
1162 FLAC__Subframe_Verbatim *subframe = &decoder->guts->frame.subframes[channel].data.verbatim;
1163 int32 x, *residual = decoder->guts->residual[channel];
1166 decoder->guts->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_VERBATIM;
1168 subframe->data = residual;
1170 for(i = 0; i < decoder->guts->frame.header.blocksize; i++) {
1171 if(!FLAC__bitbuffer_read_raw_int32(&decoder->guts->input, &x, bps, read_callback_, decoder))
1172 return false; /* the read_callback_ sets the state for us */
1176 /* decode the subframe */
1177 memcpy(decoder->guts->output[channel], subframe->data, sizeof(int32) * decoder->guts->frame.header.blocksize);
1182 bool stream_decoder_read_residual_partitioned_rice_(FLAC__StreamDecoder *decoder, unsigned predictor_order, unsigned partition_order, int32 *residual)
1184 uint32 rice_parameter;
1186 unsigned partition, sample, u;
1187 const unsigned partitions = 1u << partition_order;
1188 const unsigned partition_samples = partition_order > 0? decoder->guts->frame.header.blocksize >> partition_order : decoder->guts->frame.header.blocksize - predictor_order;
1191 for(partition = 0; partition < partitions; partition++) {
1192 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN, read_callback_, decoder))
1193 return false; /* the read_callback_ sets the state for us */
1194 for(u = (partition_order == 0 || partition > 0)? 0 : predictor_order; u < partition_samples; u++, sample++) {
1195 if(!FLAC__bitbuffer_read_rice_signed(&decoder->guts->input, &i, rice_parameter, read_callback_, decoder))
1196 return false; /* the read_callback_ sets the state for us */
1197 residual[sample] = i;
1204 bool stream_decoder_read_zero_padding_(FLAC__StreamDecoder *decoder)
1206 if(decoder->guts->input.consumed_bits != 0) {
1208 if(!FLAC__bitbuffer_read_raw_uint32(&decoder->guts->input, &zero, 8-decoder->guts->input.consumed_bits, read_callback_, decoder))
1209 return false; /* the read_callback_ sets the state for us */
1211 decoder->guts->error_callback(decoder, FLAC__STREAM_DECODER_ERROR_LOST_SYNC, decoder->guts->client_data);
1212 decoder->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
1218 bool read_callback_(byte buffer[], unsigned *bytes, void *client_data)
1220 FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder *)client_data;
1221 FLAC__StreamDecoderReadStatus status;
1222 status = decoder->guts->read_callback(decoder, buffer, bytes, decoder->guts->client_data);
1223 if(status == FLAC__STREAM_DECODER_READ_END_OF_STREAM)
1224 decoder->state = FLAC__STREAM_DECODER_END_OF_STREAM;
1225 else if(status == FLAC__STREAM_DECODER_READ_ABORT)
1226 decoder->state = FLAC__STREAM_DECODER_ABORTED;
1227 return status == FLAC__STREAM_DECODER_READ_CONTINUE;