sensorium / Mozzi

sound synthesis library for Arduino
https://sensorium.github.io/Mozzi/
GNU Lesser General Public License v2.1
1.06k stars 185 forks source link

Asynchroneous ADC (mozziAnalogRead) for Uno R4 #199

Closed tomcombriat closed 10 months ago

tomcombriat commented 11 months ago

Hi!

This is a proposal for implementing mozziAnalogRead() on the Uno R4, following #190. The result is a bit of a jigsaw puzzle between different source code I could find online (from Arduino, and from Renesas)… There are not a lot of documentation on this chip yet, not to say well documented for people green behind the ears like me…

Anyway, this seems to work quite well. I put the sources inside a separate file because they are not fancy to read but when I look at the final result it might be able to go inside the implementation file. I am up for opinions on this but also on the code in general. I might be doing things a bit naively in there but I had a bit of troubles to make that works in the first place.

I think that when this gets in there it might be time for a new release for the two newer ports (giga and R4). I do not mind trying to do it!

Cheers,

github-actions[bot] commented 11 months ago

Memory usage change @ 976607dfac9925b4df6b83755e99f7bc668b02d6

Board flash % RAM for global variables %
STMicroelectronics:stm32:GenF1:pnum=BLUEPILL_F103C8 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:avr:uno 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:mbed_giga:giga 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
arduino:samd:adafruit_circuitplayground_m0 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
esp8266:esp8266:huzzah N/A N/A N/A N/A
rp2040:rp2040:rpipico 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
Click for full report table Board|`examples/01.Basics/Control_Gain`
flash|%|`examples/01.Basics/Control_Gain`
RAM for global variables|%|`examples/01.Basics/Sinewave`
flash|%|`examples/01.Basics/Sinewave`
RAM for global variables|%|`examples/01.Basics/Sinewave_HIFI`
flash|%|`examples/01.Basics/Sinewave_HIFI`
RAM for global variables|%|`examples/01.Basics/Skeleton`
flash|%|`examples/01.Basics/Skeleton`
RAM for global variables|%|`examples/01.Basics/Table_Resolution`
flash|%|`examples/01.Basics/Table_Resolution`
RAM for global variables|%|`examples/01.Basics/Vibrato`
flash|%|`examples/01.Basics/Vibrato`
RAM for global variables|%|`examples/02.Control/Control_Echo_Theremin`
flash|%|`examples/02.Control/Control_Echo_Theremin`
RAM for global variables|%|`examples/02.Control/Control_Oscil_Wash`
flash|%|`examples/02.Control/Control_Oscil_Wash`
RAM for global variables|%|`examples/02.Control/Control_Tremelo`
flash|%|`examples/02.Control/Control_Tremelo`
RAM for global variables|%|`examples/02.Control/EventDelay`
flash|%|`examples/02.Control/EventDelay`
RAM for global variables|%|`examples/02.Control/Line_Gliss`
flash|%|`examples/02.Control/Line_Gliss`
RAM for global variables|%|`examples/02.Control/Line_Gliss_Double_32k_HIFI`
flash|%|`examples/02.Control/Line_Gliss_Double_32k_HIFI`
RAM for global variables|%|`examples/02.Control/Metronome_SampleHuffman`
flash|%|`examples/02.Control/Metronome_SampleHuffman`
RAM for global variables|%|`examples/02.Control/Stop_Start`
flash|%|`examples/02.Control/Stop_Start`
RAM for global variables|%|`examples/06.Synthesis/AMsynth`
flash|%|`examples/06.Synthesis/AMsynth`
RAM for global variables|%|`examples/06.Synthesis/AMsynth_HIFI`
flash|%|`examples/06.Synthesis/AMsynth_HIFI`
RAM for global variables|%|`examples/06.Synthesis/Brown_Noise_Realtime`
flash|%|`examples/06.Synthesis/Brown_Noise_Realtime`
RAM for global variables|%|`examples/06.Synthesis/Detuned_Beats_Wash`
flash|%|`examples/06.Synthesis/Detuned_Beats_Wash`
RAM for global variables|%|`examples/06.Synthesis/Difference_Tone`
flash|%|`examples/06.Synthesis/Difference_Tone`
RAM for global variables|%|`examples/06.Synthesis/FMsynth`
flash|%|`examples/06.Synthesis/FMsynth`
RAM for global variables|%|`examples/06.Synthesis/FMsynth_32k_HIFI`
flash|%|`examples/06.Synthesis/FMsynth_32k_HIFI`
RAM for global variables|%|`examples/06.Synthesis/NonAlias_MetaOscil`
flash|%|`examples/06.Synthesis/NonAlias_MetaOscil`
RAM for global variables|%|`examples/06.Synthesis/PDresonant`
flash|%|`examples/06.Synthesis/PDresonant`
RAM for global variables|%|`examples/06.Synthesis/PWM_Phasing`
flash|%|`examples/06.Synthesis/PWM_Phasing`
RAM for global variables|%|`examples/06.Synthesis/WaveFolder`
flash|%|`examples/06.Synthesis/WaveFolder`
RAM for global variables|%|`examples/06.Synthesis/WavePacket_Double`
flash|%|`examples/06.Synthesis/WavePacket_Double`
RAM for global variables|%|`examples/06.Synthesis/WavePacket_Sample`
flash|%|`examples/06.Synthesis/WavePacket_Sample`
RAM for global variables|%|`examples/06.Synthesis/WavePacket_Single`
flash|%|`examples/06.Synthesis/WavePacket_Single`
RAM for global variables|%|`examples/06.Synthesis/Waveshaper`
flash|%|`examples/06.Synthesis/Waveshaper`
RAM for global variables|% -|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|- `STMicroelectronics:stm32:GenF1:pnum=BLUEPILL_F103C8`|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0 `arduino:avr:uno`|0|0.0|0|0.0|0|0.0|0|0.0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|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0 `esp8266:esp8266:huzzah`|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A|N/A `rp2040:rp2040:rpipico`|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0|0|0.0
Click for full report CSV ``` Board,examples/01.Basics/Control_Gain
flash,%,examples/01.Basics/Control_Gain
RAM for global variables,%,examples/01.Basics/Sinewave
flash,%,examples/01.Basics/Sinewave
RAM for global variables,%,examples/01.Basics/Sinewave_HIFI
flash,%,examples/01.Basics/Sinewave_HIFI
RAM for global variables,%,examples/01.Basics/Skeleton
flash,%,examples/01.Basics/Skeleton
RAM for global variables,%,examples/01.Basics/Table_Resolution
flash,%,examples/01.Basics/Table_Resolution
RAM for global variables,%,examples/01.Basics/Vibrato
flash,%,examples/01.Basics/Vibrato
RAM for global variables,%,examples/02.Control/Control_Echo_Theremin
flash,%,examples/02.Control/Control_Echo_Theremin
RAM for global variables,%,examples/02.Control/Control_Oscil_Wash
flash,%,examples/02.Control/Control_Oscil_Wash
RAM for global variables,%,examples/02.Control/Control_Tremelo
flash,%,examples/02.Control/Control_Tremelo
RAM for global variables,%,examples/02.Control/EventDelay
flash,%,examples/02.Control/EventDelay
RAM for global variables,%,examples/02.Control/Line_Gliss
flash,%,examples/02.Control/Line_Gliss
RAM for global variables,%,examples/02.Control/Line_Gliss_Double_32k_HIFI
flash,%,examples/02.Control/Line_Gliss_Double_32k_HIFI
RAM for global variables,%,examples/02.Control/Metronome_SampleHuffman
flash,%,examples/02.Control/Metronome_SampleHuffman
RAM for global variables,%,examples/02.Control/Stop_Start
flash,%,examples/02.Control/Stop_Start
RAM for global variables,%,examples/06.Synthesis/AMsynth
flash,%,examples/06.Synthesis/AMsynth
RAM for global variables,%,examples/06.Synthesis/AMsynth_HIFI
flash,%,examples/06.Synthesis/AMsynth_HIFI
RAM for global variables,%,examples/06.Synthesis/Brown_Noise_Realtime
flash,%,examples/06.Synthesis/Brown_Noise_Realtime
RAM for global variables,%,examples/06.Synthesis/Detuned_Beats_Wash
flash,%,examples/06.Synthesis/Detuned_Beats_Wash
RAM for global variables,%,examples/06.Synthesis/Difference_Tone
flash,%,examples/06.Synthesis/Difference_Tone
RAM for global variables,%,examples/06.Synthesis/FMsynth
flash,%,examples/06.Synthesis/FMsynth
RAM for global variables,%,examples/06.Synthesis/FMsynth_32k_HIFI
flash,%,examples/06.Synthesis/FMsynth_32k_HIFI
RAM for global variables,%,examples/06.Synthesis/NonAlias_MetaOscil
flash,%,examples/06.Synthesis/NonAlias_MetaOscil
RAM for global variables,%,examples/06.Synthesis/PDresonant
flash,%,examples/06.Synthesis/PDresonant
RAM for global variables,%,examples/06.Synthesis/PWM_Phasing
flash,%,examples/06.Synthesis/PWM_Phasing
RAM for global variables,%,examples/06.Synthesis/WaveFolder
flash,%,examples/06.Synthesis/WaveFolder
RAM for global variables,%,examples/06.Synthesis/WavePacket_Double
flash,%,examples/06.Synthesis/WavePacket_Double
RAM for global variables,%,examples/06.Synthesis/WavePacket_Sample
flash,%,examples/06.Synthesis/WavePacket_Sample
RAM for global variables,%,examples/06.Synthesis/WavePacket_Single
flash,%,examples/06.Synthesis/WavePacket_Single
RAM for global variables,%,examples/06.Synthesis/Waveshaper
flash,%,examples/06.Synthesis/Waveshaper
RAM for global variables,% STMicroelectronics:stm32:GenF1:pnum=BLUEPILL_F103C8,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0 arduino:avr:uno,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0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A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A,N/A rp2040:rp2040:rpipico,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0 ```
tomcombriat commented 10 months ago

Hi!

If there is no objections I will merge that soon and try to bundle it into a new release. Feedback might come from users also!

Best, Tom

sensorium commented 10 months ago

Hey Tom, I don't have the knowledge to review this, but if you're ready to face the blowtorch of user feedback, I have no objections...

sensorium commented 10 months ago

Oh, do the docs need re-generating to include your changes? I can do that in the next couple of days if needed.

tomcombriat commented 10 months ago

Hi @sensorium , yes, I am ready for the blowtorch, I think putting it in the frontline is sometimes the best way to discover the potential bugs.

I don't think the doc needs re-generating as the API basically did not change. Will do that soon then, thanks!

tomcombriat commented 10 months ago

re-Tested on both Wifi and Minima and seems to work quite well. Merging.

tomcombriat commented 10 months ago

@sensorium I prepared a draft new version that I think could be released. Will wait a few days in case you want to add something! Feel free to modify it or to redo it!