circuitpython: audioio does not maintain synchonisation of A0/A1 looping some audioio.RawSample data
I appear to have made some data which despite being even in length (4930 samples = 2465*2) when passed to audio.RawSample
with channel_count=2
and then sent to output with play()
with loop=True
it will play but the A0/A1 will not stay synchronised and drift around. At 100kHz playback it takes 60 seconds to return to being very briefly in sync. I might expect this if I passed an odd number of samples, e.g. 9 could end up as 5 looping on DAC0 and 4 looping on DAC1.
Code is rather large because it contains the data as a list, see https://github.com/kevinjwalters/circuitpython-examples/blob/master/pygamer/audioio-phasebug.py. In that example there’s a boolean which controls whether to replace the data values with an alternate set of rising values without changing the total number of values (samples). Doing that makes the bug go away, the bug appears to be very dependent on the data values with no obvious explanation.
This does seem rather unlikely so there’s a minor chance I have made an error here…
BTW, what’s the intended behaviour for audioio.RawSample
if it’s given a number of samples which are not exactly divisble by the channel_count
?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 18 (9 by maintainers)
Commits related to this issue
- Adding illustration of the "three magic 0s" bizarre workaround for https://github.com/adafruit/circuitpython/issues/1992 - no idea why this works. — committed to kevinjwalters/circuitpython-examples by deleted user 5 years ago
- samd51: DAC: Make clock usage more like Arduino core This improves the behavior around #1992. The samples stay in sync now, though full scale changes still behave erratically. Testing performed: On... — committed to jepler/circuitpython by jepler 5 years ago
- samd51: DAC: Make clock usage more like Arduino core This improves the behavior around #1992. The samples stay in sync now, though full scale changes still behave erratically. Testing performed: On... — committed to jepler/circuitpython by jepler 5 years ago
Smaller reproducer:
Change the single Y back to X and the waveforms stay in sync. Change a left-channel X to Y and the waveforms stay in sync.