Skip to content
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 13 commits into from
Dec 30, 2023
26 changes: 24 additions & 2 deletions audio/context/context.node.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
namespace $ {

type AudioContextNode = {
outStream?: InstanceType<typeof $node.stream.Writable> | null
format: {
numberOfChannels: number
bitDepth: number
}
}

export class $mol_audio_context_node extends $mol_audio_context {

static override create_context(): AudioContext & AudioContextNode {
const AudioContext = this.$.$node['web-audio-api'].AudioContext
return new AudioContext()
}
Copy link
Member

@nin-jin nin-jin Dec 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Context() {
    return ( this.$.$mol_dom_context || this.$.$node['web-audio-api'] ).AudioContext
}


@ $mol_memo.method
static override context() {
const AudioContext = this.$.$mol_dom_context.AudioContext || this.$.$node['web-audio-api'].AudioContext
return new AudioContext()
const context = this.create_context()

const Speaker = this.$.$node['speaker']

context.outStream = new Speaker({
channels: context.format.numberOfChannels,
bitDepth: context.format.bitDepth,
sampleRate: context.sampleRate
})

return context
}
}

Expand Down
6 changes: 5 additions & 1 deletion audio/context/context.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
namespace $ {
export class $mol_audio_context extends $mol_object2 {
static create_context() {
return new this.$.$mol_dom_context.AudioContext()
}

@ $mol_memo.method
static context() {
return new this.$.$mol_dom_context.AudioContext()
return this.create_context()
}
}
}
Loading