Author Topic: Bass.NET BASS_Mixer and end of mixer sync[solved]  (Read 3341 times)

fishbox

  • Posts: 13
I have a method here that pre-builds a mixer stream:

Code: [Select]
private void RecreatePreviewMix()
        {
            _PreviewMixer = BassMix.BASS_Mixer_StreamCreate(44100, 2, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_MIXER_END);            
            for (int i = 0; i < AllChainSounds.Count; i++)
            {
                if (AllChainSounds[i].SoundName != "<EMPTY>")
                {
                    AllChainSounds[i].StreamChannel = Bass.BASS_StreamCreateFile(AllChainSounds[i].SoundFilePath, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);
                }
                else
                {
                    AllChainSounds[i].StreamChannel = 0;
                }
            }
            int count = 0;
            long cumulativelength = 0;

            foreach (SoundCell sc in AllChainSounds)
            {

                if (sc.SoundName != "<EMPTY>" && count == 0)
                {
                    bool dupfound = false;
                    int _dupstreamchannel = 0;
                    for (int s = count+1; s < AllChainSounds.Count; s++)
                    {
                        if (AllChainSounds[s].StreamChannel == sc.StreamChannel)
                        {
                            dupfound = true;
                            _dupstreamchannel = Bass.BASS_StreamCreateFile(sc.SoundFilePath, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);
                        }
                        
                    }
                    if (dupfound)
                    {
                        BassMix.BASS_Mixer_StreamAddChannel(_PreviewMixer, _dupstreamchannel, BASSFlag.BASS_DEFAULT);
                    }
                    else
                    {
                        BassMix.BASS_Mixer_StreamAddChannel(_PreviewMixer, sc.StreamChannel, BASSFlag.BASS_DEFAULT);
                    }
                    long length = Bass.BASS_ChannelGetLength(sc.StreamChannel);
                    cumulativelength += length;
                    
                }
                if (sc.SoundName != "<EMPTY>" && count > 0)
                {                    
                    //check for repeat streamchannel after current. If so, create new channel
                    bool dupfound = false;
                    int _dupstreamchannel = 0;
                    for (int s = count+1; s < AllChainSounds.Count; s++)
                    {
                        if (AllChainSounds[s].StreamChannel == sc.StreamChannel)
                        {
                            dupfound = true;
                            _dupstreamchannel = Bass.BASS_StreamCreateFile(sc.SoundFilePath, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);
                        }
                        
                    }
                    if (dupfound)
                    {
                        BassMix.BASS_Mixer_StreamAddChannelEx(_PreviewMixer, _dupstreamchannel, 0, cumulativelength, 0);
                    }
                    else
                    {
                        BassMix.BASS_Mixer_StreamAddChannelEx(_PreviewMixer, sc.StreamChannel, 0, cumulativelength, 0);
                    }
                    long length = Bass.BASS_ChannelGetLength(sc.StreamChannel);
                    cumulativelength += length;          
                }
                count++;
            }
            _mySync = new SYNCPROC(EndSync);
            Bass.BASS_ChannelSetSync(_PreviewMixer, BASSSync.BASS_SYNC_END | BASSSync.BASS_SYNC_MIXTIME, 0, _mySync, IntPtr.Zero);
            
        }

with play and stop like so:

Code: [Select]
private void StopButton_Click(object sender, EventArgs e)
        {
            Bass.BASS_ChannelStop(_PreviewMixer);            
            Bass.BASS_ChannelSetPosition(_PreviewMixer, 0);
        }
private void ChainPlayButton_Click(object sender, EventArgs e)
        {            
            Bass.BASS_ChannelSetPosition(_PreviewMixer, 0);
Bass.BASS_ChannelPlay(_PreviewMixer, true);
            
        }

and my end sync which I was hoping would reset the mixer to the start and let me just click Play again:

Code: [Select]
private void EndSync(int handle, int channel, int data, IntPtr user)
        {
            
            // the 'channel' has ended - jump to the beginning
            Bass.BASS_ChannelSetPosition(_PreviewMixer, 0);
            Bass.BASS_ChannelStop(_PreviewMixer);
        }

The stream plays and stops ok, but the end sync doesn't seem to reset to beginning of the stream. Also, when I stop, it doesn't return to start. If I click play during mixer playing, it doesn't restart. So I'm just wonering what I need to do to get those capabilities working correctly with bassmixer.

Thank You!
« Last Edit: 3 Feb '11 - 22:52 by fishbox »

radio42

  • Posts: 4698
Re: Bass.NET BASS_Mixer and end of mixer sync
« Reply #1 on: 3 Feb '11 - 11:59 »
You would need to 'reset' the mixer sources.
(Re)Setting the mixer position wouldn't set the position of its sources.

fishbox

  • Posts: 13
Re: Bass.NET BASS_Mixer and end of mixer sync
« Reply #2 on: 3 Feb '11 - 17:14 »
Still not getting it. I redid my code and simplified it:

