Implementation of Bytebeat algorithm on Pokitto. Bytebeat is generated music which is made by algorithm using usually one line function. The music is created as 8-bit samples. The simplest Bytebeat function is " t & (t>>8)" which combines two sawtooth waves: one higher frequency tone (t) and the other lower frequency (t<<8) tone. Read more in: http://countercomplex.blogspot.fi/2011/10/algorithmic-symphonies-from-one-line-of.html

Dependencies:   PokittoLib

ByteBeat3 - mathematical beats

Implementation of Bytebeat algorithm on Pokitto. Bytebeat is generated music which is made by algorithm using usually one line function. The music is created as 8-bit samples.

The simplest Bytebeat function is " t & (t>>8)" which combines two sawtooth waves: one higher frequency tone (t) and the other lower frequency (t<<8) tone.

Read more in: http://countercomplex.blogspot.fi/2011/10/algorithmic-symphonies-from-one-line-of.html

Revision:
0:89ca7e98cd78
Child:
1:ca29888d96a9
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Mar 30 20:09:40 2018 +0000
@@ -0,0 +1,59 @@
+#include "Pokitto.h"
+
+Pokitto::Core mygame;
+
+void generateBuffer(uint32_t bufferIndex, uint32_t nextT) {
+
+    uint32_t index= 0;
+    for(uint32_t t=nextT; t<nextT+BUFFER_SIZE; t++,index++)
+        //buffers[nextBufferIndexToFill][index] = t & (t>>8);
+        buffers[bufferIndex][index] = ((t<<1)^((t<<1)+(t>>7)&t>>12))|t>>(4-(1^7&(t>>19)))|t>>7;
+        //buffers[bufferIndex][index] = (t*9&t>>4|t*5&t>>7|t*3&t/1024)-1;
+}
+
+
+int main () {
+    mygame.begin();
+    mygame.display.persistence = true;
+    mygame.display.paletteptr[2] = COLOR_YELLOW;
+
+    // Generate 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
+    currentBuffer = 0;
+    currentPtr = buffers[currentBuffer];
+    endPtr = currentPtr + BUFFER_SIZE;
+
+    pokPlayStream(); // activate stream
+    mygame.sound.ampEnable(true);
+    mygame.sound.playMusicStream();
+
+    mygame.display.set_cursor(0,0);
+    mygame.display.println("ByteBeat function:");
+    mygame.display.println("");
+    mygame.display.color = 2;
+    mygame.display.println("((t<<1)^((t<<1)+(t>>7)");
+    mygame.display.println("&t>>12))|t>>(4-(1^7&");
+    mygame.display.println("(t>>19)))|t>>7");
+
+    uint32_t nextBufferIndexToFill = 0;
+    while (mygame.isRunning()) {
+        if (mygame.update()) {
+
+            if((uint32_t)currentBuffer != nextBufferIndexToFill) {
+
+                // Generate buffer if already played.
+                generateBuffer(nextBufferIndexToFill, nextT);
+
+                if(++nextBufferIndexToFill > 3)
+                    nextBufferIndexToFill = 0;
+                nextT += BUFFER_SIZE;
+            }
+        }
+    }
+}