Author Topic: frequency sweep with trackbar results in noise after each freq. change  (Read 404 times)


  • Guest
Hi to all, Hi Ian,

I'am trying to program a simple frequencysweep (empy form only 1 trackbar as freq.slider). I Use SampleCreate to create a sinustone and i make the frequency ajustable via a trackbar. Works fine only problem is I get a kind of "click" noise each time i change the frequency.  I tried to use Sampleloop Flag, BASS_ChannelIsSliding (wait 20ms) and some other stuff nothing gor ride od the noise at freq.-change.

Anybody a suggestion?

Code: [Select]
Imports System
Imports Un4seen.Bass
Imports System.Threading

Public Class Form1

    Public HstreamA As Integer
    Public ScRate As Integer = 3520  'SCRate SampleCreateRate e.g. 440Hz = ScRate/8
    Public Value As Integer = 8
    Public Const PI As Double = 3.14159265358979

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub TbFreq_Scroll(sender As Object, e As EventArgs) Handles TbFreq.Scroll

        LbFreq.Text = TbFreq.Value
        ScRate = TbFreq.Value * Value

        Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_CPSPEAKERS, IntPtr.Zero, Nothing)
        ' create the sample
        Dim sample As Integer = Bass.BASS_SampleCreate(256, ScRate, 1, 1, BASSFlag.BASS_SAMPLE_LOOP)
        Dim data(128 - 1) As Short     ' the data buffer (256 byte = 128 Int16)
        Dim a As Integer
        For a = 0 To 127
            data(a) = CShort(32767.0 * Math.Sin((CDbl(a) * 2 * PI / Value)))
        Next a
            ' set the sample's data
            Bass.BASS_SampleSetData(sample, data)
        ' get a sample channel
        HstreamA = Bass.BASS_SampleGetChannel(sample, False)
        ' play it
        Bass.BASS_ChannelPlay(HstreamA, False)

    End Sub

    Private Sub BtBufferSize_Click(sender As Object, e As EventArgs) Handles BtBufferSize.Click
        Bass.BASS_SetConfig(BASSConfig.BASS_CONFIG_BUFFER, CInt(TxbBufferSize.Text))   'sieht so aus als ob: min-max = 10-5000
        LbBufferSize.Text = TxbBufferSize.Text
    End Sub
End Class

Ian @ un4seen

  • Administrator
  • Posts: 22327
The issue there is that it is reinitializing BASS every time the slider is moved, which will be what's causing the click sound. A better way to do it would be to create the sample once during initialization and then have the slider just change the stream's BASS_ATTRIB_FREQ value via BASS_ChannelSetAttribute. Another (even better) way would be to create a stream instead (via BASS_StreamCreate) and have its STREAMPROC function generate the sample data in realtime.