
Originally Posted by
BlueFang
How to use the wave expression in the same way as wave2(a,b) using the show audio file instead of the live audio input?
That's a feature I have requested a long time ago. I haven't found an actual solution but the next best thing is as you suggest, using your own buffer. Creating a buffer is simple enough and reading it out is easy as well... the trouble rises when you want to fill in the buffer with data. I haven't found a way that fills the buffer continuously with audio data. You'd need to somehow create a concurrent "thread" or expression loop that runs while the other expressions are evaluated.
This is the simplest solution:
Code:
i=0;
repeat(200,
assign(gbuf(i), wave)
& assign(i, i+1)
);
result=gbuf(idx*200);
This way makes use of the gbuf(a) expression: this is a global buffer (hence the name) which can be used across expressions and across timelines. You can access it by giving it an integer as argument, this returns the value stored at that location in the buffer. Storing a value happens by using the assign(a,b) expression, which assigns the value b to the variable it finds in a. So, assign(gbuf(5), 0.5) stores the value 0.5 at location 5 in the global buffer. There are a million locations, according to the expression help.
The repeat(a,b) expression is the for loop in LSX. The first argument (a) is the number of iterations, the second (b) the statement that needs to be evaluated. Multiple statements can be separated by an & (no need for a semicolon). Inside the repeat expression, assigning a value to a variable with the = operator doesn't work, but assign(a,b) works just fine.
Reading out the buffer is done by simply using the idx variable multiplied by 200, which was the number of points in my test (maybe it's a good idea to use a var() for that instead).
So what this piece of code does is get the value stored in the wave variable and assign it to a location in the buffer which is then used to create a wavelike shape. But the result is usually a straight line at random y positions, as the wave variable doesn't or nearly doesn't change during the loop. Worse, this expression isn't evaluated constantly so you get only a small amount of all wave values that "happened".
I don't have an obvious solution for this. I'm sorry. But I can offer you this:
Code:
inttime = time - lasttime;
if( above( inttime, 1), assign(go, 1) & assign(lasttime, time), assign(go, 0));
i=0;
if(go,
repeat(201,
assign(gbuf(i), gbuf(i+1))
& assign(i, i+1)
)
,0);
assign(gbuf(200),wave);
result=gbuf(idx*201)+0.25;
This expression loops through the buffer and shifts all values one position in the buffer. The additional go part is so that it doesn't loop too fast (or you're back at the previous problem). It's a bit too slow for my taste but probably closer to the ultimate solution.