Author Topic: Playing Stream from memory  (Read 141 times)

Steve

  • Posts: 12
Playing Stream from memory
« on: 19 Apr '17 - 13:23 »
I'm trying to play a stream from memory. The stream is an .ogg music file.

If I create a stream from file, all works well. However, if I load the .ogg file to memory and then try to play it I just get silence. There's no BASS errors, so it seems like it should be working.

Here's my code:

Code: [Select]
    CfileIO file;
    file.openFromFile(fullfile, "rb", false);

    char *buffer;
    buffer = (char*)malloc(file.getSize());
    file.read(buffer, file.getSize(), 1);

    musicStreamID = BASS_StreamCreateFile(true, buffer, 0, file.getSize(), BASS_STREAM_AUTOFREE);
// Old code to play from file --- musicStreamID = BASS_StreamCreateFile(FALSE, filename, 0, 0, BASS_STREAM_AUTOFREE);

    file.close();
   
    if(!musicStreamID)
        engine->debugMsg.printff(EdebugMsg_Error, "BASS AUDIO: Can't play file %s: %s", fullfile, getBassErrorString());

    bool res = BASS_ChannelPlay(musicStreamID, FALSE);
    if(!res)
    {
        engine->debugMsg.printff(EdebugMsg_Error, "%s", getBassErrorString());
    }

    return musicStreamID;

The code returns a valid handle and the ChannelPlay function returns TRUE, but I don't hear any music.
Any ideas?

I've tried this code on Windows and Android and get the same results.

Ian @ un4seen

  • Administrator
  • Posts: 19987
Re: Playing Stream from memory
« Reply #1 on: 19 Apr '17 - 16:33 »
Are you only having the problem with a particular OGG file, or all files? Also, are you keeping the memory block in place (not freeing it) while the stream exists? Note that BASS_StreamCreateFile won't make a copy of it, so it needs to persist while the stream does.

I'm not familiar with the "CfileIO" class. Did you create that yourself? Just to be sure that's working properly, you could try writing the read data back to another file, and then compare the 2 files, eg. run "fc /b original.ogg new.ogg"

Steve

  • Posts: 12
Re: Playing Stream from memory
« Reply #2 on: 20 Apr '17 - 15:09 »
Sorry, I'm an idiot and it was working. The code is ok, it was my code that was setting the volume to zero.

Anyway, the reason I was having to make this change is because on Android you can't just open a file and stream from it in C++ using fopen because all files are zipped up in the apk.

So you know of a way round this on the off chance?

Ian @ un4seen

  • Administrator
  • Posts: 19987
Re: Playing Stream from memory
« Reply #3 on: 20 Apr '17 - 15:21 »
You could give the "BASS.Asset" class a try, something like this:

Code: [Select]
stream = BASS.BASS_StreamCreateFile(new BASS.Asset(getAssets(), "music.ogg"), 0, 0, 0);