Arbitrary Waves Resampling and Mixing #1466
-
I am using ESP32-Pico-D4 dev board and programming via Arduino 2.3.2 on windows 11. It is about a year since I have been on this forum discussion page and at that time I tried out some examples but never got them to run or combine sucessfully. So I am hoping to try again as I have been getting emails and notification to say you are still developing and have improved the system. |
Beta Was this translation helpful? Give feedback.
Replies: 21 comments 70 replies
-
I am providing example for each of your requirements, but it is up to you to put things together. |
Beta Was this translation helpful? Give feedback.
-
Thanks for letting me know. I have corrected the errors and it should compile now w/o errors. Your staircase is a display problem: there are no staircases when you render/hear the audio If you want to change the playback speed you can, as I have explained abouve, resample, if you just want to change the frequency/pitch but not the speed you can try to use pitch shifting. |
Beta Was this translation helpful? Give feedback.
-
The pin numbers indicated are always GPIO numbers so 14 is GPIO 14. There is the regular ESP32 and there are C3, S2, S3, H2 and C6. But for I2S this does not really matter and it works all the same for all of them. The differences are in the default pins and the internal DAC and ADC. So when you specify the pins, as you did above, you are on the save side... |
Beta Was this translation helpful? Give feedback.
-
The intended usage of <> is: first write or paste the code, then mark the code, then press <>. |
Beta Was this translation helpful? Give feedback.
-
I do not know the PT8211 DAC. You might need to change the format in the config. |
Beta Was this translation helpful? Give feedback.
-
you were writing: I am using a PT8211 DAC and I connect IO25 to pin1 BCK, IO26 to pin2 WS, and IO2 to Pin DIN. auto config = out.defaultConfig(TX_MODE);
config.copyFrom(info);
config.pin_bck = 25;
config.pin_ws = 26;
config.pin_data = 2;
out.begin(config); and you confirmed that you get an output this way... |
Beta Was this translation helpful? Give feedback.
-
I bet you messed up with the number of channels: In the sketch you indicated that you provide a stereo signal! |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Not sure, you could try to call the IDF method directly to set the sample rate: |
Beta Was this translation helpful? Give feedback.
-
See https://github.com/pschatzmann/arduino-audio-tools/wiki/Multicore-Processing It would be |
Beta Was this translation helpful? Give feedback.
-
Here is the easiest solution approach:
If you still want to support up-sampling and play it faster: here are the steps
With a sample rate of 44100 you can only represent a frequency range of 22050 hz. If you upsample a singnal that has some frequency components that end up > 22050 after up-sampling, this will result in aliasing noise! Can you share the Frequency Range of your signal as well ? |
Beta Was this translation helpful? Give feedback.
-
I made a test case with a sine to output as CSV on the plotter and I confirm for certain factors the interpolation seems to have an issue |
Beta Was this translation helpful? Give feedback.
-
Yes, step sizes. I committed a correction with the corresponding test case. |
Beta Was this translation helpful? Give feedback.
-
cd to the directory libraries/arduino-audio-tools and on the command line you type the command: git pull |
Beta Was this translation helpful? Give feedback.
-
I can't reproduce your issue in the AudioTools: A sine wave with a frequency of 3000 hz and a step size of 0.375 gives |
Beta Was this translation helpful? Give feedback.
-
I tried to compare the values with some precalculated values in Excel and it seems that after each write operation some samples get lost. |
Beta Was this translation helpful? Give feedback.
-
I committed a correction: Your example is working fine for me now. Instead of sineWave.begin(cfg1); it would be better just call in.begin(info); I hope I have the calculations right now for the ResampleStream: If you run the sketch in log level Debug, you see the detail calculation for each sample |
Beta Was this translation helpful? Give feedback.
-
The step index is a float value that is increased by the step size
For the calculation, I am using a linear interpolation. |
Beta Was this translation helpful? Give feedback.
-
I think this is a feature of the ESP32 analog API. Using the APLL should resolve the issue: just set config.use_apll = true; I did not do any thinking when I was setting up the fields of AudioInfo and defined everything as int: so it is about time to correct this: you can use uint16_t in a sketch if you want to use frequencies below 65'535, which in most of the times if ok. |
Beta Was this translation helpful? Give feedback.
-
I think this is a problem of the ESP32 core and not my library. Using a proper DAC with I2S gives more flexibility though some DACs only support some defined frequencies |
Beta Was this translation helpful? Give feedback.
-
I was redesigning the read parts of the resampler a bit and the combination mentioned above is working now as well. |
Beta Was this translation helpful? Give feedback.
I am providing example for each of your requirements, but it is up to you to put things together.
Start with a simple sketch and extend it step by step: this allows you to figure out the issue when you make a mistake.