-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from ctoth/synth
Add synthesis
- Loading branch information
Showing
13 changed files
with
277 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import { AudioContext, IAudioBuffer, IAudioBufferSourceNode, IBiquadFilterNode, IGainNode, IMediaElementAudioSourceNode, IPannerNode, IStereoPannerNode } from 'standardized-audio-context'; | ||
export { | ||
AudioBuffer, AudioContext, IAudioBuffer, IPannerOptions, | ||
} from 'standardized-audio-context'; | ||
import { AudioContext, IAudioBuffer, IAudioBufferSourceNode, IAudioNode, IBiquadFilterNode, IGainNode, IMediaElementAudioSourceNode, IOscillatorNode, IPannerNode, IStereoPannerNode } from 'standardized-audio-context'; | ||
export type AudioNode = IAudioNode<AudioContext>; | ||
export type BiquadFilterNode = IBiquadFilterNode<AudioContext>; | ||
export type MediaElementSourceNode = IMediaElementAudioSourceNode<AudioContext>; | ||
export type AudioBuffer = IAudioBuffer; | ||
export type AudioBufferSourceNode = IAudioBufferSourceNode<AudioContext>; | ||
export type SourceNode = AudioBufferSourceNode | MediaElementSourceNode; | ||
|
||
export type OscillatorNode = IOscillatorNode<AudioContext>; | ||
export type SourceNode = AudioBufferSourceNode | MediaElementSourceNode | OscillatorNode; | ||
|
||
export type GainNode = IGainNode<AudioContext>; | ||
export type PannerNode = IPannerNode<AudioContext>; | ||
export type StereoPannerNode = IStereoPannerNode<AudioContext>; | ||
export { AudioContext }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './cacophony'; | ||
export * from './group'; | ||
export * from './playback'; | ||
export * from './sound'; | ||
export * from './sound'; | ||
export * from './synth'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import type { OscillatorNode } from "./context"; | ||
import { BasePlayback } from "./playback"; | ||
|
||
export type OscillatorCloneOverrides = { | ||
oscillatorOptions?: Partial<OscillatorOptions>; | ||
}; | ||
|
||
type Constructor<T = {}> = abstract new (...args: any[]) => T; | ||
|
||
export function OscillatorMixin<TBase extends Constructor>(Base: TBase) { | ||
abstract class OscillatorMixin extends BasePlayback { | ||
|
||
private _oscillatorOptions: Partial<OscillatorOptions> = {}; | ||
declare public source?: OscillatorNode; | ||
|
||
get oscillatorOptions(): Partial<OscillatorOptions> { | ||
return this._oscillatorOptions; | ||
} | ||
|
||
set oscillatorOptions(options: Partial<OscillatorOptions>) { | ||
this._oscillatorOptions = options; | ||
if (this.source && this.source instanceof OscillatorNode) { | ||
Object.assign(this.source, options); | ||
} | ||
} | ||
|
||
play(): [this] { | ||
if (!this.source) { | ||
throw new Error('No source node found'); | ||
} | ||
this.source.start(); | ||
this._playing = true; | ||
return [this]; | ||
} | ||
|
||
stop() { | ||
if (this.source && this.source.stop) { | ||
this.source.stop(); | ||
this._playing = false; | ||
} | ||
} | ||
|
||
pause(): void { | ||
this.stop(); | ||
} | ||
|
||
}; | ||
return OscillatorMixin; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.