【问题标题】:Ring modulation using web audio api - javascript使用网络音频 api 进行环形调制 - javascript
【发布时间】:2022-06-20 11:22:17
【问题描述】:

我想问是否有人可以帮助我使用 javascript 进行环形调制

这是我的代码。我不确定我这样做是否正确。在开始按钮上,它只播放带增益的振荡器。不与音频文件混合。

我试着做这样的事情GitHub source

谢谢

function audioFileLoader(fileDirectory, impulseFileDirectory) {
  var audioContext = new AudioContext();
  var soundObj = [];
  soundObj.fileDirectory = fileDirectory;
  soundObj.impulseFileDirectory = impulseFileDirectory;

  // buffer loader code
  var getSound = new XMLHttpRequest();
  getSound.open("GET", soundObj.fileDirectory, true);
  getSound.responseType = "arraybuffer";
  getSound.onload = function() {
      audioContext.decodeAudioData(getSound.response, function(buffer) {
          soundObj.soundToPlay = buffer;
      });

  }

  getSound.send();

  soundObj.play = function() {

    var source = audioContext.createBufferSource();
    source.buffer = soundObj.soundToPlay;

    var oscillator = audioContext.createOscillator();
    oscillator.type = 'sine';
    oscillator.frequency.value = 500;

    var gainNode = audioContext.createGain();
    gainNode.gain.value = 0.5; 
     
    oscillator.connect(gainNode);
    source.connect(gainNode);  
    gainNode.connect(audioContext.destination);

    oscillator.start(audioContext.currentTime);
  };

   return soundObj;
};

var example = audioFileLoader("audio/AcGtr.wav");

document.getElementById('ringmodulation').addEventListener("click", example.play, 
false);

【问题讨论】:

    标签: javascript web-audio-api


    【解决方案1】:

    您的代码从不播放缓冲区源,它缺少source.start()var soundObj = [] 也应该是 var soundObj = {}

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-24
      • 1970-01-01
      • 2023-03-17
      • 2017-04-17
      • 2023-03-13
      • 1970-01-01
      • 2014-02-09
      • 2018-05-25
      相关资源
      最近更新 更多