Skip to content

Conversation

@rengels
Copy link

@rengels rengels commented Aug 26, 2023

Fix issues with interrupt timings.

Testing showed that the timer interrupts use each 25us and
have a period (at idle) of 50us.
That means a processor load at more than 100% at idle with pwm inputs.

Turns out the DAC write is using a spin lock for port access which
we don't need.
See https://forum.arduino.cc/t/esp32-dacwrite-ersetzen/653954/5

Now we are down to 10us for the variable and fixed timer interrupts
each.
Resetting the timer frequency takes around 3us.
This is unnecessary for the fixed timer.
We just need to tell the users to keep the same sample
rate for every additional sound (which we kind of already do.)

Else you would have issues anyways, when playing e.g. a horn
and indicator light ticks at the same time.
Three issues are fixed:

1.
in a lot of cases the last sample is not handled.
if (sampleCount < sampleLength-1)
will omit the last sample.

2.
Multiplying the volumes at the end for samples
that are not even outputted makes no sense.
Actually, since all the sounds have a sound volume
it is unnecessary.

3.
Adding the samples directly to a buffer is faster
than first adding it to variables.
I actually used a script for this.
Indicate if you want to have that to automatically
convert.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant