diff options
author | Vitaly Novichkov <Wohlstand@users.noreply.github.com> | 2018-04-15 20:23:26 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-15 20:23:26 +0300 |
commit | b3ea5157f09b30e17fc434f7bc86861a794c9abb (patch) | |
tree | 59831bc2949f7ad638123c4380b10bbbc1e27b4a /src | |
parent | 3ed5907fd849a27ee770fed599a22d0841fe9f19 (diff) | |
parent | 347dca55bb25f61a0cd2d2b45529944da764e734 (diff) | |
download | libADLMIDI-b3ea5157f09b30e17fc434f7bc86861a794c9abb.tar.gz libADLMIDI-b3ea5157f09b30e17fc434f7bc86861a794c9abb.tar.bz2 libADLMIDI-b3ea5157f09b30e17fc434f7bc86861a794c9abb.zip |
Merge pull request #64 from jpcima/more-sample-types
add more sample types
Diffstat (limited to 'src')
-rw-r--r-- | src/adlmidi.cpp | 44 | ||||
-rw-r--r-- | src/adlmidi_private.hpp | 26 |
2 files changed, 66 insertions, 4 deletions
diff --git a/src/adlmidi.cpp b/src/adlmidi.cpp index 91f5384..5d7b13b 100644 --- a/src/adlmidi.cpp +++ b/src/adlmidi.cpp @@ -658,26 +658,35 @@ static int SendStereoAudio(int samples_requested, left += (outputOffset / 2) * sampleOffset; right += (outputOffset / 2) * sampleOffset; + typedef int32_t(&pfnConvert)(int32_t); + switch(sampleType) { case ADLMIDI_SampleType_S8: + case ADLMIDI_SampleType_U8: + { + pfnConvert cvt = (sampleType == ADLMIDI_SampleType_S8) ? adl_cvtS8 : adl_cvtU8; switch(containerSize) { case sizeof(int8_t): - CopySamplesTransformed<int8_t>(left, right, _in, toCopy / 2, sampleOffset, adl_cvtS8); + CopySamplesTransformed<int8_t>(left, right, _in, toCopy / 2, sampleOffset, cvt); break; case sizeof(int16_t): - CopySamplesTransformed<int16_t>(left, right, _in, toCopy / 2, sampleOffset, adl_cvtS8); + CopySamplesTransformed<int16_t>(left, right, _in, toCopy / 2, sampleOffset, cvt); break; case sizeof(int32_t): - CopySamplesTransformed<int32_t>(left, right, _in, toCopy / 2, sampleOffset, adl_cvtS8); + CopySamplesTransformed<int32_t>(left, right, _in, toCopy / 2, sampleOffset, cvt); break; default: return -1; } break; + } case ADLMIDI_SampleType_S16: + case ADLMIDI_SampleType_U16: + { + pfnConvert cvt = (sampleType == ADLMIDI_SampleType_S16) ? adl_cvtS16 : adl_cvtU16; switch(containerSize) { case sizeof(int16_t): - CopySamplesTransformed<int16_t>(left, right, _in, toCopy / 2, sampleOffset, adl_cvtS16); + CopySamplesTransformed<int16_t>(left, right, _in, toCopy / 2, sampleOffset, cvt); break; case sizeof(int32_t): CopySamplesRaw<int32_t>(left, right, _in, toCopy / 2, sampleOffset); @@ -686,6 +695,33 @@ static int SendStereoAudio(int samples_requested, return -1; } break; + } + case ADLMIDI_SampleType_S24: + case ADLMIDI_SampleType_U24: + { + pfnConvert cvt = (sampleType == ADLMIDI_SampleType_S24) ? adl_cvtS24 : adl_cvtU24; + switch(containerSize) { + case sizeof(int32_t): + CopySamplesTransformed<int32_t>(left, right, _in, toCopy / 2, sampleOffset, cvt); + break; + default: + return -1; + } + break; + } + case ADLMIDI_SampleType_S32: + case ADLMIDI_SampleType_U32: + { + pfnConvert cvt = (sampleType == ADLMIDI_SampleType_S32) ? adl_cvtS32 : adl_cvtU32; + switch(containerSize) { + case sizeof(int32_t): + CopySamplesTransformed<int32_t>(left, right, _in, toCopy / 2, sampleOffset, cvt); + break; + default: + return -1; + } + break; + } case ADLMIDI_SampleType_F32: if(containerSize != sizeof(float)) return -1; diff --git a/src/adlmidi_private.hpp b/src/adlmidi_private.hpp index 271bc5e..b60c7c0 100644 --- a/src/adlmidi_private.hpp +++ b/src/adlmidi_private.hpp @@ -153,6 +153,32 @@ inline int32_t adl_cvtS8(int32_t x) { return adl_cvtS16(x) / 256; } +inline int32_t adl_cvtS24(int32_t x) +{ + return adl_cvtS16(x) * 256; +} +inline int32_t adl_cvtS32(int32_t x) +{ + return adl_cvtS16(x) * 65536; +} +inline int32_t adl_cvtU16(int32_t x) +{ + return adl_cvtS16(x) - INT16_MIN; +} +inline int32_t adl_cvtU8(int32_t x) +{ + return adl_cvtS8(x) - INT8_MIN; +} +inline int32_t adl_cvtU24(int32_t x) +{ + enum { int24_min = -(1 << 23) }; + return adl_cvtS24(x) - int24_min; +} +inline int32_t adl_cvtU32(int32_t x) +{ + // unsigned operation because overflow on signed integers is undefined + return (uint32_t)adl_cvtS32(x) - (uint32_t)INT32_MIN; +} /* Smart pointer for C heaps, created with malloc() call. |