Skip to content

nrf: PWMAudioOut: plays stereo at wrong rate #2360

@jepler

Description

@jepler

This is also one of the problems that @urish encountered on #2337.

Reproducer:

import audiopwmio
import audiocore
import board
import digitalio
import time

values = {
    'b': (-128, 127),
    'B': (0, 255),
    'h': (-32768, 32767),
    'H': (0, 65535),
}

def go(at = 'h', channel_count = 1):
    wave = array.array(at, [values[at][0]]) * channel_count * 24
    for i in range(len(wave)//2, len(wave)):
        wave[i] = values[at][1]
    print(wave)

    enable = digitalio.DigitalInOut(board.SPEAKER_ENABLE)
    enable.direction = digitalio.Direction.OUTPUT
    enable.value = True

    audio = audiopwmio.PWMAudioOut(board.SPEAKER)
    wave_sample = audiocore.RawSample(wave, channel_count = channel_count)

    audio.play(wave_sample, loop=True)
    time.sleep(1)
    audio.stop()
    audio.deinit()
    enable.deinit()

save as s8.py and import on a CPB at the REPL. s8.go(channel_count=1) and s8.go(channel_count=2) should play the same frequency, but they don't.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy