8000 Incorrect playback sample_rate · Issue #1196 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

Incorrect playback sample_rate #1196

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

Closed
tannewt opened this issue Sep 18, 2018 · 0 comments
Closed

Incorrect playback sample_rate #1196

tannewt opened this issue Sep 18, 2018 · 0 comments

Comments

@tannewt
Copy link
Member
tannewt commented Sep 18, 2018

From adafruit/Adafruit_CircuitPython_CircuitPlayground#40

@caternuson says:

Agree, I think it's going to be something lower level than CPX. I can recreate with this:

import array
import math
import time

import board
import digitalio
import audioio

speaker_enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)

# Generator thing
def sine_sample(length):
    tone_volume = (2 ** 15) - 1
    shift = 2 ** 15
    for i in range(length):
        yield int(tone_volume * math.sin(2*math.pi*(i / length)) + shift)

# Generate the sample
length = 100
sine_wave = array.array("H", sine_sample(length))
sample = audioio.AudioOut(board.SPEAKER)
sine_wave_sample = audioio.RawSample(sine_wave)

# Play tone
frequency = 330
sample_rate = int(len(sine_wave) * frequency)
speaker_enable = True
sine_wave_sample.sample_rate = sample_rate
sample.play(sine_wave_sample, loop=True)
time.sleep(1)
sample.stop()
sample.deinit()
speaker_enable = False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant
0