Getnumsamples() comes back 2048 but inspecting the data shows only 512 samples


#1

in my process block method, the buffer.getnumsamples() method returns 2048.

when i inspect the sample buffer, only the first 512 of the buffer have data, while the remaining 75% have the value “-431602080.”


#2

even when i change my plugin to 512 samples for the buffer, the array now only has 128 points of data…is there something im missing as to why there is 75% of useless info in the buffer?


#3

How is the bus layout defined?
If you have more output channels than input channels, there are channels that are not filled by the host (hence the code in the boiler plate to silence these channels)


#4

So the first half of the buffer is input and last half output? i thought the buffer was both input and output in the same place? as far as i know i have 2 input channels(l+r) and 2 output channels (l+r)


#5

How do i lock my plugin to stereo input and stereo output?


#6

No no, you got me wrong. But if a channel is not used as input channel, then the data is random, that’s why I suggested to check, if there might be just accidentally 512 samples useful data.

You are aware, that the buffer size can be different on each call of processBlock?

There are several options, the most reliant is to override the

bool MyAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const
{
    // This checks if the input layout matches the output layout
    if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
        return false;

    return (layouts.getMainOutputChannelSet() == AudioChannelSet::stereo());
}

Sorry if my previous answer was misleading…


#7

ok so i have my input channel set to stereo and output set to stereo . i have the same number of input channels as i do outputs yet there is still only half of the array populated with real data…2048 samples in a buffer, 512 are left 512 are right, the other 1024 is silent… i dont know why it is there. i have the same number of channels on both input and output…i see people doing a for loop on the number of samples, if it did this, id spent twice as much time int he for loop as i need to. i could always jut say for(int i=0; i<numsamples/2;i++) but that seems hackish, and i dont know if on another machine how it will behave

calling getnumchannels returns 2;


#8

also setting a breakpoint in the isbuseslayoutsupported method shows that it isnt executed…if built as a standalone app, does this method not get called?


#9

Rail


#10

Yes, definitively don’t do that. It is very wise of you not to trust that kind of assumptions.

Just to double check, would you mind sharing the processBlock you implemented, to understand how you experienced this obviously wrong number of getNumSamples()?

That wouldn’t surprise me much, because isBusesLayoutSupported is used, when the host negotiates a suitable layout for the plugin with the track you try to insert it.
Since the Standalone App doesn’t have a track layout, it makes not much sense to call the isBusesLayoutSupported. It could check with the deviceManagers channel settings though, but I don’t think that is the case.


#11
void AudioTattooAudioProcessor::processBlock(AudioBuffer& buffer, MidiBuffer& midiMessages)

{
float * data1 = buffer.getWritePointer(0);
//float * data2 = buffer.getWritePointer(1);
int numsam = buffer.getNumSamples();
memcpy(fftData, data1, numsam);

}
note that i am copying to the array just for breakpoint analysis.(i want to see the content of the buffer, and VS2017 only see's the first float when you inspect a float pointer)

my product is a post recording, plugin that sits at the end of the chain. it is not intended to be a live plugin.
What i want to end up doing is take a 10 second sample, do an FFT of this 10 second sample, manipulate the magnitude of the freq, invert the FFT and output the 10 second sample and keep this rolling…so the output should be 10 seconds + processing time behind the input. If this isn’t feasible, my second option is to buffer the entire song then output it. the standalone version of this is way simpler, just load a wav file and go, but getting from the live world to post recording in a vst is throwing me off. is juce not the platform to use here? how does an eq vst that uses FFT do it post recording?


#12

memcpy copies a number of bytes so your code is wrong, each float takes 4 bytes, so it should be something like :

memcpy(fftData, data1, numsam*sizeof(float));

But preferably you shouldn’t even use something like memcpy in C++…

By the way, to do something like FFT, you will need consider that the hosts are not going to provide you the exact FFT length of sample data except by chance. You will need to prepared for the length of the buffer to be pretty much anything from 1 sample to several thousand samples. And the host is not obligated to make those lengths even or power-of-2…You will also need to output the exact length of sample data that the host gave you in the input. (So that complicates doing things like FFT even more.)


#13

Wonderful, that was it, i was only allocating 25% of the space, duh. i now have 2048 floats thanks bud. also, in the situation where there isn’t 2048 samples in the buffer, will a simple if statement on the get number of samples method let me know?