| .lua Expert Cheater
 
  Reputation: 1 
 Joined: 13 Sep 2018
 Posts: 203
 
 
 | 
			
				|  Posted: Mon Nov 04, 2024 4:23 am    Post subject: May I ask questions related to bass.ll |   |  
				| 
 |  
				| As shown in the figure, I would like to call the following function: Can you help me check? It always draws a straight line.
 
  	  | Code: |  	  | local BASS_STREAM_DECODE = 0x200000 local mp3File='C:\\Users\\Administrator\\Desktop\\Test.mp3'
 if not bass.BASS_Init(-1, 44100, 0, 0, nil).vDword then
 error("BASS Erro")
 end
 local hs2 = bass.BASS_StreamCreateFile(false, Utf8ToAnsi(mp3File), 0, 0, BASS_STREAM_DECODE).vPointer
 
 
 bass.BASS_ChannelPlay(hs2, 0)--play music
 local byteLength=bass.BASS_ChannelGetLength(hs2,0).vPointer
 local time=bass.BASS_ChannelBytes2Seconds(hs2,byteLength).vDouble
 len3=os.date('%M:%S',math.floor(time))
 
 dataLength = math.floor(time * 50 + 1)
 Data={}
 for i = 1,dataLength do
 Data[i]={left=0, right=0}
 end
 for i = 1, dataLength do
 local level = bass.BASS_ChannelGetLevel(hs2, 0).vDword
 Data[i].left = (level & 0xFFFF)/32768.0
 Data[i].right= ((level >> 16) & 0xFFFF)/32768.0
 end
 
 function Trunc(x)
 if x >= 0 then
 return math.floor(x)
 else
 return math.ceil(x)
 end
 end
 
 function Draw(control)
 if pi then pi.Destroy() end
 pi = createPicture()
 --pi.Bitmap.Canvas.Clear()
 cc.Repaint()
 local ww=#Data
 local hh=128
 local ch=hh/2
 --pi.Bitmap.Width=ww
 --pi.Bitmap.Height=hh
 cc.Canvas.FillRect(0,0,ww,hh)
 cc.Canvas.Pen.Color=0xff
 for i = 1, #Data do
 local L = Data[i].left
 local R = Data[i].right
 local y1 = ch - Trunc(L*32768 * ch)
 local y2 = ch + Trunc(R*32768 * ch)
 --print(y1,y2)
 --y1 = math.max(0, math.min(y1, hh))
 --y2 = math.max(0, math.min(y2, hh))
 --if i<=700 then print(yZ) end
 cc.Canvas.LineTo(i, y1)
 cc.Canvas.MoveTo(i, y2)
 end
 cc.getCanvas().draw(0,0,pi.getBitmap())
 end
 Draw(UDF1.Image)
 | 
 
 
 
 
	
		
	 
		| Description: |  |  
		| Filesize: | 10.62 KB |  
		| Viewed: | 1815 Time(s) |  
		| 
  
 
 |  
 |  |