Open pschatzmann opened 6 months ago
Both the timer and the PWM APIs have changed: I could identify that the timer was not working. I committed a correction to address the issue with the timer.
Please note that there is quite a difference to the requested frequency: e.g. Sampling Rate 44100 vs eff: 43476 I am not sure how to address this when you need it to match. Have a look at the code. Maybe you have an idea...
Maybe you could do some resampling or use a frequency which does not need any fraction of us (e,g 20000hz or 40000hz)
Hello, thank you. I will probably need to fix this eventually. That being said, I don't think the timer is working in the new Arduino ESP32 core (v. 3), which makes it a bit harder to debug. I will file a bug report and investigate.
There is a very similar problem with ESP32S3 - there the ADC continuous sampling frequency is correct, but the I2S TX frequency is off by about 10% even for non-fractional sample rates, such as 20ksps.
I have written a proof-of-concept resampling algorithm that uses fixed-point arithmetic for FOH resampling. It's reasonably efficient, but so far I didn't finish the automatic frequency compensiation for unknown sample rates. I will need to actually automatically measure the sample rates and calculate the correction factor accordingly. This will take around 2 seconds on startup, since I need to collect enough samples to get reasonably accurate results. I think there will still be signal quality degradation since it's not possible to match the rates exactly, so you will likely have a pop every few seconds or introduce phase noise. I should be able to have some code which grabs data from an analog microphone and spits it out using pdm for ESP32S3 by this weekend (I have it already but without the self calibration of the sample rates). The code does not yet use your library since I needed to limit the number of variables. Then we can discuss how to best implement this into your library. Sounds good?
Edit: Wait, I just saw that the resample stream is already in the library... never mind, it never occured to me to check.
You can measure the actual speed with a MeasuringStream and dynamically resample with a ResampleStream
You can measure the actual speed with a MeasuringStream and dynamically resample with a ResampleStream
Good idea. Correct me if I'm wrong, but I don't think the MeasuringStream can be used to measure the I2S output rate though? Just the input, right? We need to know both to be able to correctly resample.
If you decouple both processes with a queue, you should be able to measure (and process) both.
If you decouple both processes with a queue, you should be able to measure (and process) both.
I see. I just send the data from adc to Measuring stream 1 and the queue and then send the queue data to Measuring stream 2 and I2S. This gives me the rates I can then use to resample using ResamplingStream.
Sounds pretty straightforward. Thank you very much!! I think that the best way will be to subclass Copier and make it autoresample on-the-fly.
Discussed in https://github.com/pschatzmann/arduino-audio-tools/discussions/1480