Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
Hi everybody. As I was looking for some code without finding anything to be able to load my sound files from the Irrlicht engine, I'm creating this thread to share my own code. This allow you for exemple to load all your sounds from archives loaded previously with Irrlicht. Includes there 4 files into your project : -IrrlichtSoundFactory.hpp -IrrlichtSoundFactory.cpp -IrrlichtSoundFileReader.hpp -IrrlichtSoundFileReader.cpp Content of files : IrrlichtSoundFactory.hpp :
IrrlichtSoundFactory.cpp :
IrrlichtSoundFileReader.hpp :
IrrlichtSoundFileReader.cpp : [code] #include <KLANG/irrKlang.h> #include <cstdlib> #include <iostream> #include "IrrlichtSoundFileReader.hpp" #include <IRR/irrlicht.h> using namespace irrklang; using namespace irr; IrrlichtSoundFileReader::Irrlich |
||||
|
Thanks for sharing. But note that this will cause problems if you are using some streaming files from the same archive as other files, because the Irrlicht zip file reader is not thread safe. A simple workaround would be to put files which are streamed into another zip file, the correct solution of course would be to make the seeking and reading inside the irrlicht zip file reader thread safe. |
||||
|
Hi, So, as irrKlang is multithreading, while we ask the irrlicht filesystem to load a file, for exemple a 3D Mesh from an archive witch contain also a sound file now playing in streaming, the irrklang engine could try to read a little bit of the sound file, and then it would occur a memory / file access conflit... As i'm not experimented in C++ threading, I would try create a bool value, and turn it to true before loading a file from irrlicht, set it to false after the loading, something like that :
And then give a ref of this boolean to irrklang. Then in the IrrlichtSoundFileReader at the read() method, test this boolean value and don't load anything while the other loading isn't finished :
As the irrklang is multithreading, this while block wouldn't block the main program... However this method is really weight as you have to change isLoading value each time you're doing a file loading in Irrlicht. Personally, as I'll use only not streamed sounds, I will stay with the first part of my code. But I would be intrusted in seeing if this idea could works... Thank, Stef. |
||||
|
Could work, but you really should use some of the multhreading functions of your os (Windows) to do this checking, setting a bool variable is not atomic, unfortunately. |
||||
|
the last file in this post is incomplete. Where can I get the full code? |
||||
|
problem is solved |
||||
|
Please share the solution? :P |
||||
|
thanks for sharing the last file IrrlichtSoundFileReader.cpp is incomplete! can i have it , and an exemple how to use it ? |
|