AudioWorklets

0 favourites
  • 4 posts
  • Does C3 allow AudioWorklets in scripting? And if so, how can I implement them, as currently I'm trying to register a simple noise generator, but get a "registerProcessor" is undefiuned error.

    registerProcessor( "Noise", class extends AudioWorkletProcessor {
    	constructor(){ 
    		super();
    	}
    	process( inputs, outputs ) {
    		const output = outputs[0][0];
    		for ( let i = 0; i < out.length; i++ ) {
    			output[ i ] = ( Math.random() * 2 ) - 1;
    		}
    		return true;
    	}
    });
    

    I'm doing this because using the existing audioBufferNode is too limited in terms of updating in realtime, and the built in oscillators are not great...

    Ultimately the goal is to replicate the NES's APU, which consists of:

    - 2 PulseWave Channels (needs to facilitate 12.5%, 25%, 50%, and 75% (25% inverted) duty cycles)

    - Triangle Channel (a real NES has a malformed and stepped triangle, rather than a smooth triangle, so a custom waveform is needed here)

    - Noise Channel (the NES could generate 16 preset pitches of noise across 2 "modes" of noise, as well as a long form noise generation)

    - DPCM Channel (this handled all the sample playback as heard in games like "Double Dribble" and "Lifeforce"

    Ultimately my goal is to create something that can playback NES audio, as well as allow the user to eventually create their own. So accuracy to the real sound quality is important.

  • Try opening the browser console and see if typing that function, registerProcess, is defined.

    If it is then it likely has to do with the scope that c3 ran the script you typed. It’s probably mentioned in the manual.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It all works for me - the key is to put the code with the call to registerProcessor in a separate JavaScript file in the 'Files' folder, and load it with audioContext.audioWorklet.addModule("audioWorklet.js"). Here's an example.

  • This is absolutely the answer I needed. I never once thought to put the js file in the project files folder... I just had it as a standalone file in the scripts folders. Awesome... I feel like I'm THIS close to have a working NES soundchip, at least in terms of the instruments and playback capability (it doesn't read roms or nsfs...yet)

    Ultimately, this combined with the WebMIDI plugin (which is awesome and I would LOVE to see become an official plugin) will alllow users to make their own NES music

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)