I want to rewrite my VST plugin on Purebasic, which I wrote on pure C.
This show info in DAW Reaper, and crash if i add plugin on track.
I don't understand some things in Purebasic, because I programming in C++ and pure C.
Help me please find a my bug!
Code: Select all
; test VST sdk v2.4 plugin
ImportC "msvcrt.lib"
_snprintf(*sout.p-Ascii, iCount.i, sformat.p-Ascii, s.p-Ascii, a2.d)
strncpy(*buf.p-Ascii, string.p-Ascii, count.i)
EndImport
channels.i = 2
paramvolume.f = 1.0
PrototypeC.l DispatcherProc(*effect, opcode.i, index.i, Value.i, *ptr, opt.f)
PrototypeC ProcessProc(*effect, *inputs.Float, *outputs.Float, sampleframes.l)
PrototypeC SetParameterProc(*effect, index.i, parameter.f)
PrototypeC.f GetParameterProc(*effect, index.i)
PrototypeC ProcessReplacingProc(*effect, *inputs.Float, *outputs.Float, sampleframes.l)
PrototypeC ProcessDoubleReplacingProc(*effect, *inputs.Double, *outputs.Double, sampleframes.l)
Structure AEffect Align #PB_Structure_AlignC
magic.i
dispatcher.DispatcherProc
process.ProcessProc
setParameter.SetParameterProc
getParameter.GetParameterProc
numPrograms.i
numParams.i
numInputs.i
numOutputs.i
flags.i
*resvd1
*resvd2
initialDelay.i
realQualities.i
offQualities.i
ioRatio.f
*Object
*user
uniqueID.i
version.i
processReplacing.ProcessReplacingProc
processDoubleReplacing.ProcessDoubleReplacingProc
Array future.b(56)
EndStructure
; constants
#kEffectMagic = $56737450
#effFlagsCanReplacing = 16
#kPlugCategEffect = 1
#kPlugCategSynth = 2
#kPlugCategAnalysis = 3
; AEffect constants
#effClose = 1
#effGetParamLabel = 6
#effGetParamDisplay = 7
#effGetParamName = 8
#effSetSampleRate = 10
#effSetBlockSize = 11;
#effGetPlugCategory = 35
#effGetEffectName = 45
#effGetVendorString = 47
#effGetProductString = 48
#effGetVendorVersion = 49
; string sizes
#kVstMaxParamStrLen = 8
#kVstMaxVendorStrLen = 64
#kVstMaxProductStrLen = 64
#kVstMaxEffectNameLen = 32
; other procedures
Procedure getParameterName(index.i, *text)
Select index
Case 0
strncpy(*text, "Volume", #kVstMaxParamStrLen)
EndSelect
EndProcedure
; procedures for VST sdk
ProcedureC.l DispatcherProc(*d.AEffect, opcode.i, index.i, Value.i, *ptr, opt.f)
result.l = 0
Select opcode
Case #effClose
FreeStructure(*d)
Case #effGetParamName
getParameterName(index, *ptr)
Case #effGetPlugCategory
result = #kPlugCategEffect | #kPlugCategAnalysis
Case #effGetEffectName
strncpy(*ptr, "VST test plugin", #kVstMaxEffectNameLen)
Case #effGetVendorString
strncpy(*ptr, "Alex Longard", #kVstMaxVendorStrLen)
Default
EndSelect
ProcedureReturn result
EndProcedure
ProcedureC ProcessReplacingProc(*ap.AEffect, *inputs, *outputs, sampleframes.l)
For a = 0 To sampleframes
For i = 0 To channels
*outputs = *inputs * paramvolume
Next i
Next a
EndProcedure
ProcedureC ProcessDoubleReplacingProc(*ap.AEffect, *inputs, *outputs, sampleframes.l)
EndProcedure
ProcedureC SetParameterProc(*asp.AEffect, index.i, value.f)
paramvolume = value
EndProcedure
ProcedureC.f GetParameterProc(*agp.AEffect, index.i)
ProcedureReturn paramvolume
EndProcedure
ProcedureCDLL VSTPluginMain(*audioMaster)
Protected *Aef.AEffect = AllocateStructure(AEffect)
*aef\magic = #kEffectMagic
*aef\dispatcher = @DispatcherProc()
*aef\setParameter = @SetParameterProc
*aef\getParameter = @GetParameterProc
*aef\numParams = 1
*aef\numInputs = channels
*aef\numOutputs = channels
*aef\flags = #effFlagsCanReplacing
*aef\processReplacing = @ProcessReplacingProc()
; *aef\processDoubleReplacing = @ProcessDoubleReplacingProc()
*aef\uniqueID = 1987
*aef\version = 1
*aef\Object = 0
ProcedureReturn *aef
EndProcedure