Skip to content
Snippets Groups Projects
Commit 7b88ddb4 authored by Paul Kaplan's avatar Paul Kaplan Committed by GitHub
Browse files

Merge pull request #618 from paulkaplan/safari-audio

Safari audio
parents e78ef1ca b3b254be
No related branches found
No related tags found
No related merge requests found
......@@ -112,9 +112,9 @@ class SoundEditor extends React.Component {
}
handleEffect (name) {
const effects = new AudioEffects(this.audioBufferPlayer.buffer, name);
effects.process().then(newBuffer => {
const samples = newBuffer.getChannelData(0);
const sampleRate = newBuffer.sampleRate;
effects.process(({renderedBuffer}) => {
const samples = renderedBuffer.getChannelData(0);
const sampleRate = renderedBuffer.sampleRate;
this.submitNewSamples(samples, sampleRate);
this.handlePlay();
});
......
......@@ -38,7 +38,7 @@ class AudioEffects {
buffer.getChannelData(0).reverse();
break;
}
const OfflineAudioContext = window.OfflineAudioContext || window.webkitOfflineAudioContext;
this.audioContext = new OfflineAudioContext(1, sampleCount, buffer.sampleRate);
this.buffer = buffer;
this.source = this.audioContext.createBufferSource();
......@@ -46,7 +46,7 @@ class AudioEffects {
this.source.playbackRate.value = playbackRate;
this.name = name;
}
process () {
process (done) {
// Some effects need to use more nodes and must expose an input and output
let input;
let output;
......@@ -75,7 +75,8 @@ class AudioEffects {
this.source.start();
return this.audioContext.startRendering();
this.audioContext.startRendering();
this.audioContext.oncomplete = done;
}
}
......
import StartAudioContext from 'startaudiocontext';
const AUDIO_CONTEXT = new (window.AudioContext || window.webkitAudioContext)();
StartAudioContext(AUDIO_CONTEXT);
/**
* Wrap browser AudioContext because we shouldn't create more than one
* @return {AudioContext} The singleton AudioContext
......
......@@ -13,11 +13,9 @@ export default class MockAudioEffects {
constructor (buffer, name) {
this.buffer = buffer;
this.name = name;
this._mockResult = {};
this._bufferPromise = new Promise(resolve => { // eslint-disable-line no-undef
this._finishProcessing = newBuffer => resolve(newBuffer);
this.process = jest.fn(done => {
this._finishProcessing = renderedBuffer => done({renderedBuffer});
});
this.process = jest.fn(() => this._bufferPromise);
MockAudioEffects.instance = this;
}
}
......@@ -111,7 +111,7 @@ describe('Sound Editor Container', () => {
expect(vm.renameSound).toHaveBeenCalledWith(soundIndex, 'hello');
});
test('it handles an effect by submitting the result and playing', done => {
test('it handles an effect by submitting the result and playing', () => {
const wrapper = mountWithIntl(
<SoundEditor
soundIndex={soundIndex}
......@@ -121,11 +121,8 @@ describe('Sound Editor Container', () => {
const component = wrapper.find(SoundEditorComponent);
component.props().onReverse(); // Could be any of the effects, just testing the end result
mockAudioEffects.instance._finishProcessing(soundBuffer);
process.nextTick(() => {
expect(mockAudioBufferPlayer.instance.play).toHaveBeenCalled();
expect(vm.updateSoundBuffer).toHaveBeenCalled();
done();
});
expect(mockAudioBufferPlayer.instance.play).toHaveBeenCalled();
expect(vm.updateSoundBuffer).toHaveBeenCalled();
});
test('it handles reverse effect correctly', () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment