Skip to content

Commit

Permalink
Fix 24-bit-in-32-bit being autodetected as Float32.
Browse files Browse the repository at this point in the history
Fixes #106.
  • Loading branch information
dechamps committed Jan 4, 2021
1 parent 9e09689 commit 2cf8f0d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/flexasio/FlexASIO/flexasio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,10 @@ namespace flexasio {

}

constexpr FlexASIO::SampleType FlexASIO::float32 = { ::dechamps_cpputil::endianness == ::dechamps_cpputil::Endianness::LITTLE ? ASIOSTFloat32LSB : ASIOSTFloat32MSB, paFloat32, 4 };
constexpr FlexASIO::SampleType FlexASIO::int32 = { ::dechamps_cpputil::endianness == ::dechamps_cpputil::Endianness::LITTLE ? ASIOSTInt32LSB : ASIOSTInt32MSB, paInt32, 4 };
constexpr FlexASIO::SampleType FlexASIO::int24 = { ::dechamps_cpputil::endianness == ::dechamps_cpputil::Endianness::LITTLE ? ASIOSTInt24LSB : ASIOSTInt24MSB, paInt24, 3 };
constexpr FlexASIO::SampleType FlexASIO::int16 = { ::dechamps_cpputil::endianness == ::dechamps_cpputil::Endianness::LITTLE ? ASIOSTInt16LSB : ASIOSTInt16MSB, paInt16, 2 };
constexpr FlexASIO::SampleType FlexASIO::float32 = { ::dechamps_cpputil::endianness == ::dechamps_cpputil::Endianness::LITTLE ? ASIOSTFloat32LSB : ASIOSTFloat32MSB, paFloat32, 4, KSDATAFORMAT_SUBTYPE_IEEE_FLOAT };
constexpr FlexASIO::SampleType FlexASIO::int32 = { ::dechamps_cpputil::endianness == ::dechamps_cpputil::Endianness::LITTLE ? ASIOSTInt32LSB : ASIOSTInt32MSB, paInt32, 4, KSDATAFORMAT_SUBTYPE_PCM };
constexpr FlexASIO::SampleType FlexASIO::int24 = { ::dechamps_cpputil::endianness == ::dechamps_cpputil::Endianness::LITTLE ? ASIOSTInt24LSB : ASIOSTInt24MSB, paInt24, 3, KSDATAFORMAT_SUBTYPE_PCM };
constexpr FlexASIO::SampleType FlexASIO::int16 = { ::dechamps_cpputil::endianness == ::dechamps_cpputil::Endianness::LITTLE ? ASIOSTInt16LSB : ASIOSTInt16MSB, paInt16, 2, KSDATAFORMAT_SUBTYPE_PCM };
constexpr std::pair<std::string_view, FlexASIO::SampleType> FlexASIO::sampleTypes[] = {
{"Float32", float32},
{"Int32", int32},
Expand All @@ -240,13 +240,9 @@ namespace flexasio {
}

FlexASIO::SampleType FlexASIO::WaveFormatToSampleType(const WAVEFORMATEXTENSIBLE& waveFormat) {
if (waveFormat.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT) return float32;
if (waveFormat.SubFormat == KSDATAFORMAT_SUBTYPE_PCM) {
for (const auto& sampleType : sampleTypes) {
const auto bits = sampleType.second.size * 8;
if (bits == waveFormat.Samples.wValidBitsPerSample) return sampleType.second;
if (bits == waveFormat.Format.wBitsPerSample) return sampleType.second;
}
const auto validBitsPerSample = waveFormat.Samples.wValidBitsPerSample != 0 ? waveFormat.Samples.wValidBitsPerSample : waveFormat.Format.wBitsPerSample;
for (const auto& [name, sampleType] : sampleTypes) {
if (sampleType.waveSubFormat == waveFormat.SubFormat && sampleType.size * 8 == validBitsPerSample) return sampleType;
}
throw std::runtime_error(std::string("Unable to convert wave format to sample type: ") + DescribeWaveFormat(waveFormat));
}
Expand Down
1 change: 1 addition & 0 deletions src/flexasio/FlexASIO/flexasio.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ namespace flexasio {
ASIOSampleType asio;
PaSampleFormat pa;
size_t size;
GUID waveSubFormat;
};

struct OpenStreamResult {
Expand Down

0 comments on commit 2cf8f0d

Please sign in to comment.