Created
November 6, 2018 04:24
-
-
Save shiyuugohirao/da2d2306a021f415d71694d290a86104 to your computer and use it in GitHub Desktop.
ofSoundPlayer with std::thread
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void play(string soundPath, bool bOneShotLife=false){ | |
if(ofFile::doesFileExist(soundPath)){ | |
thread soundThread([=]{ | |
ofSoundPlayer sp; | |
sp.load(soundPath); | |
sp.setLoop(false); | |
cout<< "play talk"; | |
int t = ofGetElapsedTimeMicros(); | |
sp.play(); | |
while(sp.isLoaded() && sp.isPlaying()){} | |
cout << " - about"<< ((ofGetElapsedTimeMicros() - t)*0.000001) <<"sec"<<endl; | |
if(bOneShotLife && ofFile::doesFileExist(soundPath)) ofFile::removeFile(soundPath); | |
//else ofLogError("ofxOpenJTalk")<<"not found audio file ("<<soundPath<<")"; | |
}); | |
soundThread.detach(); | |
}else{ | |
ofLogError("ofxOpenJTalk")<<"not found audio file ("<<soundPath<<")"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment