Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/components/record-modal/record-modal.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
border: 1px solid $ui-black-transparent;
border-radius: 5px;
padding: 3px;

/* Force these to be on their own render layer because they update often */
transform: translateZ(0);
}

.meter-container {
margin-right: 5px;
height: 180px;
Expand Down
8 changes: 4 additions & 4 deletions src/containers/recording-step.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ class RecordingStep extends React.Component {
alert(this.props.intl.formatMessage(messages.alertMsg)); // eslint-disable-line no-alert
}
handleLevelUpdate (level) {
this.setState({level});
if (this.props.recording) {
this.setState({levels: (this.state.levels || []).concat([level])});
}
this.setState({
level: level,
levels: this.props.recording ? (this.state.levels || []).concat([level]) : this.state.levels
});
}
handleRecord () {
this.audioRecorder.startRecording();
Expand Down
28 changes: 14 additions & 14 deletions src/lib/audio/audio-recorder.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'get-float-time-domain-data';
import getUserMedia from 'get-user-media-promise';
import SharedAudioContext from './shared-audio-context.js';
import {computeRMS} from './audio-util.js';
import {computeRMS, computeChunkedRMS} from './audio-util.js';

class AudioRecorder {
constructor () {
this.audioContext = new SharedAudioContext();
this.bufferLength = 1024;
this.bufferLength = 8192;

this.userMediaStream = null;
this.mediaStreamSource = null;
Expand Down Expand Up @@ -51,7 +51,7 @@ class AudioRecorder {
this.userMediaStream = userMediaStream;
this.mediaStreamSource = this.audioContext.createMediaStreamSource(userMediaStream);
this.sourceNode = this.audioContext.createGain();
this.scriptProcessorNode = this.audioContext.createScriptProcessor(this.bufferLength, 2, 2);
this.scriptProcessorNode = this.audioContext.createScriptProcessor(this.bufferLength, 1, 1);

this.scriptProcessorNode.onaudioprocess = processEvent => {
if (this.recording && !this.disposed) {
Expand All @@ -68,9 +68,9 @@ class AudioRecorder {

const update = () => {
if (this.disposed) return;
requestAnimationFrame(update);
this.analyserNode.getFloatTimeDomainData(dataArray);
onUpdate(computeRMS(dataArray));
requestAnimationFrame(update);
};

requestAnimationFrame(update);
Expand All @@ -83,7 +83,16 @@ class AudioRecorder {
}

stop () {
const chunkLevels = this.buffers.map(buffer => computeRMS(buffer));
const buffer = new Float32Array(this.buffers.length * this.bufferLength);

let offset = 0;
for (let i = 0; i < this.buffers.length; i++) {
const bufferChunk = this.buffers[i];
buffer.set(bufferChunk, offset);
offset += bufferChunk.length;
}

const chunkLevels = computeChunkedRMS(buffer);
const maxRMS = Math.max.apply(null, chunkLevels);
const threshold = maxRMS / 8;

Expand All @@ -105,15 +114,6 @@ class AudioRecorder {
trimEnd = 1;
}

const buffer = new Float32Array(this.buffers.length * this.bufferLength);

let offset = 0;
for (let i = 0; i < this.buffers.length; i++) {
const bufferChunk = this.buffers[i];
buffer.set(bufferChunk, offset);
offset += bufferChunk.length;
}

return {
levels: chunkLevels,
samples: buffer,
Expand Down