Skip to content
Snippets Groups Projects
Commit 82abdae9 authored by Mans Rullgard's avatar Mans Rullgard
Browse files

mqbgen: allow single-channel input

parent 8b2558b5
No related branches found
No related tags found
No related merge requests found
......@@ -144,7 +144,8 @@ int main(int argc, char **argv)
SNDFILE *ofile;
SF_INFO ifmt;
SF_INFO ofmt;
int32_t *buf;
int32_t *ibuf;
int32_t *obuf;
uint8_t mqb[32];
uint8_t *mqb_end;
int mqb_len;
......@@ -203,7 +204,7 @@ int main(int argc, char **argv)
if (!ifile)
error("%s: %s\n", argv[0], sf_strerror(NULL));
if (ifmt.channels != 2)
if (ifmt.channels > 2)
error("unsupported channel count %d\n", ifmt.channels);
if (rate < 8) {
......@@ -248,15 +249,19 @@ int main(int argc, char **argv)
break;
}
buf = malloc(BUF_SIZE * ifmt.channels * sizeof(*buf));
if (!buf)
ibuf = malloc(BUF_SIZE * ifmt.channels * sizeof(*ibuf));
if (!ibuf)
error("malloc: %s\n", strerror(errno));
memset(&ofmt, 0, sizeof(ofmt));
ofmt.samplerate = ifmt.samplerate;
ofmt.channels = ifmt.channels;
ofmt.channels = 2;
ofmt.format = SF_FORMAT_WAV | SF_FORMAT_PCM_24;
obuf = malloc(BUF_SIZE * ofmt.channels * sizeof(*obuf));
if (!obuf)
error("malloc: %s\n", strerror(errno));
ofile = sf_open(argv[1], SFM_WRITE, &ofmt);
if (!ofile)
error("%s: %s\n", argv[1], sf_strerror(NULL));
......@@ -270,16 +275,22 @@ int main(int argc, char **argv)
mqb_bit = 7;
for (;;) {
int frames = sf_readf_int(ifile, buf, BUF_SIZE);
int frames = sf_readf_int(ifile, ibuf, BUF_SIZE);
int i;
if (!frames)
break;
for (i = 0; i < frames; i++) {
int32_t l = buf[2 * i] >> 8;
int32_t r = buf[2 * i + 1] >> 8;
int bit = mqb[mqb_pos] >> mqb_bit & 1;
int32_t l, r;
if (ifmt.channels == 1) {
l = r = ibuf[i] >> 8;
} else {
l = ibuf[2 * i] >> 8;
r = ibuf[2 * i + 1] >> 8;
}
if (mqb_bit-- == 0) {
if (++mqb_pos == mqb_len)
......@@ -294,18 +305,19 @@ int main(int argc, char **argv)
mqb_write_bit(&l, &r, bit);
buf[2 * i] = l << 8;
buf[2 * i + 1] = r << 8;
obuf[2 * i] = l << 8;
obuf[2 * i + 1] = r << 8;
}
sf_writef_int(ofile, buf, frames);
sf_writef_int(ofile, obuf, frames);
}
sf_close(ifile);
sf_close(ofile);
free(buf);
free(ibuf);
free(obuf);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment