yun
yun

Reputation: 1283

Weird Audio Blips in Recorded USB Audio Signal

Might be the wrong place to ask this but I kinda need help figuring out what the real issue is...

Basically, I'm programming a microcontroller to do USB audio recording (using USB Audio Class 2.0 / high speed USB). Seems like I'm getting pretty close to getting it" aright" but I'm getting this when I record a chirp into audacity [below is an excerpt]:

chirp excerpt

I guess what I'm asking is why am I getting these weird interruptions and jumps in my recording session? Is it because I'm not reading my codec input buffers quickly enough or perhaps the frame length isn't being set correctly?

How I'm calculating my frame length which I got from a USB Audio guide from Apple (using 44.1kHz sample rate and 16 bit rate):

#define AUDIO_POLL_INT     4
#define FRAME_BYTES        (BIT_RATE_16 / 8)
#define NUM_CHANNELS       STEREO

uint16_t frame_len = 44 (44.1kHz/1000 samples) * NUM_CHANNELS * FRAME_BYTES;
if (!(frame_pos % 9)) frame_len += (1 * NUM_CHANNELS * FRAME_BYTES)
frame_len = (frame_len / 8) * (2 << (AUDIO_POLL_INT-1));
// 10 ms frames
frame_pos = (((frame_pos + 1) / 8) * (2 << (AUDIO_POLL_INT-1))) % 10;

This is also the process of reading codec input:

1) Read Codec Input; Load samples into temporary buffer (transfers from codec peripheral to a memory peripheral)

2) Memory Peripheral interrupt occurs when a transfer is complete (buffer is full; frame_len capacity has been fulfilled), send buffer samples to USB. Afterwards, read codec input again

Hopefully this isn't too confusing... let me know and I can add more info/clear up things. Thanks!

Upvotes: 2

Views: 249

Answers (1)

Russ Schultz
Russ Schultz

Reputation: 2689

it doesn't look (to my eye) that you're dropping packets, just miss-ordering them.

Look at each of your 'blips'. It's pretty clear that each 'blip' actually is a stretch of audio that fits in the waveform about 1/3rd the waveform back in time.

Likely you've got a circular buffer and you're having issues with your read/write pointer or usage manager getting lost and sending out a buffer way late.

I don't think it's (directly related to, anyways) sample rate conversion or anything like that.

Upvotes: 5

Related Questions