Commit Graph

91 Commits

Author SHA1 Message Date
Frank
d7bc6b1be7 AR: optimization for small MCUs, part2
Only run FFT when the result will be used.
Please note that this also means that `FFTTime` shown in Info is only meaningful when there is sound input and not silence.

--> To get exact FFT times, the optimization can be disabled by compiling with `-D SR_DEBUG`
2022-09-19 14:09:45 +02:00
Frank
79776ae8bc AR: optimization for smaller MCUs
- this reduces "lagging behind" of I2S sampling on smaller MCU's. The maximum time for FFT is now ~20 millis.
- small improvement for SR_DEBUG
2022-09-19 13:38:52 +02:00
Frank
90b3f009af AR: small improvement for ADC analog mics
ensure that ADC parameters are properly configured.
2022-09-19 13:30:13 +02:00
Frank
6f8deb83e3 some relaxations for S2 and C3
- AR: changed "error" into warning.
- reducing max_busses (for AR) not needed on S2
2022-09-17 22:00:33 +02:00
Frank
85fc8710dd mics that need MCLK should work 2022-09-17 20:39:23 +02:00
Frank
a766ddbebc make I2S microphones work with buggy IDF4.4.x
I2S microphones were not working any more in with the newest framework - only delivers silence.
Ther reason is stupid bug in espressif I2S "compatibility" driver: RIGHT and LEFT channel are swapped, so when only asking for LEFT, we get silence from RIGHT.

Workaround: simply change LEFT to RIGHT, until the problem is fixed in ESP-IDF --> Fix tested on "classic ESP32", but still need to check behavior on -S3.
Code compiles also on -S3, -S2, and -C3.

smaller changes:
- a few changes to use new APIs (MCLK, rouing and sample resolution)
- a few additional debug messages
- put correct value into _pinConfig.mck_io_num
2022-09-16 16:58:04 +02:00
Frank
01acb08c83 minor fix (typo) 2022-09-16 16:38:24 +02:00
Blaz Kristan
dfe4d70198 Merge branch 'audioreactive-prototype' into esp32-s2 2022-09-16 15:38:44 +02:00
Frank
925bc3b3dd AR: get rid of annoying "type conversion" warning 2022-09-11 14:32:00 +02:00
Frank
ac10b3a5c7 compilation support for audioreactive
putting all parts that will not compile between #ifdef .... #endif
Tested on S3, cannot say what will happen on other MCUs
2022-09-11 00:12:51 +02:00
Frank
cf93d6bb65 more precision for debug info (FFT timing)
keep more detailed timing info for FFT and I2S (WLED_DEBUG)
2022-09-08 22:45:32 +02:00
Blaz Kristan
e8942c2968 fix for repeating debug message 2022-09-06 15:52:09 +02:00
Blaz Kristan
42d1ab8a87 Separator in Info dialog. 2022-09-03 00:01:11 +02:00
Frank
77ace76e32 Bugfix: make UDP sound sync work in AP mode
- the connected() method only get called once a Wifi STA connection is established. UDP Sound Sync should also work when sender is in AP Mode.
- added a few comments that should help to understand the code structure.
2022-09-02 13:49:12 +02:00
Frank
37ba649930 audioreactive effect improvements
- Info Page: add a small horizontal line below usermod specific part. Improves readability.
- updated 2D mapping mode of some  1D soundreactive effects
- alllow some effects to fade slowly, even slower that possible with SEGMENT.fade_out(). Looks nice.

not sure why - most effects only fade when using SEGMENT.fade_out(), while some need SEGMENT.fadeToBlackBy().
2022-09-01 14:56:01 +02:00
Frank
64970772c7 optimization, and moving peak detection into own function
- save 1K of RAM by optimizing out
 fftBin[].
- moved several copies of the peak reset code into a single function
- moved peak detection out of getSample().
 - call peak detection function as last step of FFTcode. More optimal, and we can be sure that fresh FFT result are available.

Peak detection/reset are now called from both tasks, so I had to move some peak-related vars out of AudioReactive class and make them global (static).
2022-08-28 16:26:34 +02:00
Frank
5c792eb869 some cleanup and re-grouping of variables
- put variables with same context next to each other.
- removed a few vars that are not needed any more.
- replaced "16" by a more descriptive constant
2022-08-28 13:13:25 +02:00
Frank
be7e7ac274 AR: documentation
- clarified a misleading comment in FFTCode
- added a few more comments to describe steps of the processing
- removed some commented-out code
2022-08-22 10:08:22 +02:00
Blaz Kristan
720fae8720 Code sanitation.
Default analog pin -1
2022-08-21 19:15:42 +02:00
Frank
d053bc562f code cleanup, few optimizations, and fixing more overflows
- code cleanup in audio_reactive.h
- fixing some more under/overflows in fx.cpp
2022-08-21 13:10:16 +02:00
Blaz Kristan
ea363a8764 Minor cleanup & fix for connected(). 2022-08-21 09:51:15 +02:00
Frank
bbc8049832 The Right Thing to Do (makes GEQ look awesome)
... found that stupid commit messages get more attention ;-)

- use 22050 Hz for sampling, as it is a standard frequency. I think this is the best choise.
- redesigned the GEQ channels (fftResult[]) for 22Khz, based on channels found on old HiFi equalizer equipment. 1Kzh is now at the center; Bass/Trebble channels are using 1/4 on left/right side respectively - similar to real equalizers. Looks nice :-)

- adjusted effects that use FFT_MajorPeak so that the maximum frequency is supported.
2022-08-20 22:14:54 +02:00
Frank
b8db47e528 AR: new freq scaling option "square root"
also looks nice. It's a compromise between log() and linear. OK enough tinkering for today :-)
2022-08-19 16:11:50 +02:00
Frank
3c57e2e2b9 AR: special gain for GEO, some bugfixes andparameter tinkering
- new feature: "Input Level" (info page) can be used as global "GEQ gain" - only when AGC is ON (was already possible when AGC=off)

- some parameter tweaking in FFT function
- hidden feature: FFT decay  is slower when setting a high "dynamics Limiter Fall time" (steps: <1000, <2000, <3000, >3000)

- FFT_MajorPeak default 1.0f (as log(0.0) is invalid)
- FX.cppp: ensure that fftResult[] is always used inside array bounds
2022-08-19 14:36:47 +02:00
Blaz Kristan
753ae51dd5 Stop & restart UDP on pause/update. 2022-08-18 20:42:58 +02:00
Frank
3e494cc551 removed broken frequency squelch, added frequency scaling options
- removed broken FFTResult "squelch" feature. It was completely broken, and caused flashes in GEQ.
- added Frequency scaling options: linear and logarithmic
- fixed a few numerical accidents in FX.cpp (bouncing_balls,  ripplepeak, freqmap, gravfreq, waterfall)
2022-08-18 19:07:37 +02:00
Frank
d92a93f1d5 AR: added dynamics limiter usermod cfg options
- On/Off controls the complete feature
- Rise Time and Fall Time are the minimum times (in milliseconds) for "volume" to go from 0% to 80% and back.
- when "On" we also use some filtering to smooth FFTResults[]. Rise and Fall Times do not affect Frequency reactive effects otherwise.
2022-08-17 13:40:54 +02:00
Frank
1336de12a0 Info Page: added status info for audioreactive
- Current sound source - including "failed to initialize"
- Current AGC or Manual Gain
- Sound Sync Status
2022-08-17 00:15:06 +02:00
Frank
1a2701561b AR: bugfix for audio sync receive, and a few robustness improvements
* Header checking for sound sync receiver: removed wrong "!"
* make sure all member vars have initial values
* some robustness improvements in case of receiving bad UDP data.
2022-08-16 12:02:22 +02:00
Frank
873e41dcfb AR: change smoothing of FFTResult
FFTResult smoothing changed; rising edges will be very quick, falling down is slower.
2022-08-15 14:28:51 +02:00
Frank
5a4713950c improved ADCsample processing (from SR WLED)
improved ADCsample processing,  including replacement of "rogue" samples from other channels (this happens at least once in 5 seconds !!).

