Reading array of getArrayOfReadPointers


#1

Hey all, I’m trying to verify the accuracy of an audio buffer and the values being processed after my processing algorithm. So, I’m dbg an array of read pointers before processing and an array after debugging. Was wondering if there is an easier way to read the values within an audio buffer than DBG or std::cout. Or, if not, is there a way to read these values and not get hexadecimal values? It is my understanding that “read in” files are in binary format, but how can I see the floating point values of the read in files?

I appreciate your time


#2

If you are getting hexadecimal values, I guess you are looking at the pointers to the buffers and not the actual audio sample values…?


#3

Yes, so when I try to deference the pointer to the array I get a segmentation fault.
I’ve tried

// The values we want to inspect (file values from the input file).
auto currentValuesInBuffer = currentAudioSampleBuffer->getArrayOfReadPointers();
for (auto i = 0; i < sizeof (currentValuesInBuffer); i++)
    std::cout << currentValuesInBuffer[i];

and

    // The values we want to inspect (file values from the input file).
auto currentValuesInBuffer = currentAudioSampleBuffer->getArrayOfReadPointers();
for (auto i = 0; i < sizeof (currentValuesInBuffer); i++)
    std::cout << *currentValuesInBuffer[i];

It will not compile any other way. Unfortunately, I’ve only got about a year and a half of C++11 under my belt so I’m not incredibly familiar with how I would proceed in this case.

Thanks for the reply… I’m sure I’m doing something really stupid.


#4

You can do it like this, but it’s going to be pretty much useless, your console is just going to be filled with the sample data values. Also if this is happening in a real time audio thread, the printing will very likely cause problems for the audio playback…

    for (int i=0;i<buffer.getNumChannels();++i)
    {
        std::cout << "Channel " << i << "\n";
        for (int j=0;j<buffer.getNumSamples();++j)
        {
            std::cout << buffer.getSample(i, j) << " ";
        }
        std::cout << "\n";
    }

I didn’t use getArrayOfReadPointers in the code because it’s not necessary. I’ve actually started myself gradually to just use getSample and setSample with code that uses the JUCE AudioBuffers. The meaning of the code is much simpler and one will also get JUCE assertions during debugging if the channel and sample indexes are wrong. (If one is worried about performance, a C++ compiler would need to be pretty braindead if it can’t optimize those function calls out.)


#5

sizeof doesn’t do what you think it does. Here sizeof(currentValuesInBuffer) is equivalent to sizeof(Type**), which is either sizeof(float**) or sizeof(double**), which is 64 (or 32 depending on the architecture).

What you want to use is currentAudioSampleBuffer->getNumSamples().


#6

Thank you @Xenakios and @McMartin. Real rookie mistake not catching that sizeof error. Anyways, you both have been very helpful and I appreciate your time on such a trivial error.