19 Jun '13 - 10:52 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: 1 [2]  All
  Reply  |  Print  
Author Topic: Rewinding internet radio stream  (Read 2147 times)
std66
Posts: 20


« Reply #20 on: 26 Apr '12 - 14:52 »
Reply with quoteQuote

That is OK, but BASS still doesn't call the StreamRead method. But why?
Logged
Ian @ un4seen
Administrator
Posts: 15363


« Reply #21 on: 26 Apr '12 - 15:40 »
Reply with quoteQuote

Have you called BASS_ChannelPlay to start the stream that's using the "StreamRead" STREAMPROC function? The STREAMPROC function wouldn't be called until that (or BASS_ChannelUpdate).
Logged
std66
Posts: 20


« Reply #22 on: 26 Apr '12 - 15:58 »
Reply with quoteQuote

Well, I solved the problem partially. If I comment out this line:
BytesRead |= (int)BASSStreamProc.BASS_STREAMPROC_END;
BASS calls the StreamRead function, but no sound is played because RawStorage.Read returns 0 (that means no data was read and I get a byte array that has a length of "(int) Length" with "0" values). So if I can solve the problem, I will be able to seek in the raw data.
Logged
Ian @ un4seen
Administrator
Posts: 15363


« Reply #23 on: 27 Apr '12 - 14:19 »
Reply with quoteQuote

The BASS_STREAMPROC_END flag tells BASS that there is no more data to come, so you shouldn't set that if there will be more data coming.

If you're using the same "MemoryStream" for reading and writing, you will need to synchronize access to it so that the STREAMPROC and DSPPROC functions aren't ever trying to read and write at the same time. I believe .Net provides a "lock" statement that you can use for that, perhaps something like this...
 
private void DSPCallback(int Handle, int Channel, IntPtr Buffer, int Length, IntPtr User) {
byte[] Buf = new byte[Length];
Marshal.Copy(Buffer, Buf, 0, Length);
lock (this.RawStorage) {
        this.RawStorage.Position = writepos;
        this.RawStorage.Write(Buf , 0, length);
        writepos = this.RawStorage.Position;
}
}

...

private int StreamRead(int Handle, IntPtr Buffer, int Length, IntPtr User) {
if (this.RawStorage != null) {
byte[] Data = new byte[Length];
int BytesRead;
lock (this.RawStorage) {
this.RawStorage.Position = readpos;
BytesRead = this.RawStorage.Read(Data, 0, Length);
}
readpos += BytesRead;
Marshal.Copy(Data, 0, Buffer, Length);
return BytesRead;
}
else {
return 0;
}
}
Logged
std66
Posts: 20


« Reply #24 on: 27 Apr '12 - 16:20 »
Reply with quoteQuote

Thank you so much. Playing back from MemoryStream works.
Logged
std66
Posts: 20


« Reply #25 on: 11 May '12 - 17:45 »
Reply with quoteQuote

I solved the rewinding too, it works great. I use FileStream instead of MemoryStream, because the PCM wave data uses a high amount of storage space. But is there any way to distinguish whether the URL is a radio stream or just an uploaded fixed-size file?
« Last Edit: 11 May '12 - 17:57 by std66 » Logged
Ian @ un4seen
Administrator
Posts: 15363


« Reply #26 on: 14 May '12 - 15:22 »
Reply with quoteQuote

But is there any way to distinguish whether the URL is a radio stream or just an uploaded fixed-size file?

You could use BASS_ChannelGetLength for that, ie. if the call fails then the length is unknown.
Logged
std66
Posts: 20


« Reply #27 on: 14 May '12 - 18:02 »
Reply with quoteQuote

Thank you for your help. I finished this part of my software completely.
Logged
Pages: 1 [2]  All
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines