Beispiel #1
0
std::unique_ptr<pcm_part_t> flac_open(HANDLE &&stream)
{
	drflac *ff = drflac_open(flac_w32_read, flac_w32_seek, stream);

	auto fail = [&] (const char *text) {
		flac_l.errorf("%s", text);
		CloseHandle(stream);
		drflac_close(ff);
		return nullptr;
	};

	if(!ff) {
		return fail("Invalid FLAC file");
	} else if (ff->totalSampleCount == 0) {
		return fail("File not seekable?");
	}

	auto output_bitdepth = drflac_nearest_output_bitdepth(*ff);
	pcm_format_t pcmf = { ff->sampleRate, output_bitdepth, ff->channels };
	auto byte_size = (size_t)(ff->totalSampleCount * (output_bitdepth / 8));

	return std::make_unique<flac_part_t>(ff, pcm_part_info_t{
		pcmf, byte_size
	});
}
Beispiel #2
0
	result Wav::loadflac(MemoryFile *aReader)
	{
		drflac *decoder = drflac_open_memory(aReader->mDataPtr, aReader->mDataLength);

		if (!decoder)
		{
			return FILE_LOAD_FAILED;
		}

		drflac_uint64 samples = decoder->totalSampleCount;

		if (!samples)
		{
			drflac_close(decoder);
			return FILE_LOAD_FAILED;
		}

		mData = new float[(unsigned int)(samples * decoder->channels)];
		mBaseSamplerate = (float)decoder->sampleRate;
		mSampleCount = (unsigned int)samples;
		mChannels = decoder->channels;
		drflac_seek_to_pcm_frame(decoder, 0);

		unsigned int i, j, k;
		for (i = 0; i < mSampleCount; i += 512)
		{
			float tmp[512 * MAX_CHANNELS];
			unsigned int blockSize = (mSampleCount - i) > 512 ? 512 : mSampleCount - i;
			drflac_read_pcm_frames_f32(decoder, blockSize, tmp);
			for (j = 0; j < blockSize; j++)
			{
				for (k = 0; k < decoder->channels; k++)
				{
					mData[k * mSampleCount + i + j] = tmp[j * decoder->channels + k];
				}
			}
		}
		drflac_close(decoder);

		return SO_NO_ERROR;
	}
Beispiel #3
0
flac_part_t::~flac_part_t()
{
	CloseHandle(ff->bs.pUserData);
	drflac_close(ff);
}