Author Topic: Listen, cast and save to disk a BASS_Mixer_StreamCreate output simultaneously  (Read 202 times)

mkllc

  • Posts: 58
Hi, I'm trying to listen on speakers, save on the disk as file (encoded in Vorbis, BASS_Encode_OGG_StartFile) and broadcast (using cast to icecast, BASS_Encode_CastInit) the output of a mixer (BASS_Mixer_StreamCreate) with several added streams (2 or 3, BASS_StreamCreateFile) and a external input from sound card (BASS_RecordStart, BASS_Mixer_StreamAddChannel).

Not all playing at the same time, maybe only two of them at the same time but most of time only one. I think this last point will not change the approach as I can StreamAddChannel, ChannelRemove or even mute the source on need. The speakers are on a single output device. And if latency between stream input and speakers output could be around 100ms or less could be appreciated, but <1s will be ok.

The problem is a mixer need BASS_STREAM_DECODE source streams so... how to play in real-time thru the speakers and how I can use everything to encode to file and to cast, this will need an BASS_STREAM_DECODE mixer too (and ideally using different bitrate for each so I think I will need different encoders, not sure if they can share the same source or the lib doing the internal ChannelGetData will steal data from each other encoder).

So, how to play to hear the mixer on speakers (and how to control mixed streams as a separated/independent players: play, pause, stop, seek, get time, change volume level etc. without stalling the mixer or interfering each other) and at the same time have the mixer data available to encode to save to disk and cast. I looked at the BASS_Split_StreamCreate but doesn't seem the ideal solution as streams will get out-of-sync between can is hear on speaker and what is encoded/cast/saved and I should have to manage play, pause, etc. separately... not ideal for me, a lot of duplicated and error-prone code.

Maybe it's simply not possible and I need a different "architecture" or approach to accomplish this. I just need a few pointers in the right direction and some advice on which flags I should use. Thanks!

Ian @ un4seen

  • Administrator
  • Posts: 24792
Do you want to hear the same mix that is being encoded? If so, you could simply play the mixer (don't set BASS_STREAM_DECODE on it) and set the encoders on it too. You should also set the BASS_ENCODE_QUEUE flag on the encoders then to prevent them delaying the mixing/playback.

mkllc

  • Posts: 58
Yes I want to hear the mix that is being encoded (like a master output) and encode it to broadcast and to file.

Can I pass the mix_chan to both encoders at the same time and they get copied data instead of stealing each other?

And what about added file streams, can I still control play, pause, seek, set volume of a specific channel on the mix, get length etc? because if I add BASS_StreamCreateFile with BASS_STREAM_DECODE needed by the mixer I can't do BASS_ChannelPlay onto it.

Ian @ un4seen

  • Administrator
  • Posts: 24792
Yes I want to hear the mix that is being encoded (like a master output) and encode it to broadcast and to file.

Can I pass the mix_chan to both encoders at the same time and they get copied data instead of stealing each other?

Yes, it is fine for multiple mixers to have the same source.

And what about added file streams, can I still control play, pause, seek, set volume of a specific channel on the mix, get length etc? because if I add BASS_StreamCreateFile with BASS_STREAM_DECODE needed by the mixer I can't do BASS_ChannelPlay onto it.

You would play the sources by adding them to the mixer, ie. use BASS_Mixer_StreamAddChannel instead of BASS_ChannelPlay. For pausing, you would set the BASS_MIXER_CHAN_PAUSE flag via BASS_Mixer_ChannelFlags, and unset it to resume. For seeking, you would use BASS_Mixer_ChannelSetPosition instead of BASS_ChannelSetPosition. Setting the volume and getting the length are unchanged.