Author Topic: Stereo output with Mono Left channel / Mono Right Channel  (Read 497 times)

Cafony

  • Posts: 33
Ive made this funtion.

But cant figuire out why cant work:
Mono to stereo out
-----------right channel => right channel
-----------right channel => Left channel


Inicial stream: _stream

Code: [Select]
        public void  CreateMonoOutLeft()
        {
                     
         //int monoStream = BassMix.CreateMixerStream(44100, 2, BassFlags.Default); // 2 channel for stereo
           int monoStream = BassMix.CreateMixerStream(44100, 2, BassFlags.Float | BassFlags.MixerNonStop);


            BassMix.MixerAddChannel(monoStream, _stream, BassFlags.MixerChanDownMix | BassFlags.Float);
            // Set the matrix to swap the left and right channels
                float[,] matrix = { { 1.0f, 0.0f }, // Left speaker plays the left channel
                                        { 1.0f, 0.0f }  // Right speaker also plays the left channel
                          };

                BassMix.ChannelSetMatrix(monoStream, matrix);               
                           
        }
Thanks for help.

Ian @ un4seen

  • Administrator
  • Posts: 26209
The "MixerChanDownMix" flag only enables matrix mixing if downmixing is applicable. It isn't if the mixer and source are both stereo. You should use "MixerChanMatrix" instead to always enable matrix mixing, and that'll hopefully fix the problem you're having. The "BassFlags.Float" flag should also be removed from the MixerAddChannel call, as it's invalid and unnecessary there (the mixer's format is set in the CreateMixerStream call).

Cafony

  • Posts: 33
Im using ManagedBass library
and there is no MixerChannelMatrix method.
How can I do it?
Thanks

Ian @ un4seen

  • Administrator
  • Posts: 26209
Yep, I noticed you were using ManagedBass, so checked that for the flag's name (the original name is BASS_MIXER_CHAN_MATRIX). Here's where it's defined:

   https://github.com/ManagedBass/ManagedBass/blob/5856a8baf538e7d91fa0b4ce6ba5de45d91bb016/src/Bass/Shared/Bass/Enumerations/BassFlags.cs#L427

If you don't see it in your ManagedBass version then you could try "MixerMatrix" instead, which was a previous name for it.

Cafony

  • Posts: 33
Ive made this stream:

Code: [Select]
        public void CreateStream(string filePath)
        {
            Bass.Init();           
            _streamInitial = Bass.CreateStream(filePath, 0, 0, BassFlags.Decode);           
            _stream = BassFx.TempoCreate(_streamInitial, BassFlags.FxFreeSource);
            _mixer = BassMix.CreateMixerStream(44100, 2, BassFlags.Default);
            BassMix.MixerAddChannel(_mixer, _stream, BassFlags.Default);
        }

Can you help on why I can get no sound from this stream.

For using in this PlayMono funtion:

Code: [Select]

        public void PlayMono(bool useLeftChannel, bool stereo = false)
        {
            if (stereo)
            {
                // Add stereo stream to mixer (default behavior)
                BassMix.MixerAddChannel(_mixer, _stream, BassFlags.Default);
            }
            else
            {
                // Split the required channel (left or right)
                int[] splitterChannel = useLeftChannel ? new int[] { 0, -1 } : new int[] { 1, -1 }; // Left: 0, Right: 1
                var splitter = BassMix.CreateSplitStream(_stream, BassFlags.Decode, splitterChannel);

                if (splitter == 0)
                {
                    // Handle error if splitter creation fails
                    MessageBox.Show("Error: " + Bass.LastError);
                    return;
                }

                // Add the selected channel to both sides of the mixer
                BassMix.MixerAddChannel(_mixer, splitter, BassFlags.Mono | BassFlags.SpeakerLeft);
                BassMix.MixerAddChannel(_mixer, splitter, BassFlags.Mono | BassFlags.SpeakerRight);
            }
        }

Then I use

Code: [Select]
Bass.ChannelPlay(_mixer);

But no sound
Thanks

Ian @ un4seen

  • Administrator
  • Posts: 26209
Ive made this stream:

Code: [Select]
        public void CreateStream(string filePath)
        {
            Bass.Init();           
            _streamInitial = Bass.CreateStream(filePath, 0, 0, BassFlags.Decode);           
            _stream = BassFx.TempoCreate(_streamInitial, BassFlags.FxFreeSource);
            _mixer = BassMix.CreateMixerStream(44100, 2, BassFlags.Default);
            BassMix.MixerAddChannel(_mixer, _stream, BassFlags.Default);
        }

Can you help on why I can get no sound from this stream.

That BassMix.MixerAddChannel call will be failing (BASS_ERROR_DECODE) because "_stream" doesn't have the BassFlags.Decode flag set on it. Try adding that flag to the BassFx.TempoCreate call, and if you still get no sound, check all return values to see if any calls are failing.

Cafony

  • Posts: 33
I hadded BassFlags.Decode and it works I have sound.

Now when I activate trought my checkbox my  PlayMono funtion I get double sounds.

Please help.

Ian @ un4seen

  • Administrator
  • Posts: 26209
I do see another problem in the code you posted earlier, here:

Code: [Select]
                // Split the required channel (left or right)
                int[] splitterChannel = useLeftChannel ? new int[] { 0, -1 } : new int[] { 1, -1 }; // Left: 0, Right: 1
                var splitter = BassMix.CreateSplitStream(_stream, BassFlags.Decode, splitterChannel);

                if (splitter == 0)
                {
                    // Handle error if splitter creation fails
                    MessageBox.Show("Error: " + Bass.LastError);
                    return;
                }

                // Add the selected channel to both sides of the mixer
                BassMix.MixerAddChannel(_mixer, splitter, BassFlags.Mono | BassFlags.SpeakerLeft);
                BassMix.MixerAddChannel(_mixer, splitter, BassFlags.Mono | BassFlags.SpeakerRight);

It isn't possible to have a source (ie. "splitter") in a mixer twice. You could instead do the left/right channel duplication in the splitter:

Code: [Select]
                int[] splitterChannel = useLeftChannel ? new int[] { 0, 0, -1 } : new int[] { 1, 1, -1 }; // Left: 0, Right: 1
...
                BassMix.MixerAddChannel(_mixer, splitter, 0);

But it's probably better to use matrix mixing for this sort of thing, as in your first post.

Cafony

  • Posts: 33
Long time pass and still I cant make it work

Mono Right ==> Left out
                  ==> Right out


Code: [Select]
        public void CreateStream(string filePath)
        {
            Bass.Free();
            Bass.Init();           
            _streamInitial = Bass.CreateStream(filePath, 0, 0, BassFlags.Decode);     
             // need this to my Transpose and Tempo funtion           
            _stream = BassFx.TempoCreate(_streamInitial, BassFlags.FxFreeSource);

        }

In my checkbox "Mono Channel Right"

Code: [Select]
   
_mixer = BassMix.CreateMixerStream(44100, 2, BassFlags.Default); // Create a stereo mixer

int[] splitterChannel = new int[] { 0,-1};
var splitter = BassMix.CreateSplitStream(_stream, BassFlags.Default, splitterChannel);

BassMix.MixerAddChannel(_mixer, splitter, BassFlags.Mono | BassFlags.SpeakerLeft);
BassMix.MixerAddChannel(_mixer, splitter, BassFlags.Mono | BassFlags.SpeakerRight);

Bass.ChannelPlay(_mixer);


Im using ManagedBass

The result is double sound and not making the same mono out in boutgh left and right channels.

Please a little help . Thanks


Ian @ un4seen

  • Administrator
  • Posts: 26209
I see a couple of issues there. Firstly, splitter sources need to be decoding channels (BassFlags.Decode), so that BassMix.CreateSplitStream call will fail because "_stream" isn't a decoding channel. Secondly, it isn't possible for a source to be in a mixer twice at the same time, so the second BassMix.MixerAddChannel call would fail.

If you were already playing through a mixer then I would suggest using matrix mixing, but otherwise I think the easiest way to do what you want would be to use the BASS_FX add-on's BASS_FX_BFX_MIX effect (instead of adding a mixer or splitters), but unfortunately it doesn't look like ManagedBass currently includes support for that? If you can't use that BASS_FX effect then the next simplest way would be to use matrix mixing or a splitter, but not both (there's no need for both). For example, using a splitter might look like this:

