ref: fa59247eb1355ffd84fa8b02533a877635e66019
parent: 51927c478136cb53d12d1017e1842e3d4050b7c8
author: robs <robs>
date: Sun Nov 19 15:51:37 EST 2006
Add support for 24-bit PCM raw, wav, & flac files.
--- a/src/sox.c
+++ b/src/sox.c
@@ -293,7 +293,7 @@
return(0);
}
-static char *getoptstr = "+r:v:t:c:C:phsuUAaigbwlfdxVSqo";
+static char *getoptstr = "+r:v:t:c:C:phsuUAaigbw3lfdxVSqo";
static struct option long_options[] =
{
@@ -407,6 +407,9 @@
case 'w':
fo->info.size = ST_SIZE_WORD;
break;
+ case '3':
+ fo->info.size = ST_SIZE_24BIT;
+ break;
case 'l':
fo->info.size = ST_SIZE_DWORD;
break;
@@ -1723,7 +1726,7 @@
"-x invert auto-detected endianess of data\n"
"-s/-u/-U/-A/ sample encoding. signed/unsigned/u-law/A-law\n"
" -a/-i/-g/-f ADPCM/IMA_ADPCM/GSM/floating point\n"
-"-b/-w/-l/-d sample size. byte(8-bits)/word(16-bits)/\n"
+"-b/-w/-3/-l/-d sample size. byte(8-bits)/word(16-bits)/3-byte(24-bits)/\n"
" long(32-bits)/double long(64-bits)\n"
"\n");
--- a/src/st.h
+++ b/src/st.h
@@ -40,6 +40,9 @@
typedef int32_t st_ssize_t;
typedef uint32_t st_rate_t;
+typedef int32_t int24_t;
+typedef uint32_t uint24_t;
+
/* Minimum and maximum values a sample can hold. */
#define ST_SAMPLE_MAX 2147483647L
#define ST_SAMPLE_MIN (-ST_SAMPLE_MAX - 1L)
@@ -49,6 +52,8 @@
#define ST_SIGNED_BYTE_TO_SAMPLE(d) ((st_sample_t)(d) << 24)
#define ST_UNSIGNED_WORD_TO_SAMPLE(d) ((st_sample_t)((d) ^ 0x8000) << 16)
#define ST_SIGNED_WORD_TO_SAMPLE(d) ((st_sample_t)(d) << 16)
+#define ST_UNSIGNED_24BIT_TO_SAMPLE(d) ((st_sample_t)((d) ^ 0x800000L) << 8)
+#define ST_SIGNED_24BIT_TO_SAMPLE(d) ((st_sample_t)(d) << 8)
#define ST_UNSIGNED_DWORD_TO_SAMPLE(d) ((st_sample_t)((d) ^ 0x80000000L))
#define ST_SIGNED_DWORD_TO_SAMPLE(d) ((st_sample_t)d)
#define ST_FLOAT_DWORD_TO_SAMPLE(d) (d==1? ST_SAMPLE_MAX : (st_sample_t)(d*ST_SAMPLE_FLOAT_SCALE))
@@ -57,6 +62,8 @@
#define ST_SAMPLE_TO_SIGNED_BYTE(d) ((int8_t)((d) >> 24))
#define ST_SAMPLE_TO_UNSIGNED_WORD(d) ((uint16_t)((d) >> 16) ^ 0x8000)
#define ST_SAMPLE_TO_SIGNED_WORD(d) ((int16_t)((d) >> 16))
+#define ST_SAMPLE_TO_UNSIGNED_24BIT(d) ((uint24_t)((d) >> 8) ^ 0x800000L)
+#define ST_SAMPLE_TO_SIGNED_24BIT(d) ((int24_t)((d) >> 8))
#define ST_SAMPLE_TO_UNSIGNED_DWORD(d) ((uint32_t)(d) ^ 0x80000000L)
#define ST_SAMPLE_TO_SIGNED_DWORD(d) ((int32_t)(d))
/* FIXME: This is an approximation because its impossible to
--
⑨