PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)
Dependents: YATTT sd_map_test cPong SnowDemo ... more
PokittoLib
Library for programming Pokitto hardware
How to Use
- Import this library to online compiler (see button "import" on the right hand side
- DO NOT import mbed-src anymore, a better version is now included inside PokittoLib
- Change My_settings.h according to your project
- Start coding!
Diff: POKITTO_HW/HWSound.cpp
- Revision:
- 67:068fa6345036
- Parent:
- 52:c04087025cab
diff -r 6281a40d73e6 -r 068fa6345036 POKITTO_HW/HWSound.cpp --- a/POKITTO_HW/HWSound.cpp Sat Mar 23 20:03:34 2019 +0000 +++ b/POKITTO_HW/HWSound.cpp Thu Apr 04 17:07:28 2019 +0000 @@ -50,15 +50,8 @@ Pokitto::Sound __shw; -#ifdef XPERIMENTAL -DigitalOut e4(EXT4); -e4=0; -#endif - using namespace Pokitto; - - #ifndef POK_SIM #if POK_ENABLE_SOUND pwmout_t* obj = &audiopwm; @@ -67,7 +60,18 @@ /** Sound Variables **/ #if (POK_STREAMING_MUSIC > 0) + +#if POK_HIGH_RAM == HIGH_RAM_MUSIC +unsigned char *buffers[4] = { + (unsigned char *) 0x20000000, + (unsigned char *) 0x20000400, + (unsigned char *) 0x20004000, + (unsigned char *) 0x20004400 +}; +#else unsigned char buffers[4][BUFFER_SIZE]; +#endif + volatile int currentBuffer = 0, oldBuffer = 0; volatile int bufindex = 0, vol=1; volatile unsigned char * currentPtr; @@ -256,15 +260,24 @@ #endif } +void Pokitto::soundInit() { + soundInit(false); +} + /** SOUND INIT **/ -void Pokitto::soundInit() { +void Pokitto::soundInit(uint8_t reinit) { + #ifdef XPERIMENTAL + mbed::DigitalOut expr4(EXT4); + expr4=0; + #endif #if POK_ENABLE_SOUND > 0 uint32_t timerFreq; #if POK_USE_PWM - + if (!reinit) { pwmout_init(&audiopwm,POK_AUD_PIN); pwmout_period_us(&audiopwm,POK_AUD_PWM_US); //was 31us pwmout_write(&audiopwm,0.1f); + } #endif //#if POK_GBSOUND > 0 @@ -385,10 +398,23 @@ #else streamstep = 1; #endif // POK_STREAMFREQ_HALVE + #ifndef PROJ_SDFS_STREAMING + streamon=1; // force enable stream + #endif streamstep &= streamon; // streamon is used to toggle SD music streaming on and off if (streamstep) { output = (*currentPtr++); - if(streamvol && streamon) { + if( Pokitto::Sound::sfxDataPtr != Pokitto::Sound::sfxEndPtr ){ + #ifdef PROJ_SDFS_STREAMING + int32_t s = (int32_t(output) + int32_t(*Pokitto::Sound::sfxDataPtr++)) - 128; + #else + int32_t s = (127 + int32_t(*Pokitto::Sound::sfxDataPtr++)) - 128; + #endif + if( s < 0 ) s = 0; + else if( s > 255 ) s = 255; + output = s; + } + if(streamvol && streamon) { output >>= 3-streamvol; streambyte = output; } else { @@ -414,10 +440,18 @@ updatePlayback(); } /** oscillators update **/ - osc1.count += osc1.cinc + (osc1.pitchbend >> 4); // counts to 65535 and overflows to zero WAS 8 ! - osc2.count += osc2.cinc + (osc2.pitchbend >> 4); // counts to 65535 and overflows to zero - osc3.count += osc3.cinc + (osc3.pitchbend >> 4); // counts to 65535 and overflows to zero + osc1.count += osc1.cinc + (osc1.pitchbend); // counts to 65535 and overflows to zero WAS 8 ! + osc2.count += osc2.cinc + (osc2.pitchbend); // counts to 65535 and overflows to zero + osc3.count += osc3.cinc + (osc3.pitchbend); // counts to 65535 and overflows to zero + #if POK_ALT_MIXING > 0 // heaviest cpu load, recalculate envelopes on each cycle + uint32_t o = 0; + Marr[3](); + Marr[2](); + Marr[1](); + if (tick==0) Marr[0](); + #else Marr[tick](); // call mixing function + #endif // ALT_MIXING --tick; /** mixing oscillator output **/