Skip to content

Commit

Permalink
fix(bufferSource): fix bug with offsetTime not working in Chrome (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
benji6 committed Jul 19, 2019
1 parent 937ce59 commit 9b1181e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion docsSrc/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import createVirtualAudioGraph, {
createWorkletNode,
createNode,
createWorkletNode,
delay,
gain,
oscillator,
Expand Down
29 changes: 13 additions & 16 deletions src/VirtualAudioNodes/StandardVirtualAudioNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ import {
import { capitalize, equals, find, values } from '../utils'
import CustomVirtualAudioNode from './CustomVirtualAudioNode'

interface ITimeParameters {
offsetTime: number
startTime: number
stopTime: number
}

interface IAudioContextFactoryLookup {
[_: string]: any
}
Expand All @@ -28,9 +22,7 @@ const createAudioNode = (
audioContext: AudioContext,
name: string,
audioNodeFactoryParam: IAudioNodeFactoryParam,
{ offsetTime, startTime, stopTime }: ITimeParameters,
) => {
offsetTime = offsetTime || 0 // tslint:disable-line no-parameter-reassignment
const audioNodeFactoryName = `create${capitalize(name)}`
if (
typeof (audioContext as IAudioContextFactoryLookup)[
Expand All @@ -46,11 +38,6 @@ const createAudioNode = (
)
: (audioContext as IAudioContextFactoryLookup)[audioNodeFactoryName]()

if (startAndStopNodes.indexOf(name) !== -1) {
if (startTime == null) audioNode.start(audioContext.currentTime, offsetTime)
else audioNode.start(startTime, offsetTime)
if (stopTime != null) audioNode.stop(stopTime)
}
return audioNode
}

Expand Down Expand Up @@ -120,16 +107,26 @@ export default class StandardVirtualAudioNode {
]
const { offsetTime, startTime, stopTime } = params

this.audioNode = createAudioNode(
// TODO remove `any` when AudioScheduledSourceNode typings are correct
const audioNode: any = createAudioNode(
audioContext,
this.node,
constructorParam,
{ offsetTime, startTime, stopTime },
)

this.audioNode = audioNode
this.params = undefined
this.update(params)

return this.update(params)
if (startAndStopNodes.indexOf(this.node) !== -1) {
audioNode.start(
startTime == null ? audioContext.currentTime : startTime,
offsetTime || 0,
)
if (stopTime != null) audioNode.stop(stopTime)
}

return this
}

public update(params: IVirtualAudioNodeParams = {}): this {
Expand Down

0 comments on commit 9b1181e

Please sign in to comment.