Code: [Select]
private void ChainPlayButton_Click(object sender, EventArgs e)
        {           
            Bass.BASS_ChannelPlay(_PreviewMixer, true);           
        }

 private void RecreatePreviewMix()
        {
            _PreviewMixer = BassMix.BASS_Mixer_StreamCreate(44100, 2, BASSFlag.BASS_SAMPLE_FLOAT | BASSFlag.BASS_MIXER_END);
            long cumulativelength = 0;
            for (int i = 0; i < AllChainSounds.Count; i++)
            {
                if (AllChainSounds[i].SoundName != "<EMPTY>" && i == 0)
                {
                    PreviewStreams[i] = Bass.BASS_StreamCreateFile(AllChainSounds[i].SoundFilePath, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);
                    BassMix.BASS_Mixer_StreamAddChannel(_PreviewMixer, PreviewStreams[i], BASSFlag.BASS_DEFAULT);
                    long length = Bass.BASS_ChannelGetLength(PreviewStreams[i]);
                    cumulativelength += length;
                }
                if (AllChainSounds[i].SoundName != "<EMPTY>" && i > 0)
                {
                    PreviewStreams[i] = Bass.BASS_StreamCreateFile(AllChainSounds[i].SoundFilePath, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_SAMPLE_FLOAT);
                    BassMix.BASS_Mixer_StreamAddChannelEx(_PreviewMixer, PreviewStreams[i], BASSFlag.BASS_DEFAULT, cumulativelength, 0);
                    long length = Bass.BASS_ChannelGetLength(PreviewStreams[i]);
                    cumulativelength += length;
                }
                else
                {
                    PreviewStreams[i] = 0;
                }
            }
            _mySync = new SYNCPROC(EndSync);
            Bass.BASS_ChannelSetSync(_PreviewMixer, BASSSync.BASS_SYNC_END | BASSSync.BASS_SYNC_MIXTIME, 0, _mySync, IntPtr.Zero);           
        }
private void EndSync(int handle, int channel, int data, IntPtr user)
        {
           
            Bass.BASS_ChannelStop(_PreviewMixer);
            Bass.BASS_ChannelStop(PreviewStreams[0]);
            Bass.BASS_ChannelStop(PreviewStreams[1]);         
           
            Bass.BASS_ChannelSetPosition(PreviewStreams[0], 0);
            Bass.BASS_ChannelSetPosition(PreviewStreams[1], 0);
           
        }
       
        private void StopButton_Click(object sender, EventArgs e)
        {         
           
            Bass.BASS_ChannelStop(_PreviewMixer);
            Bass.BASS_ChannelStop(PreviewStreams[0]);
            Bass.BASS_ChannelStop(PreviewStreams[1]);
           
            Bass.BASS_ChannelSetPosition(PreviewStreams[0], 0);
            Bass.BASS_ChannelSetPosition(PreviewStreams[1], 0);
        }

I'm just testing 2 or the 8 "PreviewStreams". Using this code, it will play consecutive files fine, but when I stop or endsync, I can't replay the mixer stream again by hitting play button again. Based on your previous post, I inserted manual stop and resets of mixer and positions (I also read somewhere on here that the mixer itself has no position, so I left it out on the BASS_ChannelSetPosition). Am I losing the mixer stream on Stop or endsync? Does it need to be re-created each time I want to play the stream? I tried removing the BASSFlag.BASS_MIXER_END flag and it seems to have no effect.

Thank you for quick response and assistance!

radio42

  • Posts: 4698
Re: Bass.NET BASS_Mixer and end of mixer sync
« Reply #3 on: 3 Feb '11 - 17:29 »
Now you are stopping the mixer channel as well - but do not restart it!
Just (re)add the resetting of the mixer as well (BASS_ChannelSetPosition(_previewMixer, 0)).

fishbox

  • Posts: 13
Re: Bass.NET BASS_Mixer and end of mixer sync
« Reply #4 on: 3 Feb '11 - 18:28 »
Adding the BASS_ChannelSetPosition(_previewMixer, 0) after the Channels Stops from the above code causes the mixer to play both streams consecutively, but then it loops on the second stream endlessly until I click stop. I reversed order of channel stops and resets on stop end endsync to:

Code: [Select]
Bass.BASS_ChannelSetPosition(_PreviewMixer, 0);
            Bass.BASS_ChannelSetPosition(PreviewStreams[0], 0);
            Bass.BASS_ChannelSetPosition(PreviewStreams[1], 0);
            Bass.BASS_ChannelStop(_PreviewMixer);
            Bass.BASS_ChannelStop(PreviewStreams[0]);
            Bass.BASS_ChannelStop(PreviewStreams[1]);         

This fixes the last stream endless loop problem but I still have these issues:

  • Pressing Stop while first stream is playing does not reset to beginning. It does more of a pause and continues from stopped position. Also when that is done on the first stream. Clicking play agin will finish the first stream but not play the second stream
  • Pressing Stop during second stream does not replay again on next Play. Totally dead
  • Pressing Play after complete mixer play and endsync does nothing

Thanks again for any assistance you can provide!

radio42

  • Posts: 4698
Re: Bass.NET BASS_Mixer and end of mixer sync
« Reply #5 on: 3 Feb '11 - 19:27 »
As you are using the the BASS_Mixer_StreamAddChannelEx method and giving a specific 'pos' to start the playback of the 2nd stream you need to re-add those sources.
When resetting the mixer or the source - those positions get lost!
So you can not 'simply' reset the streams and guess it will preserve its previous settings.
In such case you really need to remove all sources and re-add them all again.

fishbox

  • Posts: 13
Re: Bass.NET BASS_Mixer and end of mixer sync
« Reply #6 on: 3 Feb '11 - 22:50 »
OMG yes of course! I just added my RecreatePreview method the end of Stop and Endsync and it works beautifully!

Thanks a bunch for the valuable input!