3 years ago
If you are getting fuzzy sound with the NeoLEDs on your prototype, update the binaries from the repo. This was because of a software bug, which is fixed by now.
For those interested as to why it happened, feel free to read below:
For the sound we need an interrupt running at 44.1kHz to be able to generate soundwaves up to 22.05kHz. Why 44.1kHz? That is commonly used for wav files, so that way we can easily stream them. And going up to 22.05kHz soundwaves satisfies the audio spectrum humans can hear.
Now, the NeoLEDs require when updating some precicely timed output, where in the official repo they do that with a preciece number of nop asm opcodes to time it and they disabled interrupts during it. The issue is now that during the NeoLED update our sound doesn't trigger. This caused a blubby sound, and I fixed that by manually modifying the NeoLED library and enabling/disabling interrupts wherever possible so that our sound interrupt has more time to run. Great! Only issue....this introduced the fuzzy sound bug you are hearing.
Now, to explain that bug, we need to get into detail on how we produce sound: Every time the interrupt runs a 10-bit unsigned integer is outputted to the DAC, which represents the amplitude of the generated soundwaves. Because soundwaves are symetrical and we want to use as much resolution as possible the zero-level was set to 0x100. Great, now we have the center right in the middle of our range! Only problem: because of the NeoLED interrupt timing, when sending, the interrupt doesn't run at 100% the correct frequency, and outputting something non-zero created noise soundwaves, which are unnoticable when actually playing sound.
The simple fix to this is to simply set the zero-level to 0, but sound-waves are symetrical so we would have cut-off sound waves.....so what about, when outputting 0x100 instead output 0? Great, that fixes the fuzzy sound bug! Except, when starting to play sound / stopping to play sound we now created a jump by 0x100, in other words an extreme square wave. You can hear that by a nice, loud plop. That is fixed by adjusting the zero-level slowly. It takes 0x100 interrupt calls for the zero-level to "flow" from 0 to 0x100 and vice-versa. That would indeed be a triangle wave, however, the frequency is way too low for humans to be able to hear it. And during the flowing we would have some non-symetrical soundwaves, however we only have that flowing during 0x100, so 512 interrupts, and at 44.1kHz that means 0.01161 seconds....so way too little to notice! Yay! We fixed the sound bug! :D
NEW 3 years ago