Author Topic: Mixing two stream channels and record result to hard disk/stream to web  (Read 3068 times)

Ian @ un4seen

  • Administrator
  • Posts: 24589
BASS_ChannelGetDevice is returning 5 after the BASS_ChannelSetDevice call with device=2? If so, please also check the BASS_ChannelSetDevice return value and error code.

kafffee

  • Posts: 136
Quote
BASS_ChannelGetDevice is returning 5 after the BASS_ChannelSetDevice call with device=2?

Yes. And BASS_ChannelSetDevice is returning True and BASS_ErrorGetCode 0.

Ian @ un4seen

  • Administrator
  • Posts: 24589
That's very strange then, as I don't see how it's possible for BASS_ChannelSetDevice to succeed without actually setting the device. Can you confirm that 5 is the BASS_ChannelGetDevice return value, not the error code? If it's the error code (BASS_ERROR_HANDLE), that may make more sense. Are you definitely using the same handle in the BASS_ChannelSetDevice and BASS_ChannelGetDevice calls?

kafffee

  • Posts: 136
Hey Ian, sorry for the late response, I've been very busy this week.  :(

I checked again, and you were right, all of the returned values are good. So for me, everything is fine.

But I encountered another issue:

When I want to pause/resume playback of a source channel, I get 8658944 as a result of BASS_Mixer_ChannelFlags (both calls), but nothing happens. This is my code:

Code: [Select]
Public IsPlaying As Boolean = False
 Public IsNewSong As Boolean = True


Public Sub Play_Execute(obj As Object)

If IsNewSong = True Then
            Bass.BASS_ChannelStop(stream)
            BassMix.BASS_Mixer_ChannelRemove(MainModule.streamfx(WhichDeck - 1))
            If stream <> 0 Then Bass.BASS_StreamFree(stream)
            stream = Bass.BASS_StreamCreateFile(CurrentMP3Info.Filename, 0, 0, BASSFlag.BASS_STREAM_PRESCAN Or BASSFlag.BASS_STREAM_DECODE)

            If MainModule.streamfx(WhichDeck - 1) <> 0 Then Bass.BASS_StreamFree(MainModule.streamfx(WhichDeck - 1))

            MainModule.streamfx(WhichDeck - 1) = BassFx.BASS_FX_TempoCreate(stream, BASSFlag.BASS_FX_FREESOURCE Or BASSFlag.BASS_STREAM_DECODE)
           
BassMix.BASS_Mixer_StreamAddChannel(MainModule.mixer, MainModule.streamfx(WhichDeck - 1), BASSFlag.BASS_MIXER_NORAMPIN Or BASSFlag.BASS_STREAM_AUTOFREE Or BASSFlag.BASS_MIXER_BUFFER)
IsPlaying = True
Else
If IsPlaying = True Then
                Dim success As BASSFlag = BassMix.BASS_Mixer_ChannelFlags(MainModule.streamfx(WhichDeck - 1), BASSFlag.BASS_MIXER_PAUSE, BASSFlag.BASS_DEFAULT)
                Debug.WriteLine(CStr(success))      'success returns 8658944
                IsPlaying = False
                IsNewSong = False
            Else
                Dim success As BASSFlag = BassMix.BASS_Mixer_ChannelFlags(MainModule.streamfx(WhichDeck - 1), Nothing, BASSFlag.BASS_DEFAULT)
                Debug.WriteLine(CStr(success))      'success returns 8658944
                IsPlaying = True
                IsNewSong = False
            End If
        End If
End Sub

Play_Execute is called when I hit the play/pause button.

When I want to start a new song, PlayNewTrack is called:

Code: [Select]
Public Sub PlayNewTrack_Execute(obj As Object)
        CurrentMP3Info = Playlist(PlaylistSelectedIndex)
        IsNewSong = True
        Abspielen_Execute(Nothing)
        IsNewSong = False
    End Sub

What am I doing wrong?

I guess it's something with the BassMix.BASS_Mixer_ChannelFlags calls... I cannot find the bass flag value 8658944 in the .NET docs of Bassflag...
« Last Edit: 17 Jul '22 - 13:51 by kafffee »

Ian @ un4seen

  • Administrator
  • Posts: 24589
Good to hear that the previous issue is resolved.

8658944 is 0x842000 in hex, which means these flags are set: BASS_MIXER_CHAN_BUFFER (0x2000), BASS_STREAM_AUTOFREE (0x40000), BASS_MIXER_CHAN_NORAMPIN (0x800000).

The issue in your case appears to be that your BASS_Mixer_ChannelFlags "mask" parameter is 0, which means don't modify any flags (only fetch them). If you want to change the BASS_MIXER_PAUSE flag then that should be included there, like this:

Code: [Select]
BASS_Mixer_ChannelFlags(channel, BASS_MIXER_PAUSE, BASS_MIXER_PAUSE); // set PAUSE flag

BASS_Mixer_ChannelFlags(channel, 0, BASS_MIXER_PAUSE); // remove PAUSE flag

Guest

  • Guest
Ich verstehe es nicht..
Du prüfst immer noch auf TRUE/FALSE warum?
Code: [Select]
If IsNewSong = True ThenNochmal
Code: [Select]
If IsNewSong Then
und was machst du wenn BASS_Mixer_StreamAddChannel fehlschlägt?
Warum gehst du dann davon aus das IsPlaying in dem fall dann True ist und du es auch noch selber setzt?
Code: [Select]
IsPlaying = TrueDie korrekte Herangehensweise wäre wenn du die Rückgabe von BASS_Mixer_StreamAddChannel auswertest..

Entweder
Code: [Select]
if BassMix.BASS_Mixer_StreamAddChannel(MainModule.mixer, MainModule.streamfx(WhichDeck - 1), BASSFlag.BASS_MIXER_NORAMPIN Or BASSFlag.BASS_STREAM_AUTOFREE Or BASSFlag.BASS_MIXER_BUFFER) <> 0 then
  IsPlaying = True

Oder
Code: [Select]
IsPlaying = BassMix.BASS_Mixer_StreamAddChannel(MainModule.mixer, MainModule.streamfx(WhichDeck - 1), BASSFlag.BASS_MIXER_NORAMPIN Or BASSFlag.BASS_STREAM_AUTOFREE Or BASSFlag.BASS_MIXER_BUFFER) <> 0
Entschuldige aber da ist noch einiges im argen bei dir.

Guest

  • Guest
Sorry habe nochmal nach der API geschaut..
Rückgabe von BASS_Mixer_StreamAddChannel ist BOOL

Daher ist die Prüfung auf <> 0 natürlich falsch.
So ist es stimmig!

Code: [Select]
IsPlaying = BassMix.BASS_Mixer_StreamAddChannel(MainModule.mixer, MainModule.streamfx(WhichDeck - 1), BASSFlag.BASS_MIXER_NORAMPIN Or BASSFlag.BASS_STREAM_AUTOFREE Or BASSFlag.BASS_MIXER_BUFFER)
if Not IsPlaying then
  BASS_ErrorGetCode.. bla,bla

kafffee

  • Posts: 136
@Guest

Alles klar danke für den Hinweis  :)

Ich muss aber noch was hinzufügen:
Ich glaube in VisualBasic.NET gibt es keine Unterscheidung zwischen Bool und Boolean, sondern nur Boolean, jedenfalls soweit ich weiss, hab auch noch mal kurz gegoogelt.
« Last Edit: 19 Jul '22 - 09:40 by kafffee »

Guest

  • Guest
@Guest

Alles klar danke für den Hinweis  :)

Ich muss aber noch was hinzufügen:
Ich glaube in VisualBasic.NET gibt es keine Unterscheidung zwischen Bool und Boolean, sondern nur Boolean, jedenfalls soweit ich weiss, hab auch noch mal kurz gegoogelt.

Ich denke das dir die BASS.NET API schon den korrekten Daten Typ zurück gibt wäre in VB.NET so wie du sagst Boolean.
Da mußt du dich nicht drum kümmern der Compiler sagt dir schon wenn was schief läuft  :)

kafffee

  • Posts: 136
@Ian

Now it works fine! Thank you again  :)

@Guest

Ja, IntelliSense sei dank! Kanns mir gar nicht mehr ohne vorstellen...  :)

kafffee

  • Posts: 136
Another question:

With my current setup, which consists of two regular stream channels, two stream effects channels to apply effects like pitch, tempo, equalizer on it and a mixer that the fx channels are "plugged" into, which is the correct respectively best way to stop a channel? Just call BASS_ChannelStop on the original (regular) stream channels?

Chris

  • Posts: 2082
Hi,
BASS_Mixer_ChannelRemove......
Will remove the Channel from the mixer

kafffee

  • Posts: 136
Hey Chris :-)

I think I have to go further into detail: What if I want to stop recording a live radio stream, as follows:

Code: [Select]
If IsRecording Is False Then
If fs IsNot Nothing Then
                    fs.Close()
                    fs.Dispose()
                End If
                fs = New System.IO.FileStream(MP3Path & "\recorded radio streams\" & StationRecorded & " - " & Date & ".mp3", FileMode.CreateNew)
Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_NET_BUFFER, 300)
                Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_BUFFER, 300)
                Bass.BASS_ChannelSetAttribute(chan, BASSAttribute.BASS_ATTRIB_MIDI_TRACK_VOL, 1)
DownloadProcedure = New DOWNLOADPROC(AddressOf MyDownload)
                Dim url As String = listPlayList(lstPlaylist.SelectedIndex).Filename
stream = Bass.BASS_StreamCreateURL(url, 0, BASSFlag.BASS_STREAM_AUTOFREE, DownloadProcedure, CType(0, IntPtr))
                Bass.BASS_ChannelPlay(chan, False)
Else
Bass.BASS_ChannelStop(stream)
End If

End Sub

Private Sub MyDownload()
[...]
End Sub

So instead of BASS_ChannelPlay and BASS_ChannelStop should I use BASS_Mixer_StreamAddChannel and BASS_Mixer_ChannelRemove instead, just like I was only playing the stream without recording?

Ian @ un4seen

  • Administrator
  • Posts: 24589
I see you're using a DOWNLOADPROC callback (MyDownload) on the stream. I guess that's saving the downloaded data, so when you say you want to "stop recording", do you mean you want to stop that being called?

kafffee

  • Posts: 136
@Ian

Ok at this point I have to make up my mind whether to record like above or just record the mixer channel (which I have already implemented)...

I will reply when I have any further questions... Thank you so far  :)

Ian @ un4seen

  • Administrator
  • Posts: 24589
OK. If you did happen to want to stop the DOWNLOADPROC being called, I was going to say that that option will be available in the next BASS release (and in the current beta), but you can also achieve similar by setting a variable for the DOWNLOADPROC to check before it does anything (ie. do nothing when it is set).