zzzz
Audio.cpp@0:6d2a1fb93e9e, 2019-07-05 (annotated)
- Committer:
- irsanjul
- Date:
- Fri Jul 05 10:33:07 2019 +0000
- Revision:
- 0:6d2a1fb93e9e
- Child:
- 1:931e45afbcb4
hhhhh
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
irsanjul | 0:6d2a1fb93e9e | 1 | #include "Audio.h" |
irsanjul | 0:6d2a1fb93e9e | 2 | |
irsanjul | 0:6d2a1fb93e9e | 3 | double nada[9] = {247, 262, 294, 330, 350, 392, 440, 494, 523}; |
irsanjul | 0:6d2a1fb93e9e | 4 | |
irsanjul | 0:6d2a1fb93e9e | 5 | Audio::Audio(PinName buzzer): out(buzzer) |
irsanjul | 0:6d2a1fb93e9e | 6 | { |
irsanjul | 0:6d2a1fb93e9e | 7 | } |
irsanjul | 0:6d2a1fb93e9e | 8 | |
irsanjul | 0:6d2a1fb93e9e | 9 | void Audio::SetVolume(double volume) |
irsanjul | 0:6d2a1fb93e9e | 10 | { |
irsanjul | 0:6d2a1fb93e9e | 11 | vol = volume; |
irsanjul | 0:6d2a1fb93e9e | 12 | } |
irsanjul | 0:6d2a1fb93e9e | 13 | |
irsanjul | 0:6d2a1fb93e9e | 14 | void Audio::SetDuration(unsigned int milisec) |
irsanjul | 0:6d2a1fb93e9e | 15 | { |
irsanjul | 0:6d2a1fb93e9e | 16 | ms = milisec; |
irsanjul | 0:6d2a1fb93e9e | 17 | } |
irsanjul | 0:6d2a1fb93e9e | 18 | |
irsanjul | 0:6d2a1fb93e9e | 19 | void Audio::PlayNote(unsigned int angka) |
irsanjul | 0:6d2a1fb93e9e | 20 | { |
irsanjul | 0:6d2a1fb93e9e | 21 | if(angka > 8) angka = 8; |
irsanjul | 0:6d2a1fb93e9e | 22 | |
irsanjul | 0:6d2a1fb93e9e | 23 | double Nada = nada[angka]; |
irsanjul | 0:6d2a1fb93e9e | 24 | PlayNote(Nada*4.24, ms, vol); |
irsanjul | 0:6d2a1fb93e9e | 25 | } |
irsanjul | 0:6d2a1fb93e9e | 26 | |
irsanjul | 0:6d2a1fb93e9e | 27 | void Audio::mute() |
irsanjul | 0:6d2a1fb93e9e | 28 | { |
irsanjul | 0:6d2a1fb93e9e | 29 | out = 0; |
irsanjul | 0:6d2a1fb93e9e | 30 | } |
irsanjul | 0:6d2a1fb93e9e | 31 | |
irsanjul | 0:6d2a1fb93e9e | 32 | void Audio::PlayNote(double frequency, double duration, double volume) |
irsanjul | 0:6d2a1fb93e9e | 33 | { |
irsanjul | 0:6d2a1fb93e9e | 34 | out.period(1.0/frequency); |
irsanjul | 0:6d2a1fb93e9e | 35 | out = volume/2.0; |
irsanjul | 0:6d2a1fb93e9e | 36 | wait_ms(duration); |
irsanjul | 0:6d2a1fb93e9e | 37 | out = 0.0; |
irsanjul | 0:6d2a1fb93e9e | 38 | } |