Author Topic: Broadcast Mixer 8 Channels  (Read 335 times)

Ed1966

  • Posts: 105
Broadcast Mixer 8 Channels
« on: 17 Nov '18 - 09:47 »
Hello,

I Broadcast with Mixer and 2 channels everything is fine.

But now I use Mixer with 8 channels and Broadcast is not correct. Slow and crackling.

Can you give some pointers to fix this? Kind of DOWNMIX 8 > 2 for broadcasting?
I can not find some solution or FLAGS.

Code: [Select]

  case FP_BroadCast[AServerIndex].Data.SetBroadCastStream of

    bcoLoopBack:  BroadCastStream := TWASAPI_LoopBack.GetStream; // 2 Chans

    { This must be 2 Chans for Broadcast? Need 8 for SPEAKER control MasterMixer }
    bcoMixer:  BroadCastStream := MasterMixer18.GetStream; // 8 Chans

    bcoLineMonitor:  BroadCastStream := SilenceMixer18.GetStream; // 2 Chans

  end;

  if not FP_BroadCast[AServerIndex].StartEncoder(TWASAPI_LoopBack.GetInfo, EncoderPath,   
    BroadCastStream, SetEncodeEnableQueue, True) then Exit;


Regards,
Eduard.
« Last Edit: 17 Nov '18 - 11:24 by Ed1966 »

Ian @ un4seen

  • Administrator
  • Posts: 21370
Re: Broadcast Mixer 8 Channels
« Reply #1 on: 19 Nov '18 - 13:43 »
Are you also playing the 8 channel mixer or is it only for generating the broadcast mix? If the latter, you could just reduce it to 2 channels in its BASS_Mixer_StreamCreate call. If the former, do you want to broadcast 2 channels from the mix (ignoring the other 6), or downmix it to stereo so that all channels are present? The solution will be different in those 2 scenarios: a splitter stream can be used to extract 2 channels from the mix, or another mixer can be used to downmix to stereo (with BASS_MIXER_DOWNMIX or BASS_MIXER_MATRIX).

Ed1966

  • Posts: 105
Re: Broadcast Mixer 8 Channels
« Reply #2 on: 20 Nov '18 - 06:31 »
I play 8 channels through the speakers. But these have to go together to 2 channels for broadcasting. So I need BASS_MIXER_DOWNMIX.
Here something has been tried but get Decoded error. And don't know if this is the right solution?

Code: [Select]
  BroadCastStream := BASS_Mixer_StreamCreate(48000, 2, BASS_SAMPLE_FLOAT or BASS_STREAM_DECODE or BASS_MIXER_NONSTOP);
  BASS_Mixer_StreamAddChannel(BroadCastStream, MasterMixer18.GetStream, BASS_MIXER_DOWNMIX);
  BASS_ChannelPlay(BroadCastStream, True); // Start     

  //  BASS_ErrorGetCode:  'the channel is/isn''t a "decoding channel"', // 38 (BASS_Mixer_StreamAddChannel)

Can you help me little bit further?
« Last Edit: 20 Nov '18 - 06:35 by Ed1966 »

Ian @ un4seen

  • Administrator
  • Posts: 21370
Re: Broadcast Mixer 8 Channels
« Reply #3 on: 20 Nov '18 - 14:55 »
The issue there is that the main mixer isn't a "decoding channel", so it can't be plugged into the broadcast mixer. To fix that, you could set a DSP function on the main mixer and have that feed the data to a "push" stream, which is plugged into the broadcast mixer. To prevent the broadcast mixer processing delaying the main mixer, you can have it processed asynchronously by playing it muted. All of that could look something like this:

Code: [Select]
BroadCastStream = BASS_Mixer_StreamCreate(48000, 2, BASS_SAMPLE_FLOAT); // create broadcast mixer
BroadCastBufferStream = BASS_StreamCreate(48000, 8, BASS_SAMPLE_FLOAT | BASS_STREAM_DECODE, STREAMPROC_PUSH, NULL); // create push stream with same format as main mixer
BASS_Mixer_StreamAddChannel(BroadCastStream, BroadCastBufferStream, BASS_MIXER_DOWNMIX); // plug it into broadcast mixer with downmixing enabled
// set encoder on broadcast mixer here
BASS_ChannelSetDSP(MainMixer, BroadcastDSP, NULL, -1000); // set a DSP function on main mixer
BASS_ChannelSetAttribute(BroadCastStream, BASS_ATTRIB_VOL, 0); // mute the broadcast mixer
BASS_ChannelPlay(BroadCastStream, 0); // start it

...

void CALLBACK BroadcastDSP(HDSP handle, DWORD channel, void *buffer, DWORD length, void *user)
{
BASS_StreamPutData(BroadCastBufferStream, buffer, length); // pass the data to the push stream
}

Note the default downmixing matrix won't set all 8 channels to the same level in the stereo downmix. If you want them to be the same then you will need to set the matrix. For example:

Code: [Select]
float matrix[2][8] = { // 2 outputs x 8 inputs
{0.25, 0, 0.25, 0, 0.25, 0, 0.25, 0}, // left out = 25% of all odd inputs
{0, 0.25, 0, 0.25, 0, 0.25, 0, 0.25} // right out = 25% of all even inputs
};
BASS_Mixer_ChannelSetMatrix(BroadCastBufferStream, matrix); // apply it

Please see the documentation for details on all of the mentioned functions.
« Last Edit: 23 Nov '18 - 14:53 by Ian @ un4seen »

Ed1966

  • Posts: 105
Re: Broadcast Mixer 8 Channels
« Reply #4 on: 22 Nov '18 - 08:43 »
I have problems sending out. No sound.

Code: [Select]

  var
  BroadCastBufferStream,
  BroadCastStream: HSTREAM;

  procedure BroadcastDSP(handle: HDSP; channel: DWORD; buffer: Pointer; length: DWORD; user: Pointer); stdcall;
  begin
    BASS_StreamPutData(BroadCastBufferStream, buffer, length); // pass the data to the push stream
  end;

  Procedure Start;
  begin
   // MasterMixer18.GetStream (Working stream local 8 channels)

    UseFreq := FP_BroadCast[AServerIndex].Data.SetCastFrequency; // 48000
    BASS_StreamFree(BroadCastStream); // Free

    BroadCastStream := BASS_Mixer_StreamCreate(UseFreq, 2, BASS_SAMPLE_FLOAT); // create broadcast mixer
    BroadCastBufferStream := BASS_Mixer_StreamCreate(UseFreq, 8, BASS_SAMPLE_FLOAT or BASS_STREAM_DECODE); // create push stream with same format as main mixer   
    BASS_Mixer_StreamAddChannel(BroadCastStream, BroadCastBufferStream, BASS_MIXER_DOWNMIX); // plug it into broadcast mixer with downmixing enabled
    // set encoder on broadcast mixer here
    BASS_ChannelSetDSP(MasterMixer18.GetStream, @BroadcastDSP, 0, -1000); // set a DSP function on main mixer   
    BASS_ChannelSetAttribute(BroadCastStream, BASS_ATTRIB_VOL, 0); // mute the broadcast mixer   
    BASS_ChannelPlay(BroadCastStream, True); // start it 

    // BroadCastStream = Used to broadcast data!
  end;


When I use:

Code: [Select]
  BroadCastStream := BASS_ChannelSetDSP(MasterMixer18.GetStream, @BroadcastDSP, 0, -1000); // set a DSP function on main mixer

Unvalid next line.

Using Delphi. Can you see what I am doing wrong?

Ed1966

  • Posts: 105
Re: Broadcast Mixer 8 Channels
« Reply #5 on: 22 Nov '18 - 09:05 »
I have problems sending out. No sound.

