PDA

View Full Version : QFile stream to SDL_mixer



doitux
2nd June 2007, 09:08
Hello

At first i have tried to use the Qt resources feature (*.qrc) directly in the SDL_mixer funktion Mix_LoadMus() like this:


Mix_LoadMUS(":/sounds/resources/beep.ogg");

Unfortunately that doesn't work.
Somebody told me to load the resource into a QFile --> "QFile myFile (":/sounds/resources/beep.ogg") and stream the content to Mix_LoadMUS().

Can anybody tell me how to do this streaming?

regards
doitux

marcel
2nd June 2007, 09:15
Read about QDataStream.
Having an opened QFile, you can open a QDataStream on it with:


QFile file( ... );
if( !file.open(...) )
...show error

QDataStream stream( &file );


To read from the stream you can use any of the convenience operator, or you can read in bigger chunks with readRawData, or readBytes, etc, depending on what you need the data for.

Regards

wysota
2nd June 2007, 09:20
The problem is SDL is not aware of Qt streams or classes, so it won't work unless there is a variant of the function that takes a block of memory containing the data instead of reading it from a file. If not, then you have to use a real file. BTW. Embedding oggs into the executable is not the best idea... I don't even know if its legal :)

doitux
2nd June 2007, 09:35
Thx.
I think i can use this SDL function

Mix_QuickLoad_RAW(Uint8 *mem, Uint32 len);

Does qunit8 and Uint8 are compatible?

doitux
2nd June 2007, 09:42
@wysota:

Why should it be illegal to include oggs?
Some of our users ask for a --nowriteaccess feature to save power on their notebooks ;) or to port to Zaurus. So we try to include all data into one static linked binary. It works fine for all files (gfx and so on) but sound ... ;)

marcel
2nd June 2007, 09:54
Thx.
I think i can use this SDL function

Mix_QuickLoad_RAW(Uint8 *mem, Uint32 len);

Does qunit8 and Uint8 are compatible?

Yes, they are. Also they match char.

Regards

wysota
2nd June 2007, 12:03
Why should it be illegal to include oggs?
If your application is commercial and OGG is licenced under let's say LGPL, then you have to allow the user to substitute the licenced content with something else, therefore embedding an OGG file directly into the binary without providing sources of the application would be illegal. Of course it all applies provided that OGG is LPGLed :)


Some of our users ask for a --nowriteaccess feature to save power on their notebooks ;) or to port to Zaurus. So we try to include all data into one static linked binary. It works fine for all files (gfx and so on) but sound ... ;)

What does write access have to do with reading files?

doitux
2nd June 2007, 13:49
@wysota: our application is opensource. The static linking is just for release. The source files including the sounds are als available to download.


What does write access have to do with reading files?
If we compile everything in a binary and need some files read from hdd we have to uncompress and save it when the application runs the first time.

doitux
2nd June 2007, 14:02
Ok i tried another sdl way with wave files.

Therfore i use:

/* Load a wave file of the mixer format from a memory buffer */
extern DECLSPEC Mix_Chunk * SDLCALL Mix_QuickLoad_WAV(Uint8 *mem);

This compiles correct but if i call this the app crashes :confused:


QFile myFile(":data/resources/data/beep.wav");
if(!myFile.open(QIODevice::ReadOnly)) cout << "could not load wav" << endl;
QDataStream in(&myFile);
//
Uint8 *myMem = new Uint8;
quint8 tempMem1;
in >> tempMem1;
quint8 *tempMem2 = new quint8;
tempMem2 = &tempMem1;
myMem = tempMem2;

Mix_QuickLoad_WAV(myMem);

What is wrong here?

marcel
2nd June 2007, 14:56
QFile myFile(":data/resources/data/beep.wav");
if(!myFile.open(QIODevice::ReadOnly)) cout << "could not load wav" << endl;
QDataStream in(&myFile);
Uint8 *myMem = new Uint8[(int)myFile.size()];
in.readRawData( (char*)myMem, (int)myFile.size() );
Mix_QuickLoad_WAV( myMem );
delete[] myMem;


It is not clear to me what you were trying to do in the first place, but you were not allocating those buffers OK there.
Try this one, but remember if those wav files are pretty big ( tens-hundreds of mb ) you will have to load them in chunks.

Anyway, it seems to me that you don't know many things about mem allocations. Please ask then, because if your app contains more of those allocations, then I'm afraid it won't work.

Regards