Cabbage Logo
Back to Cabbage Site

Changing audio buffer size in ftgen?

I’m currently storing audio as a ftgen for use in certain opcodes.

For example:

giTable ftgen 0, 0, sr, 2, 0

As I understand, this takes 1 second of audio, but I’m looking for a way to change the size of the audio buffer to another size like 0.5 seconds. Does anyone know how to achieve this?

I tried multiplying, but I only managed to change the pitch of the buffer that way…

You can always call ftgen again to change the size of the buffer, but this might cause dropouts depending on when and where you resize the function table. If you only want to play back half of the 1 second table you can just limit the amount of samples you read.

a1 phasor 1
a2 tab a1*.5, giTable, 1

or if you are not using normalised mode for the table reader:

a1 phasor 1
a2 tab a1*22050, giTable

Hmm, how would one change a2 into i-rate?

What are you trying to do exactly, if the buffer contains audio why would you want to read it at i-time?

Using this opcode as a delay-effect, which the incoming audio is the source signal function table. Trying to reduce the window to 0.5 seconds instead of 1 second as it is a bit long for the effect I’m making.

So you’re writing audio to a function table, and syncgrain is then reading from this function table? If the function table is too long, just shorten it? Instead of:

giTable ftgen 0, 0, sr, 2, 0

can you not just do:

giTable ftgen 0, 0, sr/2, 2, 0

I tried that, but it alters the pitch

I will throw together a example

1 Like

Here Example.csd (1.4 KB)

Also, any tips on how to improve the feedback functionality? Currently it also affects the volume of outgoing audio, so if the feedback is lower, the output will also be lower, and if the feedback is high the volume will be high.

A few issues here. First off, this doens’t make much sense:

gaWritePointer = phasor(1)
gaWritePointer = phasor(1)

You write ga1 to the table, and then immediately after that you overwrite the value of ga1 with ga2? Also, there is no ixmode of 2, although in this case it still works as expected because any non-0 value will cause normalisation of table length.

That code is also the problem with the repitching. You should set your phasor freq to match the size of the buffer. If you are only reading half a second long table, your phasor frequency should be two because you will be filling the buffer twice every second. Or you can just use this type of formula, which will allow you to change the buffer size to whatever you like without having to mess with the phasor frequency again:

gaWritePointer = phasor(sr/ftlen(giTable))

You might try one of the compression opcodes to sort this. There are quite a few to choose from. I don’t have much experience with them myself, but they should be pretty straightforward. You could also modify tie the two slider together and when one is at its lowest, the other should be at its highest, but this wouldn’t allow users to have them both at max volume.

Sorry, I originally had written ga1 and ga2 to to two different tables in the original code, that’s why I had that code two times.

Will test it out in the project now!

Should I add these together?

gasum = ga1 + ga2

gaWritePointer = phasor(sr/ftlen(giTable))

Also, I’m getting a lot of feedback if I increase kfreq to like 10?

You can sum them but you should probably half the result in order to prevent clipping. You are controlling the feedback yourself, can’t you just turn it down?

Yup, I will cap the max-value of the density and feedback :+1:

I owe you about 50 beers by the way :wink:

I look forward to cashing those in :beers:

1 Like