Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Help with sample rate issue (Read 4144 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Help with sample rate issue

Hi guys. I'm working on an embedded project that includes an audio capture module.

For various reasons that may be tied to Murphys laws and my inherent bad luck, I can't use any of the *sweet spot* clocks for driving my audio peripheral. Long story short, I can't get a clean 16k, 24k or 48k sample rate in the MCU power mode I'm targeting.
I can get pretty darn close, but not quite there. The best values I can get are in the following table.

Desired frequencyClosest InferiorClosest Superior
160001595716666
240002380924193
480004687548387
I'd like to compress the audio samples using Opus. What do you guys suggest?

Seeing as I'm pretty close to the standard Opus sample rates, can I get away with doubling a few samples here and there? Or should I go for the next higher sample rate and maybe throw out a few samples?
Because power consumption is a big part of the project, I wouldn't be all too happy about burning precious sleep time with a fully-blown resampling algorithm (on top of the one opus uses anyway, that is).


Re: Help with sample rate issue

Reply #2
15957
That's awfully close. Is a 0.3% error an acceptable compromise? (That's less than 4 minutes per day.)

I got lucky with that one. Even the 24k is acceptable. It's a roughly 0.7% error rate. I guess that would be ok.
But the 48k [46875], for example, has a very annoying chipmunk quality to it. :))

Re: Help with sample rate issue

Reply #3
48387 is closer, but if you ever want to play back with tempo adjustment, it goes in the opposite direction of the 16, so you cannot just give them all 0.5 percent in the same direction.

(Dumb question ... are your numbers correct? 48387/2 matches the number above it in the table, but not so in the left column?)

Re: Help with sample rate issue

Reply #4
Yeah. It has to do with the clock dividers. The numbers are correct.
48387 is closer, but if you ever want to play back with tempo adjustment, it goes in the opposite direction of the 16, so you cannot just give them all 0.5 percent in the same direction.

(Dumb question ... are your numbers correct? 48387/2 matches the number above it in the table, but not so in the left column?)

The numbers are correct. They re all tried and tested.
The problem lies in the fact that I can't use an "audio source clock" (something like 24.567 Mhz) to derive the sampling frequency. Because that clock doesn't work in deep sleep mode. So I'm stuck with a general purpose 24Mhz clock. That's divded by dividers A and B. A is between 2 and 4; B is between 2 and 16. And that's further divided by two and by the decimation rate (I'm using a PDM audio block).
Eg: 48000 Hz target sample rate: 24.000.000 / 2 / 4 / 2 / 31 ~ 48387 Hz (if I could use the *audio* clock, that would have been a clean 48.000 result).
If I could use the 24.567 Mhz clock, I'd get clean, standard audio sample rates. With the clock I'm stuck with, I can only get the values in the table (so far).

Just for clarification, because I understand pretty much 0 about how Opus works under the hood.
Is it ok to:

1. Feed Opus a 20 ms frame of audio sampled at 46875;
2. Lie to it that it's actually sampled at 48000;
3. On the PC side, decode the Opus bytes as if the audio was originally 48000;
4. Use a proper resampling algorithm to actually make it 48000?

If that's ok, my problem's pretty much solved.

Re: Help with sample rate issue

Reply #5
But where and how are you encoding to Opus? Doesn't it resample to 48kHz whatever you feed it with anyway?

Re: Help with sample rate issue

Reply #6
Is it ok to:

1. Feed Opus a 20 ms frame of audio sampled at 46875;
2. Lie to it that it's actually sampled at 48000;
3. On the PC side, decode the Opus bytes as if the audio was originally 48000;
4. Use a proper resampling algorithm to actually make it 48000?
You can do that, but the encoder's psychoacoustic model assumes you've told it the correct sample rate, so it will work better the closer you get to the actual sample rate. You should use 48387 (off by 0.8%) instead of 46875 (off by 2.4%).

Re: Help with sample rate issue

Reply #7
Is it ok to:

1. Feed Opus a 20 ms frame of audio sampled at 46875;
2. Lie to it that it's actually sampled at 48000;
3. On the PC side, decode the Opus bytes as if the audio was originally 48000;
4. Use a proper resampling algorithm to actually make it 48000?
You can do that, but the encoder's psychoacoustic model assumes you've told it the correct sample rate, so it will work better the closer you get to the actual sample rate. You should use 48387 (off by 0.8%) instead of 46875 (off by 2.4%).

Thank you. Did that, the results are quite ok.

Re: Help with sample rate issue

Reply #8
But where and how are you encoding to Opus? Doesn't it resample to 48kHz whatever you feed it with anyway?

On a microcontroller. It stores audio data on a sd card.