Just trying to work out file_riff in JSFX, I want to be able to play a section of a wav file in sync to Reaper.
If I set cur_pos to 350000 in the script I found it will play from bar 3 but it goes out of sync.
I would like to be able to get it to play a set section of the wav at a particular bar in Reaper.
So say I want to play from bar 4 in the wav for 2 bars at bar 8 in Reaper.
I have
Drums120bpm.wav in C:/Temp
Code:
desc:wav-player
@init
// declare and zero these (not needed in JSFX, but good to do anyway
// to keep track of what variables we are using).
// mem_pos = cur_pos = 0;
mem_pos = 0;
cur_pos = 350000;
handle = file_open("C:/Temp/Drums120bpm.wav");
// if our file is a RIFF then num_channels and samplerate will
// be set here
file_riff(handle, num_channels, samplerate);
// remember we have a giant array of memory, so mem_pos is the
// position in this array that the file contents will be put
num_channels > 0 ? (
amt = file_mem(handle, mem_pos, file_avail(handle));
);
// we have our samples stored (or not if the above failed) in
// memory, so close file here
file_close(handle);
@sample
// only play when reaper is playing and if valid riff file (amt is positive)
amt && play_state ? (
spl0 = mem_pos[cur_pos];
// deal with stereo or mono, ignores extra channels
num_channels == 2 ? (
spl1 = mem_pos[cur_pos + 1];
) : (
spl1 = mem_pos[cur_pos];
);
// increment our position by number of channels or loop back to zero
// if we've reached the end
cur_pos += num_channels;
cur_pos > amt ? cur_pos = 0;
);