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