Sound ogg, vorbis & vorbisfile with emscripten

354 views
Skip to first unread message

wolfviking0

unread,
Apr 25, 2013, 9:39:38 AM4/25/13
to emscripte...@googlegroups.com
Hi, I m plug the openal part of Unigine engine, i add the missing function inside library_openal, and i build ogg, vorbis and vorbisfile.

For read an ogg i have a classic function : 

int SoundFileVorbis::load(const char *name) {

file = new File();

if(file->open(name,"rb") == 0) {

Log::error("SoundFileVorbis::load(): can't open \"%s\" file\n",name);

delete file;

file = NULL;

return 0;

}

ov_callbacks callbacks;

callbacks.read_func = vorbis_read_function;

callbacks.seek_func = vorbis_seek_function;

callbacks.tell_func = vorbis_tell_function;

callbacks.close_func = NULL;

        int res = ov_open_callbacks(file,&vf,NULL,0,callbacks);

if(res < 0) {

Log::error("SoundFileVorbis::load(): \"%s\" is not ogg bitstream : error %d\n",name,res);

clear();

return 0;

}

vi = ov_info(&vf,-1);

data_size = (size_t)ov_pcm_total(&vf,-1) * vi->channels * 2;

return 1;

}



But aparently i have a big memory leak when it's build with emscripten, i can see the memory of firefox increase and give me an assert about enlarge memory.

Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value, (2) compile with ALLOW_MEMORY_GROWTH which adjusts the size at runtime but prevents some optimizations, or (3) set Module.TOTAL_MEMORY before the program runs.:
abort@file:///Users/wolfviking/Desktop/WebGL/html/js/allengine.js:397
enlargeMemory@file:///Users/wolfviking/Desktop/WebGL/html/js/allengine.js:645
Runtime.staticAlloc@file:///Users/wolfviking/Desktop/WebGL/html/js/allengine.js:377
_sbrk@file:///Users/wolfviking/Desktop/WebGL/html/js/allengine.js:12487
_malloc@file:///Users/wolfviking/Desktop/WebGL/html/js/allengine.js:18219
__Znwj@file:///Users/wolfviking/Desktop/WebGL/html/js/allengine.js:18219
__ZNK19ExternClassFunctionI5Image8TypeListIvS1_IiS1_IiS1_IiS1_IfS1_IfS1_IfS1_If11TypeListEndEEEEEEEEPFvPS0_iiiffffEE5cloneEv@file:///Users/wolfviking/Desktop/WebGL/html/js/allengine.js:18214
__get_next_page@file:///Users/wolfviking/Desktop/WebGL/html/js/allengine.js:18207
__fetch_headers@file:///Users/wolfviking/Desktop/WebGL/html/js/allengine.js:18207
__ov_open1@file:///Users/wolfviking/Desktop/WebGL/html/js/allengine.js:18207
_ov_open_callbacks@file:///Users/wolfviking/Desktop/WebGL/html/js/allengine.js:18207
__ZN15SoundFileVorbis4loadEPKc@file:///Users/wolfviking/Desktop/WebGL/html/js/allengine.js:18212
__ZN9SoundFile4loadEPKc@file:///Users/wolfviking/Desktop/WebGL/html/js/allengine.js:18212
__ZN14ALSampleStaticC2EPKc@file:///Users/wolfviking/Desktop/WebGL/html/js/allengine.js:18212
__ZNK14ALSoundManager20create_sample_staticEPKc@file:///Users/wolfviking/Desktop/WebGL/html/js/allengine.js:18212
__ZN24SoundManagedSampleStatic6createEv@file:///Users/wolfviking/Desktop/WebGL/html/js/allengine.js:18212
__ZN13AmbientSource4playEv@file:///Users/wolfviking/Desktop/WebGL/html/js/allengine.js:18212
__ZNK19ExternClassFunctionI13AmbientSource8TypeListIv11TypeListEndEMS0_FvvEE3runEPS0_R5StackI8VariableLi2048EE@file:///Users/wolfviking/Desktop/WebGL/html/js/allengine.js:18212
__ZNK11ExternClassI13AmbientSourceE12run_functionEPviR5StackI8VariableLi2048EE@file:///Users/wolfviking/Desktop/WebGL/html/js/allengine.js:18212
__ZNK11ExternClassI13AmbientSourceE12run_functionEiiiR5StackI8VariableLi2048EE@file:///Users/wolfviking/Desktop/WebGL/html/js/allengine.js:18212
__ZN7Machine3runEi@file:///Users/wolfviking/Desktop/WebGL/html/js/allengine.js:18214
__ZN11Interpreter11runFunctionEi@file:///Users/wolfviking/Desktop/WebGL/html/js/allengine.js:18213
__ZN17EngineInterpreter11runFunctionEPKci@file:///Users/wolfviking/Desktop/WebGL/html/js/allengine.js:18207
__ZN5World9loadWorldEPKcS1_@file:///Users/wolfviking/Desktop/WebGL/html/js/allengine.js:18211
__ZN5World10world_loadEiPPc@file:///Users/wolfviking/Desktop/WebGL/html/js/allengine.js:18211

