128 is the midpoint for unsigned 8-bit pulse-code modulation.
In this case a picture is worth a thousand words:
So basically a string of 128 should effectively be a sound ‘flatline’,
meaning the transition into the first sound should be smoother.
(255 is max amplitude, 0 is minimum amplitude.)
It’s possible this is related to your problem, but probably unlikely.
You could certainly try filling with 0 instead to see if that makes things better or worse.
Maybe there’s some kind of mixup between signed and unsigned PCM somewhere?
In signed PCM the baseline is 0, 127 is max amplitude and -128 is min amplitude.
(And now you probably know more or less as much about sound programming as I do. :P
)
The reason &buffers[index][0]
should work (with index
being 0, 1, 2 and 3 in your case) in both cases is because of the types involved:
In the high-RAM case decltype(buffers[index])
is unsigned char *
,
and in the other case it’s unsigned char (&)[BUFFER_SIZE]
.
In both of those cases applying [0]
retrieves an unsigned char
,
thus &
retrieves the address of that unsigned char
,
so in both cases you get an unsigned char *
from the expression despite the type of buffers
being different.
Personally I think it would be better if the buffer pointer were retrieved with a function or if buffers
had the same type under both conditions
Example code
#if POK_HIGH_RAM == HIGH_RAM_MUSIC
unsigned char * buffers[4]
{
reinterpret_cast<unsigned char *>(0x20000000),
reinterpret_cast<unsigned char *>(0x20000400),
reinterpret_cast<unsigned char *>(0x20004000),
reinterpret_cast<unsigned char *>(0x20004400),
};
#else
unsigned char bufferMemory[4][BUFFER_SIZE];
unsigned char * buffers[4]
{
&bufferMemory[0][0],
&bufferMemory[1][0],
&bufferMemory[2][0],
&bufferMemory[3][0],
};
#endif
Or
unsigned char * getBuffer(std::size_t index)
{
// Could also use a preprocessor '#if'
// but since C++17 is available I thought I'd demonstrate this
if constexpr (POK_HIGH_RAM == HIGH_RAM_MUSIC)
return buffers[index];
else
return &buffers[index][0];
}
unsigned char * getBufferSafe(std::size_t index)
{
return (index > 3) ? nullptr : getBuffer(index);
}