[Libav-user] Getting spikes in signal when reading mp3 data
Mark McKay
mark at kitfox.com
Tue Dec 3 14:56:55 EET 2019
I'm trying to use libav to read in audio PCM data. I've got it to read
in my .wav sample data correctly (the byte format is AV_SAMPLE_FMT_S16).
However, my .mp3 sample is getting a lot of strange spikes in the data.
The sample format for the .mp3 is AV_SAMPLE_FMT_FLTP and while most of
the samples appear to be correct, about 10% of them have very large
magnitudes. I'm wondering what's going wrong, and if this might have
something to do with the exponent of the floating point number being
translated incorrectly. It's not clear to me what the difference
between AV_SAMPLE_FMT_FLT and AV_SAMPLE_FMT_FLTP is.
This is a sample of the bit of my code that reads the data from the
frame. Am I reading it correctly?
int bufferSize = av_samples_get_buffer_size(NULL,
aCodecCtx->channels,
aFrame->nb_samples,
aCodecCtx->sample_fmt,
1);
uint8_t *dataBuf = aFrame->data[0];
for (int i = 0; i < aFrame->nb_samples; i++)
{
for (int ch = 0; ch < numChannels; ch++)
{
float val = 0;
switch (aCodecCtx->sample_fmt)
{
...
case AV_SAMPLE_FMT_FLT:
case AV_SAMPLE_FMT_FLTP:
{
val = ((float*)dataBuf)[ch + i * numChannels];
if (val > 1 || val < -1)
{
qDebug("Sample out of range %f", val);
val = 0;
}
break;
}
---
http://www.kitfox.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://ffmpeg.org/pipermail/libav-user/attachments/20191203/c465f41c/attachment.html>
More information about the Libav-user
mailing list