back to main JSFX reference page
JSFX Programming Reference - Memory/Slider/FFT/MDCT Functions
Memory/Slider/FFT/MDCT Functions
top Memory/Slider/FFT/MDCT Functions
- mdct(start_index, size), imdct(start_index, size)
Example:
mdct(0, 512);
Performs a modified DCT (or inverse in the case of imdct()) on the data
in the local memory buffer at the offset specified by the first parameter.
The second parameter controls the size of the MDCT, and it MUST be one of
the following: 64, 128, 256, 512, 1024, 2048, or 4096. The MDCT takes the number of
inputs provided, and replaces the first half of them with the results. The
IMDCT takes size/2 inputs, and gives size results.
Note that the MDCT must NOT cross a 65,536 item boundary, so be sure to
specify the offset accordingly.
The MDCT/IMDCT provided also provide windowing, so your code is not required
to window the overlapped results, but simply add them. See the example
effects for more information.
- fft(start_index, size), ifft(start_index, size)
fft_real(start_index, size), ifft_real(start_index, size)
fft_permute(index,size), fft_ipermute(index,size)
Example:
buffer=0;
fft(buffer, 512);
fft_permute(buffer, 512);
buffer[32]=0;
fft_ipermute(buffer, 512);
ifft(buffer, 512);
// need to scale output by 1/512.0, too.
Performs a FFT (or inverse in the case of ifft()) on the data in the local
memory buffer at the offset specified by the first parameter.
The size of the FFT is specified by the second parameter, which must be
16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, or 32768. The outputs
are permuted, so if you plan to use them in-order, call fft_permute(buffer, size)
before and fft_ipermute(buffer,size) after your in-order use.
Your inputs or outputs will need to be scaled down by 1/size, if used.
Note that the FFT/IFFT require real/imaginary input pairs (so a
256 point FFT actually works with 512 items).
Note that the FFT/IFFT must NOT cross a 65,536 item boundary, so be sure to
specify the offset accordingly.
The fft_real()/ifft_real() variants operate on a set of size real inputs, and produce size/2 complex
outputs. The first output pair is DC,nyquist. Normally this is used with fft_permute(buffer,size/2).
- convolve_c(dest,src,size)
Used to convolve two buffers, typically after FFTing them.
convolve_c works with complex numbers. The sizes specify number
of items (the number of complex number pairs).
Note that the convolution must NOT cross a 65,536 item boundary,
so be sure to specify the offset accordingly.
Memory Utility
- freembuf(top)
The freembuf() function provides a facility for you to notify the memory
manager that you are no longer using a portion of the local memory buffer.
For example, if the user changed a parameter on your effect halving your
memory requirements, you should use the lowest indices possible, and call
this function with the highest index you are using plus 1, i.e. if you are
using 128,000 items, you should call freembuf(128001); If you are no longer
using any memory, you should call freembuf(0);
Note that calling this does not guarantee that the memory is freed or
cleared, it just provides a hint that it is OK to free it.
- memcpy(dest,source,length)
The memcpy() function provides the ability to quickly copy regions of the
local memory buffer. If the buffers overlap and either buffer crosses a 65,536 item boundary, the
results may be undefined.
- memset(dest,value,length)
The memset() function provides the ability to quickly set a region of the
local memory buffer to a particular value.
- __memtop()
Returns the total number of memory slots available to the plug-in.
Stack
A small (approximately 4096 item) user stack is available for use in code (REAPER 4.25+):
- stack_push(value)
Pushes value onto the user stack, returns a reference to the value.
- stack_pop(value)
Pops a value from the user stack into value, or into a temporary buffer if value is not specified, and returns a reference to where the stack was popped. Note that no checking is done to determine if the stack is empty, and as such stack_pop() will never fail.
- stack_peek(index)
Returns a reference to the item on the top of the stack (if index is 0), or to the Nth item on the stack if index is greater than 0.
- stack_exch(value)
Exchanges a value with the top of the stack, and returns a reference to the parameter (with the new value).
Slider Functions
For these functions, the parameter can be the variables slider1-sliderN, in
which case that slider is refreshed. Otherwise, it can be a bitmask of which
sliders have changed, where 1 would be the first slider, 2 would be the
second, 4 would be the third, 32768 being the 16th slider, and so on.
- sliderchange(mask or sliderX)
Example:
sliderchange(slider4);
or
sliderchange(2 ^ sliderindex);
The sliderchange() function provides a facility for you to notify REAPER/JS
that you have changed a sliderX variable so that
it can update the display. This function is not necessary to call from the
@slider code section, it is provided so
that other code sections can update the sliders. Note that this function only
updates the display, it does not send an automation message to the host.
- slider_automate(mask or sliderX)
Example:
slider_automate(slider4);
or
slider_automate(2 ^ sliderindex);
The slider_automate() function provides a facility for you to notify REAPER/JS
that you have changed a sliderX variable so that
it can update the display, and record the move as automation. This function is not
necessary to call from the @slider code section,
it is provided so that other code sections can write programmatic automation messages.
Atomic Variable Access
Guaranteed-atomic updates/accesses of values across contexts (specifically @gfx and other contextes). Normally these are unnecessary, but they are provided for the discriminating JSFX user -- REAPER 4.5+:
- atomic_setifequal(dest,value,newvalue)
Sets dest to newvalue if dest equals value. Returns the old value of dest. On Windows this is known as InterlockedCompareExchange().
- atomic_exch(val1,val2)
Exchanges val1 and val2, returns the new value of val1.
- atomic_add(dest_val1,val2)
Adds val2 to dest_val1, returns the value of dest_val1.
- atomic_set(dest_val1,val2)
Sets dest_val1 to val2, returns the value of dest_val1.
- atomic_get(val)
Returns the value of val.