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
I understand x(-1) theory, but how is it working in the code? Please help.
No permission to create posts
November 17, 2015
11:20 am
Avatar
Skyler
Member
Members
Forum Posts: 47
Member Since:
November 17, 2015
sp_UserOfflineSmall Offline

So I understand the following in theory, however I don't understand how this code is actually grabbing or playing the previous sample.
If anybody could explain this to me, it would help so much!

I don't understand how xn_1 equal x(n-1) in theory because xn_1 is just a variable that equals another variable which is m_f_z1_left. How does it grab the previous sample?

float xn = pInputBuffer[0];

// Read Delay samp is x(n-1)
float xn_1 = m_f_z1_left;

// Difference Equation
float yn = m_f_a0_left*xn + m_f_a1_left*xn_1;

//Write Delay with current x(n)
m_f_z1_left = xn;

// Output sample is y(n)
pOutputBuffer[0] = yn*m_fVolume;

November 17, 2015
6:58 pm
Avatar
JD Young
Leiden, The Netherlands
Admin
Forum Posts: 80
Member Since:
November 5, 2014
sp_UserOfflineSmall Offline

Hi Skyler,

The processAudioFrame() function this code is in, gets called (executed) every time a sample is ready to be processed. This is something Will took care for us behind the scenes, so we don’t have to think about that. What you do need to be aware of, is that your plug-in itself is a c++ class in which you can declare member variables like m_f_z1_left that stay ‘alive’ beyond the scope of the processAudioFrame() function. On the other hand you have the local variables xn and yn that are declared in the processAudioFrame() function itself. These will be deleted when the function reaches its end.

So let’s see what happens when we loop through the processAudioFrame() function a few times:

1: In the first run the current sample will be stored in xn at the beginning of the function: float xn = pInputBuffer[0]. At the end of the function this value xn will be stored in the member variable: m_f_z1_left = xn.

2. In the second run the (new) current sample will be stored in xn again: float xn = pInputBuffer[0]. Then, the value that is stored in the member variable m_f_z1_left - which is the xn value of the previous run – will be stored in float xn_1 = m_f_z1_left. This is now your 1 sample delay.

3. and so on…

If you get the difference between local variables (like xn and yn), and member variables (like m_f_z1_left) you should be able to figure it out. Read up on the subjects of ‘scope’ and ‘persistence of data’ if you want to be thorough 😉 Hope this helps!

All the best,

JD

November 18, 2015
3:52 am
Avatar
Skyler
Member
Members
Forum Posts: 47
Member Since:
November 17, 2015
sp_UserOfflineSmall Offline

Awesome, Thanks a lot JD. This is what I needed, the direction I should be learning in. It makes a lot more sense. Thanks again!

Forum Timezone: America/New_York

Most Users Ever Online: 36

Currently Online:
2 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