old demo that i want to try in mbed studio
Dependencies: mbed SDFileSystem_Copy_of_mbed_version I2S
NotchingDemo.cpp@89:936f37f90cc2, 2019-10-03 (annotated)
- Committer:
- roryhand
- Date:
- Thu Oct 03 16:16:10 2019 +0000
- Revision:
- 89:936f37f90cc2
- Parent:
- 88:76a4563ee9c7
WIP - minor changes on this old branch
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
roryhand | 1:aac37edee302 | 1 | |
roryhand | 0:e89d7a0bfa3b | 2 | // 24/03/2018 update - I appear to be able to address the device and write something, as I am getting an ACK returned from the i2c write() function. |
roryhand | 0:e89d7a0bfa3b | 3 | //however if i use the write function with 4 arguments (as opposed to just 1 argument) then it doesnt work |
roryhand | 0:e89d7a0bfa3b | 4 | //only works with the 1 argument version!!! |
roryhand | 0:e89d7a0bfa3b | 5 | |
roryhand | 0:e89d7a0bfa3b | 6 | |
roryhand | 0:e89d7a0bfa3b | 7 | //THIS VERSION WORKED, CHANGED SOME THINGS, THEN CHANGED THEM BACK. NOW IT NO LONGER WORKS!!!! |
roryhand | 0:e89d7a0bfa3b | 8 | #include "mbed.h" |
roryhand | 0:e89d7a0bfa3b | 9 | #include "math.h" |
roryhand | 1:aac37edee302 | 10 | #include "I2S.h" |
roryhand | 1:aac37edee302 | 11 | #include "SDFileSystem.h" |
roryhand | 0:e89d7a0bfa3b | 12 | #include "wm8731_Config_setup.h" |
roryhand | 0:e89d7a0bfa3b | 13 | #include "WOLFSON_config_consts.h" |
roryhand | 54:606a83fff291 | 14 | //#include "BlockDevice.h" |
roryhand | 37:a563899ac0df | 15 | #include <string> |
roryhand | 0:e89d7a0bfa3b | 16 | #include <stdlib.h> |
roryhand | 27:a378f1f937ee | 17 | #include <fstream> |
roryhand | 27:a378f1f937ee | 18 | #include <iostream> |
roryhand | 0:e89d7a0bfa3b | 19 | #include <vector> |
roryhand | 0:e89d7a0bfa3b | 20 | #include <string> |
roryhand | 0:e89d7a0bfa3b | 21 | #define sample_freq 11025 |
roryhand | 1:aac37edee302 | 22 | #pragma import __use_two_region_memory |
roryhand | 54:606a83fff291 | 23 | //BlockDevice *bd = BlockDevice::get_default_instance(); |
roryhand | 54:606a83fff291 | 24 | //#include "LittleFileSystem.h" |
roryhand | 54:606a83fff291 | 25 | //LittleFileSystem fs("fs"); |
roryhand | 54:606a83fff291 | 26 | |
roryhand | 0:e89d7a0bfa3b | 27 | DigitalOut myled(LED1); |
roryhand | 0:e89d7a0bfa3b | 28 | DigitalOut led2(LED2); |
roryhand | 0:e89d7a0bfa3b | 29 | DigitalOut led3(LED3); |
roryhand | 0:e89d7a0bfa3b | 30 | DigitalIn NotchUp(p16); |
roryhand | 38:3b4c05af5f36 | 31 | DigitalIn NotchDown(p17);//check the pin!!! Dont know if this will actually work... |
roryhand | 0:e89d7a0bfa3b | 32 | InterruptIn Horn(p16); |
roryhand | 0:e89d7a0bfa3b | 33 | Ticker sampletick; |
roryhand | 45:0e8e1f2ec5d2 | 34 | |
roryhand | 0:e89d7a0bfa3b | 35 | Ticker TickFadeOut; |
roryhand | 0:e89d7a0bfa3b | 36 | Timer t; |
roryhand | 0:e89d7a0bfa3b | 37 | Timer t2; |
roryhand | 3:6169aeeaeeb4 | 38 | Timer NotchTimer; |
roryhand | 27:a378f1f937ee | 39 | Timer timer_open; |
roryhand | 0:e89d7a0bfa3b | 40 | |
roryhand | 0:e89d7a0bfa3b | 41 | Serial pc(USBTX, USBRX); // tx, rx //FOR DEBUGGING PROGRAM USING GNU SCREEN |
roryhand | 0:e89d7a0bfa3b | 42 | DigitalOut cs(p8); |
roryhand | 0:e89d7a0bfa3b | 43 | I2S i2s(I2S_TRANSMIT, p5, p6, p7); |
roryhand | 0:e89d7a0bfa3b | 44 | SDFileSystem sd(p11, p12, p13, p8, "sd"); // the new pinout that i am using |
roryhand | 0:e89d7a0bfa3b | 45 | |
roryhand | 0:e89d7a0bfa3b | 46 | |
roryhand | 0:e89d7a0bfa3b | 47 | /*struct A { |
roryhand | 0:e89d7a0bfa3b | 48 | int data; |
roryhand | 0:e89d7a0bfa3b | 49 | B b; |
roryhand | 0:e89d7a0bfa3b | 50 | };*/ |
roryhand | 0:e89d7a0bfa3b | 51 | |
roryhand | 0:e89d7a0bfa3b | 52 | |
roryhand | 0:e89d7a0bfa3b | 53 | |
roryhand | 0:e89d7a0bfa3b | 54 | |
roryhand | 0:e89d7a0bfa3b | 55 | class classFade |
roryhand | 0:e89d7a0bfa3b | 56 | { |
roryhand | 1:aac37edee302 | 57 | public: |
roryhand | 1:aac37edee302 | 58 | |
roryhand | 0:e89d7a0bfa3b | 59 | float powerval; |
roryhand | 0:e89d7a0bfa3b | 60 | float FadeIteration; |
roryhand | 0:e89d7a0bfa3b | 61 | float DecayFactor; |
roryhand | 0:e89d7a0bfa3b | 62 | float Denom; |
roryhand | 0:e89d7a0bfa3b | 63 | float FadeCoeff; |
roryhand | 0:e89d7a0bfa3b | 64 | float Natural_Exp; |
roryhand | 0:e89d7a0bfa3b | 65 | int LengthSecs; |
roryhand | 0:e89d7a0bfa3b | 66 | int Length; |
roryhand | 1:aac37edee302 | 67 | |
roryhand | 0:e89d7a0bfa3b | 68 | //member Functions |
roryhand | 0:e89d7a0bfa3b | 69 | float FadeOut(void) |
roryhand | 0:e89d7a0bfa3b | 70 | { |
roryhand | 0:e89d7a0bfa3b | 71 | powerval = -FadeIteration/Denom; |
roryhand | 1:aac37edee302 | 72 | if (FadeIteration >=Length) { |
roryhand | 1:aac37edee302 | 73 | FadeCoeff = 0; |
roryhand | 1:aac37edee302 | 74 | |
roryhand | 1:aac37edee302 | 75 | } else { |
roryhand | 0:e89d7a0bfa3b | 76 | FadeCoeff = (Length - FadeIteration)/Length; |
roryhand | 0:e89d7a0bfa3b | 77 | } |
roryhand | 1:aac37edee302 | 78 | FadeIteration = FadeIteration + 1; |
roryhand | 1:aac37edee302 | 79 | return FadeCoeff; |
roryhand | 1:aac37edee302 | 80 | |
roryhand | 1:aac37edee302 | 81 | } |
roryhand | 1:aac37edee302 | 82 | float FadeIn(void) |
roryhand | 0:e89d7a0bfa3b | 83 | { |
roryhand | 0:e89d7a0bfa3b | 84 | powerval = FadeIteration/Denom; |
roryhand | 1:aac37edee302 | 85 | if (FadeIteration >=Length) { |
roryhand | 1:aac37edee302 | 86 | FadeCoeff = 1; |
roryhand | 1:aac37edee302 | 87 | |
roryhand | 1:aac37edee302 | 88 | } else { |
roryhand | 0:e89d7a0bfa3b | 89 | FadeCoeff = FadeIteration/Length; |
roryhand | 0:e89d7a0bfa3b | 90 | } |
roryhand | 0:e89d7a0bfa3b | 91 | |
roryhand | 1:aac37edee302 | 92 | FadeIteration = FadeIteration + 1; |
roryhand | 1:aac37edee302 | 93 | return FadeCoeff; |
roryhand | 1:aac37edee302 | 94 | |
roryhand | 1:aac37edee302 | 95 | } |
roryhand | 0:e89d7a0bfa3b | 96 | }; |
roryhand | 0:e89d7a0bfa3b | 97 | |
roryhand | 0:e89d7a0bfa3b | 98 | classFade IdleFadeOut; |
roryhand | 0:e89d7a0bfa3b | 99 | classFade N2FadeIn; |
roryhand | 0:e89d7a0bfa3b | 100 | |
roryhand | 2:957d3b2afff4 | 101 | classFade NotchFadeOut; |
roryhand | 2:957d3b2afff4 | 102 | classFade NotchFadeIn; |
roryhand | 2:957d3b2afff4 | 103 | |
roryhand | 89:936f37f90cc2 | 104 | class classPositionIndicators |
roryhand | 89:936f37f90cc2 | 105 | { |
roryhand | 89:936f37f90cc2 | 106 | public: |
roryhand | 89:936f37f90cc2 | 107 | int notch1_indicator, notch2_indicator, notch3_indicator, notch4_indicator; |
roryhand | 89:936f37f90cc2 | 108 | int notch5_indicator, notch6_indicator, notch7_indicator, notch8_indicator; |
roryhand | 89:936f37f90cc2 | 109 | int notch1_start_pt, notch2_start_pt, notch3_start_pt, notch4_start_pt; |
roryhand | 89:936f37f90cc2 | 110 | int notch5_start_pt, notch6_start_pt, notch7_start_pt, notch8_start_pt; |
roryhand | 89:936f37f90cc2 | 111 | int N1N2_start_pt, N2N3_start_pt, N3N4_start_pt, N4N5_start_pt, N5N6_start_pt; |
roryhand | 89:936f37f90cc2 | 112 | int N6N7_start_pt, N7N8_start_pt, N8N7_start_pt, N7N6_start_pt, N6N5_start_pt; |
roryhand | 89:936f37f90cc2 | 113 | int N5N4_start_pt, N4N3_start_pt, N3N2_start_pt, N2N1_start_pt; |
roryhand | 0:e89d7a0bfa3b | 114 | |
roryhand | 89:936f37f90cc2 | 115 | int notch_start_pts [9]; |
roryhand | 89:936f37f90cc2 | 116 | int notch_position_indicators[9]; |
roryhand | 89:936f37f90cc2 | 117 | int notch_transitions_start_pts[15]; |
roryhand | 89:936f37f90cc2 | 118 | int notch_transitions_position_indicators[15]; |
roryhand | 89:936f37f90cc2 | 119 | int auxiliary_start_pts[5]; |
roryhand | 89:936f37f90cc2 | 120 | int auxiliary_position_indicators[5]; |
roryhand | 89:936f37f90cc2 | 121 | classPositionIndicators() |
roryhand | 89:936f37f90cc2 | 122 | { |
roryhand | 89:936f37f90cc2 | 123 | notch1_start_pt = 44; |
roryhand | 89:936f37f90cc2 | 124 | notch2_start_pt = 220884+44; |
roryhand | 89:936f37f90cc2 | 125 | notch3_start_pt = notch2_start_pt+217698; |
roryhand | 89:936f37f90cc2 | 126 | notch4_start_pt = notch3_start_pt + 193060; |
roryhand | 89:936f37f90cc2 | 127 | notch5_start_pt = notch4_start_pt + 92010; |
roryhand | 89:936f37f90cc2 | 128 | notch6_start_pt = notch5_start_pt + 216642; |
roryhand | 89:936f37f90cc2 | 129 | notch7_start_pt = notch6_start_pt + 250316; |
roryhand | 89:936f37f90cc2 | 130 | notch8_start_pt = notch7_start_pt + 150152; |
roryhand | 89:936f37f90cc2 | 131 | notch1_indicator = notch1_start_pt; |
roryhand | 89:936f37f90cc2 | 132 | notch2_indicator = notch2_start_pt; |
roryhand | 89:936f37f90cc2 | 133 | notch3_indicator = notch3_start_pt; |
roryhand | 89:936f37f90cc2 | 134 | notch4_indicator = notch4_start_pt; |
roryhand | 89:936f37f90cc2 | 135 | notch5_indicator = notch5_start_pt; |
roryhand | 89:936f37f90cc2 | 136 | notch6_indicator = notch6_start_pt; |
roryhand | 89:936f37f90cc2 | 137 | notch7_indicator = notch7_start_pt; |
roryhand | 89:936f37f90cc2 | 138 | notch8_indicator = notch8_start_pt; |
roryhand | 89:936f37f90cc2 | 139 | notch_start_pts[1] = notch1_start_pt; |
roryhand | 89:936f37f90cc2 | 140 | notch_start_pts[2] = notch2_start_pt; |
roryhand | 89:936f37f90cc2 | 141 | notch_start_pts[3] = notch3_start_pt; |
roryhand | 89:936f37f90cc2 | 142 | notch_start_pts[4] = notch4_start_pt; |
roryhand | 89:936f37f90cc2 | 143 | notch_start_pts[5] = notch5_start_pt; |
roryhand | 89:936f37f90cc2 | 144 | notch_start_pts[6] = notch6_start_pt; |
roryhand | 89:936f37f90cc2 | 145 | notch_start_pts[7] = notch7_start_pt; |
roryhand | 89:936f37f90cc2 | 146 | notch_start_pts[8] = notch8_start_pt; |
roryhand | 89:936f37f90cc2 | 147 | notch_position_indicators[1] = notch1_indicator; |
roryhand | 89:936f37f90cc2 | 148 | notch_position_indicators[2] = notch2_indicator; |
roryhand | 89:936f37f90cc2 | 149 | notch_position_indicators[3] = notch3_indicator; |
roryhand | 89:936f37f90cc2 | 150 | notch_position_indicators[4] = notch4_indicator; |
roryhand | 89:936f37f90cc2 | 151 | notch_position_indicators[5] = notch5_indicator; |
roryhand | 89:936f37f90cc2 | 152 | notch_position_indicators[6] = notch6_indicator; |
roryhand | 89:936f37f90cc2 | 153 | notch_position_indicators[7] = notch7_indicator; |
roryhand | 89:936f37f90cc2 | 154 | notch_position_indicators[8] = notch8_indicator; |
roryhand | 89:936f37f90cc2 | 155 | |
roryhand | 89:936f37f90cc2 | 156 | N1N2_start_pt = 44; |
roryhand | 89:936f37f90cc2 | 157 | N2N3_start_pt = N1N2_start_pt + 73220; |
roryhand | 89:936f37f90cc2 | 158 | N3N4_start_pt = N2N3_start_pt + 78164; |
roryhand | 89:936f37f90cc2 | 159 | N4N5_start_pt = N3N4_start_pt + 59432; |
roryhand | 89:936f37f90cc2 | 160 | N5N6_start_pt = N4N5_start_pt + 64984; |
roryhand | 89:936f37f90cc2 | 161 | N6N7_start_pt = N5N6_start_pt + 59924; |
roryhand | 89:936f37f90cc2 | 162 | N7N8_start_pt = N6N7_start_pt + 97874; |
roryhand | 89:936f37f90cc2 | 163 | N8N7_start_pt = N7N8_start_pt + 63992; |
roryhand | 89:936f37f90cc2 | 164 | N7N6_start_pt = N8N7_start_pt + 44506; |
roryhand | 89:936f37f90cc2 | 165 | N6N5_start_pt = N7N6_start_pt + 55052; |
roryhand | 89:936f37f90cc2 | 166 | N5N4_start_pt = N6N5_start_pt + 37038; |
roryhand | 89:936f37f90cc2 | 167 | N4N3_start_pt = N5N4_start_pt + 49692; |
roryhand | 89:936f37f90cc2 | 168 | N3N2_start_pt = N4N3_start_pt + 44100; |
roryhand | 89:936f37f90cc2 | 169 | N2N1_start_pt = N3N2_start_pt + 58346; |
roryhand | 89:936f37f90cc2 | 170 | |
roryhand | 89:936f37f90cc2 | 171 | |
roryhand | 89:936f37f90cc2 | 172 | notch_transitions_start_pts[1] = N1N2_start_pt; |
roryhand | 89:936f37f90cc2 | 173 | notch_transitions_start_pts[2] = N2N3_start_pt; |
roryhand | 89:936f37f90cc2 | 174 | notch_transitions_start_pts[3] = N3N4_start_pt; |
roryhand | 89:936f37f90cc2 | 175 | notch_transitions_start_pts[4] = N4N5_start_pt; |
roryhand | 89:936f37f90cc2 | 176 | notch_transitions_start_pts[5] = N5N6_start_pt; |
roryhand | 89:936f37f90cc2 | 177 | notch_transitions_start_pts[6] = N6N7_start_pt; |
roryhand | 89:936f37f90cc2 | 178 | notch_transitions_start_pts[7] = N7N8_start_pt; |
roryhand | 89:936f37f90cc2 | 179 | notch_transitions_start_pts[8] = N8N7_start_pt; |
roryhand | 89:936f37f90cc2 | 180 | notch_transitions_start_pts[9] = N7N6_start_pt; |
roryhand | 89:936f37f90cc2 | 181 | notch_transitions_start_pts[10] = N6N5_start_pt; |
roryhand | 89:936f37f90cc2 | 182 | notch_transitions_start_pts[11] = N5N4_start_pt; |
roryhand | 89:936f37f90cc2 | 183 | notch_transitions_start_pts[12] = N4N3_start_pt; |
roryhand | 89:936f37f90cc2 | 184 | notch_transitions_start_pts[13] = N3N2_start_pt; |
roryhand | 89:936f37f90cc2 | 185 | notch_transitions_start_pts[14] = N2N1_start_pt; |
roryhand | 89:936f37f90cc2 | 186 | |
roryhand | 89:936f37f90cc2 | 187 | |
roryhand | 89:936f37f90cc2 | 188 | notch_transitions_position_indicators[1] = N1N2_start_pt; |
roryhand | 89:936f37f90cc2 | 189 | notch_transitions_position_indicators[2] = N2N3_start_pt; |
roryhand | 89:936f37f90cc2 | 190 | notch_transitions_position_indicators[3] = N3N4_start_pt; |
roryhand | 89:936f37f90cc2 | 191 | notch_transitions_position_indicators[4] = N4N5_start_pt; |
roryhand | 89:936f37f90cc2 | 192 | notch_transitions_position_indicators[5] = N5N6_start_pt; |
roryhand | 89:936f37f90cc2 | 193 | notch_transitions_position_indicators[6] = N6N7_start_pt; |
roryhand | 89:936f37f90cc2 | 194 | notch_transitions_position_indicators[7] = N7N8_start_pt; |
roryhand | 89:936f37f90cc2 | 195 | notch_transitions_position_indicators[8] = N8N7_start_pt; |
roryhand | 89:936f37f90cc2 | 196 | notch_transitions_position_indicators[9] = N7N6_start_pt; |
roryhand | 89:936f37f90cc2 | 197 | notch_transitions_position_indicators[10] = N6N5_start_pt; |
roryhand | 89:936f37f90cc2 | 198 | notch_transitions_position_indicators[11] = N5N4_start_pt; |
roryhand | 89:936f37f90cc2 | 199 | notch_transitions_position_indicators[12] = N4N3_start_pt; |
roryhand | 89:936f37f90cc2 | 200 | notch_transitions_position_indicators[13] = N3N2_start_pt; |
roryhand | 89:936f37f90cc2 | 201 | notch_transitions_position_indicators[14] = N2N1_start_pt; |
roryhand | 89:936f37f90cc2 | 202 | } |
roryhand | 89:936f37f90cc2 | 203 | }; |
roryhand | 0:e89d7a0bfa3b | 204 | |
roryhand | 0:e89d7a0bfa3b | 205 | |
roryhand | 0:e89d7a0bfa3b | 206 | |
roryhand | 1:aac37edee302 | 207 | typedef struct uFMT_STRUCT { |
roryhand | 1:aac37edee302 | 208 | short comp_code; |
roryhand | 1:aac37edee302 | 209 | short num_channels; |
roryhand | 1:aac37edee302 | 210 | unsigned sample_rate; |
roryhand | 1:aac37edee302 | 211 | unsigned avg_Bps; |
roryhand | 1:aac37edee302 | 212 | short block_align; |
roryhand | 1:aac37edee302 | 213 | short sig_bps; |
roryhand | 0:e89d7a0bfa3b | 214 | } FMT_STRUCT; |
roryhand | 0:e89d7a0bfa3b | 215 | |
roryhand | 1:aac37edee302 | 216 | typedef struct uNotch_STRUCT { |
roryhand | 1:aac37edee302 | 217 | short Notch; |
roryhand | 1:aac37edee302 | 218 | short NotchTransUp; |
roryhand | 1:aac37edee302 | 219 | short NotchTransDown; |
roryhand | 1:aac37edee302 | 220 | short NotchDirection; |
roryhand | 1:aac37edee302 | 221 | } Notch_STRUCT; |
roryhand | 1:aac37edee302 | 222 | |
roryhand | 0:e89d7a0bfa3b | 223 | typedef struct uDATA_STRUCT { |
roryhand | 1:aac37edee302 | 224 | unsigned subchunk2_ID; |
roryhand | 1:aac37edee302 | 225 | unsigned subchunk2_size; |
roryhand | 1:aac37edee302 | 226 | char * data_buf; |
roryhand | 1:aac37edee302 | 227 | } DATA_STRUCT; |
roryhand | 0:e89d7a0bfa3b | 228 | |
roryhand | 1:aac37edee302 | 229 | typedef struct uWAV_FILE_STRUCT { |
roryhand | 1:aac37edee302 | 230 | FILE *WavFile; |
roryhand | 1:aac37edee302 | 231 | int id_number; |
roryhand | 1:aac37edee302 | 232 | char *slice_buf; |
roryhand | 1:aac37edee302 | 233 | int num_slices; |
roryhand | 1:aac37edee302 | 234 | FMT_STRUCT FileFormat; |
roryhand | 1:aac37edee302 | 235 | DATA_STRUCT FileData; |
roryhand | 0:e89d7a0bfa3b | 236 | } WAV_FILE_STRUCT; |
roryhand | 0:e89d7a0bfa3b | 237 | |
roryhand | 0:e89d7a0bfa3b | 238 | /*typedef struct uWAV_FILE_STRUCT{ |
roryhand | 1:aac37edee302 | 239 | FILE* WavFile; |
roryhand | 1:aac37edee302 | 240 | |
roryhand | 1:aac37edee302 | 241 | |
roryhand | 0:e89d7a0bfa3b | 242 | }WAV_FILE_STRUCT;*/ |
roryhand | 0:e89d7a0bfa3b | 243 | class classSoundFile |
roryhand | 0:e89d7a0bfa3b | 244 | { |
roryhand | 1:aac37edee302 | 245 | public: |
roryhand | 1:aac37edee302 | 246 | |
roryhand | 44:a9e84d333a6a | 247 | //add a class constructor at some point in the future (perform tests in visual studio) |
roryhand | 1:aac37edee302 | 248 | WAV_FILE_STRUCT FileInfo; |
roryhand | 2:957d3b2afff4 | 249 | short * data_sptr; |
roryhand | 36:569ec4335f92 | 250 | string file_location; |
roryhand | 1:aac37edee302 | 251 | //classSoundFile(string filename);//this is the constructor |
roryhand | 1:aac37edee302 | 252 | //string filename; |
roryhand | 0:e89d7a0bfa3b | 253 | }; |
roryhand | 0:e89d7a0bfa3b | 254 | |
roryhand | 1:aac37edee302 | 255 | //class constructor; |
roryhand | 1:aac37edee302 | 256 | /*classSoundFile::classSoundFile(string filename) |
roryhand | 1:aac37edee302 | 257 | { |
roryhand | 1:aac37edee302 | 258 | //Declare RootFolder and the directory for the appropriate file. |
roryhand | 1:aac37edee302 | 259 | //How we index into filename[] from the outside of this class is another |
roryhand | 1:aac37edee302 | 260 | //issue... |
roryhand | 1:aac37edee302 | 261 | FileInfo.WavFile = fopen("/sd/mydir/645Engine/Startup.wav","rb"); |
roryhand | 1:aac37edee302 | 262 | fseek(FileInfo.WavFile,20,SEEK_SET); |
roryhand | 1:aac37edee302 | 263 | fread(&FileInfo.FileFormat,sizeof(FileInfo.FileFormat),1,FileInfo.WavFile); |
roryhand | 1:aac37edee302 | 264 | printf("wav_format.sample_rate: %d\n\r",FileInfo.FileFormat.sample_rate); |
roryhand | 1:aac37edee302 | 265 | fread(&FileInfo.FileData,sizeof(FileInfo.FileData),1,FileInfo.WavFile); |
roryhand | 1:aac37edee302 | 266 | printf("wav_data.subchunk2_size: %d\n\r",FileInfo.FileData.subchunk2_size); |
roryhand | 1:aac37edee302 | 267 | FileInfo.slice_buf = ( char *)malloc(FileInfo.FileFormat.block_align); |
roryhand | 1:aac37edee302 | 268 | fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,FileInfo.WavFile); //This isnt actually required, its just a test |
roryhand | 1:aac37edee302 | 269 | FileInfo.num_slices = FileInfo.FileData.subchunk2_size/FileInfo.FileFormat.block_align; |
roryhand | 1:aac37edee302 | 270 | }*/ |
roryhand | 54:606a83fff291 | 271 | int OneOff = 0; |
roryhand | 38:3b4c05af5f36 | 272 | int notch_flag = 0; |
roryhand | 0:e89d7a0bfa3b | 273 | int i = 0; |
roryhand | 0:e89d7a0bfa3b | 274 | int h = 0; |
roryhand | 0:e89d7a0bfa3b | 275 | short bufflen = 1; |
roryhand | 0:e89d7a0bfa3b | 276 | int buffer[1]; |
roryhand | 1:aac37edee302 | 277 | int AudioFormat, NumChannels, SampleRate, BitsPerSample ; |
roryhand | 0:e89d7a0bfa3b | 278 | char *slice_buf; |
roryhand | 0:e89d7a0bfa3b | 279 | short *data_sptr; |
roryhand | 0:e89d7a0bfa3b | 280 | short *data_sptr_horn; |
roryhand | 0:e89d7a0bfa3b | 281 | short *data_sptr_IdleN2; |
roryhand | 0:e89d7a0bfa3b | 282 | short * data_sptr_bell; |
roryhand | 0:e89d7a0bfa3b | 283 | short * data_sptr_N2; |
roryhand | 0:e89d7a0bfa3b | 284 | short * data_sptr_Flange; |
roryhand | 0:e89d7a0bfa3b | 285 | unsigned char *data_bptr; |
roryhand | 0:e89d7a0bfa3b | 286 | int *data_wptr; |
roryhand | 0:e89d7a0bfa3b | 287 | unsigned channel; |
roryhand | 45:0e8e1f2ec5d2 | 288 | long slice, slice1, slice2, slice3, num_slices; |
roryhand | 0:e89d7a0bfa3b | 289 | int verbosity = 0; |
roryhand | 0:e89d7a0bfa3b | 290 | int verbosity2 = 0; |
roryhand | 0:e89d7a0bfa3b | 291 | int verbosity3 = 0; |
roryhand | 0:e89d7a0bfa3b | 292 | int verbosity4 = 0; |
roryhand | 0:e89d7a0bfa3b | 293 | int verbosity5 = 0; |
roryhand | 0:e89d7a0bfa3b | 294 | int interrupt_condition = 1; |
roryhand | 0:e89d7a0bfa3b | 295 | int sampling_freq = 11025; |
roryhand | 0:e89d7a0bfa3b | 296 | const int BufferLen = 2000; |
roryhand | 0:e89d7a0bfa3b | 297 | short Buffer1[BufferLen]; |
roryhand | 0:e89d7a0bfa3b | 298 | short Buffer2[BufferLen]; |
roryhand | 0:e89d7a0bfa3b | 299 | short place_hold1 = 0; |
roryhand | 0:e89d7a0bfa3b | 300 | short place_hold2 = 0; |
roryhand | 0:e89d7a0bfa3b | 301 | |
roryhand | 3:6169aeeaeeb4 | 302 | |
roryhand | 3:6169aeeaeeb4 | 303 | string FOLDER; |
roryhand | 3:6169aeeaeeb4 | 304 | string RootFolder = "/sd/mydir/SoundDecoder/"; |
roryhand | 3:6169aeeaeeb4 | 305 | string filename[25]; |
roryhand | 3:6169aeeaeeb4 | 306 | classSoundFile Sound[22]; |
roryhand | 3:6169aeeaeeb4 | 307 | |
roryhand | 0:e89d7a0bfa3b | 308 | volatile int flag1 = 1; |
roryhand | 0:e89d7a0bfa3b | 309 | volatile int flag2 = 0; |
roryhand | 0:e89d7a0bfa3b | 310 | volatile int flag3 = 1; |
roryhand | 0:e89d7a0bfa3b | 311 | volatile int flag4 = 0; |
roryhand | 0:e89d7a0bfa3b | 312 | int FLAGBUFF1 = 0; |
roryhand | 0:e89d7a0bfa3b | 313 | int FLAGBUFF2 = 0; |
roryhand | 0:e89d7a0bfa3b | 314 | int BellFlag = 0; |
roryhand | 0:e89d7a0bfa3b | 315 | int BellFlag2 = 0; |
roryhand | 0:e89d7a0bfa3b | 316 | int FadeFlag = 0; |
roryhand | 54:606a83fff291 | 317 | int BlockFlag = 0; |
roryhand | 32:6ee488c97dcc | 318 | int FileSwitchFlag = 0; |
roryhand | 0:e89d7a0bfa3b | 319 | |
roryhand | 0:e89d7a0bfa3b | 320 | |
roryhand | 0:e89d7a0bfa3b | 321 | short value[1]; |
roryhand | 0:e89d7a0bfa3b | 322 | FILE *HornWav; |
roryhand | 0:e89d7a0bfa3b | 323 | FILE *edsheeran_wav; |
roryhand | 0:e89d7a0bfa3b | 324 | FILE *Startup_wav; |
roryhand | 0:e89d7a0bfa3b | 325 | FILE *IdleN2Wav; |
roryhand | 0:e89d7a0bfa3b | 326 | FILE *N2Wav; |
roryhand | 0:e89d7a0bfa3b | 327 | FILE *BellWav; |
roryhand | 0:e89d7a0bfa3b | 328 | FILE *FlangeWav; |
roryhand | 16:5e3420d0509b | 329 | FILE *HeyWav; |
roryhand | 0:e89d7a0bfa3b | 330 | //long long slice_value; |
roryhand | 0:e89d7a0bfa3b | 331 | int slice_value[1]; |
roryhand | 0:e89d7a0bfa3b | 332 | |
roryhand | 0:e89d7a0bfa3b | 333 | |
roryhand | 45:0e8e1f2ec5d2 | 334 | FILE *wavfile1; |
roryhand | 45:0e8e1f2ec5d2 | 335 | FILE *wavfile2; |
roryhand | 45:0e8e1f2ec5d2 | 336 | FILE *wavfile3; |
roryhand | 45:0e8e1f2ec5d2 | 337 | |
roryhand | 45:0e8e1f2ec5d2 | 338 | classSoundFile Sound1; |
roryhand | 45:0e8e1f2ec5d2 | 339 | classSoundFile Sound2; |
roryhand | 45:0e8e1f2ec5d2 | 340 | classSoundFile Sound3; |
roryhand | 45:0e8e1f2ec5d2 | 341 | |
roryhand | 0:e89d7a0bfa3b | 342 | WAV_FILE_STRUCT WavInfo_Horn; |
roryhand | 0:e89d7a0bfa3b | 343 | WAV_FILE_STRUCT WavInfo_IdleN2; |
roryhand | 0:e89d7a0bfa3b | 344 | WAV_FILE_STRUCT WavInfo_N2; |
roryhand | 0:e89d7a0bfa3b | 345 | WAV_FILE_STRUCT WavInfo_Bell; |
roryhand | 0:e89d7a0bfa3b | 346 | WAV_FILE_STRUCT WavInfo_Flange; |
roryhand | 20:9cc7d825c07b | 347 | WAV_FILE_STRUCT WavInfo_Hey; |
roryhand | 32:6ee488c97dcc | 348 | WAV_FILE_STRUCT WavInfo_N3; |
roryhand | 16:5e3420d0509b | 349 | WAV_FILE_STRUCT WavInfo_Frustration; |
roryhand | 0:e89d7a0bfa3b | 350 | Ticker flipper; |
roryhand | 0:e89d7a0bfa3b | 351 | char * slice_buf_bell; |
roryhand | 0:e89d7a0bfa3b | 352 | char * slice_buf_ed; |
roryhand | 0:e89d7a0bfa3b | 353 | char * slice_buf_startup; |
roryhand | 0:e89d7a0bfa3b | 354 | char * slice_buf_N2; |
roryhand | 1:aac37edee302 | 355 | Notch_STRUCT NotchingSet; |
roryhand | 0:e89d7a0bfa3b | 356 | //test |
roryhand | 0:e89d7a0bfa3b | 357 | //short *data_sptr_bell = 0; |
roryhand | 0:e89d7a0bfa3b | 358 | short *data_sptr_ed = 0; |
roryhand | 0:e89d7a0bfa3b | 359 | short *data_sptr_startup = 0; |
roryhand | 32:6ee488c97dcc | 360 | FILE *StartupWav; |
roryhand | 32:6ee488c97dcc | 361 | FILE *N3Wav; |
roryhand | 33:a75f0a30fbdc | 362 | int temp = 0; |
roryhand | 1:aac37edee302 | 363 | void flip() |
roryhand | 1:aac37edee302 | 364 | { |
roryhand | 0:e89d7a0bfa3b | 365 | led2 = !led2; |
roryhand | 0:e89d7a0bfa3b | 366 | } |
roryhand | 0:e89d7a0bfa3b | 367 | |
roryhand | 0:e89d7a0bfa3b | 368 | |
roryhand | 0:e89d7a0bfa3b | 369 | void isr() |
roryhand | 0:e89d7a0bfa3b | 370 | { |
roryhand | 54:606a83fff291 | 371 | //timer_interrupt.start(); |
roryhand | 1:aac37edee302 | 372 | if(flag1 == 0) { |
roryhand | 0:e89d7a0bfa3b | 373 | value[0] = Buffer1[place_hold1]>>4; |
roryhand | 0:e89d7a0bfa3b | 374 | i2s.write(value,1);//Send next PWM value to amp |
roryhand | 0:e89d7a0bfa3b | 375 | place_hold1 = place_hold1 + 1; |
roryhand | 1:aac37edee302 | 376 | if( (place_hold1 >= BufferLen)) { |
roryhand | 0:e89d7a0bfa3b | 377 | led2 = !led2; |
roryhand | 0:e89d7a0bfa3b | 378 | place_hold1 = 0; |
roryhand | 0:e89d7a0bfa3b | 379 | place_hold2 = 0; |
roryhand | 0:e89d7a0bfa3b | 380 | flag1 = 1; |
roryhand | 0:e89d7a0bfa3b | 381 | flag2 = 0; |
roryhand | 1:aac37edee302 | 382 | } |
roryhand | 1:aac37edee302 | 383 | } else if(flag2 == 0) { |
roryhand | 0:e89d7a0bfa3b | 384 | value[0] = Buffer2[place_hold2]>>4; |
roryhand | 0:e89d7a0bfa3b | 385 | i2s.write(value,1);//Send next PWM value to amp |
roryhand | 0:e89d7a0bfa3b | 386 | place_hold2 = place_hold2 + 1; |
roryhand | 1:aac37edee302 | 387 | if( (place_hold2 >= BufferLen) ) { |
roryhand | 0:e89d7a0bfa3b | 388 | led2 = !led2; |
roryhand | 0:e89d7a0bfa3b | 389 | place_hold1 = 0; |
roryhand | 0:e89d7a0bfa3b | 390 | place_hold2 = 0; |
roryhand | 0:e89d7a0bfa3b | 391 | flag1 = 0; |
roryhand | 1:aac37edee302 | 392 | flag2 = 1; |
roryhand | 0:e89d7a0bfa3b | 393 | FLAGBUFF2 = 0; |
roryhand | 1:aac37edee302 | 394 | } |
roryhand | 0:e89d7a0bfa3b | 395 | } |
roryhand | 54:606a83fff291 | 396 | |
roryhand | 54:606a83fff291 | 397 | //timer_interrupt.stop(); |
roryhand | 54:606a83fff291 | 398 | |
roryhand | 0:e89d7a0bfa3b | 399 | } |
roryhand | 1:aac37edee302 | 400 | |
roryhand | 0:e89d7a0bfa3b | 401 | void horn_sound() |
roryhand | 0:e89d7a0bfa3b | 402 | { |
roryhand | 0:e89d7a0bfa3b | 403 | BellFlag = 1; |
roryhand | 0:e89d7a0bfa3b | 404 | fseek(HornWav,44,SEEK_SET); |
roryhand | 0:e89d7a0bfa3b | 405 | fseek(BellWav,44,SEEK_SET); |
roryhand | 0:e89d7a0bfa3b | 406 | fseek(FlangeWav,44,SEEK_SET); |
roryhand | 0:e89d7a0bfa3b | 407 | fseek(N2Wav,44,SEEK_SET); |
roryhand | 0:e89d7a0bfa3b | 408 | } |
roryhand | 0:e89d7a0bfa3b | 409 | |
roryhand | 0:e89d7a0bfa3b | 410 | |
roryhand | 32:6ee488c97dcc | 411 | void FileSwitch_isr() |
roryhand | 0:e89d7a0bfa3b | 412 | { |
roryhand | 32:6ee488c97dcc | 413 | FileSwitchFlag = 1; |
roryhand | 33:a75f0a30fbdc | 414 | temp = 1; |
roryhand | 33:a75f0a30fbdc | 415 | /*FILE* testwav = fopen("/sd/mydir/SoundDecoder_second/05.wav","rb"); |
roryhand | 33:a75f0a30fbdc | 416 | if(N3Wav == NULL) { |
roryhand | 33:a75f0a30fbdc | 417 | printf("Cannot Open testwav\n\r"); |
roryhand | 33:a75f0a30fbdc | 418 | } |
roryhand | 33:a75f0a30fbdc | 419 | */ |
roryhand | 32:6ee488c97dcc | 420 | fseek(N3Wav,44,SEEK_SET); |
roryhand | 32:6ee488c97dcc | 421 | // fclose(StartupWav); |
roryhand | 0:e89d7a0bfa3b | 422 | } |
roryhand | 0:e89d7a0bfa3b | 423 | |
roryhand | 0:e89d7a0bfa3b | 424 | |
roryhand | 0:e89d7a0bfa3b | 425 | void FadeOutIsr() |
roryhand | 0:e89d7a0bfa3b | 426 | { |
roryhand | 1:aac37edee302 | 427 | FadeFlag = 1; |
roryhand | 54:606a83fff291 | 428 | OneOff = 1; |
roryhand | 54:606a83fff291 | 429 | /* |
roryhand | 54:606a83fff291 | 430 | wavfile2 = fopen("/sd/mydir/SoundDecoder_second/09.wav","rb"); |
roryhand | 54:606a83fff291 | 431 | if(wavfile2 == NULL) { |
roryhand | 54:606a83fff291 | 432 | printf("Cannot Open wavfile2\n\r"); |
roryhand | 54:606a83fff291 | 433 | } |
roryhand | 54:606a83fff291 | 434 | */ |
roryhand | 54:606a83fff291 | 435 | |
roryhand | 54:606a83fff291 | 436 | |
roryhand | 54:606a83fff291 | 437 | |
roryhand | 54:606a83fff291 | 438 | /* |
roryhand | 54:606a83fff291 | 439 | wavfile3 = fopen("/sd/mydir/SoundDecoder_second/02.wav","rb"); |
roryhand | 54:606a83fff291 | 440 | if(wavfile3 == NULL) { |
roryhand | 54:606a83fff291 | 441 | printf("Cannot Open wavfile3\n\r"); |
roryhand | 54:606a83fff291 | 442 | } |
roryhand | 54:606a83fff291 | 443 | */ |
roryhand | 54:606a83fff291 | 444 | /* |
roryhand | 54:606a83fff291 | 445 | FILE* wavfile4 = fopen("/sd/mydir/SoundDecoder_second/04.wav","rb"); |
roryhand | 54:606a83fff291 | 446 | if(wavfile4 == NULL) { |
roryhand | 54:606a83fff291 | 447 | printf("Cannot Open wavfile3\n\r"); |
roryhand | 54:606a83fff291 | 448 | } |
roryhand | 54:606a83fff291 | 449 | */ |
roryhand | 54:606a83fff291 | 450 | //fseek(wavfile2,44,SEEK_SET); |
roryhand | 54:606a83fff291 | 451 | //fseek(wavfile3,44,SEEK_SET); |
roryhand | 54:606a83fff291 | 452 | slice2 = 0; |
roryhand | 54:606a83fff291 | 453 | slice3 = 0; |
roryhand | 54:606a83fff291 | 454 | BlockFlag = 1; |
roryhand | 47:9334a8f54997 | 455 | //printf("We are inside the FadeOut interrupt routine\n\r"); |
roryhand | 1:aac37edee302 | 456 | |
roryhand | 0:e89d7a0bfa3b | 457 | } |
roryhand | 38:3b4c05af5f36 | 458 | |
roryhand | 38:3b4c05af5f36 | 459 | |
roryhand | 38:3b4c05af5f36 | 460 | |
roryhand | 38:3b4c05af5f36 | 461 | |
roryhand | 0:e89d7a0bfa3b | 462 | |
roryhand | 3:6169aeeaeeb4 | 463 | classFade FadeDataInitialise(classFade FadeData); |
roryhand | 3:6169aeeaeeb4 | 464 | |
roryhand | 3:6169aeeaeeb4 | 465 | |
roryhand | 3:6169aeeaeeb4 | 466 | |
roryhand | 3:6169aeeaeeb4 | 467 | |
roryhand | 3:6169aeeaeeb4 | 468 | |
roryhand | 3:6169aeeaeeb4 | 469 | //function prototypes |
roryhand | 45:0e8e1f2ec5d2 | 470 | classSoundFile ReadFileInfo(classSoundFile Sound, FILE * wav_file); |
roryhand | 3:6169aeeaeeb4 | 471 | classSoundFile LoadFileStream(classSoundFile FileInfo, string filename); |
roryhand | 3:6169aeeaeeb4 | 472 | |
roryhand | 3:6169aeeaeeb4 | 473 | float FadeOut(void); |
roryhand | 3:6169aeeaeeb4 | 474 | void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo); |
roryhand | 32:6ee488c97dcc | 475 | void Play_WaveFileDual(FILE * my_wav, WAV_FILE_STRUCT FileInfo); |
roryhand | 3:6169aeeaeeb4 | 476 | //void Play_WaveFileLoop(FILE * my_wav, WAV_FILE_STRUCT FileInfo); |
roryhand | 3:6169aeeaeeb4 | 477 | //*********************INTERRUPT ROUTINE FOR NOTCHING*************************** |
roryhand | 0:e89d7a0bfa3b | 478 | |
roryhand | 1:aac37edee302 | 479 | void NotchUpIsr() |
roryhand | 0:e89d7a0bfa3b | 480 | { |
roryhand | 1:aac37edee302 | 481 | if(1 <= NotchingSet.Notch < 8) { |
roryhand | 1:aac37edee302 | 482 | |
roryhand | 1:aac37edee302 | 483 | NotchingSet.Notch = NotchingSet.Notch + 1; |
roryhand | 1:aac37edee302 | 484 | NotchingSet.NotchTransUp = NotchingSet.Notch + 7; |
roryhand | 1:aac37edee302 | 485 | NotchingSet.NotchDirection = 1; |
roryhand | 3:6169aeeaeeb4 | 486 | FadeDataInitialise(NotchFadeIn); |
roryhand | 3:6169aeeaeeb4 | 487 | FadeDataInitialise(NotchFadeOut); |
roryhand | 1:aac37edee302 | 488 | } |
roryhand | 0:e89d7a0bfa3b | 489 | } |
roryhand | 0:e89d7a0bfa3b | 490 | |
roryhand | 0:e89d7a0bfa3b | 491 | void NotchDownIsr() |
roryhand | 0:e89d7a0bfa3b | 492 | { |
roryhand | 1:aac37edee302 | 493 | if(1 < NotchingSet.Notch <= 8) { |
roryhand | 1:aac37edee302 | 494 | NotchingSet.Notch = NotchingSet.Notch - 1; |
roryhand | 1:aac37edee302 | 495 | NotchingSet.NotchTransDown = NotchingSet.Notch + 15;; |
roryhand | 1:aac37edee302 | 496 | NotchingSet.NotchDirection = 0; |
roryhand | 3:6169aeeaeeb4 | 497 | FadeDataInitialise(NotchFadeIn); |
roryhand | 3:6169aeeaeeb4 | 498 | FadeDataInitialise(NotchFadeOut); |
roryhand | 1:aac37edee302 | 499 | } |
roryhand | 1:aac37edee302 | 500 | } |
roryhand | 0:e89d7a0bfa3b | 501 | |
roryhand | 0:e89d7a0bfa3b | 502 | |
roryhand | 3:6169aeeaeeb4 | 503 | /**********************END OF INTERRUPT ROUTINE FOR NOTCHING*******************/ |
roryhand | 3:6169aeeaeeb4 | 504 | |
roryhand | 3:6169aeeaeeb4 | 505 | |
roryhand | 1:aac37edee302 | 506 | |
roryhand | 0:e89d7a0bfa3b | 507 | |
roryhand | 3:6169aeeaeeb4 | 508 | |
roryhand | 3:6169aeeaeeb4 | 509 | |
roryhand | 89:936f37f90cc2 | 510 | void Play_WaveFileLoop(classSoundFile Sound1, classSoundFile Sound2, classSoundFile Sound3, FILE* wavfile1,FILE* wavfile2, FILE* wavfile3, classPositionIndicators Positions); |
roryhand | 1:aac37edee302 | 511 | int main() |
roryhand | 1:aac37edee302 | 512 | { |
roryhand | 44:a9e84d333a6a | 513 | |
roryhand | 0:e89d7a0bfa3b | 514 | NotchUp.mode(PullUp); |
roryhand | 38:3b4c05af5f36 | 515 | NotchDown.mode(PullUp); |
roryhand | 0:e89d7a0bfa3b | 516 | |
roryhand | 0:e89d7a0bfa3b | 517 | pc.printf("Beginning of program\n"); |
roryhand | 32:6ee488c97dcc | 518 | |
roryhand | 13:8e93396a27c5 | 519 | |
roryhand | 13:8e93396a27c5 | 520 | |
roryhand | 4:55fbbb049bae | 521 | |
roryhand | 25:5336e1cf38d6 | 522 | printf("Do we even get to this stupid bloody point\n\r"); |
roryhand | 0:e89d7a0bfa3b | 523 | //Populate our class instances with some data (is there an implicit way to do this?) |
roryhand | 28:6b2353fad12d | 524 | |
roryhand | 1:aac37edee302 | 525 | |
roryhand | 3:6169aeeaeeb4 | 526 | printf("hello\n\r"); |
roryhand | 0:e89d7a0bfa3b | 527 | //Set up the wolfson Audio Codec board |
roryhand | 0:e89d7a0bfa3b | 528 | wm8731_Config_setup(); |
roryhand | 0:e89d7a0bfa3b | 529 | //i2s audio data transfer code?? |
roryhand | 0:e89d7a0bfa3b | 530 | i2s.stereomono(I2S_STEREO); |
roryhand | 0:e89d7a0bfa3b | 531 | i2s.masterslave(I2S_MASTER); |
roryhand | 0:e89d7a0bfa3b | 532 | led3 = 1; |
roryhand | 0:e89d7a0bfa3b | 533 | led2 = 1; |
roryhand | 45:0e8e1f2ec5d2 | 534 | printf("Hello i2s has started!"); |
roryhand | 30:4a8e80b243c4 | 535 | i2s.start(); |
roryhand | 0:e89d7a0bfa3b | 536 | sampletick.attach(&isr,1.0/sampling_freq); //1/16000 |
roryhand | 45:0e8e1f2ec5d2 | 537 | //fileswitch_tick.attach(&FileSwitch_isr,6.0);//So we can switch between playing file 1 and file 2, including opening and closing |
roryhand | 45:0e8e1f2ec5d2 | 538 | //not convinced we need this above line at the moment!! |
roryhand | 31:0f8c3adf09c3 | 539 | |
roryhand | 56:3755c53ac4c6 | 540 | |
roryhand | 62:ac63dfe15ef9 | 541 | |
roryhand | 31:0f8c3adf09c3 | 542 | timer_open.reset(); |
roryhand | 32:6ee488c97dcc | 543 | timer_open.start(); |
roryhand | 88:76a4563ee9c7 | 544 | wavfile1 = fopen("/sd/mydir/SoundDecoder_second/All_eight_notches.wav","rb"); |
roryhand | 54:606a83fff291 | 545 | if(wavfile1 == NULL) { |
roryhand | 45:0e8e1f2ec5d2 | 546 | printf("Cannot Open wavfile1\n\r"); |
roryhand | 32:6ee488c97dcc | 547 | } |
roryhand | 54:606a83fff291 | 548 | printf("size of wavfile1 %d\n\r",sizeof(wavfile1)); |
roryhand | 54:606a83fff291 | 549 | timer_open.stop(); |
roryhand | 31:0f8c3adf09c3 | 550 | printf("It took %d useconds to open file\n\r",timer_open.read_us()); |
roryhand | 54:606a83fff291 | 551 | timer_open.reset(); |
roryhand | 54:606a83fff291 | 552 | |
roryhand | 54:606a83fff291 | 553 | |
roryhand | 54:606a83fff291 | 554 | printf("Size of wavfile 1: %d bytes\n\r",sizeof(wavfile1)); |
roryhand | 45:0e8e1f2ec5d2 | 555 | timer_open.start(); |
roryhand | 88:76a4563ee9c7 | 556 | wavfile2 = fopen("/sd/mydir/SoundDecoder_second/All_14_Notch_Transitions.wav","rb"); |
roryhand | 54:606a83fff291 | 557 | if(wavfile2 == NULL) { |
roryhand | 45:0e8e1f2ec5d2 | 558 | printf("Cannot Open wavfile2\n\r"); |
roryhand | 45:0e8e1f2ec5d2 | 559 | } |
roryhand | 54:606a83fff291 | 560 | timer_open.stop(); |
roryhand | 45:0e8e1f2ec5d2 | 561 | printf("It took %d useconds to open file\n\r",timer_open.read_us()); |
roryhand | 54:606a83fff291 | 562 | timer_open.reset(); |
roryhand | 54:606a83fff291 | 563 | |
roryhand | 32:6ee488c97dcc | 564 | timer_open.start(); |
roryhand | 88:76a4563ee9c7 | 565 | wavfile3 = fopen("/sd/mydir/SoundDecoder_second/All_eight_notches.wav","rb"); |
roryhand | 54:606a83fff291 | 566 | if(wavfile3 == NULL) { |
roryhand | 45:0e8e1f2ec5d2 | 567 | printf("Cannot Open wavfile3\n\r"); |
roryhand | 45:0e8e1f2ec5d2 | 568 | } |
roryhand | 54:606a83fff291 | 569 | timer_open.stop(); |
roryhand | 45:0e8e1f2ec5d2 | 570 | printf("It took %d useconds to open file\n\r",timer_open.read_us()); |
roryhand | 54:606a83fff291 | 571 | timer_open.reset(); |
roryhand | 54:606a83fff291 | 572 | |
roryhand | 54:606a83fff291 | 573 | |
roryhand | 45:0e8e1f2ec5d2 | 574 | Sound1 = ReadFileInfo(Sound1,wavfile1); |
roryhand | 45:0e8e1f2ec5d2 | 575 | Sound2 = ReadFileInfo(Sound2,wavfile2); |
roryhand | 45:0e8e1f2ec5d2 | 576 | Sound3 = ReadFileInfo(Sound3,wavfile3); |
roryhand | 88:76a4563ee9c7 | 577 | |
roryhand | 13:8e93396a27c5 | 578 | |
roryhand | 88:76a4563ee9c7 | 579 | //fclose(wavfile2); |
roryhand | 88:76a4563ee9c7 | 580 | //fclose(wavfile3); |
roryhand | 47:9334a8f54997 | 581 | NotchFadeIn.LengthSecs = 2; |
roryhand | 46:de390e45c2af | 582 | NotchFadeOut.LengthSecs = 2; |
roryhand | 46:de390e45c2af | 583 | NotchFadeIn = FadeDataInitialise(NotchFadeIn); |
roryhand | 46:de390e45c2af | 584 | NotchFadeOut = FadeDataInitialise(NotchFadeOut); |
roryhand | 45:0e8e1f2ec5d2 | 585 | |
roryhand | 45:0e8e1f2ec5d2 | 586 | |
roryhand | 45:0e8e1f2ec5d2 | 587 | |
roryhand | 45:0e8e1f2ec5d2 | 588 | TickFadeOut.attach(&FadeOutIsr,10.0); |
roryhand | 45:0e8e1f2ec5d2 | 589 | |
roryhand | 54:606a83fff291 | 590 | |
roryhand | 54:606a83fff291 | 591 | //timer_interrupt.reset(); |
roryhand | 54:606a83fff291 | 592 | |
roryhand | 89:936f37f90cc2 | 593 | classPositionIndicators Positions; |
roryhand | 89:936f37f90cc2 | 594 | |
roryhand | 20:9cc7d825c07b | 595 | printf("about to play wav file\n\r"); |
roryhand | 89:936f37f90cc2 | 596 | Play_WaveFileLoop(Sound1,Sound2,Sound3,wavfile1,wavfile2,wavfile3,Positions); |
roryhand | 45:0e8e1f2ec5d2 | 597 | //Play_WaveFileDual(StartupWav,WavInfo_Startup); |
roryhand | 20:9cc7d825c07b | 598 | printf("finished playing Wav file\n\r"); |
roryhand | 54:606a83fff291 | 599 | |
roryhand | 54:606a83fff291 | 600 | |
roryhand | 31:0f8c3adf09c3 | 601 | timer_open.reset(); |
roryhand | 31:0f8c3adf09c3 | 602 | timer_open.start(); |
roryhand | 45:0e8e1f2ec5d2 | 603 | fclose(wavfile1); |
roryhand | 31:0f8c3adf09c3 | 604 | timer_open.stop(); |
roryhand | 31:0f8c3adf09c3 | 605 | printf("It took %d useconds to close file\n\r",timer_open.read_us()); |
roryhand | 54:606a83fff291 | 606 | |
roryhand | 45:0e8e1f2ec5d2 | 607 | timer_open.reset(); |
roryhand | 54:606a83fff291 | 608 | timer_open.start(); |
roryhand | 45:0e8e1f2ec5d2 | 609 | fclose(wavfile2); |
roryhand | 45:0e8e1f2ec5d2 | 610 | timer_open.stop(); |
roryhand | 54:606a83fff291 | 611 | printf("It took %d useconds to close file\n\r",timer_open.read_us()); |
roryhand | 54:606a83fff291 | 612 | |
roryhand | 54:606a83fff291 | 613 | |
roryhand | 45:0e8e1f2ec5d2 | 614 | timer_open.reset(); |
roryhand | 54:606a83fff291 | 615 | timer_open.start(); |
roryhand | 45:0e8e1f2ec5d2 | 616 | fclose(wavfile3); |
roryhand | 45:0e8e1f2ec5d2 | 617 | timer_open.stop(); |
roryhand | 45:0e8e1f2ec5d2 | 618 | printf("It took %d useconds to close file\n\r",timer_open.read_us()); |
roryhand | 54:606a83fff291 | 619 | |
roryhand | 54:606a83fff291 | 620 | |
roryhand | 54:606a83fff291 | 621 | |
roryhand | 9:dd9cae06b202 | 622 | /************************************PLAY WAV FILE LOOP*******************/ |
roryhand | 20:9cc7d825c07b | 623 | //Play_WaveFileLoop(Sound, NotchingSet); |
roryhand | 9:dd9cae06b202 | 624 | /************************************END OF PLAY WAV FILE LOOP*************/ |
roryhand | 13:8e93396a27c5 | 625 | |
roryhand | 13:8e93396a27c5 | 626 | |
roryhand | 1:aac37edee302 | 627 | i2s.stop(); |
roryhand | 0:e89d7a0bfa3b | 628 | |
roryhand | 0:e89d7a0bfa3b | 629 | } |
roryhand | 0:e89d7a0bfa3b | 630 | |
roryhand | 0:e89d7a0bfa3b | 631 | |
roryhand | 3:6169aeeaeeb4 | 632 | |
roryhand | 3:6169aeeaeeb4 | 633 | |
roryhand | 3:6169aeeaeeb4 | 634 | |
roryhand | 3:6169aeeaeeb4 | 635 | |
roryhand | 45:0e8e1f2ec5d2 | 636 | classSoundFile ReadFileInfo(classSoundFile Sound, FILE * wav_file) |
roryhand | 0:e89d7a0bfa3b | 637 | { |
roryhand | 0:e89d7a0bfa3b | 638 | fseek(wav_file,20,SEEK_SET); |
roryhand | 22:706e86dc0d45 | 639 | printf("We have just seeked through this file\n\r"); |
roryhand | 45:0e8e1f2ec5d2 | 640 | fread(&Sound.FileInfo.FileFormat,sizeof(Sound.FileInfo.FileFormat),1,wav_file); |
roryhand | 1:aac37edee302 | 641 | //printf("wav_format.sample_rate: %d\n\r",FileInfo.FileFormat.sample_rate); |
roryhand | 1:aac37edee302 | 642 | |
roryhand | 45:0e8e1f2ec5d2 | 643 | fread(&Sound.FileInfo.FileData,sizeof(Sound.FileInfo.FileData),1,wav_file); |
roryhand | 55:5a441d3b0d57 | 644 | printf("wav_data.subchunk2_size: %d\n\r",Sound.FileInfo.FileData.subchunk2_size); |
roryhand | 45:0e8e1f2ec5d2 | 645 | Sound.FileInfo.slice_buf = ( char *)malloc(Sound.FileInfo.FileFormat.block_align); |
roryhand | 45:0e8e1f2ec5d2 | 646 | fread(Sound.FileInfo.slice_buf,Sound.FileInfo.FileFormat.block_align,1,wav_file); //This isnt actually required, its just a test |
roryhand | 45:0e8e1f2ec5d2 | 647 | Sound.FileInfo.num_slices = Sound.FileInfo.FileData.subchunk2_size/Sound.FileInfo.FileFormat.block_align; |
roryhand | 1:aac37edee302 | 648 | //printf("Number of Slices: %d\n\r",FileInfo.num_slices); |
roryhand | 45:0e8e1f2ec5d2 | 649 | return Sound; |
roryhand | 0:e89d7a0bfa3b | 650 | } |
roryhand | 1:aac37edee302 | 651 | |
roryhand | 1:aac37edee302 | 652 | classSoundFile LoadFileStream(classSoundFile Sound, string filename) |
roryhand | 1:aac37edee302 | 653 | { |
roryhand | 1:aac37edee302 | 654 | //Declare RootFolder and the directory for the appropriate file. |
roryhand | 1:aac37edee302 | 655 | //How we index into filename[] from the outside of this class is another |
roryhand | 1:aac37edee302 | 656 | //issue... |
roryhand | 1:aac37edee302 | 657 | //printf("FileName: %s\n\r",filename); |
roryhand | 1:aac37edee302 | 658 | //string RootFolder = "/sd/mydir/SoundDecoder/"; |
roryhand | 1:aac37edee302 | 659 | //string Directory = RootFolder + "01.wav";// + filename[0]; |
roryhand | 1:aac37edee302 | 660 | //printf("%s\n\r",Directory); |
roryhand | 1:aac37edee302 | 661 | //const char* DirectoryChar = Directory.c_str(); |
roryhand | 1:aac37edee302 | 662 | //Sound.FileInfo.WavFile = fopen(DirectoryChar,"rb"); |
roryhand | 1:aac37edee302 | 663 | Sound.FileInfo.WavFile = fopen("/sd/mydir/645Engine/Startup.wav","rb"); |
roryhand | 1:aac37edee302 | 664 | fseek(Sound.FileInfo.WavFile,20,SEEK_SET); |
roryhand | 1:aac37edee302 | 665 | fread(&Sound.FileInfo.FileFormat,sizeof(Sound.FileInfo.FileFormat),1,Sound.FileInfo.WavFile); |
roryhand | 1:aac37edee302 | 666 | printf("wav_format.sample_rate: %d\n\r",Sound.FileInfo.FileFormat.sample_rate); |
roryhand | 1:aac37edee302 | 667 | fread(&Sound.FileInfo.FileData,sizeof(Sound.FileInfo.FileData),1,Sound.FileInfo.WavFile); |
roryhand | 1:aac37edee302 | 668 | printf("wav_data.subchunk2_size: %d\n\r",Sound.FileInfo.FileData.subchunk2_size); |
roryhand | 1:aac37edee302 | 669 | Sound.FileInfo.slice_buf = ( char *)malloc(Sound.FileInfo.FileFormat.block_align); |
roryhand | 1:aac37edee302 | 670 | fread(Sound.FileInfo.slice_buf,Sound.FileInfo.FileFormat.block_align,1,Sound.FileInfo.WavFile); //This isnt actually required, its just a test |
roryhand | 1:aac37edee302 | 671 | Sound.FileInfo.num_slices = Sound.FileInfo.FileData.subchunk2_size/Sound.FileInfo.FileFormat.block_align; |
roryhand | 1:aac37edee302 | 672 | printf("Number of Slices: %d\n\r",Sound.FileInfo.num_slices); |
roryhand | 1:aac37edee302 | 673 | return Sound; |
roryhand | 1:aac37edee302 | 674 | } |
roryhand | 1:aac37edee302 | 675 | |
roryhand | 1:aac37edee302 | 676 | |
roryhand | 0:e89d7a0bfa3b | 677 | classFade FadeDataInitialise(classFade FadeData) |
roryhand | 0:e89d7a0bfa3b | 678 | { |
roryhand | 1:aac37edee302 | 679 | FadeData.DecayFactor = 1.3; |
roryhand | 0:e89d7a0bfa3b | 680 | FadeData.FadeIteration = 1; |
roryhand | 0:e89d7a0bfa3b | 681 | //FadeData.Denom = 11025*FadeData.DecayFactor; |
roryhand | 0:e89d7a0bfa3b | 682 | FadeData.Denom = 11025*FadeData.DecayFactor; |
roryhand | 0:e89d7a0bfa3b | 683 | FadeData.Natural_Exp = 2.7183; |
roryhand | 0:e89d7a0bfa3b | 684 | FadeData.Length = 11025*FadeData.LengthSecs; |
roryhand | 0:e89d7a0bfa3b | 685 | //FadeData.Natural_Exp = 2.7; |
roryhand | 0:e89d7a0bfa3b | 686 | return FadeData; |
roryhand | 0:e89d7a0bfa3b | 687 | } |
roryhand | 0:e89d7a0bfa3b | 688 | |
roryhand | 0:e89d7a0bfa3b | 689 | //Playing Files Code |
roryhand | 46:de390e45c2af | 690 | /* |
roryhand | 45:0e8e1f2ec5d2 | 691 | float FadeIn(void) |
roryhand | 0:e89d7a0bfa3b | 692 | { |
roryhand | 0:e89d7a0bfa3b | 693 | powervalFadeIn = FadeIterationIn/denom; |
roryhand | 0:e89d7a0bfa3b | 694 | FadeCoeffFadeIn |
roryhand | 1:aac37edee302 | 695 | |
roryhand | 1:aac37edee302 | 696 | |
roryhand | 45:0e8e1f2ec5d2 | 697 | } |
roryhand | 45:0e8e1f2ec5d2 | 698 | float FadeOut(void) |
roryhand | 0:e89d7a0bfa3b | 699 | { |
roryhand | 0:e89d7a0bfa3b | 700 | powerval = -FadeIteration/denom; |
roryhand | 0:e89d7a0bfa3b | 701 | FadeCoeff = pow(natural_exp,powerval); |
roryhand | 1:aac37edee302 | 702 | FadeIteration = FadeIteration + 1; |
roryhand | 1:aac37edee302 | 703 | return FadeCoeff; |
roryhand | 1:aac37edee302 | 704 | |
roryhand | 45:0e8e1f2ec5d2 | 705 | } |
roryhand | 46:de390e45c2af | 706 | */ |
roryhand | 0:e89d7a0bfa3b | 707 | |
roryhand | 0:e89d7a0bfa3b | 708 | void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo) |
roryhand | 0:e89d7a0bfa3b | 709 | { |
roryhand | 1:aac37edee302 | 710 | while(slice<FileInfo.num_slices) { |
roryhand | 1:aac37edee302 | 711 | fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,my_wav); |
roryhand | 1:aac37edee302 | 712 | data_sptr=(short *)FileInfo.slice_buf; // 16 bit samples |
roryhand | 1:aac37edee302 | 713 | for (channel=0; channel<FileInfo.FileFormat.num_channels; channel++) { |
roryhand | 1:aac37edee302 | 714 | if(flag1 == 1) { |
roryhand | 1:aac37edee302 | 715 | Buffer1[place_hold1] = data_sptr[channel]; |
roryhand | 1:aac37edee302 | 716 | place_hold1 = place_hold1 + 1; |
roryhand | 1:aac37edee302 | 717 | if(place_hold1 >= BufferLen) { |
roryhand | 1:aac37edee302 | 718 | while(1) { |
roryhand | 1:aac37edee302 | 719 | if(flag1 == 0) { |
roryhand | 0:e89d7a0bfa3b | 720 | |
roryhand | 1:aac37edee302 | 721 | break; |
roryhand | 0:e89d7a0bfa3b | 722 | } |
roryhand | 1:aac37edee302 | 723 | |
roryhand | 0:e89d7a0bfa3b | 724 | } |
roryhand | 1:aac37edee302 | 725 | } |
roryhand | 1:aac37edee302 | 726 | |
roryhand | 1:aac37edee302 | 727 | } else if(flag2 == 1) { |
roryhand | 1:aac37edee302 | 728 | Buffer2[place_hold2] = data_sptr[channel]; |
roryhand | 1:aac37edee302 | 729 | place_hold2 = place_hold2 + 1; |
roryhand | 1:aac37edee302 | 730 | if(place_hold2 >= BufferLen) { |
roryhand | 1:aac37edee302 | 731 | |
roryhand | 1:aac37edee302 | 732 | while(1) { |
roryhand | 1:aac37edee302 | 733 | if(flag2 == 0) { |
roryhand | 1:aac37edee302 | 734 | |
roryhand | 1:aac37edee302 | 735 | break; |
roryhand | 1:aac37edee302 | 736 | } |
roryhand | 0:e89d7a0bfa3b | 737 | } |
roryhand | 1:aac37edee302 | 738 | } |
roryhand | 0:e89d7a0bfa3b | 739 | } |
roryhand | 1:aac37edee302 | 740 | |
roryhand | 1:aac37edee302 | 741 | } |
roryhand | 1:aac37edee302 | 742 | slice = slice + 1; |
roryhand | 0:e89d7a0bfa3b | 743 | } |
roryhand | 0:e89d7a0bfa3b | 744 | } |
roryhand | 0:e89d7a0bfa3b | 745 | |
roryhand | 0:e89d7a0bfa3b | 746 | |
roryhand | 0:e89d7a0bfa3b | 747 | |
roryhand | 0:e89d7a0bfa3b | 748 | |
roryhand | 32:6ee488c97dcc | 749 | void Play_WaveFileDual(FILE * my_wav, WAV_FILE_STRUCT FileInfo) |
roryhand | 32:6ee488c97dcc | 750 | { |
roryhand | 32:6ee488c97dcc | 751 | while(slice<FileInfo.num_slices) { |
roryhand | 32:6ee488c97dcc | 752 | if(FileSwitchFlag == 1) { |
roryhand | 35:4469b508dda3 | 753 | |
roryhand | 33:a75f0a30fbdc | 754 | if(temp == 1) { |
roryhand | 34:26118c8f2e48 | 755 | printf("Does it go to this point\n\r"); |
roryhand | 35:4469b508dda3 | 756 | N3Wav = fopen("/sd/mydir/SoundDecoder_second/03.wav","rb"); |
roryhand | 33:a75f0a30fbdc | 757 | if(N3Wav == NULL) { |
roryhand | 33:a75f0a30fbdc | 758 | printf("Cannot Open testwav\n\r"); |
roryhand | 33:a75f0a30fbdc | 759 | } |
roryhand | 33:a75f0a30fbdc | 760 | fclose(StartupWav); |
roryhand | 33:a75f0a30fbdc | 761 | temp = 0; |
roryhand | 33:a75f0a30fbdc | 762 | } |
roryhand | 35:4469b508dda3 | 763 | fread(WavInfo_N3.slice_buf,WavInfo_N3.FileFormat.block_align,1,N3Wav); |
roryhand | 35:4469b508dda3 | 764 | data_sptr=(short*)WavInfo_N3.slice_buf; |
roryhand | 32:6ee488c97dcc | 765 | } else { |
roryhand | 32:6ee488c97dcc | 766 | fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,my_wav); |
roryhand | 32:6ee488c97dcc | 767 | data_sptr=(short *)FileInfo.slice_buf; // 16 bit samples |
roryhand | 32:6ee488c97dcc | 768 | } |
roryhand | 32:6ee488c97dcc | 769 | for (channel=0; channel<FileInfo.FileFormat.num_channels; channel++) { |
roryhand | 32:6ee488c97dcc | 770 | if(flag1 == 1) { |
roryhand | 32:6ee488c97dcc | 771 | Buffer1[place_hold1] = data_sptr[channel]; |
roryhand | 32:6ee488c97dcc | 772 | place_hold1 = place_hold1 + 1; |
roryhand | 32:6ee488c97dcc | 773 | if(place_hold1 >= BufferLen) { |
roryhand | 32:6ee488c97dcc | 774 | while(1) { |
roryhand | 32:6ee488c97dcc | 775 | if(flag1 == 0) { |
roryhand | 0:e89d7a0bfa3b | 776 | |
roryhand | 32:6ee488c97dcc | 777 | break; |
roryhand | 32:6ee488c97dcc | 778 | } |
roryhand | 32:6ee488c97dcc | 779 | |
roryhand | 32:6ee488c97dcc | 780 | } |
roryhand | 32:6ee488c97dcc | 781 | } |
roryhand | 32:6ee488c97dcc | 782 | |
roryhand | 32:6ee488c97dcc | 783 | } else if(flag2 == 1) { |
roryhand | 32:6ee488c97dcc | 784 | Buffer2[place_hold2] = data_sptr[channel]; |
roryhand | 32:6ee488c97dcc | 785 | place_hold2 = place_hold2 + 1; |
roryhand | 32:6ee488c97dcc | 786 | if(place_hold2 >= BufferLen) { |
roryhand | 32:6ee488c97dcc | 787 | |
roryhand | 32:6ee488c97dcc | 788 | while(1) { |
roryhand | 32:6ee488c97dcc | 789 | if(flag2 == 0) { |
roryhand | 32:6ee488c97dcc | 790 | |
roryhand | 32:6ee488c97dcc | 791 | break; |
roryhand | 32:6ee488c97dcc | 792 | } |
roryhand | 32:6ee488c97dcc | 793 | } |
roryhand | 32:6ee488c97dcc | 794 | } |
roryhand | 32:6ee488c97dcc | 795 | } |
roryhand | 32:6ee488c97dcc | 796 | |
roryhand | 32:6ee488c97dcc | 797 | } |
roryhand | 32:6ee488c97dcc | 798 | slice = slice + 1; |
roryhand | 32:6ee488c97dcc | 799 | } |
roryhand | 32:6ee488c97dcc | 800 | } |
roryhand | 0:e89d7a0bfa3b | 801 | |
roryhand | 38:3b4c05af5f36 | 802 | //***************************************************************************// |
roryhand | 38:3b4c05af5f36 | 803 | |
roryhand | 38:3b4c05af5f36 | 804 | //**************************************************************************// |
roryhand | 38:3b4c05af5f36 | 805 | |
roryhand | 38:3b4c05af5f36 | 806 | |
roryhand | 38:3b4c05af5f36 | 807 | |
roryhand | 38:3b4c05af5f36 | 808 | |
roryhand | 38:3b4c05af5f36 | 809 | |
roryhand | 1:aac37edee302 | 810 | |
roryhand | 44:a9e84d333a6a | 811 | |
roryhand | 89:936f37f90cc2 | 812 | void Play_WaveFileLoop(classSoundFile Sound1, classSoundFile Sound2, classSoundFile Sound3, FILE *wavfile1, FILE *wavfile2, FILE *wavfile3, classPositionIndicators Positions) |
roryhand | 45:0e8e1f2ec5d2 | 813 | { |
roryhand | 45:0e8e1f2ec5d2 | 814 | while(1) { //might have to change this to a while(1) loop? |
roryhand | 45:0e8e1f2ec5d2 | 815 | //New format!! This should be (roughly) the way that this is done, with the new structures and classes |
roryhand | 44:a9e84d333a6a | 816 | |
roryhand | 45:0e8e1f2ec5d2 | 817 | //Block 1 of code. We need to pass in 3x classSoundFile objects, and 3x FILE* pointer objects. |
roryhand | 45:0e8e1f2ec5d2 | 818 | //This will allow us to switch between the 3 different files (using "cross-fades") as needed. |
roryhand | 45:0e8e1f2ec5d2 | 819 | /*Remember that these will need to be global varaibles to work properly*/ |
roryhand | 45:0e8e1f2ec5d2 | 820 | |
roryhand | 45:0e8e1f2ec5d2 | 821 | |
roryhand | 2:957d3b2afff4 | 822 | //make sure we are reading in the correct "notch" here |
roryhand | 2:957d3b2afff4 | 823 | |
roryhand | 44:a9e84d333a6a | 824 | |
roryhand | 44:a9e84d333a6a | 825 | |
roryhand | 54:606a83fff291 | 826 | /*Block1*/ |
roryhand | 54:606a83fff291 | 827 | /*Read in data for current sound files. We only have 3 active engine noises at a time. |
roryhand | 54:606a83fff291 | 828 | When it becomes time to transition up again, we then flip to the opposite block, and perform |
roryhand | 54:606a83fff291 | 829 | the opposite operation.*/ |
roryhand | 54:606a83fff291 | 830 | |
roryhand | 54:606a83fff291 | 831 | |
roryhand | 54:606a83fff291 | 832 | if(BlockFlag == 0) { |
roryhand | 44:a9e84d333a6a | 833 | //Sound1======================================================================================= |
roryhand | 44:a9e84d333a6a | 834 | if( slice1 == (Sound1.FileInfo.num_slices-1) ) { |
roryhand | 44:a9e84d333a6a | 835 | slice1 = 0; |
roryhand | 44:a9e84d333a6a | 836 | fseek(wavfile1,44,SEEK_SET); |
roryhand | 2:957d3b2afff4 | 837 | } |
roryhand | 47:9334a8f54997 | 838 | if(feof(wavfile1)) { |
roryhand | 47:9334a8f54997 | 839 | fseek(wavfile1,44,SEEK_SET); |
roryhand | 47:9334a8f54997 | 840 | } |
roryhand | 44:a9e84d333a6a | 841 | fread(Sound1.FileInfo.slice_buf,Sound1.FileInfo.FileFormat.block_align,1,wavfile1); |
roryhand | 44:a9e84d333a6a | 842 | Sound1.data_sptr=(short *)Sound1.FileInfo.slice_buf; // 16 bit samples |
roryhand | 44:a9e84d333a6a | 843 | //============================================================================================= |
roryhand | 54:606a83fff291 | 844 | } |
roryhand | 44:a9e84d333a6a | 845 | |
roryhand | 54:606a83fff291 | 846 | else if(BlockFlag == 1) { |
roryhand | 44:a9e84d333a6a | 847 | |
roryhand | 44:a9e84d333a6a | 848 | |
roryhand | 44:a9e84d333a6a | 849 | |
roryhand | 44:a9e84d333a6a | 850 | |
roryhand | 44:a9e84d333a6a | 851 | /*Block2*/ |
roryhand | 3:6169aeeaeeb4 | 852 | |
roryhand | 2:957d3b2afff4 | 853 | //Read in data for current (i.e. now the previous notch, according to the index!!) |
roryhand | 2:957d3b2afff4 | 854 | //We might not need this code here...as its probably done somewhere else?? |
roryhand | 44:a9e84d333a6a | 855 | //fread(Sounds[NotchingSet.Notch-1].FileInfo.slice_buf,Sounds[NotchingSet.Notch-1].FileInfo.FileFormat.block_align,1,Sounds[NotchingSet.Notch-1].FileInfo.WavFile); |
roryhand | 44:a9e84d333a6a | 856 | //Sounds[NotchingSet.Notch-1].data_sptr = (short *)Sounds[NotchingSet.Notch-1].FileInfo.slice_buf; |
roryhand | 44:a9e84d333a6a | 857 | //We are now performing this section above. |
roryhand | 3:6169aeeaeeb4 | 858 | |
roryhand | 47:9334a8f54997 | 859 | |
roryhand | 54:606a83fff291 | 860 | if(FadeFlag) { |
roryhand | 54:606a83fff291 | 861 | if( slice1 == (Sound1.FileInfo.num_slices-1) ) { |
roryhand | 54:606a83fff291 | 862 | slice1 = 0; |
roryhand | 54:606a83fff291 | 863 | fseek(wavfile1,44,SEEK_SET); |
roryhand | 54:606a83fff291 | 864 | } |
roryhand | 54:606a83fff291 | 865 | if(OneOff == 1) { |
roryhand | 47:9334a8f54997 | 866 | |
roryhand | 47:9334a8f54997 | 867 | |
roryhand | 54:606a83fff291 | 868 | wavfile2 = fopen("/sd/mydir/SoundDecoder_second/09.wav","rb"); |
roryhand | 54:606a83fff291 | 869 | if(wavfile2 == NULL) { |
roryhand | 54:606a83fff291 | 870 | printf("Cannot Open wavfile2\n\r"); |
roryhand | 54:606a83fff291 | 871 | } |
roryhand | 54:606a83fff291 | 872 | |
roryhand | 54:606a83fff291 | 873 | wavfile3 = fopen("/sd/mydir/SoundDecoder_second/02.wav","rb"); |
roryhand | 54:606a83fff291 | 874 | if(wavfile3 == NULL) { |
roryhand | 54:606a83fff291 | 875 | printf("Cannot Open wavfile3\n\r"); |
roryhand | 54:606a83fff291 | 876 | } |
roryhand | 54:606a83fff291 | 877 | fseek(wavfile2,44,SEEK_SET); |
roryhand | 54:606a83fff291 | 878 | fseek(wavfile3,44,SEEK_SET); |
roryhand | 54:606a83fff291 | 879 | /* |
roryhand | 54:606a83fff291 | 880 | FILE* wavfile4 = fopen("/sd/mydir/SoundDecoder_second/04.wav","rb"); |
roryhand | 54:606a83fff291 | 881 | if(wavfile4 == NULL) { |
roryhand | 54:606a83fff291 | 882 | printf("Cannot Open wavfile3\n\r"); |
roryhand | 54:606a83fff291 | 883 | } |
roryhand | 54:606a83fff291 | 884 | */ |
roryhand | 54:606a83fff291 | 885 | OneOff = 0; |
roryhand | 54:606a83fff291 | 886 | } |
roryhand | 54:606a83fff291 | 887 | |
roryhand | 54:606a83fff291 | 888 | fread(Sound1.FileInfo.slice_buf,Sound1.FileInfo.FileFormat.block_align,1,wavfile1); |
roryhand | 54:606a83fff291 | 889 | Sound1.data_sptr=(short *)Sound1.FileInfo.slice_buf; // 16 bit samples |
roryhand | 54:606a83fff291 | 890 | |
roryhand | 54:606a83fff291 | 891 | //Sound2======================================================================================= |
roryhand | 54:606a83fff291 | 892 | fread(Sound2.FileInfo.slice_buf,Sound2.FileInfo.FileFormat.block_align,1,wavfile2); |
roryhand | 54:606a83fff291 | 893 | Sound2.data_sptr=(short *)Sound2.FileInfo.slice_buf; // 16 bit samples |
roryhand | 54:606a83fff291 | 894 | //============================================================================================= |
roryhand | 2:957d3b2afff4 | 895 | |
roryhand | 45:0e8e1f2ec5d2 | 896 | |
roryhand | 3:6169aeeaeeb4 | 897 | |
roryhand | 54:606a83fff291 | 898 | //Sound3======================================================================================= |
roryhand | 54:606a83fff291 | 899 | fread(Sound3.FileInfo.slice_buf,Sound3.FileInfo.FileFormat.block_align,1,wavfile3); |
roryhand | 54:606a83fff291 | 900 | Sound3.data_sptr=(short *)Sound3.FileInfo.slice_buf; // 16 bit samples |
roryhand | 54:606a83fff291 | 901 | //============================================================================================= |
roryhand | 54:606a83fff291 | 902 | |
roryhand | 54:606a83fff291 | 903 | //require this to get the fadeout coefficient for Sound1. |
roryhand | 54:606a83fff291 | 904 | NotchFadeOut.FadeCoeff = NotchFadeOut.FadeOut();//compute new FadeOut Coeff value |
roryhand | 54:606a83fff291 | 905 | |
roryhand | 54:606a83fff291 | 906 | |
roryhand | 54:606a83fff291 | 907 | |
roryhand | 54:606a83fff291 | 908 | if( ((Sound2.FileInfo.FileData.subchunk2_size) - NotchFadeIn.Length - 2*11025) <= (ftell(wavfile2) + 44)) { |
roryhand | 2:957d3b2afff4 | 909 | |
roryhand | 44:a9e84d333a6a | 910 | |
roryhand | 54:606a83fff291 | 911 | //required for calculating the fade In coefficient for Sound3 |
roryhand | 54:606a83fff291 | 912 | NotchFadeIn.FadeCoeff = NotchFadeIn.FadeIn(); |
roryhand | 3:6169aeeaeeb4 | 913 | |
roryhand | 54:606a83fff291 | 914 | //Read In the next Notch |
roryhand | 44:a9e84d333a6a | 915 | |
roryhand | 54:606a83fff291 | 916 | /* |
roryhand | 54:606a83fff291 | 917 | fread(Sounds[NotchingSet.Notch].FileInfo.slice_buf,Sounds[NotchingSet.Notch].FileInfo.FileFormat.block_align,1,Sounds[NotchingSet.Notch].FileInfo.WavFile); |
roryhand | 54:606a83fff291 | 918 | Sounds[NotchingSet.Notch].data_sptr = (short *)Sounds[NotchingSet.Notch].FileInfo.slice_buf; |
roryhand | 54:606a83fff291 | 919 | */ |
roryhand | 54:606a83fff291 | 920 | //no longer require the above section as we are reading in data for Sound3 (above, at beginning of function). |
roryhand | 54:606a83fff291 | 921 | |
roryhand | 54:606a83fff291 | 922 | if( (ftell(wavfile2) + 44) >= Sound2.FileInfo.FileData.subchunk2_size ) { |
roryhand | 2:957d3b2afff4 | 923 | |
roryhand | 54:606a83fff291 | 924 | //need to explicitly test if this notation/syntax works for pointers.... |
roryhand | 54:606a83fff291 | 925 | /*Was this ever tested?? no idea... |
roryhand | 54:606a83fff291 | 926 | If not then we need to pass in the 3 different "data_sptr" variables in separately, and not tied to a specific class |
roryhand | 54:606a83fff291 | 927 | or structure.*/ |
roryhand | 54:606a83fff291 | 928 | *Sound1.data_sptr = *Sound3.data_sptr*NotchFadeIn.FadeCoeff;//Sound 3 by itself. |
roryhand | 54:606a83fff291 | 929 | //fclose(wavfile2); |
roryhand | 54:606a83fff291 | 930 | //fclose(wavfile1); |
roryhand | 54:606a83fff291 | 931 | } else { |
roryhand | 54:606a83fff291 | 932 | *Sound1.data_sptr = *Sound1.data_sptr*NotchFadeOut.FadeCoeff + *Sound2.data_sptr + *Sound3.data_sptr*NotchFadeIn.FadeCoeff;//Sounds 1, 2 and 3 Cross-fade. |
roryhand | 54:606a83fff291 | 933 | //probably later on redesign this to work with flags - that way it may be a little easier to debug any issues. |
roryhand | 54:606a83fff291 | 934 | } |
roryhand | 3:6169aeeaeeb4 | 935 | |
roryhand | 2:957d3b2afff4 | 936 | } else { |
roryhand | 54:606a83fff291 | 937 | *Sound1.data_sptr = *Sound1.data_sptr*NotchFadeOut.FadeCoeff + *Sound2.data_sptr;//Sound1 and Sound 2 cross fade |
roryhand | 2:957d3b2afff4 | 938 | } |
roryhand | 2:957d3b2afff4 | 939 | |
roryhand | 2:957d3b2afff4 | 940 | } |
roryhand | 2:957d3b2afff4 | 941 | |
roryhand | 54:606a83fff291 | 942 | |
roryhand | 54:606a83fff291 | 943 | /********************END OF DATA ASSIGNMENT SECTION*************************************************/ |
roryhand | 54:606a83fff291 | 944 | |
roryhand | 1:aac37edee302 | 945 | } |
roryhand | 1:aac37edee302 | 946 | |
roryhand | 1:aac37edee302 | 947 | |
roryhand | 44:a9e84d333a6a | 948 | |
roryhand | 44:a9e84d333a6a | 949 | /**********************************************************************************************************/ |
roryhand | 44:a9e84d333a6a | 950 | /****************************DATA OUTPUT SECTION***********************************************************/ |
roryhand | 44:a9e84d333a6a | 951 | /**********************************************************************************************************/ |
roryhand | 45:0e8e1f2ec5d2 | 952 | for (channel=0; channel<Sound1.FileInfo.FileFormat.num_channels; channel++) { |
roryhand | 45:0e8e1f2ec5d2 | 953 | switch (Sound1.FileInfo.FileFormat.sig_bps) { |
roryhand | 0:e89d7a0bfa3b | 954 | case 16: |
roryhand | 1:aac37edee302 | 955 | if(flag1 == 1) { |
roryhand | 45:0e8e1f2ec5d2 | 956 | Buffer1[place_hold1] = Sound1.data_sptr[channel]; |
roryhand | 1:aac37edee302 | 957 | place_hold1 = place_hold1 + 1; |
roryhand | 1:aac37edee302 | 958 | if(place_hold1 >= BufferLen) { |
roryhand | 1:aac37edee302 | 959 | while(1) { |
roryhand | 1:aac37edee302 | 960 | if(flag1 == 0) { |
roryhand | 1:aac37edee302 | 961 | break; |
roryhand | 1:aac37edee302 | 962 | }//if(flag1 == 0) |
roryhand | 1:aac37edee302 | 963 | |
roryhand | 1:aac37edee302 | 964 | |
roryhand | 1:aac37edee302 | 965 | }//while(1) |
roryhand | 1:aac37edee302 | 966 | }//if(place_hold1 > = BufferLen) |
roryhand | 0:e89d7a0bfa3b | 967 | |
roryhand | 1:aac37edee302 | 968 | } else if(flag2 == 1) { |
roryhand | 45:0e8e1f2ec5d2 | 969 | Buffer2[place_hold2] = Sound1.data_sptr[channel]; |
roryhand | 1:aac37edee302 | 970 | place_hold2 = place_hold2 + 1; |
roryhand | 1:aac37edee302 | 971 | if(place_hold2 >= BufferLen) { |
roryhand | 1:aac37edee302 | 972 | while(1) { |
roryhand | 1:aac37edee302 | 973 | |
roryhand | 1:aac37edee302 | 974 | if(flag2 == 0) { |
roryhand | 1:aac37edee302 | 975 | break; |
roryhand | 1:aac37edee302 | 976 | } |
roryhand | 1:aac37edee302 | 977 | } |
roryhand | 0:e89d7a0bfa3b | 978 | } |
roryhand | 1:aac37edee302 | 979 | |
roryhand | 1:aac37edee302 | 980 | } |
roryhand | 0:e89d7a0bfa3b | 981 | } |
roryhand | 0:e89d7a0bfa3b | 982 | } |
roryhand | 45:0e8e1f2ec5d2 | 983 | slice1 = slice1 + 1; |
roryhand | 45:0e8e1f2ec5d2 | 984 | slice2 = slice2 + 1; |
roryhand | 45:0e8e1f2ec5d2 | 985 | slice3 = slice3 + 1; |
roryhand | 0:e89d7a0bfa3b | 986 | } |
roryhand | 0:e89d7a0bfa3b | 987 | } |
roryhand | 0:e89d7a0bfa3b | 988 | |
roryhand | 0:e89d7a0bfa3b | 989 | |
roryhand | 0:e89d7a0bfa3b | 990 | |
roryhand | 0:e89d7a0bfa3b | 991 | |
roryhand | 0:e89d7a0bfa3b | 992 | |
roryhand | 0:e89d7a0bfa3b | 993 | |
roryhand | 0:e89d7a0bfa3b | 994 | |
roryhand | 9:dd9cae06b202 | 995 |