meenie / band.js

Band.js - Music composer interface for the Web Audio API.
Other
1.18k stars 93 forks source link

Just a suggestion #36

Open Enderlook opened 6 years ago

Enderlook commented 6 years ago

Hi, I'm new to GitHub so I don't understand how to use it so I'm sorry if this is the wrong place to post a suggestion, I haven't found that button. I'm new making music and I was trying to analyze the music produced by band.js but I didn't found a method to do that, so I create mine as I could, (I'm also new in this field).

This is how I make it. I was thinking maybe it could be added because with an audio context analyser is possible to make a visualization of the music (e.g: to make a visualization addon?).

On conductor.js after line 67:

    conductor.analyser = conductor.audioContext.createAnalyser();
    conductor.bufferLength = conductor.analyser.frequencyBinCount;
    conductor.dataArray = new Uint8Array(conductor.bufferLength);

On noises.js in line 20 add the parameter analyser like:

function NoisesInstrumentPack(name, audioContext, analyser) {

And change the createNote statement of line 32 to:

createNote: function(destination) {
        let tmp;
            switch (name) {
                case 'white':
                    tmp = createWhiteNoise(destination);
            break;
                case 'pink':
                    let tmp = createPinkNoise(destination);
                    break;
                case 'brown':
                case 'brownian':
                case 'red':
                    let tmp = createBrownianNoise(destination);
                    break;
            }
        tmp.connect(analyser);
        return tmp;
        }

On oscillators.js add the parameter analyser in line 18 like this:

function OscillatorInstrumentPack(name, audioContext) {

And in line 31 add:

o.connect(analyser);

On instrument.js add a parameter conductor.analyser to line 73 as:

instrument.instrument = conductor.packs.instrument[pack](name, conductor.audioContext, conductor.analyser);

And then do something on player.js, not sure exactly what but for example add an interval in play function (line 243):

setInterval(function(){
            conductor.analyser.getByteTimeDomainData(conductor.dataArray)
            console.log(conductor.dataArray);
        }, 100)

P.S: Sorry for my English.