-
-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
$mol_audio refactor, added sample and scheduled nodes #654
Merged
Merged
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8f48ee3
$mol_audio refactor, added sample and scheduled nodes
zerkalica b5dbf19
$mol_audio_scheduled moved duration
zerkalica 1945903
$mol_audio_scheduled fixes 1
zerkalica dd83f2d
$mol_audio_scheduled fixes 2
zerkalica 8ac790b
$mol_audio_scheduled duration fix
zerkalica 10aa7cc
$mol_audio_scheduled duration fix 2
zerkalica 25aad23
$mol_audio_room duration mem
zerkalica af0de3d
$mol_audio_room duration moved to $mol_audio_node
zerkalica e711ead
$mol_audio_context added speaker for node
zerkalica ff2c04a
$mol_audio_context moved to process.stdout for node
zerkalica 6fa0b7e
$mol_audio_context null stdout for node
zerkalica 27bf8ce
$mol_audio_context removed node version
zerkalica fc89ecd
$mol_audio_context fix AudioContext
zerkalica File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,13 @@ | ||
namespace $ { | ||
|
||
export class $mol_audio_context_node extends $mol_audio_context { | ||
|
||
@ $mol_memo.method | ||
static override context() { | ||
const AudioContext = this.$.$mol_dom_context.AudioContext || this.$.$node['web-audio-api'].AudioContext | ||
return new AudioContext() | ||
} | ||
} | ||
|
||
$.$mol_audio_context = $mol_audio_context_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,8 @@ | ||
namespace $ { | ||
export class $mol_audio_context extends $mol_object2 { | ||
@ $mol_memo.method | ||
static context() { | ||
return new this.$.$mol_dom_context.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,63 @@ | ||
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(() => this.end()) | ||
zerkalica marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return node | ||
} | ||
|
||
duration() { | ||
return 1 | ||
} | ||
|
||
promise = $mol_promise<void>() | ||
|
||
@ $mol_mem | ||
wait() { | ||
return this.promise | ||
} | ||
|
||
end() { | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
namespace $ { | ||
|
||
/** | ||
* @see https://mol.hyoo.ru/#!section=demos/demo=mol_audio_demo | ||
*/ | ||
export class $mol_audio_room extends $mol_audio_node { | ||
|
||
duration_default() { | ||
return .5 | ||
} | ||
|
||
duration() { | ||
let duration = 0 | ||
for (const input of this.input_connected()) { | ||
if (input instanceof $mol_audio_instrument) duration += input.duration() | ||
nin-jin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
return duration || this.duration_default() | ||
} | ||
|
||
@ $mol_action | ||
play() { | ||
this.output() | ||
this.$.$mol_wait_timeout( this.duration() * 1000 ) | ||
} | ||
|
||
} | ||
} |
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,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,34 @@ | ||
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 } | ||
|
||
@ $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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$node['web-audio-api']
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Возможно даже так можно:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
да все-равно надо билдер опять фиксить, пока можно стаб оставить, я так и не смог найти
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не надо тут ничего фиксить, нодовая зависимость должна динамически загружаться.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Это ж универсальная реализация. Отдельный слайс для ноды не нужен.