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

Emscripten issues traced to JS audio #8253

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 35 additions & 33 deletions addons/ofxEmscripten/src/ofxEmscriptenSoundPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "ofFileUtils.h"
#include "ofxEmscriptenSoundPlayer.h"
#include "html5audio.h"
// #include "html5audio.h"

using namespace std;

Expand All @@ -17,7 +17,7 @@ int ofxEmscriptenAudioContext(){
static bool initialized=false;
static int context = -1;
if(!initialized){
context = html5audio_context_create();
context = //html5audio_context_create();
initialized = true;
}
return context;
Expand All @@ -30,126 +30,128 @@ ofxEmscriptenSoundPlayer::ofxEmscriptenSoundPlayer()
,speed(1)
,pan(0)
,playing(false)
,player_id(html5audio_player_create()){
,player_id(0){
//,player_id(//html5audio_player_create()){
}

ofxEmscriptenSoundPlayer::~ofxEmscriptenSoundPlayer(){
html5audio_sound_free(player_id);
//html5audio_sound_free(player_id);
}

bool ofxEmscriptenSoundPlayer::load(const of::filesystem::path& filePath, bool stream){
auto soundFilePath = filePath.string();
if ( soundFilePath.substr(0, 7) != "http://" && soundFilePath.substr(0, 8) != "https://"){
soundFilePath = ofToDataPath(soundFilePath);
}
html5audio_sound_load(player_id, soundFilePath.c_str());
//html5audio_sound_load(player_id, soundFilePath.c_str());
return true;
}

//bool ofxEmscriptenSoundPlayer::load(const std::string& fileName, bool stream){
// html5audio_sound_load(player_id, fileName.c_str());
// //html5audio_sound_load(player_id, fileName.c_str());
// return true;
//}

void ofxEmscriptenSoundPlayer::unload(){
html5audio_sound_free(player_id);
//html5audio_sound_free(player_id);
}

void ofxEmscriptenSoundPlayer::play(){
if(playing && !multiplay && !html5audio_sound_done(player_id)){
html5audio_sound_stop(player_id);
}
html5audio_sound_play(player_id, multiplay, volume, speed, pan, 0);
html5audio_sound_set_rate(player_id, speed);
html5audio_sound_set_volume(player_id, volume);
// if(playing && !multiplay && !//html5audio_sound_done(player_id)){
//html5audio_sound_stop(player_id);
// }
//html5audio_sound_play(player_id, multiplay, volume, speed, pan, 0);
//html5audio_sound_set_rate(player_id, speed);
//html5audio_sound_set_volume(player_id, volume);
playing = true;
}

void ofxEmscriptenSoundPlayer::stop(){
html5audio_sound_stop(player_id);
//html5audio_sound_stop(player_id);
playing = false;
}


void ofxEmscriptenSoundPlayer::setVolume(float vol){
volume = vol;
html5audio_sound_set_volume(player_id, vol);
//html5audio_sound_set_volume(player_id, vol);
}

void ofxEmscriptenSoundPlayer::setPan(float panorama){
pan = panorama;
html5audio_sound_set_pan(player_id, pan);
//html5audio_sound_set_pan(player_id, pan);
}

void ofxEmscriptenSoundPlayer::setSpeed(float spd){
speed = spd;
html5audio_sound_set_rate(player_id, spd);
//html5audio_sound_set_rate(player_id, spd);
}

void ofxEmscriptenSoundPlayer::setPaused(bool bP){
if(bP) html5audio_sound_pause(player_id);
else html5audio_sound_play(player_id, multiplay, volume, speed, pan, 0);
// if(bP) //html5audio_sound_pause(player_id);
// else //html5audio_sound_play(player_id, multiplay, volume, speed, pan, 0);
}

void ofxEmscriptenSoundPlayer::setLoop(bool bLp){
html5audio_sound_set_loop(player_id, bLp);
//html5audio_sound_set_loop(player_id, bLp);
}

void ofxEmscriptenSoundPlayer::setMultiPlay(bool bMp){
multiplay = bMp;
}

void ofxEmscriptenSoundPlayer::setPosition(float pct){
html5audio_sound_set_position(player_id, pct);
//html5audio_sound_set_position(player_id, pct);
}

void ofxEmscriptenSoundPlayer::setPositionMS(int ms){
html5audio_sound_set_position(player_id, ms / html5audio_sound_duration(player_id) / 1000);
//html5audio_sound_set_position(player_id, ms / //html5audio_sound_duration(player_id) / 1000);
}

float ofxEmscriptenSoundPlayer::getPosition() const{
return html5audio_sound_position(player_id);
return 0;//html5audio_sound_position(player_id);
}

int ofxEmscriptenSoundPlayer::getPositionMS() const{
return html5audio_sound_position(player_id) * html5audio_sound_duration(player_id) * 1000;
return 0;//html5audio_sound_position(player_id) * //html5audio_sound_duration(player_id) * 1000;
}

bool ofxEmscriptenSoundPlayer::isPlaying() const{
return playing && !html5audio_sound_done(player_id);
return false;
//return playing && !//html5audio_sound_done(player_id);
}

float ofxEmscriptenSoundPlayer::getSpeed() const{
return html5audio_sound_rate(player_id);
return 0;//html5audio_sound_rate(player_id);
}

float ofxEmscriptenSoundPlayer::getPan() const{
return html5audio_sound_pan(player_id);
return 0;//html5audio_sound_pan(player_id);
}

bool ofxEmscriptenSoundPlayer::isLoaded() const{
return html5audio_sound_is_loaded(player_id);
return false;//html5audio_sound_is_loaded(player_id);
}

float ofxEmscriptenSoundPlayer::getVolume() const{
return html5audio_sound_volume(player_id);
return 0;//html5audio_sound_volume(player_id);
}

float ofxEmscriptenSoundPlayer::getDuration() const {
return html5audio_sound_duration(player_id);
return 0;//html5audio_sound_duration(player_id);
}

unsigned int ofxEmscriptenSoundPlayer::getDurationMS() const{
return html5audio_sound_duration(player_id) * 1000;
return 0;//html5audio_sound_duration(player_id) * 1000;
}

double ofxEmscriptenSoundPlayer::getDurationSecs() const{
return html5audio_sound_duration(player_id);
return 0;//html5audio_sound_duration(player_id);
}

float * ofxEmscriptenSoundPlayer::getSystemSpectrum(int bands){
systemSpectrum.resize(bands);
html5audio_context_spectrum(bands, &systemSpectrum[0]);
//html5audio_context_spectrum(bands, &systemSpectrum[0]);
for(size_t i = 0; i < systemSpectrum.size(); i++){
systemSpectrum[i] = (systemSpectrum[i]+100) * 0.01;
}
Expand Down
14 changes: 7 additions & 7 deletions addons/ofxEmscripten/src/ofxEmscriptenSoundStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

#include "ofxEmscriptenSoundStream.h"
#include "html5audio.h"
// #include "html5audio.h"
#include "ofBaseApp.h"
#include "ofLog.h"

Expand All @@ -26,15 +26,15 @@ ofxEmscriptenSoundStream::~ofxEmscriptenSoundStream() {
}

std::vector<ofSoundDevice> ofxEmscriptenSoundStream::getDeviceList(ofSoundDevice::Api api) const{
html5audio_list_devices();
//html5audio_list_devices();
return vector<ofSoundDevice>();
}

bool ofxEmscriptenSoundStream::setup(const ofSoundStreamSettings & settings) {
inbuffer.allocate(settings.bufferSize, settings.numInputChannels);
outbuffer.allocate(settings.bufferSize, settings.numOutputChannels);
this->settings = settings;
html5audio_stream_create(settings.bufferSize,settings.numInputChannels,settings.numOutputChannels,inbuffer.getBuffer().data(),outbuffer.getBuffer().data(),&audio_cb,this);
//html5audio_stream_create(settings.bufferSize,settings.numInputChannels,settings.numOutputChannels,inbuffer.getBuffer().data(),outbuffer.getBuffer().data(),&audio_cb,this);
return true;
}

Expand All @@ -55,15 +55,15 @@ ofSoundDevice ofxEmscriptenSoundStream::getOutDevice() const{
}

void ofxEmscriptenSoundStream::start() {
html5audio_context_start();
//html5audio_context_start();
}

void ofxEmscriptenSoundStream::stop() {
html5audio_context_stop();
//html5audio_context_stop();
}

void ofxEmscriptenSoundStream::close() {
html5audio_stream_free();
//html5audio_stream_free();
}

uint64_t ofxEmscriptenSoundStream::getTickCount() const{
Expand All @@ -79,7 +79,7 @@ int ofxEmscriptenSoundStream::getNumOutputChannels() const{
}

int ofxEmscriptenSoundStream::getSampleRate() const{
return html5audio_context_samplerate();
return 0;//html5audio_context_samplerate();
}

int ofxEmscriptenSoundStream::getBufferSize() const{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ endif

# Code Generation Option Flags (http://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html)
PLATFORM_CFLAGS = -std=c17 -fPIC $(CFLAG_PLATFORM_PTHREAD) -s ASSERTIONS=2
PLATFORM_CXXFLAGS = -Wall -std=c++17 -fPIC -Wno-warn-absolute-paths $(CFLAG_PLATFORM_PTHREAD) -s ASSERTIONS=2
PLATFORM_CXXFLAGS = -Wall -std=c++23 -fPIC -Wno-warn-absolute-paths $(CFLAG_PLATFORM_PTHREAD) -s ASSERTIONS=2

ifdef EMSCRIPTEN_MEMORY64
PLATFORM_CFLAGS += -s MEMORY64=1
Expand Down Expand Up @@ -131,15 +131,14 @@ PLATFORM_LDFLAGS += $(PLATFORM_PTHREAD)
# PLATFORM_LDFLAGS += -lhtml5
# PLATFORM_LDFLAGS += -lopenal
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
# PLATFORM_LDFLAGS += --js-library $(OF_ADDONS_PATH)/ofxEmscripten/libs/html5audio/lib/emscripten/library_html5audio.js
PLATFORM_LDFLAGS += -s MINIFY_HTML=0
PLATFORM_LDFLAGS += -s MAIN_MODULE=1 \
-s ASSERTIONS=2 \
-s EXPORT_ALL=1 \
-s MODULARIZE=1 \
-s NO_DYNAMIC_EXECUTION=1
PLATFORM_LDFLAGS += -s ALLOW_MEMORY_GROWTH=1
PLATFORM_LDFLAGS += -sLOAD_SOURCE_MAP=1 -sABORT_ON_WASM_EXCEPTIONS=1
PLATFORM_LDFLAGS += -sLOAD_SOURCE_MAP=1 -sABORT_ON_WASM_EXCEPTIONS=0
PLATFORM_LDFLAGS += -s DYNAMIC_EXECUTION=0 -s EMBIND_AOT=1
# PLATFORM_LDFLAGS += -s SINGLE_FILE=1
#PLATFORM_LDFLAGS += -s MODULARIZE=1
Expand Down
Loading