Author Topic: playing from a memory stream  (Read 3618 times)

m4him

  • Posts: 4
playing from a memory stream
« on: 23 Jul '05 - 00:39 »
I have an uncompressed mp3 file in a memorystream.  I would like to play it from that memorystream without reading it from a disk file.  How is this done?  I have been unable to figure it out.  I am using C# but will translate code from VB or C.

Sebastian Andersson

  • Posts: 372
Re: playing from a memory stream
« Reply #1 on: 23 Jul '05 - 01:35 »
If you load an MP3 file into a memory stream, you'd need to get the pointer of the actual data and pass it to BASS. I don't know C#, so I can't really provide an example. Once you have the pointer to the sample data (in memory), set the "mem" parameter in "BASS_StreamCreateFile" to "TRUE", and pass the pointer at the second parameter, and finally, set the fourth parameter to the actual length of the sample data. See the BASS documentation for more information.

m4him

  • Posts: 4
Re: playing from a memory stream
« Reply #2 on: 23 Jul '05 - 18:06 »
;D I accomplished the task!

First I added

Public Declare Function BASS_StreamCreateFile Lib "bass.dll" (ByVal mem As BassBool, ByRef f As Byte, ByVal offset As Integer, ByVal Length As Integer, ByVal flags As StreamCreateFile) As Integer
       
to the Base12.vb file

Here is my c# code to play a mp3 file from memory via a byte array.  This array I loaded from my database blob field where I have stored mp3 samples.

byte[] bv;
private void btnPlay_Click(object sender, System.EventArgs e)
{         
bv=GetMp3();  //retrieves mp3 data from dbase file blob field
strm = Bass.BASS_StreamCreateFile(Un4seen.BassLib21.Bass.BassBool.BassTrue, ref bv[0], 0,(int)bv.Length,0) ; 
if (strm==0)
{            
Bass.Bass_ErrorCodes code = (Bass.Bass_ErrorCodes)Bass.BASS_ErrorGetCode();
MessageBox.Show(Bass.BASS_GetErrorDescription(ref code));
         }
BB = Bass.BASS_ChannelPlay(strm,Un4seen.BassLib21.Bass.BassBool.BassFalse);
this.timer.Enabled=true;
}

Bass works perfectly even with large mp3 files playing from memory.

I was very interested in FMOD but had a great deal of trouble getting it to play from memory.  When I did get it to play there were problems with the buffer length and would not play large mp3 files of about 15 minutes of playing time in length without a memory error.  The FMOD 4.x library now comes with a c# wrapper and it only costs $100.00 dollars for the shareware license, has better documentation, and many more examples. 
I don't know if BASS is better or not but it works better for my application of saving mp3 files to a database and playing them from that database.

Sebastian Andersson

  • Posts: 372
Re: playing from a memory stream
« Reply #3 on: 23 Jul '05 - 19:36 »
;D I accomplished the task!

Goodie. :)

I was very interested in FMOD but had a great deal of trouble getting it to play from memory. When I did get it to play there were problems with the buffer length and would not play large mp3 files of about 15 minutes of playing time in length without a memory error. The FMOD 4.x library now comes with a c# wrapper and it only costs $100.00 dollars for the shareware license, has better documentation, and many more examples.
I don't know if BASS is better or not but it works better for my application of saving mp3 files to a database and playing them from that database.

Well, if you ask me, BASS is way better than both FMOD and FMOD Ex. BASS is fast, small and very easy to implement. Not only that, BASS has support for most formats out there (lossy and lossless) through add-ons, and an add-on called "BASS_FX" which allows you to manipulate the sound (pitch, tempo etc). Finally, the support that Ian Luck (and the community) provides can probably not be found anywhere else. If there's a problem that involves BASS (ie. not a problem on your side), patches will usually be released instantly to sort your issue.

Edit: Typo.
« Last Edit: 23 Jul '05 - 21:12 by Sebastian Andersson »

Stalkingwolf

  • Posts: 11
Re: playing from a memory stream
« Reply #4 on: 23 Jul '05 - 19:47 »
i'm using both. FMOD and BASSMOD and i have to say that the BASSMOD delivers better sound output.
I've downloaded the FMOD Ex and checked the documentation and examples. Brett changed everything and i have to think about it to change from FMOD 3.74 to FMOD Ex. The reason why i added the FMOD was because it does not used much CPU performance. But now i've got the BASSMOD. It use as low cpu performance as FMOD, but delivers a better sound output.

Ok i have to say i'm using both ( and some other) libs only to play Module Tracks (MOD/IT/S3M/MOD) :-)

Sven

Noel Quipit

  • Guest
Re: playing from a memory stream
« Reply #5 on: 24 Apr '21 - 00:49 »
this is my problem too. anyone can answer this?