将一个简单的增益节点连接到 Web Audio API 文件缓冲区

Connecting a simple gain node to Web Audio API file buffers

我似乎无法理解为什么这不起作用。我没有错误。我使用振荡器完成了这项工作,效果很好。仅供参考,这是该线程的延续:
使用 Web Audio API 将两个声音分配给两个 Div,并通过带有 javascript

的单击事件独立播放每个声音

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<style>

#divElement{
background-color: orange;
width:70px;
height:100px;
left:143px;
}

</style>



var context = new webkitAudioContext(),
    savedBuffer;

var playAudioFile = function () {
    var source = context.createBufferSource();
    var gainNode = context.createGainNode();
    source.buffer = savedBuffer;


 // START OF PROBLEM AREA: Gain not working but file still plays with no errors.

    source.connect(gainNode);          
    gainNode.connect(context.destination);
    gainNode.gain = 0;

 // END OF PROBLEM AREA

    source.noteOn(0); // Play sound immediately


};

var request = new XMLHttpRequest();

request.open('get', 'audio/A.mp3', true);
request.responseType = 'arraybuffer';

request.onload = function () {
        context.decodeAudioData(request.response,
             function(incomingBuffer) {

                 savedBuffer = incomingBuffer;

                 var divElement = document.getElementById("divElement");
                 divElement.addEventListener("click", playAudioFile , false);
             }
        );
};

request.send();

尝试 gainNode.gain.value = 0 代替。 gainNode.gain 是一个 AudioGain 对象,它具有 value 属性。

http://www.w3.org/TR/webaudio/#AudioGainNode