![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
statescriptMP
Dependencies: SMARTWAV USBDevice mbed
soundControl.cpp@0:9d97f34c6f46, 2015-05-18 (annotated)
- Committer:
- alustig3
- Date:
- Mon May 18 01:18:45 2015 +0000
- Revision:
- 0:9d97f34c6f46
statescript MP
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alustig3 | 0:9d97f34c6f46 | 1 | #include "soundControl.h" |
alustig3 | 0:9d97f34c6f46 | 2 | |
alustig3 | 0:9d97f34c6f46 | 3 | extern SMARTWAV sWav; |
alustig3 | 0:9d97f34c6f46 | 4 | extern Serial pc; |
alustig3 | 0:9d97f34c6f46 | 5 | |
alustig3 | 0:9d97f34c6f46 | 6 | soundControl::soundControl(void): |
alustig3 | 0:9d97f34c6f46 | 7 | fileNameExists(false), |
alustig3 | 0:9d97f34c6f46 | 8 | volumePtr(NULL), |
alustig3 | 0:9d97f34c6f46 | 9 | volume(-1), |
alustig3 | 0:9d97f34c6f46 | 10 | play(true), |
alustig3 | 0:9d97f34c6f46 | 11 | reset(false) { |
alustig3 | 0:9d97f34c6f46 | 12 | |
alustig3 | 0:9d97f34c6f46 | 13 | } |
alustig3 | 0:9d97f34c6f46 | 14 | |
alustig3 | 0:9d97f34c6f46 | 15 | void soundControl::setFile(string fileNameIn) { |
alustig3 | 0:9d97f34c6f46 | 16 | for (int i = 0; i < 20; i++) { |
alustig3 | 0:9d97f34c6f46 | 17 | fileName[i] = NULL; |
alustig3 | 0:9d97f34c6f46 | 18 | } |
alustig3 | 0:9d97f34c6f46 | 19 | std::size_t length = fileNameIn.size(); |
alustig3 | 0:9d97f34c6f46 | 20 | if (length <= 20) { |
alustig3 | 0:9d97f34c6f46 | 21 | fileNameIn.copy(fileName, length, 0); |
alustig3 | 0:9d97f34c6f46 | 22 | fileNameExists = true; |
alustig3 | 0:9d97f34c6f46 | 23 | } |
alustig3 | 0:9d97f34c6f46 | 24 | } |
alustig3 | 0:9d97f34c6f46 | 25 | void soundControl::setVolume(int volumeIn) { |
alustig3 | 0:9d97f34c6f46 | 26 | |
alustig3 | 0:9d97f34c6f46 | 27 | if ((volumeIn >= 0) && (volumeIn < 256)) { |
alustig3 | 0:9d97f34c6f46 | 28 | volume = volumeIn; |
alustig3 | 0:9d97f34c6f46 | 29 | volumePtr = NULL; |
alustig3 | 0:9d97f34c6f46 | 30 | } |
alustig3 | 0:9d97f34c6f46 | 31 | } |
alustig3 | 0:9d97f34c6f46 | 32 | |
alustig3 | 0:9d97f34c6f46 | 33 | void soundControl::setVolume(int* volumeIn) { |
alustig3 | 0:9d97f34c6f46 | 34 | |
alustig3 | 0:9d97f34c6f46 | 35 | volume = -1; |
alustig3 | 0:9d97f34c6f46 | 36 | volumePtr = volumeIn; |
alustig3 | 0:9d97f34c6f46 | 37 | |
alustig3 | 0:9d97f34c6f46 | 38 | } |
alustig3 | 0:9d97f34c6f46 | 39 | |
alustig3 | 0:9d97f34c6f46 | 40 | void soundControl::setPlayback(bool playIn) { |
alustig3 | 0:9d97f34c6f46 | 41 | play = playIn; |
alustig3 | 0:9d97f34c6f46 | 42 | } |
alustig3 | 0:9d97f34c6f46 | 43 | |
alustig3 | 0:9d97f34c6f46 | 44 | void soundControl::setReset() { |
alustig3 | 0:9d97f34c6f46 | 45 | reset = true; |
alustig3 | 0:9d97f34c6f46 | 46 | } |
alustig3 | 0:9d97f34c6f46 | 47 | |
alustig3 | 0:9d97f34c6f46 | 48 | void soundControl::execute() { |
alustig3 | 0:9d97f34c6f46 | 49 | |
alustig3 | 0:9d97f34c6f46 | 50 | if (reset) { |
alustig3 | 0:9d97f34c6f46 | 51 | sWav.reset(); |
alustig3 | 0:9d97f34c6f46 | 52 | } else if (!play) { |
alustig3 | 0:9d97f34c6f46 | 53 | sWav.stopTrack(); |
alustig3 | 0:9d97f34c6f46 | 54 | } else { |
alustig3 | 0:9d97f34c6f46 | 55 | if (volume > -1) { |
alustig3 | 0:9d97f34c6f46 | 56 | sWav.volume(volume); |
alustig3 | 0:9d97f34c6f46 | 57 | } else if (volumePtr != NULL) { |
alustig3 | 0:9d97f34c6f46 | 58 | sWav.volume(*volumePtr); |
alustig3 | 0:9d97f34c6f46 | 59 | } |
alustig3 | 0:9d97f34c6f46 | 60 | |
alustig3 | 0:9d97f34c6f46 | 61 | if (fileNameExists) { |
alustig3 | 0:9d97f34c6f46 | 62 | //sWav.playTracks(); |
alustig3 | 0:9d97f34c6f46 | 63 | sWav.stopTrack(); |
alustig3 | 0:9d97f34c6f46 | 64 | wait_ms(30);\\ANDY |
alustig3 | 0:9d97f34c6f46 | 65 | sWav.playTrackName(fileName); |
alustig3 | 0:9d97f34c6f46 | 66 | } |
alustig3 | 0:9d97f34c6f46 | 67 | } |
alustig3 | 0:9d97f34c6f46 | 68 | } |
alustig3 | 0:9d97f34c6f46 | 69 | |
alustig3 | 0:9d97f34c6f46 | 70 | |
alustig3 | 0:9d97f34c6f46 | 71 |