当前位置: 首页>>代码示例>>C++>>正文


C++ FLAC__stream_decoder_new函数代码示例

本文整理汇总了C++中FLAC__stream_decoder_new函数的典型用法代码示例。如果您正苦于以下问题:C++ FLAC__stream_decoder_new函数的具体用法?C++ FLAC__stream_decoder_new怎么用?C++ FLAC__stream_decoder_new使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了FLAC__stream_decoder_new函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: read_flac_file

int read_flac_file (apr_pool_t* pool,void** file_struct, const char* file_path, encoding_options_t* enc_opt){
	FLAC__StreamDecoderInitStatus status;
	FLAC__bool status2;
	flac_file_t* flac_file = *file_struct = (flac_file_t*) apr_pcalloc(pool, sizeof(flac_file_t));

	flac_file->stream_decoder = FLAC__stream_decoder_new();
	flac_file->channels = 0;
	flac_file->samples = 0;
	flac_file->total_samples = 0;
	flac_file->rate = 0;
	flac_file->buf = NULL;

	status = FLAC__stream_decoder_init_file(flac_file->stream_decoder, file_path, flac_write, flac_metadata, flac_errors, flac_file);
	if (status != FLAC__STREAM_DECODER_INIT_STATUS_OK){
		return -1;
	}

	status2 = FLAC__stream_decoder_process_until_end_of_metadata(flac_file->stream_decoder);
	if (status2 != true){
		return -2;
	}
	FLAC__stream_decoder_process_single(flac_file->stream_decoder);
	if (status2 != true){
			return -2;
	}
	enc_opt->channels = flac_file->channels;
	enc_opt->rate = flac_file->rate;
	enc_opt->total_samples_per_channel = flac_file->total_samples;
	enc_opt->samples_to_request = 1024;

	return 0;
}
开发者ID:soda0289,项目名称:mod_MP,代码行数:32,代码来源:flac.c

示例2: play_file_from_filename

void play_file_from_filename(const std::string name) {
   currently_playing = std::string(name);
   if (audiobuf) linearFree(audiobuf);

   if (name.rfind(".flac") != std::string::npos) {
      if (!FLAC_decoder) {
         FLAC_decoder = FLAC__stream_decoder_new();
         FLAC__stream_decoder_set_md5_checking(FLAC_decoder, true);
      }
      audiobuf_index = 0;
      decode_mode = AUDIO_MODE_FLAC;
      FLAC__StreamDecoderInitStatus init_status = FLAC__stream_decoder_init_file(FLAC_decoder, name.c_str(), FLAC_write_callback, FLAC_metadata_callback, FLAC_error_callback, NULL);
      if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
         printf("ERROR: initializing decoder: %s\n", FLAC__StreamDecoderInitStatusString[init_status]);
      }
      FLAC__stream_decoder_process_until_end_of_metadata(FLAC_decoder);
   } else {
      decode_mode = AUDIO_MODE_VORBIS;
      v = stb_vorbis_open_filename(name.c_str(), &error, NULL);
      info = stb_vorbis_get_info(v);
      Samples = info.sample_rate;
      audiobuf_size = Samples * sizeof(s16) * 2;
      audiobuf = (s16*)linearAlloc(audiobuf_size);
   }
   paused = false;
}
开发者ID:machinamentum,项目名称:music_player,代码行数:26,代码来源:main.cpp

示例3: ba_reader

