Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
FX Book: 2nd FeedForward Filter and other filter code
No permission to create posts
September 26, 2015
5:31 pm
Avatar
ggh1984
Member
Members
Forum Posts: 5
Member Since:
September 17, 2015
sp_UserOfflineSmall Offline

I'm currently working through the FX book (on p132 - second order feedforward filter). I'm using the code from the early chapters to work on implementing the filters in Chapter5 (the second order feed forward, 2nd order feedback, biquad etc). Does anybody know where to find the author's code implementation of these for reference?

best regards,
Greg

Thanks!! Smile

September 29, 2015
8:56 pm
Avatar
ggh1984
Member
Members
Forum Posts: 5
Member Since:
September 17, 2015
sp_UserOfflineSmall Offline

Although the following code works when I compile it, I'm not entirely sure I'm getting the correct response as shown on p166 for the first order LPF. Anybody got any advice on what I'm doing wrong? Cheers!

//HEADER FILE
#pragma once

// base class
#include "plugin.h"

class CFirstOrderLPF : public CPlugIn
{
public:
// RackAFX Plug-In API Member Methods:
// The followung 5 methods must be impelemented for a meaningful Plug-In
//
// 1. One Time Initialization
CFirstOrderLPF();

// 2. One Time Destruction
virtual ~CFirstOrderLPF(void);

// 3. The Prepare For Play Function is called just before audio streams
virtual bool __stdcall prepareForPlay();

// 4. processAudioFrame() processes an audio input to create an audio output
virtual bool __stdcall processAudioFrame(float* pInputBuffer, float* pOutputBuffer, UINT uNumInputChannels, UINT uNumOutputChannels);

// 5. userInterfaceChange() occurs when the user moves a control.
virtual bool __stdcall userInterfaceChange(int nControlIndex);

// OPTIONAL ADVANCED METHODS ------------------------------------------------------------------------------------------------
// These are more advanced; see the website for more details
//
// 6. initialize() is called once just after creation; if you need to use Plug-In -> Host methods
// such as sendUpdateGUI(), you must do them here and NOT in the constructor
virtual bool __stdcall initialize();

// 7. joystickControlChange() occurs when the user moves a control.
virtual bool __stdcall joystickControlChange(float fControlA, float fControlB, float fControlC, float fControlD, float fACMix, float fBDMix);

// 8. process buffers instead of Frames:
// NOTE: set m_bWantBuffers = true to use this function
virtual bool __stdcall processRackAFXAudioBuffer(float* pInputBuffer, float* pOutputBuffer, UINT uNumInputChannels, UINT uNumOutputChannels, UINT uBufferSize);

// 9. rocess buffers instead of Frames:
// NOTE: set m_bWantVSTBuffers = true to use this function
virtual bool __stdcall processVSTAudioBuffer(float** inBuffer, float** outBuffer, UINT uNumChannels, int inFramesToProcess);

// 10. MIDI Note On Event
virtual bool __stdcall midiNoteOn(UINT uChannel, UINT uMIDINote, UINT uVelocity);

// 11. MIDI Note Off Event
virtual bool __stdcall midiNoteOff(UINT uChannel, UINT uMIDINote, UINT uVelocity, bool bAllNotesOff);

// 12. MIDI Modulation Wheel uModValue = 0 -> 127
virtual bool __stdcall midiModWheel(UINT uChannel, UINT uModValue);

// 13. MIDI Pitch Bend
// nActualPitchBendValue = -8192 -> 8191, 0 is center, corresponding to the 14-bit MIDI value
// fNormalizedPitchBendValue = -1.0 -> +1.0, 0 is at center by using only -8191 -> +8191
virtual bool __stdcall midiPitchBend(UINT uChannel, int nActualPitchBendValue, float fNormalizedPitchBendValue);

// 14. MIDI Timing Clock (Sunk to BPM) function called once per clock
virtual bool __stdcall midiClock();

// 15. all MIDI messages -
// NOTE: set m_bWantAllMIDIMessages true to get everything else (other than note on/off)
virtual bool __stdcall midiMessage(unsigned char cChannel, unsigned char cStatus, unsigned char cData1, unsigned char cData2);

// 16. initUI() is called only once from the constructor; you do not need to write or call it. Do NOT modify this function
virtual bool __stdcall initUI();

// Add your code here: ----------------------------------------------------------- //
float m_f_a0_left; //Declaration of coefficients
float m_f_a0_right;

float m_f_b1_left;
float m_f_b1_right;

float m_f_z1_left; //Declaration of feedback delay
float m_f_z1_right;

float fc; //Declarations of system variables
float fs;
float theta_c;
float gamma;

float m_fVolume;

// END OF USER CODE -------------------------------------------------------------- //

// ADDED BY RACKAFX -- DO NOT EDIT THIS CODE!!! ----------------------------------- //
// **--0x07FD--**

float m_fVolume_dB;
float m_fSlider_fc;
float m_fSlider_Q;

// **--0x1A7F--**
// ------------------------------------------------------------------------------- //

};

