Jonne Valola / PokittoLib Featured

Dependents:   YATTT sd_map_test cPong SnowDemo ... more

PokittoLib

Library for programming Pokitto hardware

How to Use

  1. Import this library to online compiler (see button "import" on the right hand side
  2. DO NOT import mbed-src anymore, a better version is now included inside PokittoLib
  3. Change My_settings.h according to your project
  4. Start coding!
Revision:
66:6281a40d73e6
Parent:
58:5f58a2846a20
--- a/POKITTO_CORE/PokittoSound.cpp	Sat Mar 23 19:22:35 2019 +0000
+++ b/POKITTO_CORE/PokittoSound.cpp	Sat Mar 23 20:03:34 2019 +0000
@@ -43,7 +43,7 @@
  *
  * License for Gamebuino-identical code:
  *
- * (C) Copyright 2014 Aur�lien Rodot. All rights reserved.
+ * (C) Copyright 2014 Aurélien Rodot. All rights reserved.
  *
  * This file is part of the Gamebuino Library (http://gamebuino.com)
  *
@@ -68,6 +68,11 @@
 
 #ifndef POK_SIM
 #include "HWSound.h"
+
+#ifdef PROJ_SDFS_STREAMING
+#include "SDFSDisk.h"
+#endif
+
 #else
 #include "SimSound.h"
 #include "PokittoSimulator.h"
@@ -77,15 +82,22 @@
 
 using namespace Pokitto;
 
+#ifdef PROJ_SND_DEBUG
+int __sx=0;
+#endif
+
 /** discrete hardware volume control **/
 
 uint8_t Pokitto::discrete_vol = 0;
-uint8_t const Pokitto::discrete_vol_levels[]      = {0,32,64,96,128,160,192,224};
-uint8_t const Pokitto::discrete_vol_hw_levels[]   = {0,27,64,96,36,117,127,127};
-uint8_t const Pokitto::discrete_vol_multipliers[] = {0,127,127,127,192,192,255,255};
+uint8_t const Pokitto::discrete_vol_levels[8]      {0,32,64,96,128,160,192,224};
+uint8_t const Pokitto::discrete_vol_hw_levels[8]   {0,27,64,96,36,117,127,127};
+uint8_t const Pokitto::discrete_vol_multipliers[8] {0,127,127,127,192,192,255,255};
 
 Pokitto::Core _soundc;
 
+const uint8_t *Sound::sfxDataPtr = 0;
+const uint8_t *Sound::sfxEndPtr = 0;
+
 uint8_t Sound::prescaler;
 uint16_t Sound::globalVolume;
 uint16_t Sound::volumeMax = VOLUME_HEADPHONE_MAX;
@@ -135,8 +147,10 @@
 uint8_t Sound::chanVolumes[NUM_CHANNELS];
 
 #if (POK_ENABLE_SOUND < 1)
+ #ifdef NUM_CHANNELS
  #undef NUM_CHANNELS
  #define NUM_CHANNELS 0
+ #endif // NUM_CHANNELS
 #endif
 
 #if(NUM_CHANNELS > 0)
@@ -609,6 +623,7 @@
 		// jonnehw noInterrupts();
 		_chanHalfPeriod[i] = pgm_read_byte(_halfPeriods + outputPitch[i]);
 		_chanOutput[i] = _chanOutputVolume[i] = outputVolume[i] * (globalVolume>>GLOBVOL_SHIFT) * chanVolumes[i] * stepVolume[i];
+		//_chanOutput[i] = _chanOutputVolume[i] = outputVolume[i] * (globalVolume) * chanVolumes[i] * stepVolume[i];
 		//Serial.println(outputVolume[i]);
 		// jonnehw interrupts();
 	}
@@ -752,6 +767,7 @@
             output >>= 8;
             dac_write((uint8_t)output); //direct hardware mixing baby !
     soundbyte = output;
+
     #endif //POK_ENABLE_SOUND
     #else
     /** SIMULATOR **/
@@ -763,6 +779,7 @@
         #endif
         soundbyte = output;//<<headPhoneLevel;
     #endif // POK_SIM
+
 #endif
 }
 
@@ -803,12 +820,14 @@
 	if (volume<0) volume = 0;
 	//if (volume>volumeMax) volume = volumeMax;
 	globalVolume = volume;
-	#if POK_ENABLE_SOUND > 0
+	//#if POK_ENABLE_SOUND > 0
 	discrete_vol = (volume>>5);
 	#ifndef POK_SIM
+	#if POK_ENABLE_SOUND > 0
 	setHWvolume(discrete_vol_hw_levels[discrete_vol]); //boost volume if headphonelevel
 	#endif
 	#endif
+	//#endif
 	#if POK_SHOW_VOLUME > 0
 	_soundc.volbar_visible = VOLUMEBAR_TIMEOUT;
 	#endif
@@ -845,7 +864,7 @@
 
 void Sound::playTone(uint8_t os, int frq, uint8_t amp, uint8_t wav,uint8_t arpmode)
 {
-    if (wav>5) wav=0;
+    if (wav>MAX_WAVETYPES) wav=0;
     if (arpmode>MAX_ARPMODE) arpmode=MAX_ARPMODE;
     if (os==1) setOSC(&osc1,1,wav,1,0,0,frq,amp,0,0,0,0,0,0,arpmode,0,0);
     else if (os==2) setOSC(&osc2,1,wav,1,0,0,frq,amp,0,0,0,0,0,0,arpmode,0,0);
@@ -893,9 +912,9 @@
     if (currentPtr) {
             pokPlayStream();
             return 1;
-    } else return 0; //no stream
+    }
     #endif // POK_STREAMING_MUSIC
-    return 0;
+    return 0; //no stream
 }
 
 void Sound::pauseMusicStream() {
@@ -907,12 +926,16 @@
 int Sound::playMusicStream(char* filename, uint8_t options)
 {
     #if POK_STREAMING_MUSIC
+
         uint8_t result;
         result = pokInitSD();
         if (!isThisFileOpen(filename)) {
             fileClose(); // close any open files
             result = fileOpen(filename,FILE_MODE_READONLY | FILE_MODE_BINARY);
-        }
+        }else{
+	    fileRewind();
+	    result = 0;
+	}
 
         if (result) {
                 currentPtr = 0; // mark that no stream is available
@@ -948,3 +971,13 @@
     return 0;
 }
 
+void Sound::loadSampleToOsc(uint8_t os, uint8_t* data, uint32_t datasize) {
+    OSC* o;
+    if (os==3) o = &osc3;
+    else if (os==2) o = &osc2;
+    else o = &osc1;
+    o->sample = data;
+    o->samplelength = datasize;
+    o->samplepos = 0;
+}
+