Quick and horrible speech engine
Diff: main.cpp
- Revision:
- 15:bad48ea4468b
- Parent:
- 14:f25c2f72b2aa
diff -r f25c2f72b2aa -r bad48ea4468b main.cpp --- a/main.cpp Sat Dec 01 13:57:52 2018 +0000 +++ b/main.cpp Sat Jan 05 13:20:14 2019 +0000 @@ -44,16 +44,17 @@ } -uint8_t playSound(const unsigned char *sound, uint16_t soundSize, int volume = 255, int speed=255){ +uint8_t playSound(const unsigned char *sound, uint32_t soundSize, int volume = 255, float speed=255){ - int channel=0; + int channel = 0; + float spd = (POK_AUD_FREQ / 11025); - snd[channel].currentSound = sound; - snd[channel].currentSoundSize = (soundSize*255)/speed; - snd[channel].soundPoint = 0; - snd[channel].playSample = 1; - snd[channel].volume = volume; - snd[channel].speed = speed; + snd[channel].currentSound = sound; // sound to play + snd[channel].currentSoundSize = (soundSize<<8)/speed; // length of sound array adjusted for speed change + snd[channel].volume = volume; // volume, best kept below 64 as louder will cause clipping when playing multiple samples + snd[channel].speed = (speed/spd); // recalculated above + snd[channel].soundPoint = 0; // where the current sound is upto + snd[channel].playSample = 1; // 1 to play this sound, 0 not to return channel; }