static int play(char *fn) { LONGLONG filesize; DWORD thread_id; int maxlatency; /* checks */ if (decoder_ == 0) return 1; if (!(filesize = FileSize(fn))) return -1; /* init decoder */ if (!FLAC_plugin__decoder_init(decoder_, fn, filesize, &stream_data_, &flac_cfg.output)) return 1; strcpy(lastfn_, fn); /* open output */ maxlatency = mod_.outMod->Open(stream_data_.sample_rate, stream_data_.channels, stream_data_.output_bits_per_sample, -1, -1); if (maxlatency < 0) { FLAC_plugin__decoder_finish(decoder_); return 1; } /* set defaults */ mod_.outMod->SetVolume(-666); mod_.outMod->SetPan(0); /* initialize vis stuff */ mod_.SAVSAInit(maxlatency, stream_data_.sample_rate); mod_.VSASetInfo(stream_data_.sample_rate, stream_data_.channels); /* set info */ mod_.SetInfo(stream_data_.average_bps, stream_data_.sample_rate/1000, stream_data_.channels, 1); /* start playing thread */ paused = 0; thread_handle = CreateThread(NULL, 0, DecodeThread, NULL, 0, &thread_id); if (!thread_handle) return 1; return 0; }
void FLAC_plugin__decoder_delete(FLAC__StreamDecoder *decoder) { if (decoder) { FLAC_plugin__decoder_finish(decoder); FLAC__stream_decoder_delete(decoder); } }
void FLAC_plugin__decoder_delete(FLAC__FileDecoder *decoder) { if (decoder) { FLAC_plugin__decoder_finish(decoder); FLAC__file_decoder_delete(decoder); } }
FLAC__bool FLAC_plugin__decoder_init(FLAC__FileDecoder *decoder, const char *filename, FLAC__int64 filesize, file_info_struct *file_info, output_config_t *config) { FLAC__ASSERT(decoder); FLAC_plugin__decoder_finish(decoder); /* init decoder */ FLAC__file_decoder_set_md5_checking(decoder, false); FLAC__file_decoder_set_filename(decoder, filename); FLAC__file_decoder_set_metadata_ignore_all(decoder); FLAC__file_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_STREAMINFO); FLAC__file_decoder_set_metadata_respond(decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT); FLAC__file_decoder_set_metadata_callback(decoder, metadata_callback); FLAC__file_decoder_set_write_callback(decoder, write_callback); FLAC__file_decoder_set_error_callback(decoder, error_callback); FLAC__file_decoder_set_client_data(decoder, file_info); if (FLAC__file_decoder_init(decoder) != FLAC__FILE_DECODER_OK) { FLAC_plugin__show_error("Error while initializing decoder (%s).", FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]); return false; } /* process */ cfg = *config; wide_samples_in_reservoir_ = 0; file_info->is_playing = false; file_info->abort_flag = false; file_info->has_replaygain = false; if (!FLAC__file_decoder_process_until_end_of_metadata(decoder)) { FLAC_plugin__show_error("Error while processing metadata (%s).", FLAC__FileDecoderStateString[FLAC__file_decoder_get_state(decoder)]); return false; } /* check results */ if (file_info->abort_flag) return false; /* metadata callback already popped up the error dialog */ /* init replaygain */ file_info->output_bits_per_sample = file_info->has_replaygain && cfg.replaygain.enable ? cfg.resolution.replaygain.bps_out : cfg.resolution.normal.dither_24_to_16 ? min(file_info->bits_per_sample, 16) : file_info->bits_per_sample; if (file_info->has_replaygain && cfg.replaygain.enable && cfg.resolution.replaygain.dither) FLAC__replaygain_synthesis__init_dither_context(&file_info->dither_context, file_info->bits_per_sample, cfg.resolution.replaygain.noise_shaping); /* more inits */ file_info->eof = false; file_info->seek_to = -1; file_info->is_playing = true; file_info->average_bps = (unsigned)(filesize / (125.*file_info->total_samples/file_info->sample_rate)); bh_index_last_w = 0; bh_index_last_o = BITRATE_HIST_SIZE; decode_position = 0; decode_position_last = 0; written_time_last = 0; return true; }
static void stop() { if (thread_handle) { stream_data_.is_playing = false; if (WaitForSingleObject(thread_handle, 2000) == WAIT_TIMEOUT) { FLAC_plugin__show_error("Error while stopping decoding thread."); TerminateThread(thread_handle, 0); } CloseHandle(thread_handle); thread_handle = NULL; } FLAC_plugin__decoder_finish(decoder_); mod_.outMod->Close(); mod_.SAVSADeInit(); }