-
Notifications
You must be signed in to change notification settings - Fork 55
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
Missing sound data between the first and second data buffer from the microphone #446
Comments
@microbit-carlos The first packet in each recording is an old packet, and the latest packet is dropped. Based on a previous look, I think... When the StreamRecorder connects, the next generated ADC packet will prompt the pull request, but the buffer pulled from mic->output will be whatever it was holding before the packet generation, and the buffer the ADC just sent will be dropped. The mic->output DataStream holds each buffer it receives until it is pulled, and drops newer packets. I don’t understand why it does this. I expected the opposite. I think perhaps it needs a double buffer system, like the ADC hardware uses, with the event handler switching the buffer for the ADC interrupt to use before it forwards the last buffer received. By adding a serial number in the first byte of each ADC packet, and preserving it in StreamNormalizer, the packet numbers in each recording can be dumped. See below, two A presses. It's clear that a packet is dropped in each recording, and the second batch starts with the old packet 39 that was not pulled through in the last batch. In fact, I think the first packet in each recording is an old one from just after the previous recording. For the output below, I made the serial number a static. With the serial number as a member variable in NRF52ADCChannel, the numbers restart for the second batch (the first recording is 39 4 5), because the channel is released and recreated during the pause between A presses.
|
I've updated a lot of behaviour in the audio-refactor branch. Can someone please re-test this against the code in there to see if this issue is still present? |
It's looking good @finneyj ! Buffers now arrive in StreamRecording as they are generated by the ADC. The log below shows two recordings started with a button press... The first one looks like there might be a start-up buffer dropped. The second starts with the very next ADC buffer after the one that ended the first. I need to test more: track when the mic is turned off/on; try with another ADC channel being logged, look at the buffer contents etc. The recording seemed noisy when played back compared to current MakeCode - need to retest that too! I had to change my sample to remove
|
Using a custom
DataSink
, as done by MicroPython, we can see that when pulling from the splitter channel, we end up with what it looks like missing data between the first and second buffer from the ADC.This test was carried out with the current CODAL configuration where the ADC is set to 45454 Hz, and the example code then sets the splitter channel sample rate to 7812.
As the ADC DMA buffers are 512 bytes, and we have 14-bits per sample, we get 256 samples per buffer. Downsampling that buffer from 45454 to 7812, and we get 44 bytes left (
256 / (45454 / 7812) ≈ 44
).This example code is configured use a custom
DataSink
to pull 128 bytes 10 times in a row (each time connecting and disconnecting from the pipeline) and the data can be printed to serial.Then I've played a 382 Hz sine wave (just picked a random frequency that easily illustrates this issue) with my phone next to the micro:bit microphone and plotted the data. We can see that in all of the plots the wave glitches at the 44th byte.
Interestingly we don't see the same at the 88th byte, so I wonder if this only affects the boundary between the 1st and 2nd byte from the moment the splitter channel is connected?
MICROBIT.hex.zip
Source code
Press button A to record, and button B to print data to serial.
(I've omitted the first two buffers, as they contain bad data as caused by issue #442)
The text was updated successfully, but these errors were encountered: