Author Topic: Bass.net - Stream decoding and getting data  (Read 33 times)

anes08

  • Posts: 22
Bass.net - Stream decoding and getting data
« on: 10 Jun '21 - 16:05 »
Hello !
I used bass for over a year now and I'm liking it  ;D . Now I'm trying to stream sound data to Discord as a Raw PCM data , but since my whole experience with Bass didn't involve such things , I could figure it out , What I have in my head now is :
1-Make stream
2-Decode data
3-Pull data as byte array
4-Copy stream data to Discord PCM Stream
Making a stream is done using the
Code: [Select]
Bass.BASS_StreamCreate Methods but the rest I couldn't find a way to it .
Thank you!

Ian @ un4seen

  • Administrator
  • Posts: 23619
Re: Bass.net - Stream decoding and getting data
« Reply #1 on: 11 Jun '21 - 14:20 »
What is the source of the data? If it's a file then you should use BASS_StreamCreateFile rather than BASS_StreamCreate. You should also use the BASS_STREAM_DECODE flag in that call, which will then allow you to use BASS_ChannelGetData to get the decoded data. Something like this:

Code: [Select]
DWORD decoder = BASS_StreamCreateFile(false, filename, 0, 0, BASS_STREAM_DECODE); // create decoder for file
...
BYTE buffer[buflen];
int got = BASS_ChannelGetData(decoder, buffer, buflen); // get data from the decoder
...
BASS_StreamFree(decoder); // free the decoder

Repeat the BASS_ChannelGetData call until it returns -1 (at the end).

anes08

  • Posts: 22
Re: Bass.net - Stream decoding and getting data
« Reply #2 on: 11 Jun '21 - 20:00 »
Hello,
Thank you for your reply,
I don't know if i'm not figuring this out correctly but i'm still stuck , the code i'm having right now is
Code: [Select]
Dim discord = audioClient.CreatePCMStream(Audio.AudioApplication.Music)
        Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero)
        Dim decoder = Bass.BASS_StreamCreateFile("D:\Music\Release Me - Tevlo.mp3", 0, 0, BASSFlag.BASS_STREAM_DECODE) ' create decoder For file                               
        Dim Buffer(511) As Byte
        Dim Got = Bass.BASS_ChannelGetData(decoder, Buffer, BASSData.BASS_DATA_FFT1024) ' get data from the decoder 
        Do
            Try
                Got = Bass.BASS_ChannelGetData(decoder, Buffer, BASSData.BASS_DATA_FFT1024) ' get data from the decoder                 
                If got = -1 Then Exit Do
                Dim MemStream As New IO.MemoryStream(Buffer)
                MemStream.CopyTo(discord)
            Catch
            Finally
                discord.Flush()
            End Try
        Loop
        Bass.BASS_StreamFree(decoder) ' free the decoder
As you can see , i'm trying to fetch the decoded audio data to discord, the code i got fomr discord in the documentation is for FFMPEG , i'll post it , maybe it can help you understand me better.
Code: [Select]
        Using ffmepg = CreateStream("D:\Music\Release Me - Tevlo.mp3")
            Using output = ffmepg.StandardOutput.BaseStream
                Using discord = audioClient.CreatePCMStream(Audio.AudioApplication.Mixed)
                    Try
                        output.CopyTo(discord)
                    Catch
                    Finally
                        discord.Flush()
                    End Try
                End Using
            End Using
        End Using
I tried checking the data , and here is what i got


Thank you again.