//IMPLEMENTATION FILE

#include "FirstOrderLPF.h"

/* constructor()
You can initialize variables here.
You can also allocate memory here as long is it does not
require the plugin to be fully instantiated. If so, allocate in init()

*/
CFirstOrderLPF::CFirstOrderLPF()
{
// Added by RackAFX - DO NOT REMOVE
//
// initUI() for GUI controls: this must be called before initializing/using any GUI variables
initUI();
// END initUI()

// built in initialization
m_PlugInName = "FirstOrderLPF";

// Default to Stereo Operation:
// Change this if you want to support more/less channels
m_uMaxInputChannels = 2;
m_uMaxOutputChannels = 2;

// use of MIDI controllers to adjust sliders/knobs
m_bEnableMIDIControl = true; // by default this is enabled

// custom GUI stuff
m_bLinkGUIRowsAndButtons = false; // change this if you want to force-link

// DO NOT CHANGE let RackAFX change it for you; use Edit Project to alter
m_bUseCustomVSTGUI = false;

// for a user (not RackAFX) generated GUI - advanced you must compile your own resources
// DO NOT CHANGE let RackAFX change it for you; use Edit Project to alter
m_bUserCustomGUI = false;

// output only - SYNTH - plugin DO NOT CHANGE let RackAFX change it for you; use Edit Project to alter
m_bOutputOnlyPlugIn = false;

// change to true if you want all MIDI messages
m_bWantAllMIDIMessages = false;

// un-comment this for VST/AU Buffer-style processing
// m_bWantVSTBuffers = true;

// Finish initializations here

//Flush the memory registers
m_f_z1_left = 0.0;
m_f_z1_right = 0.0;

}

/* destructor()
Destroy variables allocated in the contructor()

*/
CFirstOrderLPF::~CFirstOrderLPF(void)
{

}

/*
initialize()
Called by the client after creation; the parent window handle is now valid
so you can use the Plug-In -> Host functions here (eg sendUpdateUI())
See the website http://www.willpirkle.com for more details
*/
bool __stdcall CFirstOrderLPF::initialize()
{
// Add your code here

return true;
}

/* prepareForPlay()
Called by the client after Play() is initiated but before audio streams

You can perform buffer flushes and per-run intializations.
You can check the following variables and use them if needed:

m_nNumWAVEChannels;
m_nSampleRate;
m_nBitDepth;

NOTE: the above values are only valid during prepareForPlay() and
processAudioFrame() because the user might change to another wave file,
or use the sound card, oscillators, or impulse response mechanisms

NOTE: if you allocte memory in this function, destroy it in ::destroy() above
*/
bool __stdcall CFirstOrderLPF::prepareForPlay()
{
// Add your code here:
m_f_z1_left = 0.0;
m_f_z1_right = 0.0;

return true;
}

