diff options
| author | Lucian Copeland <hierophect@gmail.com> | 2021-02-17 11:39:46 -0500 |
|---|---|---|
| committer | Lucian Copeland <hierophect@gmail.com> | 2021-02-17 11:39:46 -0500 |
| commit | a3aa48b8dffe5ed3c921ff3e9de5423ff1c588b1 (patch) | |
| tree | c8978ddb2314944dbb6876de5ebdf90e3dd0071d /tests/manual/audiopwmio/single_buffer_loop.py | |
| parent | 2d2c40b3d44bc7b73abb9534a7eeab3c27049b26 (diff) | |
| parent | 261b077209bc668de843015e4f5c26e474214769 (diff) | |
Merge remote-tracking branch 'upstream/main' into manual-tests
Diffstat (limited to 'tests/manual/audiopwmio/single_buffer_loop.py')
| -rw-r--r-- | tests/manual/audiopwmio/single_buffer_loop.py | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/manual/audiopwmio/single_buffer_loop.py b/tests/manual/audiopwmio/single_buffer_loop.py new file mode 100644 index 000000000..dfac475b5 --- /dev/null +++ b/tests/manual/audiopwmio/single_buffer_loop.py @@ -0,0 +1,65 @@ +import audiocore +import audiopwmio +import board +import digitalio +import array +import time +import math + +trigger = digitalio.DigitalInOut(board.D4) +trigger.switch_to_output(True) + +# Generate one period of sine wav. +length = 8000 // 440 + +samples = [] +sample_names = [ +"unsigned 8 bit", +"signed 8 bit", +"unsigned 16 bit", +"signed 16 bit" +] + + +# unsigned 8 bit +u8 = array.array("B", [0] * length) +for i in range(length): + u8[i] = int(math.sin(math.pi * 2 * i / length) * (2 ** 7) + 2 ** 7) + +samples.append(audiocore.RawSample(u8, sample_rate=4000)) + +# signed 8 bit +s8 = array.array("b", [0] * length) +for i in range(length): + s8[i] = int(math.sin(math.pi * 2 * i / length) * (2 ** 7)) + +samples.append(audiocore.RawSample(s8, sample_rate=16000)) + +# unsigned 16 bit +u16 = array.array("H", [0] * length) +for i in range(length): + u16[i] = int(math.sin(math.pi * 2 * i / length) * (2 ** 15) + 2 ** 15) + +samples.append(audiocore.RawSample(u16, sample_rate=8000)) + + +# signed 16 bit +s16 = array.array("h", [0] * length) +for i in range(length): + s16[i] = int(math.sin(math.pi * 2 * i / length) * (2 ** 15)) + +samples.append(audiocore.RawSample(s16, sample_rate=8000)) + + +dac = audiopwmio.PWMAudioOut(board.D13) +for sample, name in zip(samples, sample_names): + print(name) + trigger.value = False + dac.play(sample, loop=True) + time.sleep(1) + dac.stop() + time.sleep(0.1) + trigger.value = True + print() + +print("done") |
