bastibe/PySoundCard

Changing input sample rate

Closed this issue · 14 comments

When I use a smaller sample rate than the default one given by
default_input_device()['default_sample_rate']
in
Stream(sample_rate=smaller_sample_rate)
all read calls show the warning "Input overflowed" as if this does not change the sample rate of the input device and just discards leftover samples.

Is this the correct way to change the input sample rate?


In my case:

  • default sample rate: 48000
  • smaller sample rate: 44100

input overflowed merely means that recording data was lost between two calls to read because your code took longer than one block length to process the block. Usually, increasing the block length will solve this issue.

I know and I already tried with a big block length and no processing and it kept showing the warning (this for a sample rate of 44100). With the same exact configuration and sample rate of 48000 no warning at all, even using significantly smaller block lengths. It doesn't makes sense it loses samples with the slower sample rate.

Presumably, your sound card runs at a specific sample rate. Any application that writes to the sound card at a different sample rate will have its data converted to the native sample rate of the sound card. This might lead to performance problems, although frankly, this really should not matter.

What OS and API are you running?

I am on the latest macbook pro retina, with OSX 10.9.1. I'm just reading, not writing, but I guess it is the same for the matter.

Oh, and using the internal sound card.

OK, that should not be a problem then. How many samples are you reading and what is your block length? Did you set Stream(output_device=False)?

This reproduces the error:

stream = pysoundcard.Stream(sample_rate=44100, block_length=1024, output_device=False)
stream.start()
stream.read(1024)
stream.stop()

This outputs the warning:

pysoundcard.py:592: RuntimeWarning: 2718.2747: Input overflowed

If I use sample_rate=48000 instead, it works fine with no warnings.

I just tried this on my computer (MBP 2011), and I don't get this warning. Does the warning only appear initially, or do you get the warning every time you read?

Every time I read. Try a different sample rate than 44100 because in your macbook probably it is the default one (in my MB 2009 it was).

Indeed. I see it on my machine, too. Also, it happens with several sound cards.

I'm afraid this is a problem within portaudio. I just tried running this in raw=True, which reduces processing to an absolute minimum, and the problem persists. It does get less bad with really high block lengths, but that is not desirable.

I don't see any practical solution for this, sorry.

I guess, then, it just means than you cannot change the sampling rate used by the sound card from port audio, but rather you have to tell it to use the sampling rate the sound card is configured to.

Thanks for all your efforts!!

If the input sampling rate cannot be changed in any case this parameter should not exist, right?

Well, the sampling rate can be changed. It's just that portaudio will then be really slow and start skipping frames. Besides, this is possibly a problem in OSX only.

Ok. Then I close the issue