Board index » delphi » function to access dynamic array

function to access dynamic array

Hi,
BC++ 5.02, digital audio application.
I have some very large float arrays, or which the size is unknown at
design time. Therefore they are dynamically created at runtime.

I wish to access this array with a function. If I do the following, it
is ok...
int main()
{ // numBytes is variable numSamples * sizeof(SAMPLE)
  recordedSamples = (SAMPLE *) malloc (numBytes);
  removeRightSamples(recordedsamples);
  return 0;

Quote
}

void removeRightSamples(float samples[]);
{

Quote
}

My problem is that if I try to pass the value of the address of any one
of the items of the array (recordedsamples[0] for instance), I get a
compile time error.

What I am trying to do is split the array into two logical segments and
deal with each half by calling 'removeRightSamples()'. I wish to pass
recordedsamples[0], and recordedsamples[768000] (halfway point of the
array).

What is the best way to do this, assuming that I have to deal with a
single array?
The message I get is something like "error converting (float **) to
(float *)".

Gordon Gidluck

 

Re:function to access dynamic array


Gordon,

Quote
> The message I get is something like "error converting (float **) to
> (float *)

What that is saying is that the compiler is expecting the address of
a pointer to a float and you've only give it a pointer to a float.
The answer is to add an '&' prefix to what you're passing in:

  removeRightSamples( &recordedSamples[ 768000 ] );

Andrue Cope
[Bicester, UK]

Re:function to access dynamic array


I am not sure what you intend to do, but I thought that you may try to fill
a buffer use the first half then use the other half. Often its more useful
to declare two pointers to the first half and the second half, then you swap
these when time is to fill the next half array of samples. Thats common
usage when dealing w audio files, and reading one chunk at a time.

int main()
{ // numBytes is variable numSamples * sizeof(SAMPLE)
    SAMPLE *spLeftHalf, *spRightHalf;
  recordedSamples = (SAMPLE *) malloc (numBytes);
spLeftHalf = recordedSamples;
spRightHalf = &recordedSamples[768000];
/* or */
spRightHalf = spLeftHalf  + 768000;

  removeRightSamples(spRightHalf); /* ?? */
  return 0;

Quote
}

// Svenne

Other Threads