Author Topic: sample code for "Bass.BASS_SampleCreate" from the documentation doesnt work for  (Read 358 times)


  • Guest
I cant bring this sample code to work. And i do not know in what direction i should look for the mistake?
Can somebody help to fix the code or point me to the right direction?

I dont get an error BUT i dont hear a sinustone from the speakers!
I thought i should hear a continous sinus tone (if i use other code like play a .mp3 with bass all works fine).

officel exsample code from:

Code: [Select]
' for 4.5 is linked (ref. is set)
'bass.dll and are in the application folder
'System Windows 10 // Visual Studio Community 2017 // Framework 4.5
'officle Sample Code from :
'no sound from speakers when application is started
'I thought a continous sinus tone would be heared when the program is started.
'Maybe amplitude is wrong (first values for data(0)= 0 data(1)=3212 data(2)=6393...)// hmmm max Amplitude 32767 and -32767 looks correct so
'Maybe the sample is only played once and is to short to be heared // ChannelPlay Flag is set to True instead of False
Imports System
Imports Un4seen.Bass

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ' create the sample
        Dim sample As Integer = Bass.BASS_SampleCreate(256, 28160, 1, 1, BASSFlag.BASS_SAMPLE_LOOP Or BASSFlag.BASS_SAMPLE_OVER_POS)
        ' the data buffer (256 byte = 128 Int16)
        Dim data(128 - 1) As Short
        ' create the sine wave
        Dim a As Integer
        For a = 0 To 127
            data(a) = CShort(32767.0 * Math.Sin((CDbl(a) * 6.283185 / 64.0)))
        Next a
        ' set the sample's data
        Bass.BASS_SampleSetData(sample, data)
        ' get a sample channel
        Dim channel As Integer = Bass.BASS_SampleGetChannel(sample, False)
        ' play it
        Bass.BASS_ChannelPlay(channel, True)    'False sample is played once // True sample is looped (as far as i know)

    End Sub
End Class

Ian @ un4seen

  • Administrator
  • Posts: 21991
Just to be sure, when you say you don't get an error, do you mean the BASS calls are successful or just that the compiler doesn't complain about the code? If the latter, please check the BASS call return values to confirm whether they are successful. Also check that you are calling BASS_Init somewhere first.


  • Guest
Thx Ian great hint ;)

this is what was missing

Code: [Select]
Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_CPSPEAKERS, IntPtr.Zero, Nothing)