It compiles, don't ship it yet - needs more testing.
2022-08-14 16:17:34 +02:00
Frank
c6691564a5 removing dead code from getSamples() 2022-08-14 14:47:03 +02:00
Frank
8acb44b202 small improvement for limitSampleDynamics
support the case when only attackTime XOR decayTime is defined
2022-08-14 14:38:27 +02:00
Frank
968721a515 some audio processing improvements and bugfixes from SR WLED
- smoothing FFTResult (don't have a matrix to test)
- UDP sound sync improvements
- some bugfixes from SR WLED
- button.cpp: avoid starvation: strip.isUpdating() can be true for a long time.

work in progress - still needs testing!!
2022-08-14 13:58:07 +02:00
Blaž Kristan
d05b49496c Merge branch 'segment-api' into audioreactive-prototype 2022-08-11 13:24:01 +02:00
Blaz Kristan
e0a954caa2 4LD refresh task.
Scrolling text improvement.
LED settings bugfix.
Audioreactive disabled by default.
2022-08-10 20:20:36 +02:00
Frank
ecce3243de save 1KB of RAM
save one KB (4*256 bytes) by not storing the "upper half" of FFT results. Only the lower half has interesting results.
2022-08-10 18:14:28 +02:00
Frank
5e6532959b AudioSource improvements (work in progress)
-new methods: getType(), isInitailized(), postProcessSample()
- allow users to compile for RIGHT audio channel (-D I2S_USE_RIGHT_CHANNEL)
- better handling in case audio input driver failed to initialize
- removed some unneeded code and unneeded parameters
2022-08-10 17:18:43 +02:00
Frank
924073424f AR FFT task optimization - wait so I2S can fill its buffers
It seems that waiting first (before reading I2S) is much better than waiting after FFT is completed.
2022-08-08 13:53:46 +02:00
Frank
3a8c99d43c AR: removed two unneeded variables
some cleanup - no functional impact.
2022-08-08 10:51:46 +02:00
Frank
58987989da experimetal: limit rate at which the FFT task runs
this should do the trick.
Needs some more testing.
2022-08-07 22:19:38 +02:00
Frank
86e8ee334f future support: reading a single sample on 8266
audioreactive will still not work on 8266. This is just experimental code that allows to read a single sample from ADC every 20 millis.
2022-08-07 22:04:26 +02:00
Frank
8694e7a6bf AR: loop hickup protection (from SR WLED)
same "hickup protection" as implemented in SR WLED.
2022-08-06 18:17:45 +02:00
Frank
b46a6ed094 AR: samples dynamics limiter (experimental)
to enable, compile with -D SOUND_DYNAMICS_LIMITER.
still missing UI integration, and more testing.
2022-08-06 17:53:35 +02:00
Frank
d0f53cb14a AR: removing some old debug code
Align with SR WLED code:
- removed old debug code that did not work any more
- removed experimental MAJORPEAK_SUPPRESS_NOISE code
2022-08-06 17:24:39 +02:00
Frank
96d497a5cd AR: optimize sound sync, and code improvements
UDP audio sync: introduced new header version, because the new struct (without myvals[]) is not compatible with the previous struct. Also optimized structure size.
UDP audio sync: sender decides is AGC or non-AGC samples are transmitted.
getsamples: move volumeSmth/volumeRaw code out of AGC core function.
2022-08-06 16:48:26 +02:00
ewowi
84750e2605 Refactor um_data: remove fftBin 2022-07-29 15:50:09 +02:00
ewowi
dfa1a3ad90 Refactor um_data: remove inputLevel 2022-07-29 15:43:27 +02:00
ewowi
c1f9445e9d Refactor um_data variables for audio reactive
- change sample to sampleRaw
- add volumeSmth, volumeRaw, my_magnitude and calculate in agcAvg
- remove sampleAvg, soundAgc, sampleAgc, sampleRaw, rawSampleAgc, FFT_Magnitude, multAgc, sampleReal, sampleGain, (myVals), soundSquelch from um_data interface
- refactor all effects using above variables
2022-07-29 15:24:04 +02:00
ewowi
bc67bf6826 Replace myVals from audio_reactive.h to SEGMENT.data
(position in um_data reserved as free, could be cleaned up later)
2022-07-29 10:04:10 +02:00