mozilla / cubeb

Cross platform audio library
ISC License
443 stars 126 forks source link

resampler artifacts #515

Open lunixbochs opened 5 years ago

lunixbochs commented 5 years ago

I'm getting some gross wideband artifacts when recording with cubeb using lower sample rates (16khz, when my native device rate is 44.1khz), which I'm guessing is the fault of the speex resampler

The left spectrogram is the output from cubeb for a ~320hz tone. Notice the lattice of staticy artifacts, which shouldn't be there, and aren't present on the right side (recorded with baudline).

Screen Shot 2019-06-24 at 3 43 24 PM

out.wav.zip

padenot commented 5 years ago

What platform and backend are you using?

lunixbochs commented 5 years ago

This is audiounit on mac. If I set the input rate to 44100, I don't get any artifacts, so it only happens when downsampling. It happens even if I dump straight to disk from the input data callback (which is what I've done here), but I can also hear them if I turn around and pipe the samples into an output stream using the echo example from the cubeb header.

padenot commented 5 years ago

Can you attach an example program? This consistently work well here on OSX.

You should certainly not do IO or any other blocking call from the callback though, that will cause problems like what you describe.

lunixbochs commented 5 years ago

It has identical artifacts when hooked up to an output stream without IO. Adding a step to write the samples to a file did not change the output at all. My CPU is also effectively idle. I'm not getting any CoreAudio messages about dropped frames in Console.app.

It might be hard to hear on the loopback if you're just talking into a mic. When I use my phone to play a 600hz tone into the mic it's very obvious.

You might also have a different hardware capture rate than me, which could make the resampler behave differently for you. The attached source file is set to 15khz, but I get the same effect at 16khz, 32khz, 48khz, or even 96khz. Any resampled frequency. The only one that doesn't crackle under my loud 600hz tone is 44.1khz, my native input frequency.

FWIW my core use case is code I'm porting away from AudioUnit to cubeb for cross-platform support, and AudioUnit has no artifacts when resampling to 16khz for the same workload.

testcubeb.c.zip

padenot commented 5 years ago

I think I can repro and I have a possible fix for you to test: https://github.com/padenot/cubeb/commit/264cdd69f1109940b7ddb9e1514b6b431bf1ac42. If this works well, I'll write a proper fix. Can you try to apply this patch and test if it makes things better?

Indeed what was critical to repro was to have a continuous tone, I just whistled into my mic and it became very clear.

lunixbochs commented 5 years ago

Sounds much better with that patch!

lunixbochs commented 4 years ago

Is this planned to be fixed sometime soon? I'm maintaining a fork until then.

padenot commented 4 years ago

Oops sorry. I'm taking time off for Christmas, but I can clean and land this right after. Sorry about forgetting about this.

lunixbochs commented 1 year ago

just checking on this