Skip to content

AudioFrame behaviour is different for V1/V2 #47

Closed
@microbit-mark

Description

@microbit-mark

The example given behaves differently on V1 and V2

import audio
import math
def repeated_frame(frame, count):
    for i in range(count):
        yield frame
frame = audio.AudioFrame()
 
while 1:
    for i in range(len(frame)):
        frame[i] = int(math.sin(math.pi*i/16)*124+128.5)
    audio.play(repeated_frame(frame, 100),wait=True)

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:

I tried the previous program which can write 32 points of a beep that is repeated.
I saw that in your document, these 32 points were sent over a period of 4ms.
So with the following program we should hear a sound of 250Hz. One period on 32 points of the frame.

If instead of dividing by 16, we divide by 8, we should with a sound at 500Hz.

Using a smartphone application that does the FFT, I can't see the spectral line at 250Hz or 500Hz in my spectrum? A priori the sound intensity of your speaker is far too low. Obviously we can only generate multiple sounds of 250Hz. Obviously it will be difficult to go beyond 1000Hz a priori, because the sinusoid on 32 points is then too distorted.

I made a very simple little program with the V1 and with an external speaker grove. This program allows me to generate sound at the exact frequency. This program works perfectly

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions