Skip to content

Add track mute and equalizer.#33

Open
jan-ivar wants to merge 1 commit intomozilla:gh-pagesfrom
jan-ivar:trackmute
Open

Add track mute and equalizer.#33
jan-ivar wants to merge 1 commit intomozilla:gh-pagesfrom
jan-ivar:trackmute

Conversation

@jan-ivar
Copy link
Member

Address feedback in #32 (comment)

@jan-ivar jan-ivar requested a review from Pehrsons November 20, 2019 19:07
@jan-ivar jan-ivar self-assigned this Nov 20, 2019
Copy link
Collaborator

@Pehrsons Pehrsons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor issues to fix before merging, but in general LGTM.

function startEqualizer(stream) {
const audioCtx = new AudioContext();
const analyser = audioCtx.createAnalyser();
audioCtx.createMediaStreamSource(stream).connect(analyser);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a MediaStreamTrackSource now. The MediaStreamSource is obsolete really, since it locks onto the first track and basically works as the track source anyway.

muted.type = "checkbox";
muted.checked = true;
muted.onclick = () => { video.muted = muted.checked; };
const equalizer = document.createElement("canvas");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a visualizer, not an equalizer. An equalizer is used to change the gain of certain frequencies, in order to "equalize" them.

Applies throughout.

}
controls.appendChild(camOn.parentNode);
camOn.onclick = () => { videoTrack.enabled = camOn.checked; };
camOn.onclick();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't the checked state change through other means than click? keyboard navigation and selecting it with space is what I'm thinking. The "change" event looks like the right thing. Also applies to micOn and elementMuted.

for (let y of data) {
y = equalizer.height - (y / 128) * equalizer.height / 4;
let c = Math.floor((x*255)/equalizer.width);
canvasCtx.fillStyle = "rgb("+c+",0,"+(255-x)+")";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it could be psychedelic. Do you have a screenshot?

canvasCtx.fillRect(x, y, 2, equalizer.height - y)
x++;
}
analyser.getByteTimeDomainData(data);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This data is never used.


let interval = setInterval(() => {
if (stream.getAudioTracks()[0].readyState != "live") {
clearInterval(interval);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or use the ended event on the track to clear the interval. Also close the AudioContext at that point please.

clearInterval(interval);
return;
}
canvasCtx.fillStyle = "#ffffff";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clearRect shouldn't need fillStyle, only fillRect, no?

canvasCtx.lineWidth = 5;
canvasCtx.beginPath();
canvasCtx.stroke();
}, 1000 * equalizer.width / audioCtx.sampleRate);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait what, why is the width of the canvas part of the equation?

let c = Math.floor((x*255)/equalizer.width);
canvasCtx.fillStyle = "rgb("+c+",0,"+(255-x)+")";
canvasCtx.fillRect(x, y, 2, equalizer.height - y)
x++;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you made sure x doesn't overshoot the canvas width? That would be unnecessary. You can control how many frequency buckets you get from the analyser with the fftSize attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants