make format for bits helper function

adpcm
Dimitri Diakopoulos 11 years ago
parent f473e87d87
commit 5fc544366b

@ -221,10 +221,11 @@ struct AudioData
{
int channelCount;
int sampleRate;
int bitDepth;
double lengthSeconds;
size_t frameSize; // channels * bits per sample
std::vector<float> samples;
PCMFormat sourceFormat;
//@todo: add field: channel layout
//@todo: add field: lossy / lossless
//@todo: audio data loaded (for metadata only)
@ -247,6 +248,7 @@ struct NyquistFileBuffer
NyquistFileBuffer ReadFile(std::string pathToFile);
int GetFormatBitsPerSample(PCMFormat f);
PCMFormat MakeFormatForBits(int bits, bool floatingPt, bool isSigned);
} // end namespace nqr

@ -167,3 +167,22 @@ int nqr::GetFormatBitsPerSample(PCMFormat f)
return 0;
}
}
PCMFormat nqr::MakeFormatForBits(int bits, bool floatingPt, bool isSigned)
{
switch(bits)
{
case 8:
return (isSigned) ? PCM_S8 : PCM_U8;
case 16:
return PCM_16;
case 24:
return PCM_24;
case 32:
return (floatingPt) ? PCM_FLT : PCM_32;
case 64:
return (floatingPt) ? PCM_DBL : PCM_64;
default:
return PCM_END;
}
}

@ -78,7 +78,7 @@ public:
// N.B.: "Currently the reference encoder and decoders only support up to 24 bits per sample."
PCMFormat internalFmt = PCMFormat::PCM_END;
d->sourceFormat = PCMFormat::PCM_END;
switch (d->bitDepth)
{
@ -97,7 +97,7 @@ public:
}
// Next, process internal buffer into the user-visible samples array
ConvertToFloat32(d->samples.data(), internalBuffer.data(), totalSamples, internalFmt);
ConvertToFloat32(d->samples.data(), internalBuffer.data(), totalSamples, d->sourceFormat);
}
else
@ -120,7 +120,7 @@ public:
{
d->sampleRate = info.sample_rate;
d->channelCount = info.channels; // Assert 1 to 8
d->bitDepth = info.bits_per_sample; // Assert 4 to 32
d->sourceF = info.bits_per_sample; // Assert 4 to 32
d->frameSize = info.channels * info.bits_per_sample;
const size_t bytesPerSample = d->bitDepth / 8;

@ -106,7 +106,7 @@ int WavEncoder::WriteFile(const EncoderParams p, const AudioData * d, const std:
// Debugging -- assume IEEE_Float
auto LookupB
auto what = GetFormatBitsPerSample(d->sourceFmt);
fout.write(reinterpret_cast<const char*>(d->samples.data()), numSamplesBytes);
// Find size

Loading…
Cancel
Save