Code: [Select]
_streamInitial = Bass.CreateStream(filePath, 0, 0, BassFlags.Decode);
_streamTempo = BassFx.TempoCreate(_streamInitial, BassFlags.FxFreeSource | BassFlags.Decode);
_stream = BassMix.CreateSplitStream(_streamTempo, BassFlags.Default, null);
Bass.ChannelPlay(_stream);

...

// "Mono Channel Right"
Bass.StreamFree(_stream);
int[] splitterChannel = new int[] { 1, 1, -1};
_stream = BassMix.CreateSplitStream(_streamTempo, BassFlags.Default, splitterChannel);
Bass.ChannelPlay(_stream);

...

// back to stereo
Bass.StreamFree(_stream);
_stream = BassMix.CreateSplitStream(_streamTempo, BassFlags.Default, null);
Bass.ChannelPlay(_stream);

Cafony

  • Posts: 33
This is "great" it works !
Thanks
Thanks
Thanks

(Do you have a tutorial, so user can study all the great knowledge that ou have?)

Ian @ un4seen

  • Administrator
  • Posts: 26209
Good to see that you've got it working now.

Regarding tutorials, there are some examples included in the BASS packages and ManagedBass has some too, but unfortunately none cover this particular case. In general though, whenever you have any problems, the first thing to do is check all return values to find what's failing, and if something is then check the error code with BASS_ErrorGetCode (Bass.LastError in ManagedBass) and look that up in the failing function's documentation to hopefully find out why.