Cycling74/max-sdk

Feature Request : buffer_setsize() or any other good name, provide change buffer size function

Opened this issue · 2 comments

leico commented

Hello and Happy new year C74 Dev team.
First, I want to tell thank you, I appreciate your great jobs.

In this issue I would like to talk a above feature. Now I am creating a external object. It manipulate buffer~, I would like to implement a feature like std :: vector. I implemented like :

...
err = buffer_unlock( buffer_obj );
if( err != MAX_ERR_NONE ) //exception routine

object_method( buffer_obj, gensym("sizeinsamps"), samples * 2);

err = buffer_lock( buffer_obj );
if( err != MAX_ERR_NONE ) //exception routine
...

I guessed need to unlock a critical section to use buffer~ 's "sizeinsamps" message. But it allowed to interrupt other thread. This code may safe about multi thread process, but it can not guarantee data integrity.

If can change size without unlock, buffer manipulation is going to more useful I guess.

On the other hands, yes you can tell It doesn't need, or It is not supported.

Thanks to read.

tap commented

Changing buffer sizes is indeed a tricky situation.

If the buffer is locked then it will not resize, as you note. When you send the message to the buffer object, the buffer will lock itself (or wait until it can lock itself).

leico commented

@tap , thanks reply. Now I am manipulating a buffer~ in normal thread. Above point, sometimes DSP thread steal buffer~ . groove~ plays fragment data, also 'record~' overwrites buffer~. I would like to keep buffer~ when change buffer~ size.