Building a 1024 size array from 512 chunks of data


#1

Hi all,

I’m trying to create a plug in that does processing on 512 sample chunks. Part of the code performs an auto-correlation on a 1024 size array. So my idea is read data into 1024 array using these lines of code

for (int fillHalfBuffer = 0; fillHalfBuffer < numSamples; fillHalfBuffer++)
	{
		bufferSize_2[fillHalfBuffer] = bufferSize_2[fillHalfBuffer + 512];
	}

	for (int fillRemaining = 512; fillRemaining < 1024; fillRemaining++)
	{
		bufferSize_2[fillRemaining] = channelData[fillRemaining - 512];
	}

I tried this out in a console application in VS (for debugging purposes) and it works fine , but as a .dll it does not. Performing an auto-correlation on lower guitar notes ( say E ) that take > 1000 samples for 2 cycles returns gibberish, but any note <512 samples per 2 cycles seems to work ok. Obviously something is getting messed up in my 1024 buffer…

Any ideas why this may be happening?


#2

Is numSamples always 512? The buffer size coming into a plug-in can vary, so you should be buffering however much arrives until you’ve got enough to do the autocorrelation.


#3

Yes it should always be 512. I m using plug in within reaper and have buffer size set to 512 under audio preferences. . Is debuggin .dll files always this hard lol. Im basically using the Gui of plug in to aid me but it gives me limited scope to debug


#4

You may have set it to 512 but the audio hardware and/or Reaper doesn’t necessarily ask you to process buffers of that exact length. In any case, you should not make your code based on the assumption the buffer length is going to be anything particular. You must be prepared to handle arbitrary buffer lengths. (And the lengths may also change between each call to processBlock.)


#5

I think i understand your point. Although if the buffer size is set to 512 ( i realize this is not a great way of doing things as plug in will crash if its set higher and not fill 1024 buffer if set <512 ) , how could it be messing up the auto correlation?

Also could you recommend any good reading material on coding audio plug ins ? Im basically working off of JUCE examples at mo… thanks for reply !


#6

Your code must be prepared to handle buffers of arbitrary size!..including zero! The host may choose to send different buffer sizes with every block!

As Jules is always reminding us, do not make any assumptions about what the host will send. Make sure your code can handle all scenarios!


#7

Ah i didnt realise that… so the when you set up a 512 size buffer in host it will try to send 512 samples but does not guarantee it ?

Its odd because originally i had my code waiting on 1024 chunks, and it worked very well so i thought the problem was with building a 1024 buffer out of 512 chunks… i thought maybe c++ memory management was clearing buffers or something similar thus causing my 1024 buffer to never be full…