2011-10-20 42 views

Trả lời

6

Hãy xem ví dụ here.

Cụ thể, tôi tạo ra một đường cong waveshaper với chức năng này:

WAAMorningStar.prototype.createWSCurve = function (amount, n_samples) { 

if ((amount >= 0) && (amount < 1)) { 

    ND.dist = amount; 

    var k = 2 * ND.dist/(1 - ND.dist); 

    for (var i = 0; i < n_samples; i+=1) { 
     // LINEAR INTERPOLATION: x := (c - a) * (z - y)/(b - a) + y 
     // a = 0, b = 2048, z = 1, y = -1, c = i 
     var x = (i - 0) * (1 - (-1))/(n_samples - 0) + (-1); 
     this.wsCurve[i] = (1 + k) * x/(1+ k * Math.abs(x)); 
    } 

} 

Sau đó "tải" nó trong một nút waveshaper như thế này:

this.createWSCurve(ND.dist, this.nSamples); 
this.sigmaDistortNode = this.context.createWaveShaper(); 
this.sigmaDistortNode.curve = this.wsCurve; 

Mỗi lần tôi cần phải thay đổi các tham số biến dạng , Tôi tạo lại đường cong waveshaper:

WAAMorningStar.prototype.setDistortion = function (distValue) { 
    var distCorrect = distValue; 
    if (distValue < -1) { 
     distCorrect = -1; 
    } 
    if (distValue >= 1) { 
     distCorrect = 0.985; 
    } 
    this.createWSCurve (distCorrect, this.nSamples); 
} 

(Tôi sử dụng distCorrect để làm cho dist úc âm thanh đẹp hơn, các giá trị được tìm thấy theo kiểu châu Âu). Bạn có thể tìm thuật toán tôi sử dụng để tạo đường cong waveshaper here

Các vấn đề liên quan