diff --git a/example/sio_microphone.c b/example/sio_microphone.c index 0e3d3d4..c95e106 100644 --- a/example/sio_microphone.c +++ b/example/sio_microphone.c @@ -22,6 +22,8 @@ static enum SoundIoFormat prioritized_formats[] = { SoundIoFormatS32FE, SoundIoFormatS24NE, SoundIoFormatS24FE, + SoundIoFormatS24PackedNE, + SoundIoFormatS24PackedFE, SoundIoFormatS16NE, SoundIoFormatS16FE, SoundIoFormatFloat64NE, @@ -30,6 +32,8 @@ static enum SoundIoFormat prioritized_formats[] = { SoundIoFormatU32FE, SoundIoFormatU24NE, SoundIoFormatU24FE, + SoundIoFormatU24PackedNE, + SoundIoFormatU24PackedFE, SoundIoFormatU16NE, SoundIoFormatU16FE, SoundIoFormatS8, diff --git a/example/sio_record.c b/example/sio_record.c index 29c07ef..82ec635 100644 --- a/example/sio_record.c +++ b/example/sio_record.c @@ -25,6 +25,8 @@ static enum SoundIoFormat prioritized_formats[] = { SoundIoFormatS32FE, SoundIoFormatS24NE, SoundIoFormatS24FE, + SoundIoFormatS24PackedNE, + SoundIoFormatS24PackedFE, SoundIoFormatS16NE, SoundIoFormatS16FE, SoundIoFormatFloat64NE, @@ -33,6 +35,8 @@ static enum SoundIoFormat prioritized_formats[] = { SoundIoFormatU32FE, SoundIoFormatU24NE, SoundIoFormatU24FE, + SoundIoFormatU24PackedNE, + SoundIoFormatU24PackedFE, SoundIoFormatU16NE, SoundIoFormatU16FE, SoundIoFormatS8, diff --git a/soundio/soundio.h b/soundio/soundio.h index 6aa8359..3d7a0fb 100644 --- a/soundio/soundio.h +++ b/soundio/soundio.h @@ -234,24 +234,28 @@ enum SoundIoDeviceAim { /// which point to the respective SoundIoFormat values. enum SoundIoFormat { SoundIoFormatInvalid, - SoundIoFormatS8, ///< Signed 8 bit - SoundIoFormatU8, ///< Unsigned 8 bit - SoundIoFormatS16LE, ///< Signed 16 bit Little Endian - SoundIoFormatS16BE, ///< Signed 16 bit Big Endian - SoundIoFormatU16LE, ///< Unsigned 16 bit Little Endian - SoundIoFormatU16BE, ///< Unsigned 16 bit Little Endian - SoundIoFormatS24LE, ///< Signed 24 bit Little Endian using low three bytes in 32-bit word - SoundIoFormatS24BE, ///< Signed 24 bit Big Endian using low three bytes in 32-bit word - SoundIoFormatU24LE, ///< Unsigned 24 bit Little Endian using low three bytes in 32-bit word - SoundIoFormatU24BE, ///< Unsigned 24 bit Big Endian using low three bytes in 32-bit word - SoundIoFormatS32LE, ///< Signed 32 bit Little Endian - SoundIoFormatS32BE, ///< Signed 32 bit Big Endian - SoundIoFormatU32LE, ///< Unsigned 32 bit Little Endian - SoundIoFormatU32BE, ///< Unsigned 32 bit Big Endian - SoundIoFormatFloat32LE, ///< Float 32 bit Little Endian, Range -1.0 to 1.0 - SoundIoFormatFloat32BE, ///< Float 32 bit Big Endian, Range -1.0 to 1.0 - SoundIoFormatFloat64LE, ///< Float 64 bit Little Endian, Range -1.0 to 1.0 - SoundIoFormatFloat64BE, ///< Float 64 bit Big Endian, Range -1.0 to 1.0 + SoundIoFormatS8, ///< Signed 8 bit + SoundIoFormatU8, ///< Unsigned 8 bit + SoundIoFormatS16LE, ///< Signed 16 bit Little Endian + SoundIoFormatS16BE, ///< Signed 16 bit Big Endian + SoundIoFormatU16LE, ///< Unsigned 16 bit Little Endian + SoundIoFormatU16BE, ///< Unsigned 16 bit Little Endian + SoundIoFormatS24LE, ///< Signed 24 bit Little Endian using low three bytes in 32-bit word + SoundIoFormatS24BE, ///< Signed 24 bit Big Endian using low three bytes in 32-bit word + SoundIoFormatU24LE, ///< Unsigned 24 bit Little Endian using low three bytes in 32-bit word + SoundIoFormatU24BE, ///< Unsigned 24 bit Big Endian using low three bytes in 32-bit word + SoundIoFormatS24PackedLE, ///< Signed 24 bit Little Endian using three bytes + SoundIoFormatS24PackedBE, ///< Signed 24 bit Big Endian using three bytes + SoundIoFormatU24PackedLE, ///< Unsigned 24 bit Little Endian using three bytes + SoundIoFormatU24PackedBE, ///< Unsigned 24 bit Big Endian using three bytes + SoundIoFormatS32LE, ///< Signed 32 bit Little Endian + SoundIoFormatS32BE, ///< Signed 32 bit Big Endian + SoundIoFormatU32LE, ///< Unsigned 32 bit Little Endian + SoundIoFormatU32BE, ///< Unsigned 32 bit Big Endian + SoundIoFormatFloat32LE, ///< Float 32 bit Little Endian, Range -1.0 to 1.0 + SoundIoFormatFloat32BE, ///< Float 32 bit Big Endian, Range -1.0 to 1.0 + SoundIoFormatFloat64LE, ///< Float 64 bit Little Endian, Range -1.0 to 1.0 + SoundIoFormatFloat64BE, ///< Float 64 bit Big Endian, Range -1.0 to 1.0 }; #if defined(SOUNDIO_OS_BIG_ENDIAN) @@ -259,6 +263,8 @@ enum SoundIoFormat { #define SoundIoFormatU16NE SoundIoFormatU16BE #define SoundIoFormatS24NE SoundIoFormatS24BE #define SoundIoFormatU24NE SoundIoFormatU24BE +#define SoundIoFormatS24PackedNE SoundIoFormatS24PackedBE +#define SoundIoFormatU24PackedNE SoundIoFormatU24PackedBE #define SoundIoFormatS32NE SoundIoFormatS32BE #define SoundIoFormatU32NE SoundIoFormatU32BE #define SoundIoFormatFloat32NE SoundIoFormatFloat32BE @@ -268,6 +274,8 @@ enum SoundIoFormat { #define SoundIoFormatU16FE SoundIoFormatU16LE #define SoundIoFormatS24FE SoundIoFormatS24LE #define SoundIoFormatU24FE SoundIoFormatU24LE +#define SoundIoFormatS24PackedFE SoundIoFormatS24PackedLE +#define SoundIoFormatU24PackedFE SoundIoFormatU24PackedLE #define SoundIoFormatS32FE SoundIoFormatS32LE #define SoundIoFormatU32FE SoundIoFormatU32LE #define SoundIoFormatFloat32FE SoundIoFormatFloat32LE @@ -283,6 +291,8 @@ enum SoundIoFormat { #define SoundIoFormatU16NE SoundIoFormatU16LE #define SoundIoFormatS24NE SoundIoFormatS24LE #define SoundIoFormatU24NE SoundIoFormatU24LE +#define SoundIoFormatS24PackedNE SoundIoFormatS24PackedLE +#define SoundIoFormatU24PackedNE SoundIoFormatU24PackedLE #define SoundIoFormatS32NE SoundIoFormatS32LE #define SoundIoFormatU32NE SoundIoFormatU32LE #define SoundIoFormatFloat32NE SoundIoFormatFloat32LE @@ -292,6 +302,8 @@ enum SoundIoFormat { #define SoundIoFormatU16FE SoundIoFormatU16BE #define SoundIoFormatS24FE SoundIoFormatS24BE #define SoundIoFormatU24FE SoundIoFormatU24BE +#define SoundIoFormatS24PackedFE SoundIoFormatS24PackedBE +#define SoundIoFormatU24PackedFE SoundIoFormatU24PackedBE #define SoundIoFormatS32FE SoundIoFormatS32BE #define SoundIoFormatU32FE SoundIoFormatU32BE #define SoundIoFormatFloat32FE SoundIoFormatFloat32BE diff --git a/src/alsa.c b/src/alsa.c index 5a1e541..81a2fda 100644 --- a/src/alsa.c +++ b/src/alsa.c @@ -236,6 +236,10 @@ static snd_pcm_format_t to_alsa_fmt(enum SoundIoFormat fmt) { case SoundIoFormatS24BE: return SND_PCM_FORMAT_S24_BE; case SoundIoFormatU24LE: return SND_PCM_FORMAT_U24_LE; case SoundIoFormatU24BE: return SND_PCM_FORMAT_U24_BE; + case SoundIoFormatS24PackedLE: return SND_PCM_FORMAT_S24_3LE; + case SoundIoFormatS24PackedBE: return SND_PCM_FORMAT_S24_3BE; + case SoundIoFormatU24PackedLE: return SND_PCM_FORMAT_U24_3LE; + case SoundIoFormatU24PackedBE: return SND_PCM_FORMAT_U24_3BE; case SoundIoFormatS32LE: return SND_PCM_FORMAT_S32_LE; case SoundIoFormatS32BE: return SND_PCM_FORMAT_S32_BE; case SoundIoFormatU32LE: return SND_PCM_FORMAT_U32_LE; @@ -350,6 +354,10 @@ static int probe_open_device(struct SoundIoDevice *device, snd_pcm_t *handle, in snd_pcm_format_mask_set(fmt_mask, SND_PCM_FORMAT_S24_BE); snd_pcm_format_mask_set(fmt_mask, SND_PCM_FORMAT_U24_LE); snd_pcm_format_mask_set(fmt_mask, SND_PCM_FORMAT_U24_BE); + snd_pcm_format_mask_set(fmt_mask, SND_PCM_FORMAT_S24_3LE); + snd_pcm_format_mask_set(fmt_mask, SND_PCM_FORMAT_S24_3BE); + snd_pcm_format_mask_set(fmt_mask, SND_PCM_FORMAT_U24_3LE); + snd_pcm_format_mask_set(fmt_mask, SND_PCM_FORMAT_U24_3BE); snd_pcm_format_mask_set(fmt_mask, SND_PCM_FORMAT_S32_LE); snd_pcm_format_mask_set(fmt_mask, SND_PCM_FORMAT_S32_BE); snd_pcm_format_mask_set(fmt_mask, SND_PCM_FORMAT_U32_LE); @@ -364,7 +372,7 @@ static int probe_open_device(struct SoundIoDevice *device, snd_pcm_t *handle, in if (!device->formats) { snd_pcm_hw_params_get_format_mask(hwparams, fmt_mask); - device->formats = ALLOCATE(enum SoundIoFormat, 18); + device->formats = ALLOCATE(enum SoundIoFormat, 22); if (!device->formats) return SoundIoErrorNoMem; @@ -379,6 +387,10 @@ static int probe_open_device(struct SoundIoDevice *device, snd_pcm_t *handle, in test_fmt_mask(device, fmt_mask, SoundIoFormatS24BE); test_fmt_mask(device, fmt_mask, SoundIoFormatU24LE); test_fmt_mask(device, fmt_mask, SoundIoFormatU24BE); + test_fmt_mask(device, fmt_mask, SoundIoFormatS24PackedLE); + test_fmt_mask(device, fmt_mask, SoundIoFormatS24PackedBE); + test_fmt_mask(device, fmt_mask, SoundIoFormatU24PackedLE); + test_fmt_mask(device, fmt_mask, SoundIoFormatU24PackedBE); test_fmt_mask(device, fmt_mask, SoundIoFormatS32LE); test_fmt_mask(device, fmt_mask, SoundIoFormatS32BE); test_fmt_mask(device, fmt_mask, SoundIoFormatU32LE); diff --git a/src/dummy.c b/src/dummy.c index f1a3828..5e0ff61 100644 --- a/src/dummy.c +++ b/src/dummy.c @@ -380,7 +380,7 @@ static int instream_get_latency_dummy(struct SoundIoPrivate *si, struct SoundIoI } static int set_all_device_formats(struct SoundIoDevice *device) { - device->format_count = 18; + device->format_count = 22; device->formats = ALLOCATE(enum SoundIoFormat, device->format_count); if (!device->formats) return SoundIoErrorNoMem; @@ -395,14 +395,18 @@ static int set_all_device_formats(struct SoundIoDevice *device) { device->formats[7] = SoundIoFormatS24FE; device->formats[8] = SoundIoFormatU24NE; device->formats[9] = SoundIoFormatU24FE; - device->formats[10] = SoundIoFormatFloat64NE; - device->formats[11] = SoundIoFormatFloat64FE; - device->formats[12] = SoundIoFormatS16NE; - device->formats[13] = SoundIoFormatS16FE; - device->formats[14] = SoundIoFormatU16NE; - device->formats[15] = SoundIoFormatU16FE; - device->formats[16] = SoundIoFormatS8; - device->formats[17] = SoundIoFormatU8; + device->formats[10] = SoundIoFormatS24PackedNE; + device->formats[11] = SoundIoFormatS24PackedFE; + device->formats[12] = SoundIoFormatU24PackedNE; + device->formats[13] = SoundIoFormatU24PackedFE; + device->formats[14] = SoundIoFormatFloat64NE; + device->formats[15] = SoundIoFormatFloat64FE; + device->formats[16] = SoundIoFormatS16NE; + device->formats[17] = SoundIoFormatS16FE; + device->formats[18] = SoundIoFormatU16NE; + device->formats[19] = SoundIoFormatU16FE; + device->formats[20] = SoundIoFormatS8; + device->formats[21] = SoundIoFormatU8; return 0; } diff --git a/src/soundio.c b/src/soundio.c index 32d3455..4f5dc6f 100644 --- a/src/soundio.c +++ b/src/soundio.c @@ -97,24 +97,28 @@ const char *soundio_strerror(int error) { int soundio_get_bytes_per_sample(enum SoundIoFormat format) { switch (format) { - case SoundIoFormatU8: return 1; - case SoundIoFormatS8: return 1; - case SoundIoFormatS16LE: return 2; - case SoundIoFormatS16BE: return 2; - case SoundIoFormatU16LE: return 2; - case SoundIoFormatU16BE: return 2; - case SoundIoFormatS24LE: return 4; - case SoundIoFormatS24BE: return 4; - case SoundIoFormatU24LE: return 4; - case SoundIoFormatU24BE: return 4; - case SoundIoFormatS32LE: return 4; - case SoundIoFormatS32BE: return 4; - case SoundIoFormatU32LE: return 4; - case SoundIoFormatU32BE: return 4; - case SoundIoFormatFloat32LE: return 4; - case SoundIoFormatFloat32BE: return 4; - case SoundIoFormatFloat64LE: return 8; - case SoundIoFormatFloat64BE: return 8; + case SoundIoFormatU8: return 1; + case SoundIoFormatS8: return 1; + case SoundIoFormatS16LE: return 2; + case SoundIoFormatS16BE: return 2; + case SoundIoFormatU16LE: return 2; + case SoundIoFormatU16BE: return 2; + case SoundIoFormatS24LE: return 4; + case SoundIoFormatS24BE: return 4; + case SoundIoFormatU24LE: return 4; + case SoundIoFormatU24BE: return 4; + case SoundIoFormatS24PackedLE: return 3; + case SoundIoFormatS24PackedBE: return 3; + case SoundIoFormatU24PackedLE: return 3; + case SoundIoFormatU24PackedBE: return 3; + case SoundIoFormatS32LE: return 4; + case SoundIoFormatS32BE: return 4; + case SoundIoFormatU32LE: return 4; + case SoundIoFormatU32BE: return 4; + case SoundIoFormatFloat32LE: return 4; + case SoundIoFormatFloat32BE: return 4; + case SoundIoFormatFloat64LE: return 8; + case SoundIoFormatFloat64BE: return 8; case SoundIoFormatInvalid: return -1; } @@ -123,24 +127,28 @@ int soundio_get_bytes_per_sample(enum SoundIoFormat format) { const char * soundio_format_string(enum SoundIoFormat format) { switch (format) { - case SoundIoFormatS8: return "signed 8-bit"; - case SoundIoFormatU8: return "unsigned 8-bit"; - case SoundIoFormatS16LE: return "signed 16-bit LE"; - case SoundIoFormatS16BE: return "signed 16-bit BE"; - case SoundIoFormatU16LE: return "unsigned 16-bit LE"; - case SoundIoFormatU16BE: return "unsigned 16-bit LE"; - case SoundIoFormatS24LE: return "signed 24-bit LE"; - case SoundIoFormatS24BE: return "signed 24-bit BE"; - case SoundIoFormatU24LE: return "unsigned 24-bit LE"; - case SoundIoFormatU24BE: return "unsigned 24-bit BE"; - case SoundIoFormatS32LE: return "signed 32-bit LE"; - case SoundIoFormatS32BE: return "signed 32-bit BE"; - case SoundIoFormatU32LE: return "unsigned 32-bit LE"; - case SoundIoFormatU32BE: return "unsigned 32-bit BE"; - case SoundIoFormatFloat32LE: return "float 32-bit LE"; - case SoundIoFormatFloat32BE: return "float 32-bit BE"; - case SoundIoFormatFloat64LE: return "float 64-bit LE"; - case SoundIoFormatFloat64BE: return "float 64-bit BE"; + case SoundIoFormatS8: return "signed 8-bit"; + case SoundIoFormatU8: return "unsigned 8-bit"; + case SoundIoFormatS16LE: return "signed 16-bit LE"; + case SoundIoFormatS16BE: return "signed 16-bit BE"; + case SoundIoFormatU16LE: return "unsigned 16-bit LE"; + case SoundIoFormatU16BE: return "unsigned 16-bit LE"; + case SoundIoFormatS24LE: return "signed 24-bit LE"; + case SoundIoFormatS24BE: return "signed 24-bit BE"; + case SoundIoFormatU24LE: return "unsigned 24-bit LE"; + case SoundIoFormatU24BE: return "unsigned 24-bit BE"; + case SoundIoFormatS24PackedLE: return "signed 24-bit packed LE"; + case SoundIoFormatS24PackedBE: return "signed 24-bit packed BE"; + case SoundIoFormatU24PackedLE: return "unsigned 24-bit packed LE"; + case SoundIoFormatU24PackedBE: return "unsigned 24-bit packed BE"; + case SoundIoFormatS32LE: return "signed 32-bit LE"; + case SoundIoFormatS32BE: return "signed 32-bit BE"; + case SoundIoFormatU32LE: return "unsigned 32-bit LE"; + case SoundIoFormatU32BE: return "unsigned 32-bit BE"; + case SoundIoFormatFloat32LE: return "float 32-bit LE"; + case SoundIoFormatFloat32BE: return "float 32-bit BE"; + case SoundIoFormatFloat64LE: return "float 64-bit LE"; + case SoundIoFormatFloat64BE: return "float 64-bit BE"; case SoundIoFormatInvalid: return "(invalid sample format)"; diff --git a/test/overflow.c b/test/overflow.c index 43b6d22..dcff2e9 100644 --- a/test/overflow.c +++ b/test/overflow.c @@ -21,6 +21,8 @@ static enum SoundIoFormat prioritized_formats[] = { SoundIoFormatS32FE, SoundIoFormatS24NE, SoundIoFormatS24FE, + SoundIoFormatS24PackedNE, + SoundIoFormatS24PackedFE, SoundIoFormatS16NE, SoundIoFormatS16FE, SoundIoFormatFloat64NE, @@ -29,6 +31,8 @@ static enum SoundIoFormat prioritized_formats[] = { SoundIoFormatU32FE, SoundIoFormatU24NE, SoundIoFormatU24FE, + SoundIoFormatU24PackedNE, + SoundIoFormatU24PackedFE, SoundIoFormatU16NE, SoundIoFormatU16FE, SoundIoFormatS8,