Results 1 to 10 of 10

Thread: QFile stream to SDL_mixer

  1. #1
    Join Date
    Jun 2007
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QFile stream to SDL_mixer

    Hello

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

    Qt Code:
    1. Mix_LoadMUS(":/sounds/resources/beep.ogg");
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: QFile stream to SDL_mixer

    Read about QDataStream.
    Having an opened QFile, you can open a QDataStream on it with:
    Qt Code:
    1. QFile file( ... );
    2. if( !file.open(...) )
    3. ...show error
    4.  
    5. QDataStream stream( &file );
    To copy to clipboard, switch view to plain text mode 

    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

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QFile stream to SDL_mixer

    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

  4. #4
    Join Date
    Jun 2007
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFile stream to SDL_mixer

    Thx.
    I think i can use this SDL function

    Mix_QuickLoad_RAW(Uint8 *mem, Uint32 len);

    Does qunit8 and Uint8 are compatible?

  5. #5
    Join Date
    Jun 2007
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFile stream to SDL_mixer

    @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 ...

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: QFile stream to SDL_mixer

    Quote Originally Posted by doitux View Post
    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

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: QFile stream to SDL_mixer

    Quote Originally Posted by doitux View Post
    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?

  8. #8
    Join Date
    Jun 2007
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFile stream to SDL_mixer

    @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.

  9. #9
    Join Date
    Jun 2007
    Posts
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFile stream to SDL_mixer

    Ok i tried another sdl way with wave files.

    Therfore i use:
    Qt Code:
    1. /* Load a wave file of the mixer format from a memory buffer */
    2. extern DECLSPEC Mix_Chunk * SDLCALL Mix_QuickLoad_WAV(Uint8 *mem);
    To copy to clipboard, switch view to plain text mode 

    This compiles correct but if i call this the app crashes

    Qt Code:
    1. QFile myFile(":data/resources/data/beep.wav");
    2. if(!myFile.open(QIODevice::ReadOnly)) cout << "could not load wav" << endl;
    3. QDataStream in(&myFile);
    4. //
    5. Uint8 *myMem = new Uint8;
    6. quint8 tempMem1;
    7. in >> tempMem1;
    8. quint8 *tempMem2 = new quint8;
    9. tempMem2 = &tempMem1;
    10. myMem = tempMem2;
    11.  
    12. Mix_QuickLoad_WAV(myMem);
    To copy to clipboard, switch view to plain text mode 

    What is wrong here?

  10. #10
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    8
    Thanked 541 Times in 521 Posts

    Default Re: QFile stream to SDL_mixer

    Qt Code:
    1. QFile myFile(":data/resources/data/beep.wav");
    2. if(!myFile.open(QIODevice::ReadOnly)) cout << "could not load wav" << endl;
    3. QDataStream in(&myFile);
    4. Uint8 *myMem = new Uint8[(int)myFile.size()];
    5. in.readRawData( (char*)myMem, (int)myFile.size() );
    6. Mix_QuickLoad_WAV( myMem );
    7. delete[] myMem;
    To copy to clipboard, switch view to plain text mode 

    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.