-
Notifications
You must be signed in to change notification settings - Fork 1.3k
audioio does not maintain synchonisation of A0/A1 looping some audioio.RawSample data #1992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'd expect it to throw an exception when the sample count isn't divisible by channel_count. I'm not positive it does though. I'd encourage you to dig into the C side of the audio APIs. I bet you could fix a number of these issues. |
I'm in the middle of some application programming at the moment but will have a look when I get to end of that. I've also discovered another problem with |
I'm running with a smaller amount of data now (882 * 2 = 1764) and if I transform those values keeping length identical sometimes A0/A1 stay in sync and sometimes they don't. "When they are in sync there might be a few samples missing too". I was wrong here, this was due to a bit of visual confusion from an in-place update on an existing |
Another observation, I was looking for a workaround and I've noted for similar code/data I've found the bug appears if I use the range 0-32768 on DAC but with same data rescaled to 0-25000 the sync bug goes away. |
It's possible that a bizarre workaround for this is to do a single
on the end of the data. This doesn't make sense as for 2 channels one would expect the array to always need to be even in length! CORRECTION, it takes three magic
|
…afruit/circuitpython#1992 - no idea why this works.
Reproducible on a Feather M4 too. The |
Also on a Metro M4. |
Worth monitoring #1908 as this also relates to (more fatal) problems that are being attributed to DMA woes. |
Reproduced on Metro M4 express. On my scope, the one trace slowly moves with respect to the other one at a constant rate. Just to add to the findings, if I decrease the sample rate enough (24 * 1000) the problem goes away, at least for this sample data. As the original reporter states, somehow this is dependent on specific sample values, too, which really is a problem for any explanations I might have put forward. Debugging hasn't yielded any insights yet. |
Nice to know it's not just me! |
Not only is it data-dependent, but for some data combinations the order of relative movement is reversed! |
I'm not saying this is related but there's more unexplained, weird stuff going on with these DACs: Adafruit Forums: SAMD51 M4 DAC has problems getting it up |
CircuitPython does not intentionally enable the oversampling or dithering modes. |
fwiw your stair step on 0-to-65535 I can also reproduce, and the "data dependent" nature of the problem seems to be that when the "stair step" is going on at the moment the buffer flips over, the problem doesn't manifest. weirder and weirder. |
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. |
With 3 samples per channel and a sample rate of 200kHz, the observed frequency should be (200/3) = 66.7kHz. Instead, I measure ~55.5kHz with [0,0,X,X,X,X], and 12.8kHz with [0,0,Y,Y,Y,Y]. |
This improves the behavior around adafruit#1992. The samples stay in sync now, though full scale changes still behave erratically. Testing performed: On a Metro M4, with both analog channels going to a scope, I looked for synchronization and waveform shape. Original reproducer: Stays synchronized. adafruit#1992 (comment) reproducer: Stays synchronized and plays at the nominal 100kHz sample rate. However, waveform peaks are "regularly irregular", with every other high peak being truncated, usually. A difference I'm aware of between this and Arduino's M4 core is that Arduino uses CCTRL_CC100K; however, doing this makes CP worse, so I went with the more "correct" CC12M setting. Closes: adafruit#1992
This improves the behavior around adafruit#1992. The samples stay in sync now, though full scale changes still behave erratically. Testing performed: On a Metro M4, with both analog channels going to a scope, I looked for synchronization and waveform shape. Original reproducer: Stays synchronized. adafruit#1992 (comment) reproducer: Stays synchronized and plays at the nominal 100kHz sample rate. However, waveform peaks are "regularly irregular", with every other high peak being truncated, usually. A difference I'm aware of between this and Arduino's M4 core is that Arduino uses CCTRL_CC100K; however, doing this makes CP worse, so I went with the more "correct" CC12M setting.
Since #2552 we have just one DMA channel, so becoming out of sync like this should be impossible. Please feel free to reopen this if you still reproduce the problem on 5.3.0. |
I appear to have made some data which despite being even in length (4930 samples = 2465*2) when passed to
audio.RawSample
withchannel_count=2
and then sent to output withplay()
withloop=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 thechannel_count
?The text was updated successfully, but these errors were encountered: