Skip to content

Add track mute and equalizer.#33

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

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

Conversation

@jan-ivar

Copy link
Copy Markdown
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

@Pehrsons Pehrsons left a comment

Copy link
Copy Markdown
Collaborator

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.

Comment thread gum_test.html
function startEqualizer(stream) {
const audioCtx = new AudioContext();
const analyser = audioCtx.createAnalyser();
audioCtx.createMediaStreamSource(stream).connect(analyser);

Copy link
Copy Markdown
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.

Comment thread gum_test.html
muted.type = "checkbox";
muted.checked = true;
muted.onclick = () => { video.muted = muted.checked; };
const equalizer = document.createElement("canvas");

Copy link
Copy Markdown
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.

Comment thread gum_test.html
}
controls.appendChild(camOn.parentNode);
camOn.onclick = () => { videoTrack.enabled = camOn.checked; };
camOn.onclick();

Copy link
Copy Markdown
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.

Comment thread gum_test.html
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
Copy Markdown
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?

Comment thread gum_test.html
canvasCtx.fillRect(x, y, 2, equalizer.height - y)
x++;
}
analyser.getByteTimeDomainData(data);

Copy link
Copy Markdown
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.

Comment thread gum_test.html

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

Copy link
Copy Markdown
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.

Comment thread gum_test.html
clearInterval(interval);
return;
}
canvasCtx.fillStyle = "#ffffff";

Copy link
Copy Markdown
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?

Comment thread gum_test.html
canvasCtx.lineWidth = 5;
canvasCtx.beginPath();
canvasCtx.stroke();
}, 1000 * equalizer.width / audioCtx.sampleRate);

Copy link
Copy Markdown
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?

Comment thread gum_test.html
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
Copy Markdown
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