Skip to content

Commit cab4072

Browse files
committed
audioconv64: add undocumented option to disable huffman compression in VADPCM
1 parent 54aa7cb commit cab4072

File tree

2 files changed

+46
-11
lines changed

2 files changed

+46
-11
lines changed

tools/audioconv64/audioconv64.c

+37-2
Original file line numberDiff line numberDiff line change
@@ -239,11 +239,46 @@ int main(int argc, char *argv[]) {
239239
fprintf(stderr, "missing argument for --wav-compress\n");
240240
return 1;
241241
}
242-
flag_wav_compress = atoi(argv[i]);
243-
if (flag_wav_compress != 0 && flag_wav_compress != 1 && flag_wav_compress != 3) {
242+
char *opts = strchr(argv[i], ',');
243+
if (opts) *opts++ = '\0';
244+
if (!strcmp(argv[i], "0") || !strcmp(argv[i], "none"))
245+
flag_wav_compress = 0;
246+
else if (!strcmp(argv[i], "1") || !strcmp(argv[i], "vadpcm"))
247+
flag_wav_compress = 1;
248+
else if (!strcmp(argv[i], "3") || !strcmp(argv[i], "opus"))
249+
flag_wav_compress = 3;
250+
else {
244251
fprintf(stderr, "invalid argument for --wav-compress: %s\n", argv[i]);
245252
return 1;
246253
}
254+
while (opts && *opts) {
255+
char *key = opts;
256+
char *value = strchr(opts, '=');
257+
if (!value) {
258+
fprintf(stderr, "invalid option for --wav-compress: %s\n", opts);
259+
return 1;
260+
}
261+
*value = '\0';
262+
value++;
263+
opts = strchr(value, ',');
264+
if (opts) {
265+
*opts = '\0';
266+
opts++;
267+
}
268+
if (!strcmp(key, "huffman")) {
269+
if (!strcmp(value, "true") || !strcmp(value, "1"))
270+
flag_wav_compress_huffman = true;
271+
else if (!strcmp(value, "false") || !strcmp(value, "0"))
272+
flag_wav_compress_huffman = false;
273+
else {
274+
fprintf(stderr, "invalid value for compression option 'huffman': %s\n", value);
275+
return 1;
276+
}
277+
} else {
278+
fprintf(stderr, "invalid option for --wav-compress: %s\n", key);
279+
return 1;
280+
}
281+
}
247282
} else if (!strcmp(argv[i], "--wav-resample")) {
248283
if (++i == argc) {
249284
fprintf(stderr, "missing argument for --wav-resample\n");

tools/audioconv64/conv_wav64.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
bool flag_wav_looping = false;
3636
int flag_wav_looping_offset = 0;
3737
int flag_wav_compress = 1;
38+
bool flag_wav_compress_huffman = true;
3839
int flag_wav_resample = 0;
3940
bool flag_wav_mono = false;
4041
const int OPUS_SAMPLE_RATE = 48000;
@@ -162,8 +163,6 @@ bool wav64_write(const char *infn, const char *outfn, FILE *out, wav_data_t* wav
162163
} break;
163164

164165
case 1: { // vadpcm
165-
bool huffman = true;
166-
167166
// The state is 16 bytes per channel, but the runtime code requires to
168167
// always allocate both channels even for mono files.
169168
placeholder_set_offset(out, 48, "state_size");
@@ -212,16 +211,17 @@ bool wav64_write(const char *infn, const char *outfn, FILE *out, wav_data_t* wav
212211
uint8_t *compbuf = malloc(maxcompbuflen);
213212
uint8_t *ctxbuf = calloc(HUFF_CONTEXT_LEN, 1);
214213
int compbuflen = 0;
215-
if (huffman)
214+
if (flag_wav_compress_huffman) {
216215
compbuflen = huffv_compress(dest, nframes * kVADPCMFrameByteSize * wav->channels, compbuf, maxcompbuflen, ctxbuf, HUFF_CONTEXT_LEN);
217216

218-
if (flag_verbose)
219-
fprintf(stderr, " huffman compressed %d bytes into %d bytes (ratio: %.1f)\n",
220-
nframes * kVADPCMFrameByteSize * wav->channels, compbuflen,
221-
100.0f * compbuflen / (nframes * kVADPCMFrameByteSize * wav->channels));
217+
if (flag_verbose)
218+
fprintf(stderr, " huffman compressed %d bytes into %d bytes (ratio: %.1f%%)\n",
219+
nframes * kVADPCMFrameByteSize * wav->channels, compbuflen,
220+
100.0f * compbuflen / (nframes * kVADPCMFrameByteSize * wav->channels));
221+
}
222222

223223
uint8_t flags = 0;
224-
if (huffman) flags |= (1<<0);
224+
if (flag_wav_compress_huffman) flags |= (1<<0);
225225

226226
struct vadpcm_vector state = {0};
227227
w8(out, kPREDICTORS);
@@ -238,7 +238,7 @@ bool wav64_write(const char *infn, const char *outfn, FILE *out, wav_data_t* wav
238238

239239
// Start of samples data
240240
placeholder_set(out, "samples");
241-
if (huffman)
241+
if (flag_wav_compress_huffman)
242242
fwrite(compbuf, 1, compbuflen, out);
243243
else
244244
fwrite(dest, 1, nframes * kVADPCMFrameByteSize * wav->channels, out);

0 commit comments

Comments
 (0)