Commit 4bd2c9df authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf
Browse files

libndi: Attempt to decode float audio

parent 520e980c
......@@ -243,11 +243,13 @@ static int process_audio_message(ndi_ctx *ndi_ctx, uint8_t *data, int header_len
uint32_t sample_rate = (data[15] << 24) | (data[14] << 16) | (data[13] << 8) | data[12];
float scale_factors[16];
uint32_t num_nonzero_channels = 0;
uint16_t bps = sizeof(int16_t);
// XXX: some more things in the header
data += header_len;
if(fourcc == MKTAG('f','o','w','t')) {
bps = sizeof(float);
for(uint32_t i = 0; i < num_channels; i++) {
uint32_t tmp = data[0] | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
memcpy(&scale_factors[i], &tmp, sizeof(float));
......@@ -273,7 +275,7 @@ static int process_audio_message(ndi_ctx *ndi_ctx, uint8_t *data, int header_len
ndi_data.sample_rate = sample_rate;
for(uint32_t i = 0; i < num_channels; i++) {
ndi_data.buf[i] = av_buffer_alloc(ndi_data.num_channels * ndi_data.samples * sizeof(int16_t));
ndi_data.buf[i] = av_buffer_alloc(ndi_data.num_channels * ndi_data.samples * bps);
if(!ndi_data.buf[i]) {
ret = -1;
goto end;
......@@ -282,9 +284,20 @@ static int process_audio_message(ndi_ctx *ndi_ctx, uint8_t *data, int header_len
for(uint32_t j = 0; j < samples; j++) {
for(uint32_t i = 0; i < num_channels; i++) {
ndi_data.buf[i]->data[2*j+0] = data[1];
ndi_data.buf[i]->data[2*j+1] = data[0];
data += sizeof(int16_t);
if(scale_factors[i] == 0.0f)
memset(&ndi_data.buf[i]->data[4*j], 0, bps);
else {
if(bps == 2) {
ndi_data.buf[i]->data[2*j+0] = data[1];
ndi_data.buf[i]->data[2*j+1] = data[0];
} else(bps == 4) {
float sf = scale_factors[i] / 32767.0f;
int16_t sample = ((uint16_t)data[1] << 8) | data[0];
sf *= sample;
memcpy(&ndi_data.buf[i]->data[4*j], sf, sizeof(sf));
}
data += sizeof(int16_t);
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment