Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
logging-scratch-gui
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
David Goessmann
logging-scratch-gui
Commits
df0bf268
Unverified
Commit
df0bf268
authored
7 years ago
by
Paul Kaplan
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #1383 from paulkaplan/fix-safari-audio
Fix several safari audio issues
parents
9163f73a
85f2aeed
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/containers/sound-editor.jsx
+15
-12
15 additions, 12 deletions
src/containers/sound-editor.jsx
src/lib/audio/audio-buffer-player.js
+7
-1
7 additions, 1 deletion
src/lib/audio/audio-buffer-player.js
src/lib/audio/audio-effects.js
+8
-2
8 additions, 2 deletions
src/lib/audio/audio-effects.js
with
30 additions
and
15 deletions
src/containers/sound-editor.jsx
+
15
−
12
View file @
df0bf268
...
...
@@ -16,7 +16,7 @@ class SoundEditor extends React.Component {
constructor
(
props
)
{
super
(
props
);
bindAll
(
this
,
[
'
copyCurrent
Samples
'
,
'
copyCurrent
Buffer
'
,
'
handleStoppedPlaying
'
,
'
handleChangeName
'
,
'
handlePlay
'
,
...
...
@@ -70,7 +70,7 @@ class SoundEditor extends React.Component {
if
(
this
.
undoStack
.
length
>=
UNDO_STACK_SIZE
)
{
this
.
undoStack
.
shift
();
// Drop the first element off the array
}
this
.
undoStack
.
push
(
this
.
copyCurrent
Samples
());
this
.
undoStack
.
push
(
this
.
copyCurrent
Buffer
());
}
this
.
resetState
(
samples
,
sampleRate
);
this
.
props
.
onUpdateSoundBuffer
(
...
...
@@ -102,12 +102,12 @@ class SoundEditor extends React.Component {
if
(
this
.
state
.
trimStart
===
null
&&
this
.
state
.
trimEnd
===
null
)
{
this
.
setState
({
trimEnd
:
0.95
,
trimStart
:
0.05
});
}
else
{
const
samples
=
this
.
copyCurrent
Samples
();
const
{
samples
,
sampleRate
}
=
this
.
copyCurrent
Buffer
();
const
sampleCount
=
samples
.
length
;
const
startIndex
=
Math
.
floor
(
this
.
state
.
trimStart
*
sampleCount
);
const
endIndex
=
Math
.
floor
(
this
.
state
.
trimEnd
*
sampleCount
);
const
clippedSamples
=
samples
.
slice
(
startIndex
,
endIndex
);
this
.
submitNewSamples
(
clippedSamples
,
this
.
props
.
sampleRate
);
this
.
submitNewSamples
(
clippedSamples
,
sampleRate
);
}
}
handleUpdateTrimEnd
(
trimEnd
)
{
...
...
@@ -119,9 +119,12 @@ class SoundEditor extends React.Component {
effectFactory
(
name
)
{
return
()
=>
this
.
handleEffect
(
name
);
}
copyCurrent
Samples
()
{
copyCurrent
Buffer
()
{
// Cannot reliably use props.samples because it gets detached by Firefox
return
this
.
audioBufferPlayer
.
buffer
.
getChannelData
(
0
);
return
{
samples
:
this
.
audioBufferPlayer
.
buffer
.
getChannelData
(
0
),
sampleRate
:
this
.
audioBufferPlayer
.
buffer
.
sampleRate
};
}
handleEffect
(
name
)
{
const
effects
=
new
AudioEffects
(
this
.
audioBufferPlayer
.
buffer
,
name
);
...
...
@@ -133,18 +136,18 @@ class SoundEditor extends React.Component {
});
}
handleUndo
()
{
this
.
redoStack
.
push
(
this
.
copyCurrent
Samples
());
const
samples
=
this
.
undoStack
.
pop
();
this
.
redoStack
.
push
(
this
.
copyCurrent
Buffer
());
const
{
samples
,
sampleRate
}
=
this
.
undoStack
.
pop
();
if
(
samples
)
{
this
.
submitNewSamples
(
samples
,
this
.
props
.
sampleRate
,
true
);
this
.
submitNewSamples
(
samples
,
sampleRate
,
true
);
this
.
handlePlay
();
}
}
handleRedo
()
{
const
samples
=
this
.
redoStack
.
pop
();
const
{
samples
,
sampleRate
}
=
this
.
redoStack
.
pop
();
if
(
samples
)
{
this
.
undoStack
.
push
(
this
.
copyCurrent
Samples
());
this
.
submitNewSamples
(
samples
,
this
.
props
.
sampleRate
,
true
);
this
.
undoStack
.
push
(
this
.
copyCurrent
Buffer
());
this
.
submitNewSamples
(
samples
,
sampleRate
,
true
);
this
.
handlePlay
();
}
}
...
...
This diff is collapsed.
Click to expand it.
src/lib/audio/audio-buffer-player.js
+
7
−
1
View file @
df0bf268
...
...
@@ -45,7 +45,13 @@ class AudioBufferPlayer {
stop
()
{
if
(
this
.
source
)
{
this
.
source
.
onended
=
null
;
// Do not call onEnded callback if manually stopped
this
.
source
.
stop
();
try
{
this
.
source
.
stop
();
}
catch
(
e
)
{
// This is probably Safari, which dies when you call stop more than once
// which the spec says is allowed: https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode
console
.
log
(
'
Caught error while stopping buffer source node.
'
);
// eslint-disable-line no-console
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/lib/audio/audio-effects.js
+
8
−
2
View file @
df0bf268
...
...
@@ -38,8 +38,14 @@ class AudioEffects {
buffer
.
getChannelData
(
0
).
reverse
();
break
;
}
const
OfflineAudioContext
=
window
.
OfflineAudioContext
||
window
.
webkitOfflineAudioContext
;
this
.
audioContext
=
new
OfflineAudioContext
(
1
,
sampleCount
,
buffer
.
sampleRate
);
if
(
window
.
OfflineAudioContext
)
{
this
.
audioContext
=
new
window
.
OfflineAudioContext
(
1
,
sampleCount
,
buffer
.
sampleRate
);
}
else
{
// Need to use webkitOfflineAudioContext, which doesn't support all sample rates.
// Resample by adjusting sample count to make room and set offline context to desired sample rate.
const
sampleScale
=
44100
/
buffer
.
sampleRate
;
this
.
audioContext
=
new
window
.
webkitOfflineAudioContext
(
1
,
sampleScale
*
sampleCount
,
44100
);
}
this
.
buffer
=
buffer
;
this
.
source
=
this
.
audioContext
.
createBufferSource
();
this
.
source
.
buffer
=
this
.
buffer
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment