1

EDIT: C++ bits removed to avoid confusion

I have an array of data like so

int numSamples = 16;
float *lData  = (float*)calloc(numSamples, sizeof(float));

...and I would like to pass this data into a function with a definition like this . . .

void processSampleBlock (const float ** inputChannelData,
                         int    numInputChannels,
                         ...)

As you can see, this function accepts a 2D array, that can have multiple channels. My data is only a single channel (1D), but I can get the code to compile fine by doing a cast like this . .

processSampleBlock ((const float**)(lData),
                            1,
                            ...)

However, I get a bad access error at runtime then code within the function block attempts to dereference the data within the function . .

for (int nn=0; nn< numSamples; ++nn)
{
    float x = inputChannelData[0][nn]; //--> Computer says no
}

I am useless with C style multi-dimensional arrays and am probably making a fundamental error here. Any help would be great! Thanks

4
  • boost::scoped_array<float> - Why is this tagged C? Commented May 25, 2012 at 10:53
  • Sorry, my problem was with the C-style bit :) Commented May 25, 2012 at 11:03
  • Why can't the array of pointers to the rows just contain a single pointer to a single row? Commented May 25, 2012 at 11:09
  • 1
    @learnvst - if you compile C-style code with a C++ compiler, it's not C code. These are two languages with subtle differences. If you intend to get a C++ answer, tag it as C++. Commented May 25, 2012 at 11:16

1 Answer 1

5

You need to give it a pointer to an array of rows, so of you have one row give it a pointer to that row:

float *data = ...;
processSampleBlock(&data, 1);
Sign up to request clarification or add additional context in comments.

3 Comments

@Bo, he said he has only 1 channel
lData.get() returns a pointer. The syntax you posted gives a compiler error
I have edited the question to remove all of the potentially confusing boosty stuff.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.