Skip to content

Added mono to stereo conversion and panning to audiomixer.Mixer #10529

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

relic-se
Copy link

Allow mono audiosample sources to play through a stereo audiomixer.Mixer object and add audiomixer.MixerVoice.panning (with synthio.BlockInput support).

These new features greatly improve audiomixer.Mixer usability for sample-based musical instruments. It also optimizes flash storage when stereo audio files are unnecessary when mixed with a stereo source (you'd otherwise have to double the channel count + file size).

Code Demonstration (requires appropriate mono.wav and stereo.wav files):

import board
import audiobusio
import audiocore
import audiomixer
import synthio

wav_stereo = audiocore.WaveFile("/stereo.wav")
wav_mono = audiocore.WaveFile("/mono.wav")
if wav_stereo.channel_count != 2 or wav_mono.channel_count != 1:
    raise ValueError("audio file channel counts are incorrect")

audio = audiobusio.I2SOut(
    bit_clock=board.GP20,
    word_select=board.GP21,
    data=board.GP22,
)

mixer = audiomixer.Mixer(
    voice_count=2,
    channel_count=2,
    sample_rate=wav_stereo.sample_rate,
    bits_per_sample=wav_stereo.bits_per_sample,
)

for i in range(len(mixer.voice)):
    mixer.voice[i].level = 0.5
    mixer.voice[i].panning = synthio.LFO(rate=0.5*(i+1))

audio.play(mixer)

mixer.voice[0].play(wav_stereo, loop=True)
mixer.voice[1].play(wav_mono, loop=True)

Closes #4463

@relic-se relic-se marked this pull request as draft July 30, 2025 19:31
@relic-se relic-se marked this pull request as ready for review July 30, 2025 19:44
@dhalbert dhalbert marked this pull request as draft July 30, 2025 19:47
@dhalbert dhalbert marked this pull request as ready for review July 30, 2025 19:48
relic-se added a commit to relic-se/pico_test_synth that referenced this pull request Jul 30, 2025
@relic-se
Copy link
Author

It looks like a few atmel-samd boards are running out of flash firmware space. Would it be better for me to disable this feature (panning and mono-to-stereo) on those boards or disable a larger existing feature?

The following boards are affected:

  • feather_m4_express
  • itsybitsy_m4_express
  • metro_m4_express
  • seeeduino_wio_terminal

@gamblor21 gamblor21 self-requested a review July 31, 2025 19:17
@gamblor21 gamblor21 assigned gamblor21 and unassigned gamblor21 Jul 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Positional audio (balance) for audiomixer
2 participants