void SampleBuffer::loadFromBase64( const QString & _data )
{
	char * dst = NULL;
	int dsize = 0;
	base64::decode( _data, &dst, &dsize );

#ifdef LMMS_HAVE_FLAC_STREAM_DECODER_H

	QByteArray orig_data = QByteArray::fromRawData( dst, dsize );
	QBuffer ba_reader( &orig_data );
	ba_reader.open( QBuffer::ReadOnly );

	QBuffer ba_writer;
	ba_writer.open( QBuffer::WriteOnly );

	flacStreamDecoderClientData cdata = { &ba_reader, &ba_writer } ;

	FLAC__StreamDecoder * flac_dec = FLAC__stream_decoder_new();

	FLAC__stream_decoder_set_read_callback( flac_dec,
					flacStreamDecoderReadCallback );
	FLAC__stream_decoder_set_write_callback( flac_dec,
					flacStreamDecoderWriteCallback );
	FLAC__stream_decoder_set_error_callback( flac_dec,
					flacStreamDecoderErrorCallback );
	FLAC__stream_decoder_set_metadata_callback( flac_dec,
					flacStreamDecoderMetadataCallback );
	FLAC__stream_decoder_set_client_data( flac_dec, &cdata );

	FLAC__stream_decoder_init( flac_dec );

	FLAC__stream_decoder_process_until_end_of_stream( flac_dec );

	FLAC__stream_decoder_finish( flac_dec );
	FLAC__stream_decoder_delete( flac_dec );

	ba_reader.close();

	orig_data = ba_writer.buffer();
	printf("%d\n", (int) orig_data.size() );

	m_origFrames = orig_data.size() / sizeof( sampleFrame );
	MM_FREE( m_origData );
	m_origData = MM_ALLOC( sampleFrame, m_origFrames );
	memcpy( m_origData, orig_data.data(), orig_data.size() );

#else /* LMMS_HAVE_FLAC_STREAM_DECODER_H */

	m_origFrames = dsize / sizeof( sampleFrame );
	MM_FREE( m_origData );
	m_origData = MM_ALLOC( sampleFrame, m_origFrames );
	memcpy( m_origData, dst, dsize );

#endif

	delete[] dst;

	m_audioFile = QString();
	update();
}
开发者ID:floft,项目名称:lmms,代码行数:60,代码来源:SampleBuffer.cpp

示例4: gst_flac_dec_start

static gboolean
gst_flac_dec_start (GstAudioDecoder * audio_dec)
{
  FLAC__StreamDecoderInitStatus s;
  GstFlacDec *dec;

  dec = GST_FLAC_DEC (audio_dec);

  dec->adapter = gst_adapter_new ();

  dec->decoder = FLAC__stream_decoder_new ();

  gst_audio_info_init (&dec->info);
  dec->depth = 0;

  /* no point calculating MD5 since it's never checked here */
  FLAC__stream_decoder_set_md5_checking (dec->decoder, false);

  GST_DEBUG_OBJECT (dec, "initializing decoder");
  s = FLAC__stream_decoder_init_stream (dec->decoder,
      gst_flac_dec_read_stream, NULL, NULL, NULL, NULL,
      gst_flac_dec_write_stream, gst_flac_dec_metadata_cb,
      gst_flac_dec_error_cb, dec);

  if (s != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
    GST_ELEMENT_ERROR (GST_ELEMENT (dec), LIBRARY, INIT, (NULL), (NULL));
    return FALSE;
  }

  dec->got_headers = FALSE;

  return TRUE;
}
开发者ID:PeterXu,项目名称:gst-mobile,代码行数:33,代码来源:gstflacdec.c

示例5: DEBUG_ASSERT

Result SoundSourceFLAC::tryOpen(const AudioSourceConfig& /*audioSrcCfg*/) {
    DEBUG_ASSERT(!m_file.isOpen());
    if (!m_file.open(QIODevice::ReadOnly)) {
        qWarning() << "Failed to open FLAC file:" << m_file.fileName();
        return ERR;
    }

    m_decoder = FLAC__stream_decoder_new();
    if (m_decoder == NULL) {
        qWarning() << "Failed to create FLAC decoder!";
        return ERR;
    }
    FLAC__stream_decoder_set_md5_checking(m_decoder, FALSE);
    const FLAC__StreamDecoderInitStatus initStatus(
            FLAC__stream_decoder_init_stream(m_decoder, FLAC_read_cb,
                    FLAC_seek_cb, FLAC_tell_cb, FLAC_length_cb, FLAC_eof_cb,
                    FLAC_write_cb, FLAC_metadata_cb, FLAC_error_cb, this));
    if (initStatus != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
        qWarning() << "Failed to initialize FLAC decoder:" << initStatus;
        return ERR;
    }
    if (!FLAC__stream_decoder_process_until_end_of_metadata(m_decoder)) {
        qWarning() << "Failed to process FLAC metadata:"
                << FLAC__stream_decoder_get_state(m_decoder);
        return ERR;
    }

    m_curFrameIndex = getMinFrameIndex();

    return OK;
}
开发者ID:jox58,项目名称:mixxx,代码行数:31,代码来源:soundsourceflac.cpp

示例6: FLAC__stream_decoder_new

	bool OAFLACReader::open(const SPtr<DataStream>& stream, AudioFileInfo& info, UINT32 offset)
	{
		if (stream == nullptr)
			return false;

		stream->seek(offset);

		mDecoder = FLAC__stream_decoder_new();
		if (mDecoder == nullptr)
		{
			LOGERR("Failed to open a FLAC file.");
			return false;
		}

		mData.stream = stream;
		mData.streamOffset = offset;
		FLAC__stream_decoder_init_stream(mDecoder, &streamRead, &streamSeek, &streamTell, &streamLength, &streamEof,
			&streamWrite, &streamMetadata, &streamError, &mData);

		if (!FLAC__stream_decoder_process_until_end_of_metadata(mDecoder))
		{
			close();
			LOGERR("Failed to open a FLAC file.");
			return false;
		}

		info = mData.info;

		return true;
	}
开发者ID:maximwreznikov,项目名称:BansheeEngine,代码行数:30,代码来源:BsOAFLACReader.cpp

示例7: HandleFLAC

static status_t HandleFLAC(const char *filename, MediaScannerClient* client)
{
    status_t status = UNKNOWN_ERROR;
    FLAC__StreamDecoder *decoder;

    decoder = FLAC__stream_decoder_new();
    if (!decoder)
        return status;

    FLAC__stream_decoder_set_md5_checking(decoder, false);
    FLAC__stream_decoder_set_metadata_ignore_all(decoder);
    FLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_STREAMINFO);
    FLAC__stream_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT);

    FLAC__StreamDecoderInitStatus init_status;
    init_status = FLAC__stream_decoder_init_file(decoder, filename, flac_write, flac_metadata, flac_error, client);
    if (init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK)
        goto exit;

    if (!FLAC__stream_decoder_process_until_end_of_metadata(decoder))
        goto exit;

    status = OK;

exit:
    FLAC__stream_decoder_finish(decoder);
    FLAC__stream_decoder_delete(decoder);

    return status;
}
开发者ID:HyperDroid,项目名称:android_frameworks_base_deprecated,代码行数:30,代码来源:StagefrightMediaScanner.cpp

示例8: FLAC__stream_decoder_new

bool SoundFileReaderFlac::open(InputStream& stream, Info& info)
{
    // Create the decoder
    m_decoder = FLAC__stream_decoder_new();
    if (!m_decoder)
    {
        err() << "Failed to open FLAC file (failed to allocate the decoder)" << std::endl;
        return false;
    }

    // Initialize the decoder with our callbacks
    m_clientData.stream = &stream;
    FLAC__stream_decoder_init_stream(m_decoder, &streamRead, &streamSeek, &streamTell, &streamLength, &streamEof, &streamWrite, &streamMetadata, &streamError, &m_clientData);

    // Read the header
    if (!FLAC__stream_decoder_process_until_end_of_metadata(m_decoder))
    {
        close();
        err() << "Failed to open FLAC file (failed to read metadata)" << std::endl;
        return false;
    }

    // Retrieve the sound properties
    info = m_clientData.info; // was filled in the "metadata" callback

    // We must keep the channel count for the seek function
    m_channelCount = info.channelCount;

    return true;
}
开发者ID:42bottles,项目名称:SFML,代码行数:30,代码来源:SoundFileReaderFlac.cpp

示例9: DEBUG_ASSERT

SoundSource::OpenResult SoundSourceFLAC::tryOpen(
        OpenMode /*mode*/,
        const OpenParams& /*config*/) {
    DEBUG_ASSERT(!m_file.isOpen());
    if (!m_file.open(QIODevice::ReadOnly)) {
        kLogger.warning() << "Failed to open FLAC file:" << m_file.fileName();
        return OpenResult::Failed;
    }

    m_decoder = FLAC__stream_decoder_new();
    if (m_decoder == nullptr) {
        kLogger.warning() << "Failed to create FLAC decoder!";
        return OpenResult::Failed;
    }
    FLAC__stream_decoder_set_md5_checking(m_decoder, false);
    const FLAC__StreamDecoderInitStatus initStatus(
            FLAC__stream_decoder_init_stream(m_decoder, FLAC_read_cb,
                    FLAC_seek_cb, FLAC_tell_cb, FLAC_length_cb, FLAC_eof_cb,
                    FLAC_write_cb, FLAC_metadata_cb, FLAC_error_cb, this));
    if (initStatus != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
        kLogger.warning() << "Failed to initialize FLAC decoder:" << initStatus;
        return OpenResult::Failed;
    }
    if (!FLAC__stream_decoder_process_until_end_of_metadata(m_decoder)) {
        kLogger.warning() << "Failed to process FLAC metadata:"
                << FLAC__stream_decoder_get_state(m_decoder);
        return OpenResult::Failed;
    }

    m_curFrameIndex = frameIndexMin();

    return OpenResult::Succeeded;
}
开发者ID:DJMaxergy,项目名称:mixxx,代码行数:33,代码来源:soundsourceflac.cpp

示例10: FLAC__stream_decoder_new

bool CFlacDec::GetMetaData(FILE *in, const bool /*nice*/, CAudioMetaData* m)
{
	FLAC__StreamDecoder *vf;

	vf = FLAC__stream_decoder_new();
	FLAC__stream_decoder_set_metadata_ignore_all(vf);
	// we need streaminfo (default on) and FLAC__METADATA_TYPE_VORBIS_COMMENT (default off) for ID3 tags
	FLAC__stream_decoder_set_metadata_respond(vf, FLAC__METADATA_TYPE_STREAMINFO);
	FLAC__stream_decoder_set_metadata_respond(vf, FLAC__METADATA_TYPE_VORBIS_COMMENT);
	if (!Open(in, vf))
	{
		return false;
	}

	if (FLAC__stream_decoder_process_until_end_of_metadata(vf)) {
		// if the metadata callback was called mMetadata should be filled with infos
		if (mMetadata) {
			SetMetaData(mMetadata, m);
		}
	}
	// clean up stuff, the mMetadata may be used later again so let the decoder free it
	FLAC__stream_decoder_finish(vf);
	FLAC__stream_decoder_delete(vf);

	return true;
}
开发者ID:FFTEAM,项目名称:evolux-spark-sh4,代码行数:26,代码来源:flacdec.cpp

示例11: do_test

bool do_test(const char* filename)
{
    drge_timer* pTimer = drge_create_timer();

    double decodeTimeReference = 1;
#ifndef DISABLE_REFERENCE_FLAC
    // Reference first.
    reference_data referenceData;
    referenceData.pDecodedData = NULL;
    referenceData.pDecodedDataWalker = NULL;
    referenceData.totalSampleCount = 0;
    referenceData.pDecoder = FLAC__stream_decoder_new();
    FLAC__stream_decoder_init_file(referenceData.pDecoder, filename, flac__write_callback, flac__metadata_callback, flac__error_callback, &referenceData);

    drge_tick_timer(pTimer);
    FLAC__stream_decoder_process_until_end_of_stream(referenceData.pDecoder);
    decodeTimeReference = drge_tick_timer(pTimer);
#endif

    // dr_flac second.
    drflac_data drflacData;
    drflacData.pDecodedData = NULL;
    drflacData.pFlac = drflac_open_file(filename);

    drflacData.pDecodedData = malloc((size_t)drflacData.pFlac->totalSampleCount * sizeof(int32_t));

    drge_tick_timer(pTimer);
    drflac_read_s32(drflacData.pFlac, (size_t)drflacData.pFlac->totalSampleCount, drflacData.pDecodedData);
    double decodeTime = drge_tick_timer(pTimer);


    (void)decodeTimeReference;
    (void)decodeTime;

    // Sample-by-Sample comparison.
    bool result = true;
#ifndef DISABLE_REFERENCE_FLAC
    if (drflacData.pFlac->totalSampleCount != referenceData.totalSampleCount) {
        result = false;
        printf("TEST FAILED: %s: Total sample count differs. %lld != %lld\n", filename, drflacData.pFlac->totalSampleCount, referenceData.totalSampleCount);
        goto finish_test;
    }

    for (uint64_t i = 0; i < drflacData.pFlac->totalSampleCount; ++i) {
        if (drflacData.pDecodedData[i] != referenceData.pDecodedData[i]) {
            result = false;
            printf("TEST FAILED: %s: Sample at %lld differs. %d != %d\n", filename, i, drflacData.pDecodedData[i], referenceData.pDecodedData[i]);
            goto finish_test;
        }
    }

    printf("Reference Time: %f : dr_flac Time: %f - %d%%\n", decodeTimeReference, decodeTime, (int)(decodeTime/decodeTimeReference*100));

finish_test:
    free(referenceData.pDecodedData);
    free(drflacData.pDecodedData);
#endif
    return result;
}
开发者ID:alzwded,项目名称:dr_libs,代码行数:59,代码来源:dr_flac_test1.c

示例12: init

static void init()
{
	decoder_ = FLAC__stream_decoder_new();
	strcpy(lastfn_, "");

	InitConfig();
	ReadConfig();
	InitInfobox();
}
开发者ID:mikemakuch,项目名称:muzikbrowzer,代码行数:9,代码来源:in_flac.c

示例13: populate_seekpoint_values

FLAC__bool populate_seekpoint_values(const char *filename, FLAC__StreamMetadata *block, FLAC__bool *needs_write)
{
	FLAC__StreamDecoder *decoder;
	ClientData client_data;
	FLAC__bool ok = true;

	FLAC__ASSERT(0 != block);
	FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_SEEKTABLE);

	client_data.seektable_template = &block->data.seek_table;
	client_data.samples_written = 0;
	/* client_data.audio_offset must be determined later */
	client_data.first_seekpoint_to_check = 0;
	client_data.error_occurred = false;

	decoder = FLAC__stream_decoder_new();

	if(0 == decoder) {
		fprintf(stderr, "%s: ERROR (--add-seekpoint) creating the decoder instance\n", filename);
		return false;
	}

	FLAC__stream_decoder_set_md5_checking(decoder, false);
	FLAC__stream_decoder_set_metadata_ignore_all(decoder);

	if(FLAC__stream_decoder_init_file(decoder, filename, write_callback_, /*metadata_callback=*/0, error_callback_, &client_data) != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
		fprintf(stderr, "%s: ERROR (--add-seekpoint) initializing the decoder instance (%s)\n", filename, FLAC__stream_decoder_get_resolved_state_string(decoder));
		ok = false;
	}

	if(ok && !FLAC__stream_decoder_process_until_end_of_metadata(decoder)) {
		fprintf(stderr, "%s: ERROR (--add-seekpoint) decoding file (%s)\n", filename, FLAC__stream_decoder_get_resolved_state_string(decoder));
		ok = false;
	}

	if(ok && !FLAC__stream_decoder_get_decode_position(decoder, &client_data.audio_offset)) {
		fprintf(stderr, "%s: ERROR (--add-seekpoint) decoding file\n", filename);
		ok = false;
	}
	client_data.last_offset = client_data.audio_offset;

	if(ok && !FLAC__stream_decoder_process_until_end_of_stream(decoder)) {
		fprintf(stderr, "%s: ERROR (--add-seekpoint) decoding file (%s)\n", filename, FLAC__stream_decoder_get_resolved_state_string(decoder));
		ok = false;
	}

	if(ok && client_data.error_occurred) {
		fprintf(stderr, "%s: ERROR (--add-seekpoint) decoding file (%u:%s)\n", filename, (unsigned)client_data.error_status, FLAC__StreamDecoderErrorStatusString[client_data.error_status]);
		ok = false;
	}

	*needs_write = true;
	FLAC__stream_decoder_delete(decoder);
	return ok;
}
开发者ID:jeeb,项目名称:flac,代码行数:55,代码来源:operations_shorthand_seektable.c

