Coder Social home page Coder Social logo

Comments (14)

oregu1 avatar oregu1 commented on May 29, 2024

@sbc100
Sam could you help me?

from emscripten.

sbc100 avatar sbc100 commented on May 29, 2024

I think with wasm workers you allocate your own stack explicitly right? What size are you using? Have you tried upping it?

from emscripten.

oregu1 avatar oregu1 commented on May 29, 2024

@sbc100 Size?
I don't know. I guess default value.
Added -sALLOW_MEMORY_GROWTH=1 to raise memory automatically if it is needed.
As for stack size in documentation it's said that there is no way to enlarge the stack.
Tried to use -sSTACK_SIZE=5mb and other values but still nothing.

from emscripten.

sbc100 avatar sbc100 commented on May 29, 2024

I mean when you create you wasm worker you specify a stack right? What does the code you have for wasm worker creation look like?

from emscripten.

oregu1 avatar oregu1 commented on May 29, 2024

https://github.com/mackron/miniaudio/issues/816
@mackron There is another issue with miniaudio as well.

from emscripten.

oregu1 avatar oregu1 commented on May 29, 2024

I mean when you create you wasm worker you specify a stack right? What does the code you have for wasm worker creation look like?

I'm trying to make work miniaudio and emscripten together. In miniaudio documentation is said to use these flags to make it work.
-sAUDIO_WORKLET=1 -sWASM_WORKERS=1 -sASYNCIFY
It automatically creates wask-worker and audio worklet and I guess it specify stack by itself. I'm not sure.

My code of initialization of sound

Sound engine initialization

void _KBSoundHelper::Init()
{
    // init auidio context
    
    ma_engine* engine = new ma_engine();
    ma_result result = ma_engine_init(NULL, engine);
    if (result != MA_SUCCESS)
    {
        LOG("[SoundHelper] Cannot initalize engine, result %d", result);
        return;  // Failed to initialize the engine.
    }
    LOG("[SoundHelper] Engine has been initialized");
    _engine = engine;
    _initialized = true;

}

Sound load & play

/// load sound into context (or prepare it as stream audio)
int _KBSoundHelper::Load(const char*name, int sampleLimit, bool buffered, bool loopable)
{
    if(!_initialized) return -1;

    _KBSound* sound =  new _KBSound(_engine, _lastSoundId++, sampleLimit, name, buffered, loopable);
//    if(buffered) sound->Buffering();
    _sounds[sound->GetId()] = sound;
    return sound->GetId();
}

/// play preloaded sound with attributes
void _KBSoundHelper::Play(int soundId, float volume, float rate, float overDuration, bool changeIfExist)
{
    if(!_initialized) return;

    auto it = _sounds.find(soundId);
    if(it == _sounds.end()) return;
    LOG("play in helper");
    it->second->Play(volume, rate, overDuration, changeIfExist);
}

Sound-files are buffered here

ma_sound* _KBSound::Buffering()
{
    ma_sound* sound = new ma_sound();
    ma_sound_config soundConfig;
    soundConfig = ma_sound_config_init_2(_engine);
    soundConfig.pFilePath   = _fileName; // Set this to load from a file path.
    soundConfig.endCallback = &soundPlaybackEnd;
    soundConfig.pEndCallbackUserData = this;
    soundConfig.flags              = MA_SOUND_FLAG_NO_SPATIALIZATION | MA_SOUND_FLAG_NO_PITCH;// | MA_SOUND_FLAG_STREAM;
    soundConfig.isLooping = _loopable;
    soundConfig.pInitialAttachment = NULL;
    soundConfig.pDoneFence         = NULL;
    soundConfig.channelsOut = 0;

    ma_result result = ma_sound_init_ex(_engine, &soundConfig, sound);
    if (result != MA_SUCCESS)
    {
        LOG("Sound %d cannot be buffered, result %d", _id, result);
        return 0;
    }
    _nativeSounds.push_back(sound);
    return sound;
}

Maybe I'm missing something but don't know what.

from emscripten.

sbc100 avatar sbc100 commented on May 29, 2024

Sounds like a question for the developers of miniaudio perhaps.

from emscripten.

oregu1 avatar oregu1 commented on May 29, 2024

Sounds like a question for the developers of miniaudio perhaps.

Yeah. I asked for his help as well =)

Hoped you both could help me)

from emscripten.

mackron avatar mackron commented on May 29, 2024

miniaudio defaults to a stack size of 16384. I can't remember how I came up with that number, but it can be configured to anything you like via the MA_AUDIO_WORKLETS_THREAD_STACK_SIZE define. Either define it on the command line, or in code like this:

#define MA_AUDIO_WORKLETS_THREAD_STACK_SIZE 32768
#define MINIAUDIO_IMPLEMENTATION
#include "miniaudio.h"

It needs to be visible to the implementation section of miniaudio.h, and it must be a multiple of 16.

If you play around with that and find a value that works for you, I'd be happy to consider upping the default value. The AudioWorklets path of miniaudio is not enabled by default, so I don't think many people are using it which might be why this hasn't been discovered yet.

from emscripten.

oregu1 avatar oregu1 commented on May 29, 2024

miniaudio defaults to a stack size of 16384. I can't remember how I came up with that number, but it can be configured to anything you like via the MA_AUDIO_WORKLETS_THREAD_STACK_SIZE define. Either define it on the command line, or in code like this:

#define MA_AUDIO_WORKLETS_THREAD_STACK_SIZE 32768
#define MINIAUDIO_IMPLEMENTATION
#include "miniaudio.h"

It needs to be visible to the implementation section of miniaudio.h, and it must be a multiple of 16.

If you play around with that and find a value that works for you, I'd be happy to consider upping the default value. The AudioWorklets path of miniaudio is not enabled by default, so I don't think many people are using it which might be why this hasn't been discovered yet.

Unfortunately, MA_AUDIO_WORKLETS_THREAD_STACK_SIZE 32768 doesn't help. Error remains.

from emscripten.

sbc100 avatar sbc100 commented on May 29, 2024

Can you try setting it to 5MB?

Does the error message change? What does it say for the values in the (Attempt to set SP to 0x00065260, with stack limits [0x00065a50 - 0x00069a40] message?

from emscripten.

oregu1 avatar oregu1 commented on May 29, 2024

I set to

#define MA_AUDIO_WORKLETS_THREAD_STACK_SIZE 81920

and error is gone.

from emscripten.

sbc100 avatar sbc100 commented on May 29, 2024

Great! Seems like a straight forward fox. I guess we can close this issue now?

from emscripten.

oregu1 avatar oregu1 commented on May 29, 2024

Yeah I guess so.
Thanks for your help guys. Really appreciate it =)

from emscripten.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.