openFrameworks icon indicating copy to clipboard operation
openFrameworks copied to clipboard

Emscripten - AUDIO not defined error with video player

Open ofTheo opened this issue 10 months ago • 13 comments

Uncaught ReferenceError: AUDIO is not defined

Uncaught ReferenceError: AUDIO is not defined
    at _html5video_player_create (http://localhost:6931/index.js:22482:16)
    at index.wasm.ofxEmscriptenVideoPlayer::ofxEmscriptenVideoPlayer()_581 (http://localhost:6931/index.wasm:wasm-function[553]:0x1d24bd)
    at index.wasm.ofVideoPlayer::load(std::__2::filesystem::path const&) (http://localhost:6931/index.wasm:wasm-function[1421]:0x2163e3)
    at index.wasm.ofApp::setup() (http://localhost:6931/index.wasm:wasm-function[494]:0x1d0604)

with current nightly and any example using ofVideoPlayer

ofTheo avatar Feb 26 '25 23:02 ofTheo

@danoli3 could it be due to this commit? https://github.com/openframeworks/openFrameworks/commit/cd463eeb6aa005ea26f96447aaab5d68bf3390de#diff-90c5b050f4260e0bc98d6cab8e4bf95fcc8674a8a2628b1e5e7f7e009a3f11bbR20

Wondering why Audio is disabled. cc @Jonathhhan

ofTheo avatar Feb 27 '25 19:02 ofTheo

@ofTheo It seems to be related to this PR: https://github.com/openframeworks/openFrameworks/pull/8253

Jonathhhan avatar Feb 28 '25 17:02 Jonathhhan

@Jonathhhan would you be up for getting your Audio Worklet PR working now that OF is working again in emscripten and pthreads are enabled?

ofTheo avatar Feb 28 '25 18:02 ofTheo

@ofTheo I can (and will) do that, but probably not the next days, because I am quite busy at the moment.

Jonathhhan avatar Mar 01 '25 15:03 Jonathhhan

@Jonathhhan @danoli3 I have a audioworklet implementation but the issue I am having is it requires -s MAIN_MODULE=0

Currently if we change -s MAIN_MODULE=1 to -s MAIN_MODULE=0 here: https://github.com/openframeworks/openFrameworks/blob/master/libs/openFrameworksCompiled/project/emscripten/config.emscripten.default.mk#L132

The main function of the OF app doesn't get called ( even if we export "_main" in the exported functions list ).

This happens even with the graphicsExample. If someone can advise on a way to get the graphicsExample in the nightly building with MAIN_MODULE=0 then I think we can get audioWorklets / web audio working again.

MAIN_MODULE=1

Image

MAIN_MODULE=0

Image

ofTheo avatar Mar 11 '25 23:03 ofTheo

@ofTheo this is my PR from last year, there was no -s MAIN_MODULE=0 needed: https://github.com/Jonathhhan/openFrameworks/blob/emscripten_3.1.57_audioWorklet/libs/openFrameworksCompiled/project/emscripten/config.emscripten.default.mk But possibly Emscripten changed a lot since then.

Jonathhhan avatar Mar 12 '25 00:03 Jonathhhan

Yes the old audio system was the cause of emscripten not compiling, re that pr and comments!

Wasted so much time and it was just that broken js system not compatible with newer edk

On Wed, 12 Mar 2025 at 10:52 am, Theodore Watson @.***> wrote:

@Jonathhhan https://github.com/Jonathhhan @danoli3 https://github.com/danoli3 I have a audioworklet implementation but the issue I am having is it requires -s MAIN_MODULE=0

Currently if we change -s MAIN_MODULE=1 to -s MAIN_MODULE=0 here:

https://github.com/openframeworks/openFrameworks/blob/master/libs/openFrameworksCompiled/project/emscripten/config.emscripten.default.mk#L132

The main function of the OF app doesn't get called ( even if we export "_main" in the exported functions list ).

This happens even with the graphicsExample. If someone can advise on a way to get the graphicsExample in the nightly building with MAIN_MODULE=0 then I think we can get audioWorklets / web audio working again.

MAIN_MODULE=1

Screenshot.2025-03-11.at.4.49.46.PM.png (view on web) https://github.com/user-attachments/assets/47d1eecc-a848-49e8-8f5c-8369465e56d6

MAIN_MODULE=0

Screenshot.2025-03-11.at.4.50.25.PM.png (view on web) https://github.com/user-attachments/assets/d36e6826-beae-465b-a1b2-5de3ce630250

— Reply to this email directly, view it on GitHub https://github.com/openframeworks/openFrameworks/issues/8291#issuecomment-2715984636, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGK2HB5RK34SINQS2L2UEL2T5ZKPAVCNFSM6AAAAABX6PFLL6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMJVHE4DINRTGY . You are receiving this because you were mentioned.Message ID: @.***> [image: ofTheo]ofTheo left a comment (openframeworks/openFrameworks#8291) https://github.com/openframeworks/openFrameworks/issues/8291#issuecomment-2715984636

@Jonathhhan https://github.com/Jonathhhan @danoli3 https://github.com/danoli3 I have a audioworklet implementation but the issue I am having is it requires -s MAIN_MODULE=0

Currently if we change -s MAIN_MODULE=1 to -s MAIN_MODULE=0 here:

https://github.com/openframeworks/openFrameworks/blob/master/libs/openFrameworksCompiled/project/emscripten/config.emscripten.default.mk#L132

The main function of the OF app doesn't get called ( even if we export "_main" in the exported functions list ).

This happens even with the graphicsExample. If someone can advise on a way to get the graphicsExample in the nightly building with MAIN_MODULE=0 then I think we can get audioWorklets / web audio working again.

MAIN_MODULE=1

Screenshot.2025-03-11.at.4.49.46.PM.png (view on web) https://github.com/user-attachments/assets/47d1eecc-a848-49e8-8f5c-8369465e56d6

MAIN_MODULE=0

Screenshot.2025-03-11.at.4.50.25.PM.png (view on web) https://github.com/user-attachments/assets/d36e6826-beae-465b-a1b2-5de3ce630250

— Reply to this email directly, view it on GitHub https://github.com/openframeworks/openFrameworks/issues/8291#issuecomment-2715984636, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGK2HB5RK34SINQS2L2UEL2T5ZKPAVCNFSM6AAAAABX6PFLL6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMJVHE4DINRTGY . You are receiving this because you were mentioned.Message ID: @.***>

danoli3 avatar Mar 12 '25 00:03 danoli3

At this point I think I am stuck - everything I am reading doesn't allow:

-s MAIN_MODULE=1 -s AUDIO_WORKLET=1 -s WASM_WORKERS=1

Yet -s MAIN_MODULE=0 completely borks all the calls we need to start and run the app.

As mentioned if anyone has tips for OF app working with -s MAIN_MODULE=0 then I think the rest will work. Otherwise audio will remain broken.

ofTheo avatar Mar 12 '25 02:03 ofTheo

Audioworklets (and I guess the old audio method, too) work for me with -sSTANDALONE_WASM, I removed -sMAIN_MODULE=0 and some other options:

PLATFORM_LDFLAGS = --preload-file bin/data@data --emrun --bind --profiling-funcs -sSTANDALONE_WASM
PLATFORM_LDFLAGS += -s MAX_WEBGL_VERSION=2 -s WEBGL2_BACKWARDS_COMPATIBILITY_EMULATION=1 -s FULL_ES2

PLATFORM_LDFLAGS +=  $(PLATFORM_PTHREAD)

PLATFORM_LDFLAGS += --js-library $(OF_ADDONS_PATH)/ofxEmscripten/libs/html5video/lib/emscripten/library_html5video.js
PLATFORM_LDFLAGS += --js-library $(OF_ADDONS_PATH)/ofxEmscripten/libs/html5audio/lib/emscripten/library_html5audio.js

#Do not change this!  
#If there are errors we need to see them! 
PLATFORM_LDFLAGS += -sERROR_ON_UNDEFINED_SYMBOLS=1

PLATFORM_LDFLAGS += -s AUDIO_WORKLET=1 -s WASM_WORKERS=1 -sENVIRONMENT="web,worker" -s WEBAUDIO_DEBUG=1

Jonathhhan avatar Mar 13 '25 01:03 Jonathhhan

Thanks @Jonathhhan !! Will give that a try - fingers crossed it works and we can have audio back in emscripten.

ofTheo avatar Mar 13 '25 02:03 ofTheo

@Jonathhhan can confirm that I can build and run with these symbols now: PLATFORM_LDFLAGS += -s AUDIO_WORKLET=1 -s WASM_WORKERS=1 -sENVIRONMENT="web,worker" -s WEBAUDIO_DEBUG=1

and regular examples work as expected. Wohoo!!!!

I'm debugging my audio workout implementation, which isn't working due to other non-related issues.

Happy if you want to PR your branch or point me to your working implementation.

Thanks!! Theo

ofTheo avatar Mar 13 '25 03:03 ofTheo

@ofTheo nice. I will make a PR soon (its working, but maybe can be optimized).

Jonathhhan avatar Mar 13 '25 14:03 Jonathhhan

@ofTheo here is a branch. Those are basically my changes from last year with the current master and a updated config file: https://github.com/openframeworks/openFrameworks/compare/master...Jonathhhan:openFrameworks:Audioworklet2025 Only tested the audio output example, but that works fine. I also optimized 3 of the audio examples for Emscripten. Feel free to change / optimize my code or pick only parts of it (can also just make a PR with this branch). Not sure about the ofxEmscriptenVideoPlayer changes, I think I made them because it is possible the load videos from the web...

Jonathhhan avatar Mar 15 '25 03:03 Jonathhhan