orottier / web-audio-api-rs

A Rust implementation of the Web Audio API, for use in non-browser contexts
https://docs.rs/web-audio-api/
MIT License
300 stars 16 forks source link

disconnect -> connect does not work on PannerNode #494

Closed kuviman closed 7 months ago

kuviman commented 7 months ago

Using PannerNode, the sound is working normally unless i try to disconnect and reconnect the node to something else (or even same thing):

use web_audio_api::{
    context::{AudioContext, BaseAudioContext},
    node::{AudioBufferSourceNode, AudioNode, PannerNode},
};

fn main() {
    let audio = AudioContext::new(Default::default());
    let buffer = audio
        .decode_audio_data_sync(std::io::Cursor::new(
            std::fs::read("sound.wav").unwrap(),
        ))
        .unwrap();
    let mut source = AudioBufferSourceNode::new(&audio, Default::default());
    source.set_buffer(buffer);
    let panner = PannerNode::new(&audio, Default::default());
    source.connect(&panner);
    panner.connect(&audio.destination());

    // No sound, but is sound if these two lines are commented
    panner.disconnect();
    panner.connect(&audio.destination());

    source.start_at_with_offset(0.0, 0.0);
    std::thread::sleep(std::time::Duration::from_secs(1));
}
orottier commented 7 months ago

Hi @kuviman, thanks for the report. We literally yesterday fixed a bug where disconnect would also remove incoming connections (instead of only the outgoing ones): #493 I think your code is also affected by that bug. You could try if source.connect(&panner) brings back the sound. The fix is on master already and I intend to release a new version to crates.io later today.

orottier commented 7 months ago

I have just released version v1.0.0-rc.5 which should solve your problem. Please let us know if you still run into issues!