20 May '13 - 06:21 *
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]
  Reply  |  Print  
Author Topic: [solved] Changing stream for BASS_Encode_ServerInit  (Read 343 times)
raketenhund
Posts: 3


« on: 10 Jul '12 - 14:23 »
Reply with quoteQuote

Hello BASS community,

I'm trying to create a audio streaming server for my local network. Streaming to the internet is not allowed so as far as I know the only possibility is using the BASS_Encode_ServerInit function.

I'm able to start a server and to connect to it via VLC i have no idea how to switch to another stream without restarting the server. Currently this is what I've done:

stream = Bass.BASS_StreamCreateFile("MYFILE.mp3", 0L, 0L, BASSFlag.BASS_DEFAULT);

_encoderHandle = BassEnc.BASS_Encode_Start(stream, "lame -r -s 44100 -b 128 -", un4seen.Bass.AddOn.Enc.BASSEncode.BASS_ENCODE_NOHEAD, null, IntPtr.Zero);
if (_encoderHandle == 0)
  return false;

_serverHandle = Un4seen.Bass.AddOn.Enc.BassEnc.BASS_Encode_ServerInit(_encoderHandle, "127.0.0.1:" + Port.ToString(), 8000, 8000, Un4seen.Bass.AddOn.Enc.BASSEncodeServer.BASS_ENCODE_SERVER_DEFAULT, clientProc, IntPtr.Zero);
if (_serverHandle == 0)
  return false;

Bass.BASS_ChannelPlay(stream, false);

What would be the best way, to change the currently playing track?

Thanks in advance!

raketenhund
« Last Edit: 10 Jul '12 - 16:01 by raketenhund » Logged
Ian @ un4seen
Administrator
Posts: 15244


« Reply #1 on: 10 Jul '12 - 15:11 »
Reply with quoteQuote

An encoder can be moved to another stream via the BASS_Encode_SetChannel function. If you would like that to happen at the end of a stream, you could use a BASS_SYNC_END sync. It could look something like this...

BASS_ChannelSetSync(stream, BASS_SYNC_END, 0, EndSyncProc, NULL); // set an END sync on the stream

...

void CALLBACK EndSyncProc(HSYNC handle, DWORD channel, DWORD data, void *user)
{
BASS_Encode_SetChannel(encoder, nextstream); // move the encoder to the next stream
BASS_ChannelPlay(nextstream, 0); // start the next stream
}

Note the encoder will still be expecting the same sample format (sample rate and channel count) when it is moved to another stream, so all of your files should have the same sample format. If they don't, then they will need to be resampled to a common format. That can be done with the BASSmix add-on, eg. create a mixer (via BASS_Mixer_StreamCreate) with the wanted format and set the encoder on that, and then plug the streams into it (via BASS_Mixer_StreamAddChannel) one after another. Note the streams will need to be "decoding channels" in that case (add the BASS_STREAM_DECODE flag to the BASS_StreamCreateFile calls).
Logged
raketenhund
Posts: 3


« Reply #2 on: 10 Jul '12 - 15:13 »
Reply with quoteQuote

Thank you for your fast response! Smiley

I'll try it and post the result!
Logged
raketenhund
Posts: 3


« Reply #3 on: 10 Jul '12 - 16:00 »
Reply with quoteQuote

I tested what you said and it works perfectly!

Thanks again!
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines