32blit-sdk icon indicating copy to clipboard operation
32blit-sdk copied to clipboard

Audible pop when turning on the first channel (hardware only)

Open ali1234 opened this issue 4 years ago • 1 comments
trafficstars

When a channel first starts playing there is an audible pop. If you turn off the channel and then start it again it pops again. If another channel is playing this does not happen. Seems to be the DAC or amp turning on? It does not happen in SDL and is not affected by volume setting.

Demonstration code that plays silence on two channels while turning them on and off:

#include <cstring>

#include "game.hpp"

bool on = false;
bool on2 = false;

void cb(blit::AudioChannel &channel) {
    // wave_buffer is 16 bit signed.
    memset(channel.wave_buffer, 0, 128);
}

void init() {
    blit::channels[0].waveforms = blit::Waveform::WAVE;
    blit::channels[0].wave_buffer_callback = &cb;
    blit::channels[1].waveforms = blit::Waveform::WAVE;
    blit::channels[1].wave_buffer_callback = &cb;
}

void render(uint32_t time) {
    blit::screen.pen = blit::Pen(0, 0, 0);
    blit::screen.clear();

    blit::screen.pen = blit::Pen(255, 255, 255);
    if (on)
        blit::screen.text("ON", blit::minimal_font, blit::Point(5, 4));
    else
        blit::screen.text("OFF", blit::minimal_font, blit::Point(5, 4));
    if (on2)
        blit::screen.text("ON2", blit::minimal_font, blit::Point(25, 4));
    else
        blit::screen.text("OFF2", blit::minimal_font, blit::Point(25, 4));
}

void update(uint32_t time) {
    static uint32_t last_time = 0;
    static int32_t timer = 0;
    timer += time - last_time;
    last_time = time;
    if (timer > 500) {
        on = !on;
        if (on) on2 = !on2;
        timer -= 500;
    }
    if (on)
        blit::channels[0].trigger_attack();
    else
        blit::channels[0].off();
    if (on2)
        blit::channels[1].trigger_attack();
    else
        blit::channels[1].off();
}

ali1234 avatar Feb 19 '21 01:02 ali1234

Not totally sure there's a way to handle this without hardware support for a slow soft-start ramp up on the DAC. I believe the issue is the amp turning on - as you suggest - the sudden snap from "off" to "active" takes the speaker from floating to midrail and that produces the pop.

Gadgetoid avatar Feb 23 '21 13:02 Gadgetoid