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