Managed to port the graphic spectrum of the player to the example, but am still stuck with a 1.5 second delay, which is unbearable.
EDIT: I noticed that if you put two times BASS_ChannelGetData, it seems to clear the buffer and the spectrum display is immediate. But when pressing escape, the program crashes :P
Note that what I find irritable is this:
They are not giving any solution as to how I should make the buffer shorter or fix it so there is no delay!
Include "includes\bass.bb" Include "includes\bassrecord.bb" Const BASSMAXIMUM%=60 ;Spektrum-Balkenhöhe Const BASSSMOOTH#=4 ;Horizontale-Weichzeichnerstärke Const PEAKBASSAGRESSIVITY%=16 ;Peakagressivität spectrum = CreateBank(1024) ; bank for data transfer to make the visualisation NPeakBank= CreateBank(1024) ;Umgerechneter-Spectrumanalyser APeakBank= CreateBank(1024) ;Alter-[NPeakBank]-Für-Differenzberechnung LPeakBank= CreateBank(1024) ;Background-Falling-Lines-Position RXPosBank= CreateBank(256) ;Reale-Lese-Position-Einer-Bank*4 For Q=0 To 255 PokeByte(RXPosBank,Q,Floor(Q/8.0+(Q*Q*Q/106000))) Next Global Timer=CreateTimer (60) volume = 100 Graphics 640,480,32,2 SetBuffer BackBuffer() Global myinput = 5 ; for my SBLIVE, default here HWND = BASS_HWND() BASS_Init(-1,48000,0,HWND,BASS_NULL) BASS_RecordInit (0) BASS_RecordSetInput (myinput,BASS_INPUT_ON) ; we switch to the input BassHandle = BASS_RecordStartSimple(48000,2,0) ; BASS_RecordStart but without callbacks Global in% = BASS_RecordGetDeviceCount() -1 ;the first input = 0 so -1 While Not KeyHit (1) Cls Color 255,0,0 Text 0,0,"Bass Record Tutorial 2" device$ = BASS_GetDeviceDescriptionString(1) Text 0,20,"First (real) Hardware : "+device ; the soundcart (1 = first because 0 = nosound Color 255,255,0 port$ = BASS_RecordGetDeviceDescriptionString(0); the selected hardware for inputs (0=first) Text 0,40,"Recording Hardware : " + port indev$ = BASS_RecordGetInputNameString(myinput) ; get the name of the selected input Text 0,60,"Selected Input : "+indev Switch() Text 0,410,"Use keys 1<->9 to select an input. Now you have input "+(myinput+1) +" of "+(in+1) BASS_RecordSetInputVolume (myinput,volume) ; 1.5 seconds delay. What you see is the end of the recording buffer. You can make other visualisations ; with the BASS_DATA_AVAILABLE flag, see the docs for this. BASS_ChannelGetData(BassHandle,spectrum,BASS_DATA_FFT512) For Q=0 To 255 Step+1 PokeFloat(APeakBank,Q*4,PeekFloat(NPeakBank,Q*4)) RXPos=PeekByte(RXPosBank,Q)*4 PeakLevel# = PeekFloat(Spectrum,RXPos) PeakLevel# = PeakLevel * (5+RXPos/2) PeakLevel# = 1 - (1.0 / (1 + PeakLevel / (8.0/PEAKBASSAGRESSIVITY))) PokeFloat(NPeakBank,Q*4,PeakLevel) Next PeakLevel#=PeekFloat(NPeakBank,0)/2 For Q=0 To 255 Step+1 PeakLevel# = PeakLevel - (PeakLevel - PeekFloat(NPeakBank,Q*4)) / BASSSMOOTH PokeFloat(NPeakBank,Q*4,PeakLevel) Next For Q=255 To 0 Step-1 PeakLevel# = PeakLevel - (PeakLevel - PeekFloat(NPeakBank,Q*4)) / BASSSMOOTH PokeFloat(NPeakBank,Q*4,2+PeakLevel*BASSMAXIMUM) Next For Q=0 To 255 Step+1 APeak#=PeekFloat(APeakBank,Q*4) NPeak#=PeekFloat(NPeakBank,Q*4) LPeak#=PeekFloat(LPeakBank,Q*4) DiffPeak#=APeak-NPeak If APeak>NPeak Then NPeak=APeak-DiffPeak/BASSSMOOTH*1 PokeFloat(NPeakBank,Q*4,NPeak) End If BassVerstaerker# = 8 - (8-NPeak) / 20000.0 DiffPeak# = Abs(DiffPeak) * WHITEBASSAGRESSIVITY If NPeak > LPeak Then LPeak = NPeak LPeak#=LPeak-.02-BassVerstaerker/100.0 PokeFloat(LPeakBank,Q*4,LPeak) Color 255-Q+DiffPeak*(1+Q/40), NPeak*4+DiffPeak, Q+DiffPeak Rect Q*2, 256 - APeak * 3, 2, APeak * 3, 1 Rect Q*2, 256, 2, APeak * 3, 1 Next If KeyHit (59) Then volume = volume - 5 If KeyHit (60) Then volume = volume + 5 If volume < 0 volume = 0 If volume > 100 Then volume = 100 Color 255,255,255 Text 0,430,"Use keys F1 and F2 to change the input volume : "+volume +" Text 0,450,"ESC to exit" WaitTimer Timer Flip 0 Wend FreeBank spectrum BASS_RecordFree() BASS_Free() End Function Switch() For i = 0 To in If KeyHit(i+1) Then myinput = i - 1 BASS_RecordSetInput (myinput,BASS_INPUT_ON) EndIf Next End Function
EDIT: I noticed that if you put two times BASS_ChannelGetData, it seems to clear the buffer and the spectrum display is immediate. But when pressing escape, the program crashes :P
Note that what I find irritable is this:
Not using a callback (proc = NULL) allows lower latency for full-duplex recording (ie. playing the data as it's being recorded), as you get the recorded data on demand via the BASS_ChannelGetData function. To keep latency at a minimum, the amount of data in the recording buffer should be monitored (also done via BASS_ChannelGetData, with the BASS_DATA_AVAILABLE flag) to check that there's not too much data. If there is too much data in the buffer, then that means the data currently being recorded will be delayed by the older data in the buffer being retrieved first.
They are not giving any solution as to how I should make the buffer shorter or fix it so there is no delay!