Update audio play demo to play in a loop (easier for testing)

This commit is contained in:
inmarket 2014-03-30 19:07:17 +10:00
parent 1e1385d569
commit cd5abc421d

View file

@ -52,7 +52,7 @@ int main(void) {
uint32_t frequency; uint32_t frequency;
ArrayDataFormat datafmt; ArrayDataFormat datafmt;
uint32_t len; uint32_t len;
GAudioData *paud; GDataBuffer *pd;
// Initialise everything // Initialise everything
gfxInit(); gfxInit();
@ -69,6 +69,7 @@ int main(void) {
goto theend; goto theend;
} }
repeatplay:
// Open the wave file // Open the wave file
if (!(f = gfileOpen("allwrong.wav", "r"))) { if (!(f = gfileOpen("allwrong.wav", "r"))) {
errmsg = "Err: Open WAV"; errmsg = "Err: Open WAV";
@ -164,20 +165,20 @@ int main(void) {
gdispDrawString(0, gdispGetHeight()/2, "Playing...", font, Yellow); gdispDrawString(0, gdispGetHeight()/2, "Playing...", font, Yellow);
while(toplay) { while(toplay) {
// Get a buffer to put the data into // Get a buffer to put the data into
paud = gfxBufferGet(TIME_INFINITE); // This should never fail as we are waiting forever pd = gfxBufferGet(TIME_INFINITE); // This should never fail as we are waiting forever
// How much data can we put in // How much data can we put in
len = toplay > paud->size ? paud->size : toplay; len = toplay > pd->size ? pd->size : toplay;
paud->len = len; pd->len = len;
toplay -= len; toplay -= len;
// Read the data // Read the data
if (gfileRead(f, paud+1, len) != len) { if (gfileRead(f, pd+1, len) != len) {
errmsg = "Err: Read fail"; errmsg = "Err: Read fail";
goto theend; goto theend;
} }
gaudioPlay(paud); gaudioPlay(pd);
} }
gfileClose(f); gfileClose(f);
@ -185,6 +186,11 @@ int main(void) {
gaudioPlayWait(TIME_INFINITE); gaudioPlayWait(TIME_INFINITE);
gdispDrawString(0, gdispGetHeight()/2+10, "Done", font, Green); gdispDrawString(0, gdispGetHeight()/2+10, "Done", font, Green);
// Repeat the whole thing
gfxSleepMilliseconds(1500);
gdispClear(Black);
goto repeatplay;
// The end // The end
theend: theend:
if (errmsg) if (errmsg)