Add check and normalization for more than 16 bits per sample FLAC-files
This commit is contained in:
parent
3971a5b662
commit
97f61bb40c
@ -294,16 +294,28 @@ bool FLACtoMP3::scaleJPEG(const FLAC__StreamMetadata_Picture& picture) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FLACtoMP3::decodeFrame(const int32_t * const buffer[], uint32_t size) {
|
bool FLACtoMP3::decodeFrame(const int32_t * const buffer[], uint32_t size, const uint32_t bitsPerSample) {
|
||||||
if (!outputInitilized) {
|
if (!outputInitilized) {
|
||||||
bool success = initializeOutput();
|
bool success = initializeOutput();
|
||||||
if (!success)
|
if (!success)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bitsPerSample >= 16)
|
||||||
|
return decodeFrameImpl(buffer, size, 1 << (bitsPerSample - 16));
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FLACtoMP3::decodeFrameImpl(const int32_t * const buffer[], uint32_t size, const uint32_t divisor)
|
||||||
|
{
|
||||||
for (size_t i = 0; i < size; ++i) {
|
for (size_t i = 0; i < size; ++i) {
|
||||||
pcm[pcmCounter++] = (int16_t)buffer[0][i];
|
int32_t left = buffer[0][i];
|
||||||
pcm[pcmCounter++] = (int16_t)buffer[1][i];
|
int32_t right = buffer[1][i];
|
||||||
|
left /= divisor;
|
||||||
|
right /= divisor;
|
||||||
|
pcm[pcmCounter++] = (int16_t)left;
|
||||||
|
pcm[pcmCounter++] = (int16_t)right;
|
||||||
|
|
||||||
if (pcmCounter == pcmSize)
|
if (pcmCounter == pcmSize)
|
||||||
return flush();
|
return flush();
|
||||||
@ -395,7 +407,7 @@ FLAC__StreamDecoderWriteStatus FLACtoMP3::write(
|
|||||||
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
|
return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool result = self->decodeFrame(buffer, frame->header.blocksize);
|
bool result = self->decodeFrame(buffer, frame->header.blocksize, frame->header.bits_per_sample);
|
||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
|
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
|
||||||
|
@ -29,7 +29,8 @@ private:
|
|||||||
void processTags(const FLAC__StreamMetadata_VorbisComment& tags);
|
void processTags(const FLAC__StreamMetadata_VorbisComment& tags);
|
||||||
void processInfo(const FLAC__StreamMetadata_StreamInfo& info);
|
void processInfo(const FLAC__StreamMetadata_StreamInfo& info);
|
||||||
void processPicture(const FLAC__StreamMetadata_Picture& picture);
|
void processPicture(const FLAC__StreamMetadata_Picture& picture);
|
||||||
bool decodeFrame(const int32_t * const buffer[], uint32_t size);
|
bool decodeFrame(const int32_t * const buffer[], uint32_t size, const uint32_t bitsPerSample);
|
||||||
|
bool decodeFrameImpl(const int32_t * const buffer[], uint32_t size, const uint32_t divisor);
|
||||||
bool flush();
|
bool flush();
|
||||||
bool initializeOutput();
|
bool initializeOutput();
|
||||||
bool scaleJPEG(const FLAC__StreamMetadata_Picture& picture);
|
bool scaleJPEG(const FLAC__StreamMetadata_Picture& picture);
|
||||||
|
Loading…
Reference in New Issue
Block a user