Author Topic: Cache media in memory from BASS_StreamCreateURL  (Read 703 times)

purenoise

  • Posts: 78
Hi,
I use DownloadProc in BASS_StreamCreateURL
to buffer media File *.

And i'm trying to make caching in memory from void * chunks, and
can't figure it out.

Using c++[ with Qt], and
any suggestions are welcome.

Thanks.

purenoise

  • Posts: 78
Re: Cache media in memory from BASS_StreamCreateURL
« Reply #1 on: 27 Mar '19 - 16:42 »
Implemented storing chunks in vector, but
when i fwrite, header of mp3 file is changed.

How to properly convert const void * to
suitable type ?

Ian @ un4seen

  • Administrator
  • Posts: 22121
Re: Cache media in memory from BASS_StreamCreateURL
« Reply #2 on: 27 Mar '19 - 16:51 »
You can cast the void* pointer to whatever type you need for your vector, eg. char* or byte*.

purenoise

  • Posts: 78
Re: Cache media in memory from BASS_StreamCreateURL
« Reply #3 on: 27 Mar '19 - 18:18 »
You can cast the void* pointer to whatever type you need for your vector, eg. char* or byte*.

Yes, i tried this ways
    const char * cb = static_cast< const char *>( buffer);
    const char * cb = (const char *) buffer;

and also stored copies of "const void * buffer", but
for some reason when i "fwrite" only header of mp3 files
get "scrambled"; rest data chunks is ok.

purenoise

  • Posts: 78
Re: Cache media in memory from BASS_StreamCreateURL
« Reply #4 on: 28 Mar '19 - 07:38 »
Made it working, but
not sure it's good.

1. For each buffer chunk

Code: [Select]
    char * cb = ( char *) buffer;

    for( int i = 0; i < length; i ++)

        vChar.push_back( cb[ i]);

And i ned to save

Code: [Select]
        ofstream of( "buffered.mp3", ofstream:: binary);
        copy( begin( vChar), end( vChar),
              ostreambuf_iterator< char>( of));

If someone has better method,
please post.
If it helps someone, good.

Ian @ un4seen

  • Administrator
  • Posts: 22121
Re: Cache media in memory from BASS_StreamCreateURL
« Reply #5 on: 28 Mar '19 - 12:52 »
Something like this may be a bit more efficient:

Code: [Select]
char *cb = (char *)buffer;
vChar.insert(vChar.end(), &cb[0], &cb[length]);

...

ofstream of("buffered.mp3", ofstream::binary);
of.write(&vChar[0], vChar.size());
of.close();

purenoise

  • Posts: 78
Re: Cache media in memory from BASS_StreamCreateURL
« Reply #6 on: 28 Mar '19 - 14:43 »
Definitely,
Thank You.
[ Answered topic]