Code: [Select]

  var
  BroadCastBufferStream,
  BroadCastStream: HSTREAM;

  procedure BroadcastDSP(handle: HDSP; channel: DWORD; buffer: Pointer; length: DWORD; user: Pointer); stdcall;
  begin
    BASS_StreamPutData(BroadCastBufferStream, buffer, length); // pass the data to the push stream
  end;

  Procedure Start;
  begin
   // MasterMixer18.GetStream (Working stream local 8 channels)

    UseFreq := FP_BroadCast[AServerIndex].Data.SetCastFrequency; // 48000
    BASS_StreamFree(BroadCastStream); // Free

    BroadCastStream := BASS_Mixer_StreamCreate(UseFreq, 2, BASS_SAMPLE_FLOAT); // create broadcast mixer
    BroadCastBufferStream := BASS_Mixer_StreamCreate(UseFreq, 8, BASS_SAMPLE_FLOAT or BASS_STREAM_DECODE); // create push stream with same format as main mixer   
    BASS_Mixer_StreamAddChannel(BroadCastStream, BroadCastBufferStream, BASS_MIXER_DOWNMIX); // plug it into broadcast mixer with downmixing enabled
    // set encoder on broadcast mixer here
    BASS_ChannelSetDSP(MasterMixer18.GetStream, @BroadcastDSP, 0, -1000); // set a DSP function on main mixer   
    BASS_ChannelSetAttribute(BroadCastStream, BASS_ATTRIB_VOL, 0); // mute the broadcast mixer   
    BASS_ChannelPlay(BroadCastStream, True); // start it 

    // BroadCastStream = Used to broadcast data!
  end;


When I use:

Code: [Select]
  BroadCastStream := BASS_ChannelSetDSP(MasterMixer18.GetStream, @BroadcastDSP, 0, -1000); // set a DSP function on main mixer

Unvalid next line.

Using Delphi. Can you see what I am doing wrong?
Or is BASS_Mixer_ChannelSetMatrix the problem? Not added and tested.

Ian @ un4seen

  • Administrator
  • Posts: 21370
Re: Broadcast Mixer 8 Channels
« Reply #6 on: 22 Nov '18 - 17:39 »
I have problems sending out. No sound.

Are the listeners receiving data but it contains silence?

When I use:

Code: [Select]
  BroadCastStream := BASS_ChannelSetDSP(MasterMixer18.GetStream, @BroadcastDSP, 0, -1000); // set a DSP function on main mixer

Unvalid next line.

Using Delphi. Can you see what I am doing wrong?

Do you mean the compiler is giving an error message on that line? If so, please post exactly what it says.

The third parameter is a pointer, so you should probably use "nil" instead of 0 there.

Ed1966

  • Posts: 105
Re: Broadcast Mixer 8 Channels
« Reply #7 on: 23 Nov '18 - 09:46 »
Hello again,

1. The listeners receiving data but it contains silence, correct.

2. I ment: BASS_ERROR_HANDLE - handle is not a valid channel. Ok now.

I Added 'BASS_Mixer_ChannelSetMatrix'. Full source now:

Code: [Select]
const
  // 2 outputs x 8 inputs
  OutputMatrix: array[1..2] of array [1..8] of Single =
  (
    (0.25, 0, 0.25, 0, 0.25, 0, 0.25, 0), // left out = 25% of all odd inputs
  (0, 0.25, 0, 0.25, 0, 0.25, 0, 0.25)  // right out = 25% of all even inputs
  );

var
  DSPResult: HDSP;
  BroadCastBufferStream,
  BroadCastStream: HSTREAM;

procedure BroadcastDSP(handle: HDSP; channel: DWORD; buffer: Pointer; length: DWORD; user: Pointer); stdcall;
begin
  BASS_StreamPutData(BroadCastBufferStream, buffer, length); // pass the data to the push stream
end;

procedure Start;
begin
  BroadCastStream := BASS_Mixer_StreamCreate(UseFreq, 2, BASS_SAMPLE_FLOAT); // create broadcast mixer
  BroadCastBufferStream := BASS_Mixer_StreamCreate(UseFreq, 8, BASS_SAMPLE_FLOAT or BASS_STREAM_DECODE); // create push stream with same format as main mixer
  Result := BASS_Mixer_StreamAddChannel(BroadCastStream, BroadCastBufferStream, BASS_MIXER_DOWNMIX); // plug it into broadcast mixer with downmixing enabled
   
  // set encoder on broadcast mixer here
  DSPResult := BASS_ChannelSetDSP(MasterMixer18.GetStream, @BroadcastDSP, nil, -1000); // set a DSP function on main mixer
 
  Result := BASS_Mixer_ChannelSetMatrix(BroadCastBufferStream, @OutputMatrix); // apply it
     
  Result := BASS_ChannelSetAttribute(BroadCastStream, BASS_ATTRIB_VOL, 0); // mute the broadcast mixer
  Result := BASS_ChannelPlay(BroadCastStream, True); // start it     
end;

LOG: You can see Broadcast is valid:

23-11-2018 10:32:48 ~ DownMix: Frequency (48000)
23-11-2018 10:32:48 ~ DownMix: InputMasterMixer (2147483659)
23-11-2018 10:32:48 ~ DownMix: BASS_Mixer_StreamCreateStream (-2147483587)
23-11-2018 10:32:48 ~ DownMix: BASS_Mixer_StreamCreateStream (-2147483585)
23-11-2018 10:32:48 ~ DownMix: BASS_Mixer_StreamAddChannel (0, True)
23-11-2018 10:32:48 ~ DownMix: BASS_ChannelSetDSPResult (-2147483582)
23-11-2018 10:32:48 ~ DownMix: BASS_Mixer_ChannelSetMatrix (0, True)
23-11-2018 10:32:48 ~ DownMix: BASS_ChannelSetAttribute (0, True)
23-11-2018 10:32:48 ~ DownMix: BASS_ChannelPlay (0, True)
23-11-2018 10:32:48 ~ DownMix: OutputMasterMixer (2147483709)
23-11-2018 10:32:48 ~ Broadcast: Encoder (48000, 256)
23-11-2018 10:32:48 ~ Broadcast: EncoderCommand: lame -r -s 48000 -b 256 -
23-11-2018 10:32:48 ~ Broadcast: EncoderContent: audio/mpeg
23-11-2018 10:32:48 ~ Broadcast: BASS_Encode_Start (2144)
23-11-2018 10:32:48 ~ Broadcast: BASS_Encode_CastInit (Default) (True)

I can not solve the problem. Suggestions?

Regards,
Eduard.
« Last Edit: 23 Nov '18 - 09:51 by Ed1966 »

Ian @ un4seen

  • Administrator
  • Posts: 21370
Re: Broadcast Mixer 8 Channels
« Reply #8 on: 23 Nov '18 - 14:54 »
Oops! I see I accidentally put BASS_Mixer_StreamCreate instead of BASS_StreamCreate to create the "BroadCastBufferStream" stream in my post above. As a result of that, the BASS_StreamPutData call will be failing and the broadcast mixer will have no data to play. I have updated the code now. See if you still get a problem with that.

Ed1966

  • Posts: 105
Re: Broadcast Mixer 8 Channels
« Reply #9 on: 23 Nov '18 - 15:52 »
Thanks.

We now got sound but fast sound like speedy gonzales?
(There is also little disturbance but can be test line)
I tried 44100 and 48000 with 256Kbit for broadcasting.

Any idea?

Ian @ un4seen

  • Administrator
  • Posts: 21370
Re: Broadcast Mixer 8 Channels
« Reply #10 on: 23 Nov '18 - 16:47 »
That probably means the push stream (BroadCastBufferStream) doesn't have the correct sample rate. Note it should have the same rate (and channel count) as the main mixer that's feeding it, not necessarily the same as the broadcast mixer.

Ed1966

  • Posts: 105
Re: Broadcast Mixer 8 Channels
« Reply #11 on: 23 Nov '18 - 16:56 »
The BASS_Init frequency you mean?

Ian @ un4seen

  • Administrator
  • Posts: 21370
Re: Broadcast Mixer 8 Channels
« Reply #12 on: 23 Nov '18 - 17:01 »
No, the "freq" (and "chans") parameter used in the BASS_Mixer_StreamCreate call that created the main mixer ("MasterMixer18.GetStream" handle in your code).

Ed1966

  • Posts: 105
Re: Broadcast Mixer 8 Channels
« Reply #13 on: 23 Nov '18 - 17:11 »
Thank You. I will figure it out this weekend. :)