Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: PokittoLib
Diff: main.cpp
- Revision:
- 1:ca29888d96a9
- Parent:
- 0:89ca7e98cd78
diff -r 89ca7e98cd78 -r ca29888d96a9 main.cpp
--- a/main.cpp Fri Mar 30 20:09:40 2018 +0000
+++ b/main.cpp Fri Mar 30 20:25:48 2018 +0000
@@ -2,6 +2,7 @@
Pokitto::Core mygame;
+// Fills an audio buffer with the samples generated by the Bytebeat function
void generateBuffer(uint32_t bufferIndex, uint32_t nextT) {
uint32_t index= 0;
@@ -14,25 +15,27 @@
int main () {
mygame.begin();
- mygame.display.persistence = true;
+ mygame.display.persistence = true; // Do not clear screen
mygame.display.paletteptr[2] = COLOR_YELLOW;
- // Generate 4 buffers ahead
+ // The audio engine uses 4 buffers. Generate all 4 buffers ahead.
uint32_t nextT = 0;
generateBuffer(0, nextT); nextT += BUFFER_SIZE;
generateBuffer(1, nextT); nextT += BUFFER_SIZE;
generateBuffer(2, nextT); nextT += BUFFER_SIZE;
generateBuffer(3, nextT); nextT += BUFFER_SIZE;
- // Set global variables
+ // Set global audio variables
currentBuffer = 0;
currentPtr = buffers[currentBuffer];
endPtr = currentPtr + BUFFER_SIZE;
+ // Init audio stream.
pokPlayStream(); // activate stream
mygame.sound.ampEnable(true);
mygame.sound.playMusicStream();
+ // Print to the screen once.
mygame.display.set_cursor(0,0);
mygame.display.println("ByteBeat function:");
mygame.display.println("");
@@ -45,9 +48,10 @@
while (mygame.isRunning()) {
if (mygame.update()) {
+ // Fill the next buffer if it is not used currently
if((uint32_t)currentBuffer != nextBufferIndexToFill) {
- // Generate buffer if already played.
+ // Generate buffer
generateBuffer(nextBufferIndexToFill, nextT);
if(++nextBufferIndexToFill > 3)