Yeah, I realized. I opted instead to use malloc() to allocate an array of char pointers, like so...
Code:
wav->chunkData = malloc(sizeof(char*) * ceil(wav->fileSize / wav->chunkSize));
for (int i = 0; i < ceil(wav->fileSize / wav->chunkSize); i++) {
wav->chunkData[i] = malloc(wav->chunkSize);
}
...then I read each chunk into memory like this...
Code:
fseek(fp, 44, SEEK_SET);
for (int i = 0; i < (int)ceil(wav->fileSize / wav->chunkSize); i++) {
fread(wav->chunkData[i], wav->chunkSize, 1, fp);
}
...then, for the initial buffer, I set it to the first element in the array. I replaced the pointer override with just some basic memcpy() usage...
Code:
memcpy(wav->data, wav->chunkData[0], wav->chunkSize);
...then, during the audio buffer feeding loop, I read the next chunk into memory like so:
Code:
stream->chunkIndex++;
memset(stream->nextData, 0, chunkSize);
memcpy(stream->nextData, wav->chunkData[stream->chunkIndex], chunkSize);
...then flush as usual.
There's a problem however; while the initial buffer flush seems to work just fine, subsequent flushes in the audio buffer feeding loop seem to fail with a result code of 0xe0e01bf5:
Code:
Module:
OS (6)
Description:
Invalid address (1013)
Summary:
Invalid argument (7)
Level:
Usage (28)
...so it seems that I'm passing an invalid address, which is odd, considering the buffer seemed to work fine when I was reading directly from the file. The fact that the initial flush works seems to indicate that the actual audio data is fine (I've tried passing copying other chunks other than the initial one into memory, and they seem to work fine). I tried inserting memset() to see if that would fix anything; it didn't. Is this another case of memory mismanagement? Or is it something else? Am I still allocating the wrong-sized buffers?