-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f045f9
commit 393317d
Showing
7 changed files
with
218 additions
and
66 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
class AudioProcessor extends AudioWorkletProcessor { | ||
constructor() { | ||
super(); | ||
this.position = 0; | ||
this.buffers = []; | ||
this.current = null; | ||
|
||
this.port.onmessage = (e) => { | ||
this.buffers.push(e.data); | ||
if (this.buffers.length > 3) { | ||
this.buffers.shift(); | ||
} | ||
}; | ||
} | ||
|
||
process(inputs, outputs, parameters) { | ||
let output = outputs[0]; | ||
let channel = output[0]; | ||
|
||
if (!this.current || this.position >= this.current.length) { | ||
this.current = this.buffers.shift(); | ||
this.position = 0; | ||
|
||
if (!this.current) { | ||
for (let i = 0; i < channel.length; i++) { | ||
channel[i] = 0; | ||
} | ||
return true; | ||
} | ||
} | ||
|
||
for (let i = 0; i < channel.length; i++) { | ||
channel[i] = this.current[this.position++]; | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
|
||
registerProcessor("audio-processor", AudioProcessor); |
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.