diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2018-06-06 16:30:49 +0200 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2018-06-06 16:30:49 +0200 |
| commit | 31fbca46a82a33bd8038f2d40722e9e0ffc61253 (patch) | |
| tree | c77e362e50f9656ff4e47df453ca042a3d97acd5 /app/client/audio | |
| parent | 1ba1d455167bfd507d3cf14d43fbd430caeb7fe7 (diff) | |
starting frame offset
Diffstat (limited to 'app/client/audio')
| -rw-r--r-- | app/client/audio/wav2pix.js | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/app/client/audio/wav2pix.js b/app/client/audio/wav2pix.js index 5f48814..9bd7a15 100644 --- a/app/client/audio/wav2pix.js +++ b/app/client/audio/wav2pix.js @@ -53,7 +53,7 @@ export const loadPCM = (file) => { }) } -export const renderFrames = (file, { frame_step=FRAME_STEP, max=12 }) => dispatch => { +export const renderFrames = (file, { frame_step=FRAME_STEP, frame_start=0, max=12 }) => dispatch => { return new Promise((resolve, reject) => { loadPCM(file).then((pcmProps) => { const { file, buffer, pcm, sr } = pcmProps @@ -61,7 +61,7 @@ export const renderFrames = (file, { frame_step=FRAME_STEP, max=12 }) => dispatc let frames = [] let count = 0 let _len = pcm.length - FRAME_LENGTH - let offset = _len / 4 + let offset = Math.round(_len * frame_start) for (; offset < _len && count < max; offset += frame_step, count += 1 @@ -74,7 +74,7 @@ export const renderFrames = (file, { frame_step=FRAME_STEP, max=12 }) => dispatc }) } -export const buildZip = (name, file, { frame_step=FRAME_STEP, max=10000 }) => dispatch => { +export const buildZip = (name, file, { frame_step=FRAME_STEP, frame_start=0, max=10000 }) => dispatch => { return new Promise((resolve, reject) => { loadPCM(file).then(({ buffer, pcm, sr }) => { dispatch({ type: types.wav2pix.load }) @@ -85,13 +85,15 @@ export const buildZip = (name, file, { frame_step=FRAME_STEP, max=10000 }) => di let steps = (pcm.length - FRAME_LENGTH) / frame_step console.log(steps) - let offset = 0, count = 0, _len = pcm.length - FRAME_LENGTH + let count = 0 + let _len = pcm.length - FRAME_LENGTH + let offset = Math.round(_len * frame_start) for (; offset < _len && count < max; offset += frame_step, count += 1 ) { if ((count % 10) === 0) { - dispatch({ type: types.wav2pix.progress, progress: { i: count / steps * 6, n: 6 } }) + dispatch({ type: types.wav2pix.progress, progress: { i: count / max * 6, n: 6 } }) } render(pcm.slice(offset, offset+FRAME_LENGTH), sr, count, zip_folder) } |
