Bug when run plugin

Just starting out? Need help? Post your questions and find answers here.
Aleks_Longard
User
User
Posts: 59
Joined: Mon Dec 24, 2012 9:07 am
Location: Germany, Munich

Bug when run plugin

Post by Aleks_Longard »

Hello all!
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
Sory my bad english
infratec
Always Here
Always Here
Posts: 6867
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Bug when run plugin

Post by infratec »

Hi,

if you use

Code: Select all

EnableExplicit
You were able to find some faults.

I fixed these, but I can not test it.

Code: Select all

EnableExplicit

; 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

Global channels.l = 2
Global 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)
 
  Protected result.l
 
 
  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)
 
  Protected a.i, i.i
 
  For a = 0 To sampleframes - 1
    For i = 0 To channels - 1
      PokeF(*outputs + (a * channels * SizeOf(float) + i * SizeOf(float)), PeekF(*inputs + (a * channels * SizeOf(float) + i * SizeOf(float))) * paramvolume)
    Next i
  Next a
  
EndProcedure

ProcedureC ProcessDoubleReplacingProc(*ap.AEffect, *inputs, *outputs, sampleframes.l)
  
 Protected a.i, i.i
 
  For a = 0 To sampleframes - 1
    For i = 0 To channels - 1
      PokeD(*outputs + (a * channels * SizeOf(double) + i * SizeOf(double)), PeekD(*inputs + (a * channels * SizeOf(double) + i * SizeOf(double))) * paramvolume)
    Next i
  Next a
  
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
Last edited by infratec on Thu Apr 11, 2019 2:02 pm, edited 2 times in total.
Aleks_Longard
User
User
Posts: 59
Joined: Mon Dec 24, 2012 9:07 am
Location: Germany, Munich

Re: Bug when run plugin

Post by Aleks_Longard »

Infratec,
big thanks, you changes work!
Plugin loads, just not change volume... :(
Do you can tell me how to properly translate my old code into Purebasic?

Code: Select all

void process32(AEffect* effect, float** inputs, float** outputs, VstInt32 sampleframes)
{
for (int i = 0; i < sampleframes; i++)
{
for (int a = 0; a < channels; a++)
{
outputs[a][i] = inputs[a][i] * param_volume;
}
}
}

In PB not work instruction:
for a = 0 to a < sampleframes
Sory my bad english
infratec
Always Here
Always Here
Posts: 6867
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Bug when run plugin

Post by infratec »

I changed the code above.

Maybe this works.
infratec
Always Here
Always Here
Posts: 6867
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Bug when run plugin

Post by infratec »

Or this:

Code: Select all

ProcedureC ProcessReplacingProc(*ap.AEffect, *inputs, *outputs, sampleframes.l)
 
;   Protected a.i, i.i
;  
;   For a = 0 To sampleframes - 1
;     For i = 0 To channels - 1
;       PokeF(*outputs + (a * channels * SizeOf(float) + i * SizeOf(float)), PeekF(*inputs + (a * channels * SizeOf(float) + i * SizeOf(float))) * paramvolume)
;     Next i
;   Next a
  
  Protected *In1, *In2, *Out1, *Out2, i.i
  
  *In1 = PeekI(*inputs)
  *Out1 = PeekI(*outputs)
  
  If channels = 2
    *In2 = PeekI(*inputs + SizeOf(integer))
    *Out2 = PeekI(*outputs + SizeOf(integer))
  EndIf
  
  For i = 0 To sampleframes - 1
    PokeF(*Out1 + i * SizeOf(float), PeekF(*In1 + i * SizeOf(float)) * paramvolume)
    If channels = 2
      PokeF(*Out2 + i * SizeOf(float), PeekF(*In2 + i * SizeOf(float)) * paramvolume)
    EndIf
  Next i
  
EndProcedure
Aleks_Longard
User
User
Posts: 59
Joined: Mon Dec 24, 2012 9:07 am
Location: Germany, Munich

Re: Bug when run plugin

Post by Aleks_Longard »

Infratec
vielen dank für die hilfe, jetzt funktioniert alles super!
Ich habe es verstanden mit zeigern in PB zu arbeiten.
Sory my bad english
Post Reply