Plugins_SDKv8_Example2
Audio Plugin (DSP) using SDK v8
Here is an example to start developping a plugin "MyPlugin8". We use the class "CMyPlugin8" to define our object but you can use what you want. The file "Main.cpp" is the caller of your object "CMyPlugin8" and is the entry point to communicate with VirtualDJ.
For this example, you need to include the following files from the SDK v8 in your project: vdjPlugin8.h (basic common base-class for all plugins) and vdjDsp8.h (base classes for all Dsp plugins)
You can use other compiler but please find one example of Visual C++ project for this project on a PC. It will generate a .dll file
For the case of this example, please copy all the files in the same folder.
MyPlugin8.h:
#ifndef MYPLUGIN8_H
#define MYPLUGIN8_H
#include "vdjDsp8.h"
class CMyPlugin8 : public IVdjPluginDsp8
{
public:
HRESULT VDJ_API OnLoad();
HRESULT VDJ_API OnGetPluginInfo(TVdjPluginInfo8 *infos);
ULONG VDJ_API Release();
HRESULT VDJ_API OnStart();
HRESULT VDJ_API OnStop();
HRESULT VDJ_API OnProcessSamples(float *buffer, int nb);
private:
// ADD YOUR VARIABLES HERE
};
#endif
MyPlugin8.cpp:
#include "MyPlugin8.h"
//-----------------------------------------------------------------------------
HRESULT VDJ_API CMyPlugin8::OnLoad()
{
return S_OK;
}
//-----------------------------------------------------------------------------
HRESULT VDJ_API CMyPlugin8::OnGetPluginInfo(TVdjPluginInfo8 *infos)
{
infos->PluginName = "MyPlugin8";
infos->Author = "Atomix Productions";
infos->Description = "My first VirtualDJ 8 plugin";
infos->Version = "1.0";
infos->Flags = 0x00;
infos->Bitmap = NULL;
return S_OK;
}
//---------------------------------------------------------------------------
ULONG VDJ_API CMyPlugin8::Release()
{
delete this;
return 0;
}
//---------------------------------------------------------------------------
HRESULT VDJ_API CMyPlugin8::OnStart()
{
// ADD YOUR CODE HERE WHEN THE AUDIO PLUGIN IS STARTED
return S_OK;
}
//---------------------------------------------------------------------------
HRESULT VDJ_API CMyPlugin8::OnStop()
{
// ADD YOUR CODE HERE WHEN THE AUDIO PLUGIN IS STOPPED
return S_OK;
}
//---------------------------------------------------------------------------
HRESULT VDJ_API CMyPlugin8::OnProcessSamples(float *buffer, int nb)
{
// ADD YOUR AUDIO TREATMENT CODE HERE USING THE AUDIO BUFFER *buffer OF 2*nb FLOAT SAMPLES (STEREO SIGNAL)
// A FLOAT SAMPLE HAS A VALUE BETWEEN -1.0f AND 1.0f
float SampleOut_Left, SampleOut_Right;
float SampleIn_Left, SampleIn_Right;
int i;
// we read the 'nb' stereo samples ( = 2 * 'nb' mono samples) from the sound buffer
// read left samples : buffer[0], buffer[2], ... , buffer[2*nb-2]
// read right samples : buffer[1], buffer[3], ... , buffer[2*nb-1]
for(i=0;i<nb;i++)
{
SampleIn_Left = buffer[2*i];
SampleIn_Right = buffer[2*i+1];
// ADD YOUR AUDIO TREATMENT CODE HERE.
// For the purpose of this example, we mute the left channel and keep (copy) the right channel
float WetDry = 0.0f; // we want to force the sample to 0 (no volume)
SampleOut_Left = WetDry * SampleIn_Left ;
SampleOut_Right = SampleIn_Right;
buffer[2*i] = SampleOut_Left;
buffer[2*i+1] = SampleOut_Right;
}
return S_OK;
}
Main.cpp:
// This is the standard DLL loader for COM object.
#include "MyPlugin8.h"
HRESULT VDJ_API DllGetClassObject(const GUID &rclsid,const GUID &riid,void** ppObject)
{
if (memcmp(&rclsid,&CLSID_VdjPlugin8,sizeof(GUID))==0 && memcmp(&riid,&IID_IVdjPluginDsp8,sizeof(GUID))==0)
{
*ppObject=new CMyPlugin8();
}
else
{
return CLASS_E_CLASSNOTAVAILABLE;
}
return NO_ERROR;
}