/* processAudioFrame

// ALL VALUES IN AND OUT ON THE RANGE OF -1.0 TO + 1.0

LEFT INPUT = pInputBuffer[0];
RIGHT INPUT = pInputBuffer[1]

LEFT OUTPUT = pInputBuffer[0]
RIGHT OUTPUT = pOutputBuffer[1]

*/
bool __stdcall CFirstOrderLPF::processAudioFrame(float* pInputBuffer, float* pOutputBuffer, UINT uNumInputChannels, UINT uNumOutputChannels)
{
// output = input -- change this for meaningful processing
//
// Do LEFT (MONO) Channel; there is always at least one input/one output
// (INSERT Effect)
//INPUT sample is x(n)
float xn = pInputBuffer[0];

//Delay Sample is y(n-1)
float yn_1 = m_f_z1_left;

//Difference equation
float yn = m_f_a0_left*xn - m_f_b1_left*yn_1;

//Populate Delay
m_f_z1_left = yn;

//Output Sample is yn
pOutputBuffer[0] = yn*m_fVolume;

// Mono-In, Stereo-Out (AUX Effect)
if(uNumInputChannels == 1 && uNumOutputChannels == 2)
pOutputBuffer[1] = yn;

// Stereo-In, Stereo-Out (INSERT Effect)
if(uNumInputChannels == 2 && uNumOutputChannels == 2)
{
//INPUT sample is x(n)
float xn = pInputBuffer[1];

//Delay Sample is y(n-1)
float yn_1 = m_f_z1_right;

//Difference equation
float yn = m_f_a0_right*xn - m_f_b1_right*yn_1;

//Populate Delay
m_f_z1_right = yn;

//Output Sample is yn
pOutputBuffer[1] = yn*m_fVolume;

}

return true;
}

/* ADDED BY RACKAFX -- DO NOT EDIT THIS CODE!!! ----------------------------------- //
**--0x2983--**

Variable Name Index
-----------------------------------------------
m_fVolume_dB 0
m_fSlider_fc 1
m_fSlider_Q 2

Assignable Buttons Index
-----------------------------------------------
B1 50
B2 51
B3 52

-----------------------------------------------
Joystick Drop List Boxes Index
-----------------------------------------------
Drop List A 60
Drop List B 61
Drop List C 62
Drop List D 63

-----------------------------------------------

**--0xFFDD--**
// ------------------------------------------------------------------------------- */
// Add your UI Handler code here ------------------------------------------------- //
//
bool __stdcall CFirstOrderLPF::userInterfaceChange(int nControlIndex)
{
// decode the control index, or delete the switch and use brute force calls
switch(nControlIndex)
{
case 0:
{
m_fVolume = pow(10.0,m_fVolume_dB/20.0);
break;
}
case 1:
{
fc = m_fSlider_fc;
fs = 44100.0;
theta_c = 2*pi*fc/fs;
gamma = 2 - cos(theta_c);

m_f_b1_left = sqrt(gamma*gamma - 1) - gamma;
m_f_b1_right = sqrt(gamma*gamma - 1) - gamma;
m_f_a0_left = 1 + m_f_b1_left;
m_f_a0_right = 1 + m_f_b1_right;
break;
}
default:
break;
}

return true;
}

October 10, 2015
8:16 am
Avatar
ggh1984
Member
Members
Forum Posts: 5
Member Since:
September 17, 2015
sp_UserOfflineSmall Offline

http://www.willpirkle.com/fx-b.....t-gallery/

On the navigation bar on the website:
FX book > Download FX projects.

Forum Timezone: America/New_York

Most Users Ever Online: 36

Currently Online:
3 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Skyler: 47

Peter: 41

Derek: 41

clau_ste: 39

Frodson: 38

Gwen: 32

EZB: 24

lppier: 23

Msaldaña: 18

Jorge: 17

Member Stats:

Guest Posters: 1

Members: 476

Moderators: 1

Admins: 4

Forum Stats:

Groups: 11

Forums: 30

Topics: 482

Posts: 1876

Newest Members:

sam, annaharris, Marie Weaver, kev, Steven, Mr Anderson, mguy, omelc

Moderators: W Pirkle: 143

Administrators: Tom: 65, JD Young: 80, Will Pirkle: 0, W Pirkle: 143