ESP32-PICO-KIT Arduino and Audio Tools Resampling need faster polling of Touch Pins #537
-
This is my first post, so here goes..... //xxxxxxxxxxxxxxxxxxxxxxxxxxxxx Also in Arduino Library in file "esp32-hal-touch.c" I changed the SleepCycles and MeasureCycles down from 1000 to 300. /* #if SOC_TOUCH_VERSION_1 // ESP32 //xxxxxxxxxxxxxxxxxxxxxx PS ...... I tried using the add code <> brackets and also Ctrl E .... but unable to paste in sketch to look like code in preview..?? //xxxxxxxxxxxxxxxx // Sketch for ESP32-PICO-KIT using Arduino 2.0.3 with Audio Tools Library Resampling to DAC pin 25 out. #include "AudioTools.h" #define SA 0.4 const int pinPico[] = {27, 14, 12, 13, 15, 2, 32, 33}; // working pico touchpins ??? uint16_t sample_rate=44100; //CsvStream<int16_t> out(Serial); // this was original line in audio tool example AnalogAudioStream out; // changed to this to Analog out via internal DAC pin 25 StreamCopy copier(out, resample); // Arduino Setup // Setup sine wave // define resample // Define CSV Output xxxxxxxxx is this config still correct now Analog via DAC pin xxxx ?? // Arduino loop - copy sound to out // SndIndx = random(8); // xxxxx use this random() to test sounds 0 to 7 playing at loop speed xxxxx fast good .... SndIndx = TouchESP(); // xxxxx use this line TouchESP() to test speed with touchRead polling xxxxxx Too Slow .... if (SndIndx != lastSnd)
//this next code gets highest priority bit of combination untouched xxxxxxx //xxxxxxxxxxxxxxxxxxxxxxxxxxxx |
Beta Was this translation helpful? Give feedback.
Replies: 15 comments 6 replies
-
I suggest that you explore if you can make it work with attachinterrupt |
Beta Was this translation helpful? Give feedback.
-
Thanks for reply. I did think about interrupts but my problem is what has to occur to provide the interrupt and what process do I attach it to. As I see it I have a bundle of 7 or 8 pins that at any moment in time ESP32 needs to know the state of what is touched and what is untouched and play a sound depending on that combination, not just any specific pin touched or untouched. I suppose for 8 pins 0 to 7 there are 255 possibilities of sounds depending on the encoding/decoding. For example say if none touched (call that min touch) and play a low freq sound, then if all touched (call that max touch) play a high freq sound. The pins in between may not be all evenly "weighted" (as bits in binary) so say touching the top 3 pins would play a different sound from touching the bottom 3 pins. For the example shown in my code I used a priority encoder to simplify things which sets a higher priority on each untouched pin up the list and play a sound for that priority and "don't care" about other lower untouched at that instance. This gives 8 sounds for untouched and if a sound for all touched then 9 sounds alltogether. But various methods of encoding should be possible or just use all 255. The problem is still how to poll a group quickly or how to generate an interrupt for the actual state of a group at any one instance. |
Beta Was this translation helpful? Give feedback.
-
Reading pins is quite fast and if the Arduino API is too slow you can still access the register values directly as in this example: https://github.com/pschatzmann/logic-analyzer/blob/main/src/config_esp32.h |
Beta Was this translation helpful? Give feedback.
-
Thanks for reply but to understand setting up access to register values directly I would need to read up on it a bit more ?? |
Beta Was this translation helpful? Give feedback.
-
It's in the documentation: Wiki - Performance |
Beta Was this translation helpful? Give feedback.
-
Thanks for reply, Is this the type of thing I have to do...... Just add the #defiines into the sketch #define USE_AUDIO_LOGGING false |
Beta Was this translation helpful? Give feedback.
-
When checking audio delay at output pin 25 DAC on scope I am unable to see the instant the sound changes relative to being triggered to change. I see the freq changing but not as an instant I can capture. So I toggled a pin using ( digitalWrite(21, !digitalRead(21)); ) at the top of the loop and measured 12 ms for each repeat of the loop with the Touch polling running the audio resampling library. |
Beta Was this translation helpful? Give feedback.
-
You should change the buffer size via the config With 32000 samples per second, 16bit , a buffersize of 128 and a buffer_count of 2 you should get a lag of 8msecs end to end |
Beta Was this translation helpful? Give feedback.
-
I changed it in AudioConfig.h to 128 buffersize and count of 2. It has helped, it is now more or less workable with no speed to spare. in AudioConfig.h #ifndef I2S_BUFFER_SIZE #ifndef I2S_BUFFER_COUNT Will this not get overwritten due to updates etc of Arduino ide......? ?? |
Beta Was this translation helpful? Give feedback.
-
PS .... I am still getting 11.5 ms to 12 ms for the sketch loop time as measured on the scope from the toggle on pin 21. |
Beta Was this translation helpful? Give feedback.
-
You would change the values only in the AudioCofnig.h if you intend to use these values in all your sketches. Otherwise you would change it in your sketch via the config object. The same is valid if you optimize the copy buffer size which defines how many bytes you process in each loop step. The alternatives for improving on the pin reading times we have already discussed... |
Beta Was this translation helpful? Give feedback.
-
Thanks for your help. My problem is my old school studies it was all C and procedural code and not much on Classes and Objects or OOPs. |
Beta Was this translation helpful? Give feedback.
-
I don't really have any recommendation because I was learning by doing. Copared to simple c the big difference is that the structs (=classes) not have only variables but they can have methods as well and that you have some cool class initialization and destruction functionality and arrage your structs/classes in hierarchies. If you want to learn my library the best starting point is the
|
Beta Was this translation helpful? Give feedback.
-
Yes to increase the precision you can increase the sampling rate (or in your working more samples). I don't really know what you mean that the sketch used the sinewave oscillator: If you check in the documentation, where are at least 3 or alternative implementations to choose from and even more options if you use the supported DSP libraries. If you want to combine multiple inputs using the provided classes, I suggest that you read the corresponding chapter about splitting and merging in the Wiki. |
Beta Was this translation helpful? Give feedback.
-
The readme has a link to the class documentation: https://pschatzmann.github.io/arduino-audio-tools/html/modules.html |
Beta Was this translation helpful? Give feedback.
It's in the documentation: Wiki - Performance