SoundManager2 - 停止声音时失真 [英] SoundManager2 - Distortion When Stopping Sound

查看:162
本文介绍了SoundManager2 - 停止声音时失真的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过SoundManager2中的一些声音文件循环播放,并在各个时间点播放它们。下面的代码需要一个看起来像这样的songArray,音符由一个声音文件和播放该声音文件的持续时间组成:

  var songArray = [[null],[[clarinet_e4.mp3,1],[clarinet_a4.mp3,1]],[null],[null],[null]空],[[ clarinet_c4.mp3,1]],[[ clarinet_c5.mp3,1]],[空],[[ clarinet_ab4.mp3,1]],[[ clarinet_f3.mp3 ,1]],[null],[[clarinet_g4.mp3,1]],[[clarinet_d5.mp3,1]],[null],[null]] 

它会遍历数组中的每个X,并播放给定X的声音,然后在持续时间。代码运行完全不同,只是当声音停止时,它会在歌曲结束时发出爆音。

 函数playSong(X){
playSongNotesAtXValue(X);
window.setTimeout(function(){
X ++;
if(X> = theSong.songArray.length){
X = 0;
}
playSong(X);
},(30 / theSong.tempo)* 1000)
}



function playSongNotesAtXValue(X){
var columnToPlay = theSong.songArray [X];如果(columnToPlay [0]!= null){
for(i = 0; i< columnToPlay.length; i ++){
var note = columnToPlay [i];
soundManager.play(note [0],{volume:30});
window.setTimeout(function(){
soundManager.stop(note [0]);
},(note [1] * 30 / theSong.tempo)* 1000);





任何想法都可能是错了?



PS我们已经尝试了最新版本的Safari,Chrome和Firefox。

播放音频文件,然后停在文件中间的任意一点。这往往会导致输出的不连续性,这将导致一个弹出或咔嗒声,因为在一个样本中信号从高电平跳到零。要消除这种情况,您必须平滑地将输入音量从初始音量减小到零,而不是从初始音量突然改变为零。

使用线性插值来完成这个平滑任务: http://blog.bjornroche.com/2010/10/linear-interpolation-for-audio-in-cc.html



对不起,不知道SoundManager2是否足够了解你是否已经这样做了。


I am trying to loop through a bunch of sound files in SoundManager2 and play them at various points in time. The code below takes a songArray that looks like this, with the "note" consisting of a sound file and a duration for how long to play that sound file:

var songArray = [[null],[["clarinet_e4.mp3",1],["clarinet_a4.mp3",1]],[null],[null],[null],[null],[["clarinet_c4.mp3",1]],[["clarinet_c5.mp3",1]],[null],[["clarinet_ab4.mp3",1]],[["clarinet_f3.mp3",1]],[null],[["clarinet_g4.mp3",1]],[["clarinet_d5.mp3",1]],[null],[null]]

It goes through each X in the array and plays the sounds found for the given X. It then stops the sound after a time given by the duration. The code runs perfectly except that when a sound is stopped, it gives a popping noise just at the end of the song.

function playSong(X) {
    playSongNotesAtXValue(X);
    window.setTimeout(function() {
        X++;
        if (X >= theSong.songArray.length) {
            X = 0;
        }
        playSong(X);
    }, (30/theSong.tempo)*1000)
}



function playSongNotesAtXValue(X) {
    var columnToPlay = theSong.songArray[X];
    if (columnToPlay[0] != null) {
        for (i = 0; i < columnToPlay.length; i++) {
            var note = columnToPlay[i]; 
            soundManager.play(note[0],{volume:30});
            window.setTimeout(function() {
                soundManager.stop(note[0]);
            }, (note[1]*30/theSong.tempo)*1000);   
        }
    }
}

Any ideas for what could be wrong?

P.S. We have tried it on the latest version of Safari, Chrome, and Firefox.

解决方案

If I am following you correctly, you are playing audio files and then stopping at an arbitrary point in the middle of the file. This will often lead to a discontinuity in the output which will result in a popping or clicking noise because the signal is jumping from a high level to zero in one sample. To eliminate this, you must smoothly reduce the volume of the input from the initial volume to zero, rather than changing it abruptly from the initial volume to zero.

You can usually use linear interpolation to accomplish this "smoothing" task: http://blog.bjornroche.com/2010/10/linear-interpolation-for-audio-in-c-c.html

Sorry I don't know SoundManager2 well enough to understand if you are already doing this.

这篇关于SoundManager2 - 停止声音时失真的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