I just begin the test, but may be someone try to do something similar for read ogg file ?? I digg a little more the problem but the same code work perfectly when he build natively.

wolfviking0

unread,
Apr 25, 2013, 10:41:43 AM4/25/13
to emscripte...@googlegroups.com
Ok i just make a basic sample for debug and, i found some little thing : 

1) The result is different if i use ASM_JS=0 or ASM_JS=1

ASM_JS=1
-----------------
Load sound.oga ...
AL --> Before callback read_func ...
7:
abort@file:///Users/wolfviking/Desktop/ogg_asm/sample.html:490
b7@file:///Users/wolfviking/Desktop/ogg_asm/sample.html:37535
__get_data@file:///Users/wolfviking/Desktop/ogg_asm/sample.html:27942
__get_next_page@file:///Users/wolfviking/Desktop/ogg_asm/sample.html:27197
__fetch_headers@file:///Users/wolfviking/Desktop/ogg_asm/sample.html:27512
__ov_open1@file:///Users/wolfviking/Desktop/ogg_asm/sample.html:26121
_ov_open_callbacks@file:///Users/wolfviking/Desktop/ogg_asm/sample.html:26005
_main@file:///Users/wolfviking/Desktop/ogg_asm/sample.html:29212
callMain@file:///Users/wolfviking/Desktop/ogg_asm/sample.html:39110
doRun@file:///Users/wolfviking/Desktop/ogg_asm/sample.html:39149
@file:///Users/wolfviking/Desktop/ogg_asm/sample.html:39168

ASM_JS=0
-----------------

Load sound.oga ...
AL --> Before callback read_func ...

but inside the web console i have [16:36:19.687] TypeError: FUNCTION_TABLE[$12] is not a function @ file:///Users/wolfviking/Desktop/ogg_asm/sample.html:28186



2) Seems very similar at the problem with Freetype is about callback too :

ov_open_callbacks it's a function for open ogg, it's call some callback define like : 

ov_callbacks callbacks;
callbacks.read_func = vorbis_read_function;
callbacks.seek_func = vorbis_seek_function;
callbacks.tell_func = vorbis_tell_function;
callbacks.close_func = NULL;
 
int res = ov_open_callbacks(file,&vf,NULL,0,callbacks);

Where vorbis_read_function / vorbis_seek_function / vorbis_tell_function are some function define static in my code.

The last stack i found is when the callbacks must be call, inside vorbisfile.c line 72 : 

static long _get_data(OggVorbis_File *vf){
  errno=0;
  if(!(vf->callbacks.read_func))return(-1);
  if(vf->datasource){
    char *buffer=ogg_sync_buffer(&vf->oy,READSIZE);
    printf("AL --> Before callback read_func ...\n");    <-- OK
    long bytes=(vf->callbacks.read_func)(buffer,1,READSIZE,vf->datasource); <-- STOP
    printf("AL --> After callback read_func %ld\n",bytes);    
    if(bytes>0)ogg_sync_wrote(&vf->oy,bytes);
    if(bytes==0 && errno)return(-1);
    return(bytes);
  }else
    return(0);
}

Hi add a very short sample test. 

Tony

ogg_asm.zip

wolfviking0

unread,
Apr 26, 2013, 5:33:54 AM4/26/13
to emscripte...@googlegroups.com
HI,

Apparently, the problem with ogg callback are not the same of freetype, this time i don't have any warning about pointer function.

Looking inside the js i found the function calbback vorbis_read_function but apparently javascript say it not found the function inside the TABLE_FUNCTION.

Any idea ??

Alon Zakai

unread,
Apr 26, 2013, 9:10:11 PM4/26/13
to emscripte...@googlegroups.com
Thanks for the testcase, was easy to work with.

So, this is a related problem with function pointers. Not something new with asm.js, actually a problem we always had. In clang, C and C++ calling conventions for structures passed by value are different, and this breaks for us. We normally show a warning for this, but due to 2 unrelated issues it was not shown here. I fixed those two issues on incoming now.

I will write some docs for these function pointer issues at

https://github.com/kripken/emscripten/wiki/CodeGuidlinesAndLimitations

but basically the solution is not to mix C and C++ where using a structure passed by value. Passing a pointer to it would work, or don't mix C and C++ in that location.

- Alon



--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages