c++ - Using PlayFile apple example with OpenGL freezes OpenGL until playing sound is over -


i working on little app in c++ xcode uses opengl. tried find way add simple sounds app. not succesful openal (alut not available in mac) , couldn't make sfml , sdl work on system. decided try apple's playfile example:

http://developer.apple.com/library/mac/#samplecode/playfile/introduction/intro.html#//apple_ref/doc/uid/dts40008651

i can play sounds using example. however, when sound starts playing, opengl freezes, namely animation stops until sound done playing.

i checked file playfile.cpp , found line:

    usleep ((int)(fileduration * 1000. * 1000.)); 

which think responsible freezing opengl. before line, start playing sound. after line clean buffers. there way can change code, that, sound starts playing, opengl continues tasks, once sound done playing clean buffers? tried use other solutions pointers, clean after playing started, can not make sound out of app.

any suggestions?

ok, after days of research found way fix problem. used pthread create multiple threads, 1 each sound. added

#include <pthread.h> 

to file defines thread. defined list sounds , threads:

pthread_t threads[3]; string sounds[3] = {"back.wav", "arrow1.wav", "arrow2.wav"}; 

and used simple function:

void * playsound(void *threadid) { long tid; tid = (long)threadid; player(sounds[tid], 1); pthread_exit(null); } 

that plays sound when create thread:

pthread_create(&threads[2], null, playsound, (void *)2); 

this way animation can combined sound easily.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -