-
Notifications
You must be signed in to change notification settings - Fork 27
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
AudioFrame behaviour is different for V1/V2 #47
Comments
@martinwork can you take a look if you are able to this week. |
@microbit-mark Will do! |
The code that plays the AudioFrame in V2 is completely different to the V1 code. I don't know enough about the CODAL audio pipeline right now to be able to tell if the V2 problem is in CODAL or micropython. The data supplied to uBit.audio.mixer by the AudioSource class is the AudioFrame expanded BUFFER_EXPANSION times by linear interpolation, but the sample rate is multiplied by BUFFER_EXPANSION / 4. I've experimented in C++ with supplying similar data to MemorySource (which is similar to AudioSource) and that doesn't sound right either. AudioSource
audio_init
linear interpolation
|
@dpgeorge I think this is related to the reproducing case you are building for Joe? |
I have been trying to reproduce the "buffering" problem in pure C++ but I can not do it. So at this stage I'd suggest working around any buffering issues by just making it work correctly from the MicroPython side. |
I'm not too familiar with this buffering issue, is there a CODAL ticket present already, or were we pending the C++ reproducer? Is this something is still worthing opening in a ticket over there even if it is worked around in the MicroPython side? |
AFAIK there is no CODAL ticket for this, mainly because I cannot pin point it enough to describe it in technical detail. This was first seen with the initial issues with speech when moving it over to use the mixer, and fixed only by adding some extra buffering to the speech output. I'm still not sure why it doesn't work without the buffering, but the plan is to do a similar buffering for audio.play. |
Okay, thanks for the clarification Damien. |
I will try! |
Audio output should now be improved, see commit 9679263 I'm not sure if it's exactly the same as v1, it will need to be tested on a variety of examples. |
CODAL v0.2.25 was updated in 76054c2 and that improved the sampling rate accuracy of |
Great, thanks Damien! |
The example in https://microbit-micropython.readthedocs.io/en/v2-docs/audio.html# still sounds different on V1 and V2. On V2 There is an audible click between samples that is less evident on V1. I will ask the person on the support ticket to also test. |
@microbit-mark If the PWM output is well behaved and the samples start and end at the midpoint you shouldn't get any clicks/pops at start/end? |
This repo was updated to use CODAL v0.2.35 in 76c1b31, which changed the audio sampling time from 50ms to 5ms, to make V2 behave more like V1. |
@martinwork as with #67 could you please test with the version of MicroPython in https://python.microbit.org/v/beta and close this if the issue is now resolved? |
@jaustin I loaded the original python sample into beta and WebUSB downloaded it. V1 makes a tone with lots of crackles, and clicks between. Is it already known that switching to the beta editor tab resets micro:bit? |
I can confirm that with the latest MicroPython (2b57ddd, which has been updated to CODAL v0.2.40), this script still throws the |
Otherwise audio_data_fetcher may be called while it's running, if the CODAL just finished playing another sound and schedules audio_data_fetcher. See issue #47. Signed-off-by: Damien George <damien@micropython.org>
The |
As difference in V1 and V2 was shipped in v2.0.0, and we have tight deadline for v2.1.0, we'll push this one to v2.2.0. |
Changes to codal-core: - added a lock to the initial access/events for the level detector - setGain and getGain now return floats, as they use fractional values internally - StreamRecording objects now use a linked list of buffers for storage - StreamSplitter now correctly connects to its upstream - added virtual to isConnected on DataSource to prevent internal misrouting - extended DMESG with optional Fiber and Time markers - updated CodalFiber to correctly behave as a counting semaphore - corrected locking behaviour on the LevelDetectorSPL to avoid race conditions - refactored assert to remove assert_true and assert_false - set the default FiberLock count to 1 - added a "fast path" route to reduce delays on getValue calls - added a new arg to FiberLock to run in legacy MUTEX mode, or SEMAPHORE mode with corrected semantics - TouchSensor: added missing public as part of declaration - Compass::clearCalibration() resets calibration member variable - update touch code to release/reconnect on pin reuse (codal-microbit-v2#345) Changes to codal-microbit-v2: - fix BLE panic 071 (#334) - remove FXOS vestiges - removed unused include for the old LevelDetector, updated event handling for demand activation - MicroBitUtilityService - replaces PR 178 (#287) - added isMicrophoneEnabled() to MicroBitAudio to match isSpeakerEnabled - removed spurious duplicate documentation, added support for isMicrophoneEnabled - MicroBitCompassCalibrator avoid using max(int,int) (#290) - disbled the MICROBIT_BLE_UTILITY_SERVICE_PAIRING configuration by default, enabled on BETA - MicroBitBLEManager - Move MICROBIT_BLE_MAXIMUM_BONDS to MicroBitConfig (#299) Changes to codal-nrf52: - fix NeoPixel/WS2812B timing (#47) - update touch code to release/reconnect on pin reuse (codal-microbit-v2#345) Signed-off-by: Damien George <damien@micropython.org>
Some of the differences in the original code were due to the CPU speed change between V1 and V2, as V2 can process the sine wave quicker and constantly entering and exiting This modified example better shows the output sound difference between V1 and V2 when outputting a sine wave on pin0, which needs headphones. import audio
import math
import microbit
def repeated_frame():
frame = audio.AudioFrame()
for i in range(len(frame)):
frame[i] = int(math.sin(math.pi*i/16)*124+128.5)
while True:
yield frame
if hasattr(microbit, 'speaker'):
microbit.speaker.off()
audio.play(repeated_frame(), wait=True) audioframe-play-diff-v1-v2 (5).hex.zip This video shows how they sound with an external speaker, using headphone the sound is very similar. 20240806_161813.mp4 |
Okay, the test above on a V2 was with MicroPython v2.1.2 from the Python Editor. I think this is as close as we are gonna get, so we can close this as completed. |
The example given behaves differently on V1 and V2
And the one in https://microbit-micropython.readthedocs.io/en/v2-docs/audio.html# seems to have another behaviour where the square wave is combined with the sawtooth one rather than being distinct from it.
From user:
The text was updated successfully, but these errors were encountered: