The bellow code attempts to grab audio noninterleaved at 48khz and then use swresample to convert it to a sample rate of 16khz. When run i get an printf "swr_convert error: -22" printed. I can not find any documentation on what these error values mean and cant find any example code which explains clear enough exactly what format these apis are expecting. Any ideas or example code of how to do this? Im thinking that the library does not like how i am trying to give it the input data but i have been unable to find any example code which explains it explicitly.
SwrContext *swr = swr_alloc_set_opts(NULL,
AV_CH_LAYOUT_STEREO, // out_ch_layout
AV_SAMPLE_FMT_S16, // out_sample_fmt
16000, // out_sample_rate
AV_CH_LAYOUT_STEREO, // in_ch_layout
AV_SAMPLE_FMT_S16, // in_sample_fmt
48000, // in_sample_rate
0, NULL); // log_offset, log_ctx
const size_t buffSize = 1024 / 4;
short leftBuff[buffSize];
short rightBuff[buffSize];
short *bufs[] = { leftBuff , rightBuff };
get_input(bufs, buffSize);
uint8_t *output;
int64_t delay = swr_get_delay(swr, 48000);
int out_samples = av_rescale_rnd(delay + buffSize, 16000, 48000, AV_ROUND_UP);
printf("av_rescale_rnd delay: %" SCNd64 " outSamps: %d\n", delay, out_samples);
if ((err = av_samples_alloc(&output, NULL, 2, out_samples, AV_SAMPLE_FMT_S16, 0)) < 0)
{
printf("av_samples_alloc error: %d\n", err);
break;
}
if ((out_samples = swr_convert(swr, &output, out_samples, (uint8_t **) bufs, buffSize)) != buffSize)
{
printf("swr_convert error: %d\n", out_samples);
}
handle_audio_recieved((short*)&output[0], (short*)&output[1], out_samples);
av_freep(&output);
Aucun commentaire:
Enregistrer un commentaire