-
-
Notifications
You must be signed in to change notification settings - Fork 59
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 #654 from hyoo-ru/audio-node
$mol_audio refactor, added sample and instrument nodes, isomorphic context
- Loading branch information
Showing
13 changed files
with
179 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace $ { | ||
export class $mol_audio_context extends $mol_object2 { | ||
@ $mol_memo.method | ||
static context() { | ||
const AudioContext = this.$.$mol_dom_context.AudioContext || this.$.$node['web-audio-api'].AudioContext | ||
return new 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
File renamed without changes.
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
File renamed without changes.
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,20 @@ | ||
namespace $ { | ||
|
||
export class $mol_audio_gain extends $mol_audio_node { | ||
|
||
@ $mol_mem | ||
override node_raw() { return this.context().createGain() } | ||
|
||
@ $mol_mem | ||
override node() { | ||
const node = super.node() | ||
node.gain.setValueAtTime( this.gain(), this.time() ) | ||
return node | ||
} | ||
|
||
@ $mol_mem | ||
gain( next = 1 ) { return next } | ||
|
||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
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,59 @@ | ||
namespace $ { | ||
export class $mol_audio_instrument extends $mol_audio_node { | ||
override node_raw(): AudioScheduledSourceNode { | ||
throw new Error('implement') | ||
} | ||
|
||
@ $mol_mem | ||
override node() { | ||
const node = super.node() | ||
node.onended = $mol_wire_async((e: Event) => this.end(e)) | ||
|
||
return node | ||
} | ||
|
||
protected promise = $mol_promise<void>() | ||
|
||
@ $mol_mem | ||
wait() { | ||
return this.promise | ||
} | ||
|
||
end(e: Event) { | ||
this.active( false ) | ||
} | ||
|
||
@ $mol_mem | ||
active( next?: boolean ): boolean { | ||
|
||
$mol_wire_solid() | ||
|
||
const node = next === false ? this.node_raw() : this.node() | ||
|
||
const prev = $mol_wire_probe( ()=> this.active() ) | ||
if( prev === next ) return next ?? false | ||
|
||
if( next === true ) { | ||
node.start() | ||
} else if( prev === true ) { | ||
node.stop() | ||
this.promise.done() | ||
this.promise = $mol_promise() | ||
} | ||
|
||
return next ?? false | ||
} | ||
|
||
override destructor() { | ||
this.active( false ) | ||
super.destructor() | ||
} | ||
|
||
@ $mol_mem | ||
override output() { | ||
this.active( true ) | ||
return super.output() | ||
} | ||
|
||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
namespace $ { | ||
export class $mol_audio_sample extends $mol_audio_instrument { | ||
@ $mol_mem | ||
override node_raw() { return this.context().createBufferSource() } | ||
|
||
override duration() { | ||
return this.audio_buffer().duration | ||
} | ||
|
||
buffer() { | ||
return new ArrayBuffer(0) | ||
} | ||
|
||
@ $mol_mem | ||
audio_buffer() { | ||
return $mol_wire_sync(this.context()).decodeAudioData(this.buffer()) | ||
} | ||
|
||
@ $mol_mem | ||
override node() { | ||
const node = super.node() | ||
node.buffer = this.audio_buffer() | ||
|
||
return node | ||
} | ||
|
||
} | ||
} |
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,38 @@ | ||
namespace $ { | ||
|
||
export type $mol_audio_vibe_shape = | ||
| 'sine' | ||
| 'square' | ||
| 'sawtooth' | ||
| 'triangle' | ||
| 'custom' | ||
|
||
/** | ||
* @see https://mol.hyoo.ru/#!section=demos/demo=mol_audio_demo_vibe | ||
*/ | ||
export class $mol_audio_vibe extends $mol_audio_instrument { | ||
|
||
@ $mol_mem | ||
override node_raw() { return this.context().createOscillator() } | ||
|
||
@ $mol_mem | ||
freq( next = 440 ) { return next } | ||
|
||
@ $mol_mem | ||
shape( next: $mol_audio_vibe_shape = 'sine' ) { return next } | ||
|
||
override duration() { | ||
return 0.5 | ||
} | ||
|
||
@ $mol_mem | ||
override node() { | ||
const node = super.node() | ||
node.frequency.setValueAtTime( this.freq(), this.time() ) | ||
node.type = this.shape() | ||
|
||
return node | ||
} | ||
|
||
} | ||
} |
This file was deleted.
Oops, something went wrong.