z ysaito
/
APro_B2DTst_0_Can_Class
2018.07.26
music.cpp@0:b3376afd10d8, 2018-07-26 (annotated)
- Committer:
- sayzyas
- Date:
- Thu Jul 26 00:20:04 2018 +0000
- Revision:
- 0:b3376afd10d8
2018.07.26
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sayzyas | 0:b3376afd10d8 | 1 | #include "mbed.h" |
sayzyas | 0:b3376afd10d8 | 2 | #include "stdio.h" |
sayzyas | 0:b3376afd10d8 | 3 | #include "common.h" |
sayzyas | 0:b3376afd10d8 | 4 | #include "music.h" |
sayzyas | 0:b3376afd10d8 | 5 | |
sayzyas | 0:b3376afd10d8 | 6 | // JKSoft Blue mbed Board Specific Seting |
sayzyas | 0:b3376afd10d8 | 7 | AnalogOut DACout(p18); |
sayzyas | 0:b3376afd10d8 | 8 | DigitalOut AMPEnable(p12); |
sayzyas | 0:b3376afd10d8 | 9 | |
sayzyas | 0:b3376afd10d8 | 10 | void waveMusic::wave(float volume , float fq , float time) |
sayzyas | 0:b3376afd10d8 | 11 | { |
sayzyas | 0:b3376afd10d8 | 12 | float w_time = 1.0 / fq; |
sayzyas | 0:b3376afd10d8 | 13 | |
sayzyas | 0:b3376afd10d8 | 14 | AMPEnable = 0; |
sayzyas | 0:b3376afd10d8 | 15 | for (float i=0; i<time / w_time; i++) { |
sayzyas | 0:b3376afd10d8 | 16 | DACout = volume; |
sayzyas | 0:b3376afd10d8 | 17 | wait(w_time/2); |
sayzyas | 0:b3376afd10d8 | 18 | DACout = 0.0; |
sayzyas | 0:b3376afd10d8 | 19 | wait(w_time/2); |
sayzyas | 0:b3376afd10d8 | 20 | } |
sayzyas | 0:b3376afd10d8 | 21 | AMPEnable = 1; |
sayzyas | 0:b3376afd10d8 | 22 | |
sayzyas | 0:b3376afd10d8 | 23 | } |
sayzyas | 0:b3376afd10d8 | 24 | |
sayzyas | 0:b3376afd10d8 | 25 | void waveMusic::pi( int count ) |
sayzyas | 0:b3376afd10d8 | 26 | { |
sayzyas | 0:b3376afd10d8 | 27 | for( int i=0; i < count; i++) |
sayzyas | 0:b3376afd10d8 | 28 | { |
sayzyas | 0:b3376afd10d8 | 29 | // vol freq time |
sayzyas | 0:b3376afd10d8 | 30 | wave( 0.8, 3000.0 * 1, 0.1 ); |
sayzyas | 0:b3376afd10d8 | 31 | wave( 0.0, 3000.0 * 1, 0.1 ); |
sayzyas | 0:b3376afd10d8 | 32 | } |
sayzyas | 0:b3376afd10d8 | 33 | Thread::wait(80); // msec |
sayzyas | 0:b3376afd10d8 | 34 | } |
sayzyas | 0:b3376afd10d8 | 35 | |
sayzyas | 0:b3376afd10d8 | 36 | |
sayzyas | 0:b3376afd10d8 | 37 | void waveMusic::bz( int count ) |
sayzyas | 0:b3376afd10d8 | 38 | { |
sayzyas | 0:b3376afd10d8 | 39 | for( int i=0; i < count; i++) |
sayzyas | 0:b3376afd10d8 | 40 | { |
sayzyas | 0:b3376afd10d8 | 41 | // vol freq time |
sayzyas | 0:b3376afd10d8 | 42 | wave( 0.6, 3000.0, 0.1 ); |
sayzyas | 0:b3376afd10d8 | 43 | wave( 0.0, 3000.0, 0.1 ); |
sayzyas | 0:b3376afd10d8 | 44 | } |
sayzyas | 0:b3376afd10d8 | 45 | Thread::wait(150); // msec |
sayzyas | 0:b3376afd10d8 | 46 | } |
sayzyas | 0:b3376afd10d8 | 47 | |
sayzyas | 0:b3376afd10d8 | 48 | void waveMusic::bz_error( int count ) |
sayzyas | 0:b3376afd10d8 | 49 | { |
sayzyas | 0:b3376afd10d8 | 50 | for( int i=0; i < count; i++) |
sayzyas | 0:b3376afd10d8 | 51 | { |
sayzyas | 0:b3376afd10d8 | 52 | // vol freq time |
sayzyas | 0:b3376afd10d8 | 53 | wave( 0.6, 3000.0, 0.3 ); |
sayzyas | 0:b3376afd10d8 | 54 | wave( 0.0, 3000.0, 0.3 ); |
sayzyas | 0:b3376afd10d8 | 55 | } |
sayzyas | 0:b3376afd10d8 | 56 | Thread::wait(300); // msec |
sayzyas | 0:b3376afd10d8 | 57 | } |
sayzyas | 0:b3376afd10d8 | 58 | |
sayzyas | 0:b3376afd10d8 | 59 | |
sayzyas | 0:b3376afd10d8 | 60 | void waveMusic::note( |
sayzyas | 0:b3376afd10d8 | 61 | float on_freq, |
sayzyas | 0:b3376afd10d8 | 62 | float on_time, |
sayzyas | 0:b3376afd10d8 | 63 | float off_time |
sayzyas | 0:b3376afd10d8 | 64 | ){ |
sayzyas | 0:b3376afd10d8 | 65 | wave( 0.03, on_freq, on_time ); |
sayzyas | 0:b3376afd10d8 | 66 | wave( 0.0, on_freq, off_time ); |
sayzyas | 0:b3376afd10d8 | 67 | } |
sayzyas | 0:b3376afd10d8 | 68 | |
sayzyas | 0:b3376afd10d8 | 69 | void waveMusic::m_poteto( int count ) |
sayzyas | 0:b3376afd10d8 | 70 | { |
sayzyas | 0:b3376afd10d8 | 71 | for( int i=0; i < count; i++) |
sayzyas | 0:b3376afd10d8 | 72 | { |
sayzyas | 0:b3376afd10d8 | 73 | Thread::wait(30); // msec |
sayzyas | 0:b3376afd10d8 | 74 | note( 392.00*3, 0.2, 0.01 ); // so |
sayzyas | 0:b3376afd10d8 | 75 | note( 329.00*3, 0.3, 0.01 ); // mi |
sayzyas | 0:b3376afd10d8 | 76 | note( 392.00*3, 0.2, 0.01 ); // so |
sayzyas | 0:b3376afd10d8 | 77 | Thread::wait(30); // msec |
sayzyas | 0:b3376afd10d8 | 78 | } |
sayzyas | 0:b3376afd10d8 | 79 | } |
sayzyas | 0:b3376afd10d8 | 80 | |
sayzyas | 0:b3376afd10d8 | 81 | void waveMusic::knkk( void ) |
sayzyas | 0:b3376afd10d8 | 82 | { |
sayzyas | 0:b3376afd10d8 | 83 | Thread::wait(300); // msec |
sayzyas | 0:b3376afd10d8 | 84 | note( 146.82*3, 0.3, 0.08 ); // shi |
sayzyas | 0:b3376afd10d8 | 85 | note( 220.00*3, 0.6, 0.08 ); // ra |
sayzyas | 0:b3376afd10d8 | 86 | note( 246.94*3, 0.3, 0.08 ); // shi |
sayzyas | 0:b3376afd10d8 | 87 | /* note( 261.63*3, 0.1, 0.02 ); // do |
sayzyas | 0:b3376afd10d8 | 88 | note( 261.63*3, 0.1, 0.02 ); // do |
sayzyas | 0:b3376afd10d8 | 89 | note( 246.94*3, 0.1, 0.02 ); // shi |
sayzyas | 0:b3376afd10d8 | 90 | note( 220.00*3, 0.1, 0.02 ); // ra |
sayzyas | 0:b3376afd10d8 | 91 | note( 146.835*3, 0.1, 0.02 ); // re |
sayzyas | 0:b3376afd10d8 | 92 | note( 146.835*3, 0.1, 0.02 ); // re |
sayzyas | 0:b3376afd10d8 | 93 | note( 146.835*3, 0.1, 0.02); // re |
sayzyas | 0:b3376afd10d8 | 94 | note( 164.82*3, 0.1, 0.02 ); // mi |
sayzyas | 0:b3376afd10d8 | 95 | note( 174.62*3, 0.3, 0.02 ); // fa */ |
sayzyas | 0:b3376afd10d8 | 96 | Thread::wait(300); // msec |
sayzyas | 0:b3376afd10d8 | 97 | } |
sayzyas | 0:b3376afd10d8 | 98 | |
sayzyas | 0:b3376afd10d8 | 99 | void waveMusic::PC9801( void ) |
sayzyas | 0:b3376afd10d8 | 100 | { |
sayzyas | 0:b3376afd10d8 | 101 | Thread::wait(300); // msec |
sayzyas | 0:b3376afd10d8 | 102 | note( 2000.0, 0.2, 0.05 ); // pi |
sayzyas | 0:b3376afd10d8 | 103 | note( 1000.0, 0.2, 0.05 ); // po |
sayzyas | 0:b3376afd10d8 | 104 | Thread::wait(300); // msec |
sayzyas | 0:b3376afd10d8 | 105 | } |
sayzyas | 0:b3376afd10d8 | 106 | |
sayzyas | 0:b3376afd10d8 | 107 | //#define ON_TIME 0.08 |
sayzyas | 0:b3376afd10d8 | 108 | //#define OFF_TIME 0.008 |
sayzyas | 0:b3376afd10d8 | 109 | #define ON_TIME 0.08 |
sayzyas | 0:b3376afd10d8 | 110 | #define OFF_TIME 0.008 |
sayzyas | 0:b3376afd10d8 | 111 | void waveMusic::FFPre(void) |
sayzyas | 0:b3376afd10d8 | 112 | { |
sayzyas | 0:b3376afd10d8 | 113 | Thread::wait(300); // msec |
sayzyas | 0:b3376afd10d8 | 114 | // note( 130.815*3, ON_TIME, OFF_TIME ); // do |
sayzyas | 0:b3376afd10d8 | 115 | // note( 146.835*3, ON_TIME, OFF_TIME ); // re |
sayzyas | 0:b3376afd10d8 | 116 | // note( 164.820*3, ON_TIME, OFF_TIME ); // mi |
sayzyas | 0:b3376afd10d8 | 117 | // note( 196.000*3, ON_TIME, OFF_TIME ); // so |
sayzyas | 0:b3376afd10d8 | 118 | |
sayzyas | 0:b3376afd10d8 | 119 | note( 261.630*2, ON_TIME, OFF_TIME ); // do |
sayzyas | 0:b3376afd10d8 | 120 | note( 293.670*2, ON_TIME, OFF_TIME ); // re |
sayzyas | 0:b3376afd10d8 | 121 | note( 329.630*2, ON_TIME, OFF_TIME ); // mi |
sayzyas | 0:b3376afd10d8 | 122 | note( 392.000*2, ON_TIME, OFF_TIME ); // so |
sayzyas | 0:b3376afd10d8 | 123 | |
sayzyas | 0:b3376afd10d8 | 124 | note( 523.230*2, ON_TIME, OFF_TIME ); // do |
sayzyas | 0:b3376afd10d8 | 125 | note( 587.340*2, ON_TIME, OFF_TIME ); // re |
sayzyas | 0:b3376afd10d8 | 126 | note( 659.250*2, ON_TIME, OFF_TIME ); // mi |
sayzyas | 0:b3376afd10d8 | 127 | note( 783.980*2, ON_TIME, OFF_TIME*2 ); // so |
sayzyas | 0:b3376afd10d8 | 128 | |
sayzyas | 0:b3376afd10d8 | 129 | note( 1046.500*2, ON_TIME, OFF_TIME ); // do |
sayzyas | 0:b3376afd10d8 | 130 | note( 1174.700*2, ON_TIME, OFF_TIME ); // re |
sayzyas | 0:b3376afd10d8 | 131 | note( 1318.600*2, ON_TIME, OFF_TIME ); // mi |
sayzyas | 0:b3376afd10d8 | 132 | note( 1567.960*2, ON_TIME, OFF_TIME ); // so |
sayzyas | 0:b3376afd10d8 | 133 | |
sayzyas | 0:b3376afd10d8 | 134 | note( 2093.000*2, ON_TIME, OFF_TIME ); // do |
sayzyas | 0:b3376afd10d8 | 135 | note( 1567.960*2, ON_TIME, OFF_TIME ); // so |
sayzyas | 0:b3376afd10d8 | 136 | note( 1318.600*2, ON_TIME, OFF_TIME ); // mi |
sayzyas | 0:b3376afd10d8 | 137 | note( 1174.700*2, ON_TIME, OFF_TIME ); // re |
sayzyas | 0:b3376afd10d8 | 138 | |
sayzyas | 0:b3376afd10d8 | 139 | note( 1046.500*2, ON_TIME, OFF_TIME ); // do |
sayzyas | 0:b3376afd10d8 | 140 | note( 783.980*2, ON_TIME, OFF_TIME ); // so |
sayzyas | 0:b3376afd10d8 | 141 | note( 659.250*2, ON_TIME, OFF_TIME ); // mi |
sayzyas | 0:b3376afd10d8 | 142 | note( 587.340*2, ON_TIME, OFF_TIME ); // re |
sayzyas | 0:b3376afd10d8 | 143 | |
sayzyas | 0:b3376afd10d8 | 144 | note( 523.230*2, ON_TIME, OFF_TIME ); // do |
sayzyas | 0:b3376afd10d8 | 145 | note( 392.000*2, ON_TIME, OFF_TIME ); // so |
sayzyas | 0:b3376afd10d8 | 146 | note( 329.630*2, ON_TIME, OFF_TIME ); // mi |
sayzyas | 0:b3376afd10d8 | 147 | note( 293.670*2, ON_TIME, OFF_TIME ); // re |
sayzyas | 0:b3376afd10d8 | 148 | |
sayzyas | 0:b3376afd10d8 | 149 | // Thread::wait(300); // msec |
sayzyas | 0:b3376afd10d8 | 150 | } |