sanity check out target format

adpcm
Dimitri Diakopoulos 11 years ago
parent b72127c862
commit ed8ca06aa4

@ -46,6 +46,7 @@ class WavEncoder
FileIOError, FileIOError,
UnsupportedSamplerate, UnsupportedSamplerate,
UnsupportedChannelConfiguration, UnsupportedChannelConfiguration,
UnsupportedBitdepth,
BufferTooBig, BufferTooBig,
}; };

@ -73,6 +73,12 @@ int WavEncoder::WriteFile(const EncoderParams p, const AudioData * d, const std:
return EncoderError::UnsupportedSamplerate; return EncoderError::UnsupportedSamplerate;
} }
// Don't support PCM_64 or PCM_DBL
if (GetFormatBitsPerSample(p.targetFormat) > 32)
{
return EncoderError::UnsupportedBitdepth;
}
std::ofstream fout(path.c_str(), std::ios::out | std::ios::binary); std::ofstream fout(path.c_str(), std::ios::out | std::ios::binary);
if (!fout.is_open()) if (!fout.is_open())
@ -95,6 +101,14 @@ int WavEncoder::WriteFile(const EncoderParams p, const AudioData * d, const std:
auto header = MakeWaveHeader(p); auto header = MakeWaveHeader(p);
fout.write(reinterpret_cast<char*>(&header), sizeof(WaveChunkHeader)); fout.write(reinterpret_cast<char*>(&header), sizeof(WaveChunkHeader));
auto sourceBits = GetFormatBitsPerSample(d->sourceFormat);
auto targetBits = GetFormatBitsPerSample(p.targetFormat);
if (p.targetFormat == PCM_FLT || p.targetFormat == PCM_DBL)
{
}
// Data header // Data header
fout.write(GenerateChunkCodeChar('d', 'a', 't', 'a'), 4); fout.write(GenerateChunkCodeChar('d', 'a', 't', 'a'), 4);
@ -102,10 +116,6 @@ int WavEncoder::WriteFile(const EncoderParams p, const AudioData * d, const std:
toBytes(int(samplesSizeInBytes), chunkSizeBuff); toBytes(int(samplesSizeInBytes), chunkSizeBuff);
fout.write(chunkSizeBuff, 4); fout.write(chunkSizeBuff, 4);
// Debugging -- assume IEEE_Float
auto sourceBits = GetFormatBitsPerSample(d->sourceFormat);
auto targetBits = GetFormatBitsPerSample(p.targetFormat);
// Apply dithering // Apply dithering
if (sourceBits != targetBits && p.dither != DITHER_NONE) if (sourceBits != targetBits && p.dither != DITHER_NONE)
{ {

Loading…
Cancel
Save