Bug 257447 - StereoPannerNode distorts left panned audio
Summary: StereoPannerNode distorts left panned audio
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Audio (show other bugs)
Version: Safari 16
Hardware: Mac (Apple Silicon) macOS 13
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-05-28 23:44 PDT by Jason Boyd
Modified: 2023-06-04 23:45 PDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jason Boyd 2023-05-28 23:44:28 PDT
When I create a StereoPannerNode and pan it to anything less than 0, the audio is very distorted. This happens in both Chrome and Safari on my Mac running Ventura 13.2.1.

The problem is identical if I do new StereoPannerNode() or audioContext.createStereoPanner(), and is identical whether I use a mono or stereo version of the same audio sample. It is also identical wherever I place the stereo panner node in the audio chain. 

When I play the audio sample using the OS (right-click from finder and preview), changing the OS pan setting, there is no distortion. 

Here's a bit of code: 

function playSound(name, volume=1, pan=0, octave=0) {
    const buffer = loadedAudio[name]; 
    if (!buffer) {
        console.warn('sound buffer not loaded for '+name); 
        return; 
    }
    if (audioCtx.state === 'suspended') {
        return; 
    }
    const source = audioCtx.createBufferSource();
    const gainNode = audioCtx.createGain(); 
    // const panNode = new StereoPannerNode(audioCtx, {pan: pan}); 
    const panNode = audioCtx.createStereoPanner();
    source.buffer = buffer;
    const note = Math.floor(Math.random() * NOTES.length); 
    const pitch = Math.pow(2, octave) * NOTES[note];
    source.playbackRate.value = pitch; 
    panNode.pan.value = pan;
    gainNode.gain.value = volume; 
    source.connect(gainNode);
    gainNode.connect(panNode); 
    panNode.connect(audioCtx.destination); 
    source.start(0);
}
Comment 1 Jason Boyd 2023-05-28 23:46:09 PDT
Oops should have removed the pitch change bit. The issue exists without that.
Comment 2 Chris Dumez 2023-05-30 10:37:12 PDT
(In reply to Jason Boyd from comment #1)
> Oops should have removed the pitch change bit. The issue exists without that.

Are you able to provide a standalone reproduction case?
Comment 3 Radar WebKit Bug Importer 2023-06-04 23:45:17 PDT
<rdar://problem/110249209>