示例14: main

/**
 * Main.
 */
int main(int argc, char *argv[])
{
    FLAC__bool ok = true;
	FLAC__StreamDecoder* decoder = 0;
	FLAC__StreamDecoderInitStatus init_status;

	// init system
	SystemInit();
	RCC_configure();
	GPIO_configure();

    //TODO
    // setup UART, LEDs, SDIO, I2S, etc

    // setup decoder
	if((decoder = FLAC__stream_decoder_new()) == NULL) {
		fprintf(stderr, "ERROR: allocating decoder\n");
		return 1;
	}

    // optional MD5 check. How much cycles does this cost?
	//FLAC__stream_decoder_set_md5_checking(decoder, true);

    // init decoder
    void* client_data = 0;  //TODO
	init_status = FLAC__stream_decoder_init_stream(decoder, 
        read_callback,
        seek_callback,
        tell_callback,
        length_callback,
        eof_callback,
        write_callback, 
        metadata_callback,
        error_callback,
        client_data);
	if (init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
		fprintf(stderr, "ERROR: initializing decoder: %s\n", FLAC__StreamDecoderInitStatusString[init_status]);
		ok = false;
	}

	if (ok) {
		ok = FLAC__stream_decoder_process_until_end_of_stream(decoder);
		fprintf(stderr, "decoding: %s\n", ok? "succeeded" : "FAILED");
		fprintf(stderr, "   state: %s\n", FLAC__StreamDecoderStateString[FLAC__stream_decoder_get_state(decoder)]);
	}

    // loop forever, just handle IRQs
	while(1);
     
    // never called but usefull to know
    //FLAC__stream_decoder_delete(decoder);
    
	return 0;
}
开发者ID:Bendernet-hu,项目名称:flacie,代码行数:57,代码来源:main.c

示例15: Flac2Wav

int __stdcall
Flac2Wav(const char *fromFlacPath, const char *toWavPath)
{
    int result = F2WRT_Success;
    FLAC__bool ok = true;
    FLAC__StreamDecoder *decoder = NULL;
    FLAC__StreamDecoderInitStatus init_status;
    FlacDecodeArgs args;

    memset(&args, 0, sizeof args);
    args.errorCode = F2WRT_OtherError;

    args.fout = fopen(toWavPath, "wb");
    if (args.fout == NULL) {
        result = F2WRT_WriteOpenFailed;
        goto end;
    }

    decoder = FLAC__stream_decoder_new();
    if(decoder == NULL) {
        result = F2WRT_FlacStreamDecoderNewFailed;
        goto end;
    }

    FLAC__stream_decoder_set_md5_checking(decoder, true);

    init_status = FLAC__stream_decoder_init_file(
        decoder, fromFlacPath, WriteCallback, MetadataCallback, ErrorCallback, &args);
    if(init_status != FLAC__STREAM_DECODER_INIT_STATUS_OK) {
        result = F2WRT_FlacStreamDecoderInitFailed;
        goto end;
    }

    ok = FLAC__stream_decoder_process_until_end_of_stream(decoder);
    if (!ok) {
        result = args.errorCode;
        goto end;
    }

    result = F2WRT_Success;
end:
    if (NULL != decoder) {
        FLAC__stream_decoder_delete(decoder);
        decoder = NULL;
    }
    if (NULL != args.fout) {
        fclose(args.fout);
        args.fout = NULL;
    }

    return result;
}
开发者ID:kekyo,项目名称:PlayPcmWin,代码行数:52,代码来源:Flac2Wav.cpp


注:本文中的FLAC__stream_decoder_new函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。