This is a winamp dsp plugin skeleton fully fuctional with winamp5.
Credits given at the start of the code.
Have fun.
Code: Select all
;DSP Winamp Plugin
;Adapted by ricardo from Vis Plugin example by Doobrey. (Thanks to KarLKoX for poiting me to read buffer with 32 bits)
;You can use this code as you wish, except making a plugin with this remove vocals example. Do you own DSP algo ;)
#DSP_HDRVER = $20
;#DSP_HDRVER = $21
Structure winampDSPModule
description.l ;## Pointer to plugin description string
hWndParent.l ;## This lot is filled by Winamp .
hDllInstance.l
Config.l ;## These 4 are the pointers to your routines.
Init.l
ModifySamples.l
Quit.l
UserData.l ;## pfffff??
EndStructure
Structure winampDSPHeader
Version.l ;## **MUST** always be #VIS_HDRVER
description.l ;## Addr of module title string
getmodule.l ;## Addr of your getmodule() proc
sf.l ; // DSP_HDRVER == 0x21
EndStructure
DefType .winampDSPHeader hdr
DefType .winampDSPModule Mod0,Mod1
Global hdr,Mod0,Mod1
ProcedureCDLL .l getModule(modnum.l)
pr.l=0
Select modnum ;## ONCE CASE PER MODULE
Case 0
pr= @Mod0
EndSelect
ProcedureReturn pr
EndProcedure
Procedure CallBackWindow(HWND,uMsg,WPARAM,LPARAM)
Result = #PB_ProcessPureBasicEvents
Select uMsg
Case #WM_COMMAND
Select WPARAM>>16 & $FFFF
Case #BN_CLICKED
If LPARAM ;Button
Select WPARAM & $FFFF
Case 1
MessageRequester("","Apply: " + Str(GetGadgetState(3)) + "% in trackbar")
;Do your stuff here. What ever the user choose in your settings
Case 2
MessageRequester("","Cancel " )
HideWindow(0,1)
EndSelect
EndIf
EndSelect
EndSelect
ProcedureReturn Result
EndProcedure
ProcedureCDLL Config(*this_mod.winampDSPModule) ;Called from winamp when user want to config
wintitle.s=Str(*this_mod\hWndParent)
winamphwnd=*this_mod\hWndParent
If OpenWindow(0,0,0,288,150,0,"PB Winamp Remove Vocals",winamphwnd) ;## REALLY NEED TO ADD WINAMP PARENT WINDOW !
SetWindowCallback(@CallBackWindow())
CreateGadgetList(WindowID())
TextGadget(0,10,10,200,25,"")
ButtonGadget(1,180,120,100,25,"Apply",#PB_Button_Default)
ButtonGadget(2,10,120,100,25,"Cancel")
TrackBarGadget(3,10,40,260,25,0,100)
SetGadgetState(3,27)
ProcedureReturn 0
Else
;## Should really add an error msg here
ProcedureReturn 1
EndIf
EndProcedure
ProcedureCDLL Init0(*this_mod.winampDSPModule);called when your dll is loaded. Sometimes could be usefull for read ini files per example
ProcedureReturn 0
EndProcedure
ProcedureCDLL Quit0(*this_mod.winampDSPModule) ;called whne closes winamp or your dll is unloaded
CloseWindow(0)
Karaoke = 1
ProcedureReturn 0
EndProcedure
ProcedureCDLL ModifySamples1(*this_mod.winampDSPModule,*samples,numsamples,bps,nch,srate)
;/HERE SHOULD BE THE DSP STUFF
;Here is where DSP (Digital Signal Processing) comes. This is finally the main stuff. All the rest is the 'container'.
;In this example we are doing just a 'remove vocals' example. But you can do other stuff.
Select bps
Case 16
numbytes = 2
sLenght = numsamples*nch*2
Case 24
numbytes = 3
sLenght = numsamples*nch*numbytes
Case 32
numbytes = 4
sLenght = numsamples*nch*numbytes
EndSelect
For i = 0 To sLenght - 1 Step 8
Channel1 = PeekL(*samples+i)
Channel2 = PeekL(*samples+i+numbytes)
If Channel1 > OldChannel1
OldChannel1 = Channel1
EndIf
nChannel1 = Channel1 * -1
nChannel2 = Channel2 * -1
Channel1 + nChannel2
Channel2 + nChannel1
PokeL(*samples+i,Channel1)
PokeL(*samples+i+numbytes,Channel2)
Next
ProcedureReturn numsamples
EndProcedure
ProcedureDLL.l winampDSPGetHeader2()
;## GENERAL HEADER STUFF
hdr\Version=#DSP_HDRVER
hdr\description=?desc_label
hdr\getmodule=@getModule()
hdr\sf=$21
;## MODULE STUFF ..fill out one of these for each module in the plugin.
Mod0\description=?mod0_label
Mod0\hWndParent = #Null
Mod0\hDllInstance = #Null
Mod0\Config=@Config()
Mod0\Init=@Init0()
Mod0\ModifySamples=@ModifySamples1()
Mod0\Quit=@Quit0()
; ;## MODULE 1..WINDOW MODE
; Mod1\description=?mod1_label
; Mod0\Config=@Config()
; Mod0\Init=@Init1()
; Mod0\ModifySamples=@ModifySamples1()
; Mod0\Quit=@Quit1()
ProcedureReturn @hdr
EndProcedure
;## Quick and easy static strings
DataSection
desc_label:
Data.s "DSP PureBasic example (remove vocals)"
mod0_label:
Data.s "DSP 1"
mod1_label:
Data.s "DSP 2"
EndDataSection