Example #1
0
 FLACInputStream::~FLACInputStream() {
   if (m_decoder) {
     FLAC__seekable_stream_decoder_finish(m_decoder);
     FLAC__seekable_stream_decoder_delete(m_decoder);
     m_decoder = 0;
   }
 }
Example #2
0
void FlacPcm::cleanup()
{
	if(decoder) {
		FLAC__seekable_stream_decoder_finish(decoder);
		FLAC__seekable_stream_decoder_delete(decoder);
		decoder = 0;
	}
}
Example #3
0
void FLAC__file_decoder_delete(FLAC__FileDecoder *decoder)
{
	FLAC__ASSERT(0 != decoder);
	FLAC__ASSERT(0 != decoder->protected_);
	FLAC__ASSERT(0 != decoder->private_);
	FLAC__ASSERT(0 != decoder->private_->seekable_stream_decoder);

	(void)FLAC__file_decoder_finish(decoder);

	FLAC__seekable_stream_decoder_delete(decoder->private_->seekable_stream_decoder);

	free(decoder->private_);
	free(decoder->protected_);
	free(decoder);
}
Example #4
0
  bool
  FLACInputStream::initialize(FilePtr file) {
    m_file = file;

    // initialize the decoder
    m_decoder = FLAC__seekable_stream_decoder_new();
    if (!m_decoder) {
      m_file = 0;
      return false;
    }

#define SET_CALLBACK(name)                                   \
  FLAC__seekable_stream_decoder_set_##name##_callback(       \
    m_decoder,                                               \
    name##_callback)

    // set callbacks
    FLAC__seekable_stream_decoder_set_client_data      (m_decoder, this);
    SET_CALLBACK(read);
    SET_CALLBACK(seek);
    SET_CALLBACK(tell);
    SET_CALLBACK(length);
    SET_CALLBACK(eof);
    SET_CALLBACK(write);
    SET_CALLBACK(metadata);
    SET_CALLBACK(error);

    FLAC__SeekableStreamDecoderState state =
      FLAC__seekable_stream_decoder_init(m_decoder);
    if (state != FLAC__SEEKABLE_STREAM_DECODER_OK) {
      FLAC__seekable_stream_decoder_finish(m_decoder);
      FLAC__seekable_stream_decoder_delete(m_decoder);
      m_decoder = 0;
      m_file = 0;
      return false;
    }

    // make sure we have metadata before we return!
    if (!FLAC__seekable_stream_decoder_process_until_end_of_metadata(m_decoder)) {
      FLAC__seekable_stream_decoder_finish(m_decoder);
      FLAC__seekable_stream_decoder_delete(m_decoder);
      m_decoder = 0;
      m_file = 0;
      return false;
    }

    // process one frame so we can do something!
    if (!FLAC__seekable_stream_decoder_process_single(m_decoder)) {
      FLAC__seekable_stream_decoder_finish(m_decoder);
      FLAC__seekable_stream_decoder_delete(m_decoder);
      m_decoder = 0;
      m_file = 0;
      return false;
    }

    // get info about the flac file
    m_channel_count = FLAC__seekable_stream_decoder_get_channels(m_decoder);
    m_sample_rate   = FLAC__seekable_stream_decoder_get_sample_rate(m_decoder);
    int bps         = FLAC__seekable_stream_decoder_get_bits_per_sample(m_decoder);
    if (bps == 16) {
      m_sample_format = SF_S16;
    } else if (bps == 8) {
      m_sample_format = SF_U8;
    } else {
      return false;
    }

    return true;
  }
Example #5
0
int main(int argc, char *argv[])
{
	if (argc!=2)
	{
		fprintf(stderr, "usage: %s flacfile\n", argv[0]);
		return -1;
	}
	myfile = fopen(argv[1], "ro");
	if (!myfile)
	{
		perror("fopen()");
		return -1;
	}

	decoder = FLAC__seekable_stream_decoder_new();
	if (!decoder)
	{
		fprintf(stderr, "FLAC__seekable_stream_decoder_new() failed, out of memory?\n");
		return 1;
	}
	
	FLAC__seekable_stream_decoder_set_md5_checking(decoder, 0);

	FLAC__seekable_stream_decoder_set_read_callback(decoder, read_callback);
	FLAC__seekable_stream_decoder_set_write_callback(decoder, write_callback);
	FLAC__seekable_stream_decoder_set_metadata_callback(decoder, metadata_callback);
	FLAC__seekable_stream_decoder_set_seek_callback(decoder, seek_callback);
	FLAC__seekable_stream_decoder_set_tell_callback(decoder, tell_callback);
	FLAC__seekable_stream_decoder_set_length_callback(decoder, length_callback);
	FLAC__seekable_stream_decoder_set_eof_callback(decoder, eof_callback);

	FLAC__seekable_stream_decoder_set_client_data(decoder, myvar);

	FLAC__seekable_stream_decoder_set_error_callback(decoder, error_callback);

	switch (FLAC__seekable_stream_decoder_init(decoder))
	{
		case FLAC__SEEKABLE_STREAM_DECODER_OK:
			fprintf(stderr, "init ok\n");
			break;
		case FLAC__SEEKABLE_STREAM_DECODER_SEEKING:
			fprintf(stderr, "seeking\n");
			break;
		case FLAC__SEEKABLE_STREAM_DECODER_END_OF_STREAM:
			fprintf(stderr, "eof\n");
			break;
		case FLAC__SEEKABLE_STREAM_DECODER_MEMORY_ALLOCATION_ERROR:
			fprintf(stderr, "malloc failed\n");
			break;
		case FLAC__SEEKABLE_STREAM_DECODER_STREAM_DECODER_ERROR:
			fprintf(stderr, "decoder error\n");
			break;
		case FLAC__SEEKABLE_STREAM_DECODER_READ_ERROR:
			fprintf(stderr, "read error\n");
			break;
		case FLAC__SEEKABLE_STREAM_DECODER_SEEK_ERROR:
			fprintf(stderr, "seek error\n");
			break;
		case FLAC__SEEKABLE_STREAM_DECODER_ALREADY_INITIALIZED:
			fprintf(stderr, "already init'ed\n");
			break;
		case FLAC__SEEKABLE_STREAM_DECODER_INVALID_CALLBACK:
			fprintf(stderr, "invalid callback\n");
			break;
		case FLAC__SEEKABLE_STREAM_DECODER_UNINITIALIZED:
			fprintf(stderr, "decoder uninted\n");
			break;
		default:
			fprintf(stderr, "init not ok\n");
			break;
	}

	FLAC__seekable_stream_decoder_process_until_end_of_metadata(decoder);

	FLAC__seekable_stream_decoder_process_single(decoder);

	fprintf(stderr, "channels=%d\n", FLAC__seekable_stream_decoder_get_channels(decoder));
	fprintf(stderr, "bits per sample=%d\n", FLAC__seekable_stream_decoder_get_bits_per_sample(decoder));

/*
	fprintf(stderr, "position=%d\n", FLAC__seekable_stream_decoder_get_decode_position(decoder));
*/


	FLAC__seekable_stream_decoder_finish(decoder);
	FLAC__seekable_stream_decoder_delete(decoder);

	fclose(myfile);

	return 0;
}