Minor change to buffer size

Set buffer size back to set value rather than bases on values obtained
from file.
Fixed some indentation and removed some old debugging chaff.

Signed-off-by: Mahyar Koshkouei <deltabeard@users.noreply.github.com>
This commit is contained in:
Mahyar Koshkouei
2016-12-04 13:29:54 +00:00
parent 3c49a862c3
commit 7a08c05e1a

View File

@@ -164,8 +164,6 @@ int playWav(const char *wav)
u32 blockalign; u32 blockalign;
u32* buffer1 = NULL; u32* buffer1 = NULL;
u32* buffer2 = NULL; u32* buffer2 = NULL;
off_t size;
off_t buffer_size;
ndspWaveBuf waveBuf[2]; ndspWaveBuf waveBuf[2];
bool playing = true; bool playing = true;
bool lastbuf = false; bool lastbuf = false;
@@ -248,17 +246,14 @@ int playWav(const char *wav)
ndspChnSetFormat(CHANNEL, bitness); ndspChnSetFormat(CHANNEL, bitness);
memset(waveBuf, 0, sizeof(waveBuf)); memset(waveBuf, 0, sizeof(waveBuf));
/* TODO: Use return value of fread to get number of samples. buffer1 = (u32*) linearAlloc(BUFFER_SIZE);
* TODO: Move all of this in the while loop. buffer2 = (u32*) linearAlloc(BUFFER_SIZE);
*/
buffer1 = (u32*) linearAlloc(sample);
buffer2 = (u32*) linearAlloc(sample);
fread(buffer1, 1, sample, file); fread(buffer1, 1, BUFFER_SIZE, file);
fread(buffer2, 1, sample, file); fread(buffer2, 1, BUFFER_SIZE, file);
waveBuf[0].nsamples = sample / blockalign; waveBuf[0].nsamples = BUFFER_SIZE / blockalign;
waveBuf[0].data_vaddr = &buffer1[0]; waveBuf[0].data_vaddr = &buffer1[0];
waveBuf[1].nsamples = sample / blockalign; waveBuf[1].nsamples = BUFFER_SIZE / blockalign;
waveBuf[1].data_vaddr = &buffer2[0]; waveBuf[1].data_vaddr = &buffer2[0];
ndspChnWaveBufAdd(CHANNEL, &waveBuf[0]); ndspChnWaveBufAdd(CHANNEL, &waveBuf[0]);
ndspChnWaveBufAdd(CHANNEL, &waveBuf[1]); ndspChnWaveBufAdd(CHANNEL, &waveBuf[1]);
@@ -289,25 +284,19 @@ int playWav(const char *wav)
if(kDown & KEY_A) if(kDown & KEY_A)
playing = !playing; playing = !playing;
if(kDown & KEY_X)
{
debug_print("Pos: %lx of %lx\n", ndspChnGetSamplePos(CHANNEL),
buffer_size / bitness);
}
if(playing == false || lastbuf == true) if(playing == false || lastbuf == true)
continue; continue;
if(waveBuf[0].status == NDSP_WBUF_DONE) if(waveBuf[0].status == NDSP_WBUF_DONE)
{ {
size_t read = fread(buffer1, 1, sample, file); size_t read = fread(buffer1, 1, BUFFER_SIZE, file);
if(read == 0) if(read == 0)
{ {
lastbuf = true; lastbuf = true;
continue; continue;
} }
else if(read < sample) else if(read < BUFFER_SIZE)
waveBuf[0].nsamples = read / blockalign; waveBuf[0].nsamples = read / blockalign;
ndspChnWaveBufAdd(CHANNEL, &waveBuf[0]); ndspChnWaveBufAdd(CHANNEL, &waveBuf[0]);
@@ -315,21 +304,21 @@ int playWav(const char *wav)
if(waveBuf[1].status == NDSP_WBUF_DONE) if(waveBuf[1].status == NDSP_WBUF_DONE)
{ {
size_t read = fread(buffer2, 1, sample, file); size_t read = fread(buffer2, 1, BUFFER_SIZE, file);
if(read == 0) if(read == 0)
{ {
lastbuf = true; lastbuf = true;
continue; continue;
} }
else if(read < sample) else if(read < BUFFER_SIZE)
waveBuf[1].nsamples = read / blockalign; waveBuf[1].nsamples = read / blockalign;
ndspChnWaveBufAdd(CHANNEL, &waveBuf[1]); ndspChnWaveBufAdd(CHANNEL, &waveBuf[1]);
} }
DSP_FlushDataCache(buffer1, sample); DSP_FlushDataCache(buffer1, BUFFER_SIZE);
DSP_FlushDataCache(buffer2, sample); DSP_FlushDataCache(buffer2, BUFFER_SIZE);
// TODO: Remove this printf. // TODO: Remove this printf.
printf("\rBuf0: %s, Buf1: %s.", waveBuf[0].status == NDSP_WBUF_QUEUED ? "Queued" : "Playing", printf("\rBuf0: %s, Buf1: %s.", waveBuf[0].status == NDSP_WBUF_QUEUED ? "Queued" : "Playing",