Old 06-24-2020, 01:11 PM   #1
Sebaloh
Human being with feelings
 
Join Date: Jun 2020
Posts: 3
Default How to use buffer?

Ok, I am a newbie in programming and I want to do the following with JSFX. I want to make a vst plug-in which takes a signal, buffers the first four values of that signal, and outputs the the sum. Something like this:

spl0=in[0]+in[1]+in[2]+in[3]

(where spl0 is the standard output and in[i] represents the i-th sample of the incoming signal.) How can I so that? I think I need to use the "buffer" but i am clueless on how to implement that.
Sebaloh is offline   Reply With Quote
Old 06-24-2020, 01:33 PM   #2
Fabian
Human being with feelings
 
Fabian's Avatar
 
Join Date: Sep 2008
Location: Sweden
Posts: 5,771
Default

Something like this (untested code)

Code:
@init
in = 1024; // This positions the buffer at address 1024
NUMELEMS = 4; // Number of elements
inpos = 0; // Buffer insertion starts at position 0

@sample
in[inpos] = spl0; // Store the current sample at the current pos
inpos += 1;  // Increase position by one
inpos >= NUMELEMS ? inpos = 0; // Wrap around

spl0 = in[0] + in[1] + in[2] + in[3]; // What you wrote
To be more general, we can loop the summation, like so:

Code:
// This replaces what you wrote
temp = 0; // Stores the temporary calculation
outpos = 0; // Always sum from the start
loop(NUMELEMS,
    temp += in[outpos];
    outpos += 1;
);

spl0 = temp;
The good thing with the loop is that we can now sum over arbitrary number of samples just by changing NUMELEMS.

Beware that summing up samples in this way may result in a sample larger than one. Though not really a problem unless you output it to your audio interface, it may not be what you really want.
__________________
// MVHMF
I never always did the right thing, but all I did wasn't wrong...
Fabian is offline   Reply With Quote
Old 06-25-2020, 02:47 AM   #3
Sebaloh
Human being with feelings
 
Join Date: Jun 2020
Posts: 3
Default

@Fabian yes man it works

In the same spirit, lets say that i want to buffer up a some samples take the FFT of them, do some manipulations in the frequency domain and then use the inverse fft to hear the result. How can I do that? Do I need to control the delay compensation of the plug in? And if so, how can I do that?
Sebaloh is offline   Reply With Quote
Old 06-25-2020, 03:31 AM   #4
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 9,198
Default

Of course you can do that.

JSFX provides FFT functions for you.

FAIR, There are several FFT examples coming with the Reaper distribution.

You may want to search the forum for fft_real to find some relevant threads.

Usually fft enabled plugins delay the audio stream at least a full FFT window which is a lot, as the window size defines the ratio between lowest and the highest frequency that can be modified by the plugin.

In JSFX you can simply set a variable to define the delay compensation your plugin requests.

-Michael

Last edited by mschnell; 06-25-2020 at 03:37 AM.
mschnell is online now   Reply With Quote
Old 06-25-2020, 05:17 AM   #5
Sebaloh
Human being with feelings
 
Join Date: Jun 2020
Posts: 3
Default

@mschnell Do you have a very easy example in mind? yes I read the documentation. My problem is that I don't know how to implement this. Most of the times it helps if i have a simple example. When I searched "fft_real" I found some code but it is mingled with other stuff making it a bit difficult to understand which part of the code is for fft and which part is for the other stuff. Sorry, but i might be too noob to understand
Sebaloh is offline   Reply With Quote
Old 06-25-2020, 05:56 AM   #6
IXix
Human being with feelings
 
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,504
Default

You might find this thread useful... https://forum.cockos.com/showthread.php?t=225955
IXix is offline   Reply With Quote
Old 06-25-2020, 07:43 PM   #7
junh1024
Human being with feelings
 
Join Date: Feb 2014
Posts: 158
Default

Also https://forum.cockos.com/showthread.php?t=190168 thread has examples & discussion
junh1024 is online now   Reply With Quote
Old 06-25-2020, 09:22 PM   #8
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 9,198
Default

Doing FFT in a JSFX in fact is not "basic", but definitely doable and works perfectly if correctly done.

-Michael
mschnell is online now   Reply With Quote
Old 06-26-2020, 02:47 AM   #9
mschnell
Human being with feelings
 
mschnell's Avatar
 
Join Date: Jun 2013
Location: Krefeld, Germany
Posts: 9,198
Default

Maybe see
-> https://forum.cockos.com/showthread....light=fft_real
-> https://forum.cockos.com/showthread....light=spectral

-Michael

Last edited by mschnell; 06-26-2020 at 02:52 AM.
mschnell is online now   Reply With Quote
Old 06-26-2020, 11:21 AM   #10
Fabian
Human being with feelings
 
Fabian's Avatar
 
Join Date: Sep 2008
Location: Sweden
Posts: 5,771
Default

Also, look at the fft_splitter JSFX by Schwa. It is in <Reaper's resource dir>/Effects/schwa. It sorted out a whole lot of things for me related to fft.
__________________
// MVHMF
I never always did the right thing, but all I did wasn't wrong...
Fabian is offline   Reply With Quote
Old 06-30-2020, 05:42 PM   #11
junh1024
Human being with feelings
 
Join Date: Feb 2014
Posts: 158
Default

I would say that included examples such as fft_splitter are bad examples for beginners since they're not self- describing or have comments, and the "typical" FFT fx isn't written in terms of memcpy & memset. Threads with discussion & examples are more useful.
junh1024 is online now   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 05:01 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.