rserota / wad

Web Audio DAW. Use the Web Audio API for dynamic sound synthesis. It's like jQuery for your ears.
MIT License
1.89k stars 160 forks source link

Allow setting filters properties before and during playback #59

Closed torch2424 closed 6 years ago

torch2424 commented 8 years ago

Currently, in another application that implements the use of wad (see here: https://github.com/julianpoy/Flyxer), I was able to set the filter of a wad doing the following:

//Lowpass filter
    $scope.masterLowPass = 4000;
    $scope.setLowPass = function() {

      for(var i=0;i<$scope.tracks.length;i++){
        if($scope.tracks[i].playing){
          //Set the value
          $scope.tracks[i].player.filter[0].frequency = $scope.masterLowPass;

          //Set the node's value
          $scope.tracks[i].player.filter[0].node.frequency.value = $scope.masterLowPass;
        }
      }
    }

Where masterLowpass is bound to a slider using angularJS' ngModel.

Currently, I am only accessing the first filter in the array, implying there are multiple filters.

I am setting the wad as follows:

$scope.tracks[index].player = new Wad({
                source : 'file://' + $scope.tracks[index].uri,
                volume: 1.0,
                wait    : 0,
                loop: true,
                env : { hold : 100000000 },
                delay   : {
                      delayTime : 0.5,  // Time in seconds between each delayed playback.
                      wet : 0, // Relative volume change between the original sound and the first delayed playback.
                      feedback : 0, // Relative volume change between each delayed playback and the next.
                },
                reverb  : {
                    wet : 0,  // Volume of the reverberations.
                    impulse : 'sounds/impulse.wav' // A URL for an impulse response file, if you do not want to use the default impulse response.
                },
                filter  : {
                      type : 'lowpass', // What type of filter is applied.
                      frequency : 4000,       // The frequency, in hertz, to which the filter is applied.
                      q : 1,         // Q-factor.  No one knows what this does. The default value is 1. Sensible values are from 0 to 10.
                },
                tuna   : {
                    Bitcrusher : {
                        bits: 16,          //1 to 16
                        normfreq: 1,    //0 to 1
                        bufferSize: 4096  //256 to 16384
                    }
                }
            });

I was thinking I could simply allow developers to pass the index of the filter they would like to change. However, I dont see how they can set multiple filters. So I was hoping for a bit of help to solve this issue. Thank You!

rserota commented 8 years ago

Is this just a question about API design? You could make two methods, setFilter() (singular), and setFilters (plural).

setFilters() could take an array of filters, and replace all current filters with the filters passed as arguments. setFilter() could take a single filter, and an index, and replace only that filter (assume index 0, if not specified).

How does that sound?

torch2424 commented 8 years ago

That sounds great!

And yes, it was more of a question of API design I will admit, I dont understand wad fully, since I am still learning and diving into it. but I am getting there! I figured it'd be best to ask you how this should be implemented, since you understand the filter create a lot better than I do.