[Automatic clock-in and walking timing system based on face recognition] Maixbit/MaixPy pitfall! The audio playback function blocks the call
[Copy link]
Problem: The audio file is blocked from playing in a loop, and the screen cannot refresh the image captured by the camera in real time (there is a "stuck picture"). Try to use the state machine to play and refresh the LCD at the same time, but the played voice is incomplete (the time of acquisition + LCD is greater than the minimum period of 44.1K playback call).
Slots : 400MHz CPU, 400MHz KPU~~~Such an effect is indeed a bit "unexpected"~~~The reason is that Sipeed/MaixPy~should not use DMA or consider multi-threaded operation when implementing the bottom layer of micropython~~~,
Platform: Maixbit/MaixPy
Task: Camera acquisition + LCD screen refresh + audio playback
Description: Official Documentation: Usage of audio - Sipeed Wiki The play() function must be called in a while(1) Loop
# loop to play audio
while True:
ret = player.play()
if ret == None:
print("format error")
break
elif ret==0:
print("end")
break
~~I once hoped to use a state machine~~to alleviate the problem by refreshing the LCD while playing~~~~The next step is to try to reduce the samplerate of the WAV file to 8K~~~and see the effect~~~~
#播放状态机
if (_thread_state == 0):
music_player = auido_thread_pre(dev, "/sd/4.wav", 50)
_thread_state = 1
elif (_thread_state == 1):
while(True):
if(True == audio_thread_loop(music_player)):
_thread_state = 2
break
img = sensor.snapshot()
lcd.display(img)
elif (_thread_state == 2):
audio_thread_exit(music_player)
_thread_state = 3
~~ I don't have time to go deep into the bottom layer of K210~~~~ After the Digi-Jet competition, I will try to compile the firmware myself and try again~~~ Or call the bottom layer C method to customize the bottom layer again~~~
|