old demo that i want to try in mbed studio
Dependencies: mbed SDFileSystem_Copy_of_mbed_version I2S
NotchingDemo.cpp@84:0a259e261532, 2019-10-02 (annotated)
- Committer:
- roryhand
- Date:
- Wed Oct 02 19:16:26 2019 +0000
- Branch:
- LargeFile_Tests
- Revision:
- 84:0a259e261532
- Parent:
- 78:69a0c7a5fbdf
- Child:
- 85:e0c9ba778ae0
WIP - have switched to this branch as I could not get this to work without "blipping" in the later commits
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 | 73:a5ab93214728 | 34 | Ticker NotchUpTick; |
roryhand | 45:0e8e1f2ec5d2 | 35 | |
roryhand | 0:e89d7a0bfa3b | 36 | Ticker TickFadeOut; |
roryhand | 0:e89d7a0bfa3b | 37 | Timer t; |
roryhand | 0:e89d7a0bfa3b | 38 | Timer t2; |
roryhand | 75:8a71e269b890 | 39 | Timer OperationsTimer; |
roryhand | 3:6169aeeaeeb4 | 40 | Timer NotchTimer; |
roryhand | 27:a378f1f937ee | 41 | Timer timer_open; |
roryhand | 0:e89d7a0bfa3b | 42 | |
roryhand | 0:e89d7a0bfa3b | 43 | Serial pc(USBTX, USBRX); // tx, rx //FOR DEBUGGING PROGRAM USING GNU SCREEN |
roryhand | 0:e89d7a0bfa3b | 44 | DigitalOut cs(p8); |
roryhand | 0:e89d7a0bfa3b | 45 | I2S i2s(I2S_TRANSMIT, p5, p6, p7); |
roryhand | 0:e89d7a0bfa3b | 46 | SDFileSystem sd(p11, p12, p13, p8, "sd"); // the new pinout that i am using |
roryhand | 0:e89d7a0bfa3b | 47 | |
roryhand | 65:8b6a4e307941 | 48 | class classFade |
roryhand | 65:8b6a4e307941 | 49 | { |
roryhand | 65:8b6a4e307941 | 50 | public: |
roryhand | 65:8b6a4e307941 | 51 | |
roryhand | 65:8b6a4e307941 | 52 | float powerval; |
roryhand | 65:8b6a4e307941 | 53 | float FadeIteration; |
roryhand | 65:8b6a4e307941 | 54 | float DecayFactor; |
roryhand | 65:8b6a4e307941 | 55 | float Denom; |
roryhand | 65:8b6a4e307941 | 56 | float FadeCoeff; |
roryhand | 65:8b6a4e307941 | 57 | float Natural_Exp; |
roryhand | 65:8b6a4e307941 | 58 | int LengthSecs; |
roryhand | 65:8b6a4e307941 | 59 | int Length; |
roryhand | 67:043fe0b81343 | 60 | void FadeDataInitialise() |
roryhand | 67:043fe0b81343 | 61 | { |
roryhand | 67:043fe0b81343 | 62 | DecayFactor = 1.3; |
roryhand | 67:043fe0b81343 | 63 | FadeIteration = 1; |
roryhand | 67:043fe0b81343 | 64 | //FadeData.Denom = 11025*FadeData.DecayFactor; |
roryhand | 67:043fe0b81343 | 65 | Denom = 11025*DecayFactor; |
roryhand | 67:043fe0b81343 | 66 | Natural_Exp = 2.7183; |
roryhand | 67:043fe0b81343 | 67 | Length = 11025*LengthSecs; |
roryhand | 67:043fe0b81343 | 68 | //FadeData.Natural_Exp = 2.7; |
roryhand | 67:043fe0b81343 | 69 | } |
roryhand | 65:8b6a4e307941 | 70 | //member Functions |
roryhand | 65:8b6a4e307941 | 71 | float FadeOut(void) |
roryhand | 65:8b6a4e307941 | 72 | { |
roryhand | 65:8b6a4e307941 | 73 | powerval = -FadeIteration/Denom; |
roryhand | 65:8b6a4e307941 | 74 | if (FadeIteration >=Length) { |
roryhand | 65:8b6a4e307941 | 75 | FadeCoeff = 0; |
roryhand | 65:8b6a4e307941 | 76 | |
roryhand | 65:8b6a4e307941 | 77 | } else { |
roryhand | 65:8b6a4e307941 | 78 | FadeCoeff = (Length - FadeIteration)/Length; |
roryhand | 65:8b6a4e307941 | 79 | } |
roryhand | 65:8b6a4e307941 | 80 | FadeIteration = FadeIteration + 1; |
roryhand | 65:8b6a4e307941 | 81 | return FadeCoeff; |
roryhand | 65:8b6a4e307941 | 82 | |
roryhand | 65:8b6a4e307941 | 83 | } |
roryhand | 65:8b6a4e307941 | 84 | float FadeIn(void) |
roryhand | 65:8b6a4e307941 | 85 | { |
roryhand | 65:8b6a4e307941 | 86 | powerval = FadeIteration/Denom; |
roryhand | 65:8b6a4e307941 | 87 | if (FadeIteration >=Length) { |
roryhand | 65:8b6a4e307941 | 88 | FadeCoeff = 1; |
roryhand | 65:8b6a4e307941 | 89 | |
roryhand | 65:8b6a4e307941 | 90 | } else { |
roryhand | 65:8b6a4e307941 | 91 | FadeCoeff = FadeIteration/Length; |
roryhand | 65:8b6a4e307941 | 92 | } |
roryhand | 65:8b6a4e307941 | 93 | |
roryhand | 65:8b6a4e307941 | 94 | FadeIteration = FadeIteration + 1; |
roryhand | 65:8b6a4e307941 | 95 | return FadeCoeff; |
roryhand | 65:8b6a4e307941 | 96 | |
roryhand | 65:8b6a4e307941 | 97 | } |
roryhand | 65:8b6a4e307941 | 98 | }; |
roryhand | 65:8b6a4e307941 | 99 | |
roryhand | 65:8b6a4e307941 | 100 | |
roryhand | 67:043fe0b81343 | 101 | //Do these variables have to be global?? Find out - may be better (safer) to make them local. |
roryhand | 67:043fe0b81343 | 102 | classFade NotchFadeIn; |
roryhand | 67:043fe0b81343 | 103 | classFade NotchFadeOut; |
roryhand | 67:043fe0b81343 | 104 | |
roryhand | 67:043fe0b81343 | 105 | |
roryhand | 67:043fe0b81343 | 106 | //Dont require the class below. Turns out I had already made a Structure to hold the same information. |
roryhand | 67:043fe0b81343 | 107 | //If in the futre I need to embed functions then I will switch to using this class |
roryhand | 67:043fe0b81343 | 108 | /* |
roryhand | 67:043fe0b81343 | 109 | class classNotchingValue{ |
roryhand | 67:043fe0b81343 | 110 | public: |
roryhand | 67:043fe0b81343 | 111 | |
roryhand | 67:043fe0b81343 | 112 | int Notch, Previous_Notch; |
roryhand | 67:043fe0b81343 | 113 | int NotchDirection; |
roryhand | 67:043fe0b81343 | 114 | int NotchTransUp; |
roryhand | 67:043fe0b81343 | 115 | classNotchingValue() |
roryhand | 67:043fe0b81343 | 116 | { |
roryhand | 67:043fe0b81343 | 117 | Notch = 1; |
roryhand | 67:043fe0b81343 | 118 | Previous_Notch = 0; |
roryhand | 67:043fe0b81343 | 119 | NotchDirection = 1; |
roryhand | 67:043fe0b81343 | 120 | NotchTransUp = 0; |
roryhand | 67:043fe0b81343 | 121 | } |
roryhand | 67:043fe0b81343 | 122 | |
roryhand | 67:043fe0b81343 | 123 | }; |
roryhand | 67:043fe0b81343 | 124 | |
roryhand | 67:043fe0b81343 | 125 | |
roryhand | 67:043fe0b81343 | 126 | |
roryhand | 67:043fe0b81343 | 127 | classNotchingValue NotchingSet; |
roryhand | 67:043fe0b81343 | 128 | |
roryhand | 67:043fe0b81343 | 129 | */ |
roryhand | 67:043fe0b81343 | 130 | |
roryhand | 1:aac37edee302 | 131 | typedef struct uFMT_STRUCT { |
roryhand | 1:aac37edee302 | 132 | short comp_code; |
roryhand | 1:aac37edee302 | 133 | short num_channels; |
roryhand | 1:aac37edee302 | 134 | unsigned sample_rate; |
roryhand | 1:aac37edee302 | 135 | unsigned avg_Bps; |
roryhand | 1:aac37edee302 | 136 | short block_align; |
roryhand | 1:aac37edee302 | 137 | short sig_bps; |
roryhand | 0:e89d7a0bfa3b | 138 | } FMT_STRUCT; |
roryhand | 0:e89d7a0bfa3b | 139 | |
roryhand | 1:aac37edee302 | 140 | typedef struct uNotch_STRUCT { |
roryhand | 1:aac37edee302 | 141 | short Notch; |
roryhand | 1:aac37edee302 | 142 | short NotchTransUp; |
roryhand | 1:aac37edee302 | 143 | short NotchTransDown; |
roryhand | 1:aac37edee302 | 144 | short NotchDirection; |
roryhand | 1:aac37edee302 | 145 | } Notch_STRUCT; |
roryhand | 1:aac37edee302 | 146 | |
roryhand | 67:043fe0b81343 | 147 | Notch_STRUCT NotchingSet; |
roryhand | 67:043fe0b81343 | 148 | |
roryhand | 67:043fe0b81343 | 149 | |
roryhand | 0:e89d7a0bfa3b | 150 | typedef struct uDATA_STRUCT { |
roryhand | 1:aac37edee302 | 151 | unsigned subchunk2_ID; |
roryhand | 1:aac37edee302 | 152 | unsigned subchunk2_size; |
roryhand | 1:aac37edee302 | 153 | char * data_buf; |
roryhand | 1:aac37edee302 | 154 | } DATA_STRUCT; |
roryhand | 0:e89d7a0bfa3b | 155 | |
roryhand | 1:aac37edee302 | 156 | typedef struct uWAV_FILE_STRUCT { |
roryhand | 1:aac37edee302 | 157 | FILE *WavFile; |
roryhand | 1:aac37edee302 | 158 | int id_number; |
roryhand | 1:aac37edee302 | 159 | char *slice_buf; |
roryhand | 1:aac37edee302 | 160 | int num_slices; |
roryhand | 1:aac37edee302 | 161 | FMT_STRUCT FileFormat; |
roryhand | 1:aac37edee302 | 162 | DATA_STRUCT FileData; |
roryhand | 0:e89d7a0bfa3b | 163 | } WAV_FILE_STRUCT; |
roryhand | 0:e89d7a0bfa3b | 164 | |
roryhand | 0:e89d7a0bfa3b | 165 | /*typedef struct uWAV_FILE_STRUCT{ |
roryhand | 1:aac37edee302 | 166 | FILE* WavFile; |
roryhand | 1:aac37edee302 | 167 | |
roryhand | 1:aac37edee302 | 168 | |
roryhand | 0:e89d7a0bfa3b | 169 | }WAV_FILE_STRUCT;*/ |
roryhand | 59:8e7c25a915a0 | 170 | |
roryhand | 59:8e7c25a915a0 | 171 | |
roryhand | 59:8e7c25a915a0 | 172 | |
roryhand | 59:8e7c25a915a0 | 173 | |
roryhand | 59:8e7c25a915a0 | 174 | |
roryhand | 59:8e7c25a915a0 | 175 | class classSoundFile |
roryhand | 59:8e7c25a915a0 | 176 | { |
roryhand | 59:8e7c25a915a0 | 177 | public: |
roryhand | 59:8e7c25a915a0 | 178 | |
roryhand | 59:8e7c25a915a0 | 179 | //add a class constructor at some point in the future (perform tests in visual studio) |
roryhand | 59:8e7c25a915a0 | 180 | WAV_FILE_STRUCT FileInfo; |
roryhand | 59:8e7c25a915a0 | 181 | short * data_sptr; |
roryhand | 59:8e7c25a915a0 | 182 | string file_location; |
roryhand | 59:8e7c25a915a0 | 183 | //classSoundFile(string filename);//this is the constructor |
roryhand | 59:8e7c25a915a0 | 184 | //string filename; |
roryhand | 59:8e7c25a915a0 | 185 | }; |
roryhand | 58:a174e7a8f5f2 | 186 | class classPositionIndicators |
roryhand | 57:0c76b15cabaf | 187 | { |
roryhand | 57:0c76b15cabaf | 188 | public: |
roryhand | 57:0c76b15cabaf | 189 | int notch1_indicator, notch2_indicator, notch3_indicator, notch4_indicator; |
roryhand | 57:0c76b15cabaf | 190 | int notch5_indicator, notch6_indicator, notch7_indicator, notch8_indicator; |
roryhand | 57:0c76b15cabaf | 191 | int notch1_start_pt, notch2_start_pt, notch3_start_pt, notch4_start_pt; |
roryhand | 57:0c76b15cabaf | 192 | int notch5_start_pt, notch6_start_pt, notch7_start_pt, notch8_start_pt; |
roryhand | 63:a8c1971d3d42 | 193 | int N1N2_start_pt, N2N3_start_pt, N3N4_start_pt, N4N5_start_pt, N5N6_start_pt; |
roryhand | 63:a8c1971d3d42 | 194 | int N6N7_start_pt, N7N8_start_pt, N8N7_start_pt, N7N6_start_pt, N6N5_start_pt; |
roryhand | 63:a8c1971d3d42 | 195 | int N5N4_start_pt, N4N3_start_pt, N3N2_start_pt, N2N1_start_pt; |
roryhand | 67:043fe0b81343 | 196 | |
roryhand | 61:212d2db45c56 | 197 | int notch_start_pts [9]; |
roryhand | 61:212d2db45c56 | 198 | int notch_position_indicators[9]; |
roryhand | 61:212d2db45c56 | 199 | int notch_transitions_start_pts[15]; |
roryhand | 61:212d2db45c56 | 200 | int notch_transitions_position_indicators[15]; |
roryhand | 61:212d2db45c56 | 201 | int auxiliary_start_pts[5]; |
roryhand | 61:212d2db45c56 | 202 | int auxiliary_position_indicators[5]; |
roryhand | 58:a174e7a8f5f2 | 203 | classPositionIndicators() |
roryhand | 57:0c76b15cabaf | 204 | { |
roryhand | 57:0c76b15cabaf | 205 | notch1_start_pt = 44; |
roryhand | 57:0c76b15cabaf | 206 | notch2_start_pt = 220884+44; |
roryhand | 57:0c76b15cabaf | 207 | notch3_start_pt = notch2_start_pt+217698; |
roryhand | 57:0c76b15cabaf | 208 | notch4_start_pt = notch3_start_pt + 193060; |
roryhand | 57:0c76b15cabaf | 209 | notch5_start_pt = notch4_start_pt + 92010; |
roryhand | 57:0c76b15cabaf | 210 | notch6_start_pt = notch5_start_pt + 216642; |
roryhand | 57:0c76b15cabaf | 211 | notch7_start_pt = notch6_start_pt + 250316; |
roryhand | 61:212d2db45c56 | 212 | notch8_start_pt = notch7_start_pt + 150152; |
roryhand | 57:0c76b15cabaf | 213 | notch1_indicator = notch1_start_pt; |
roryhand | 57:0c76b15cabaf | 214 | notch2_indicator = notch2_start_pt; |
roryhand | 57:0c76b15cabaf | 215 | notch3_indicator = notch3_start_pt; |
roryhand | 57:0c76b15cabaf | 216 | notch4_indicator = notch4_start_pt; |
roryhand | 57:0c76b15cabaf | 217 | notch5_indicator = notch5_start_pt; |
roryhand | 57:0c76b15cabaf | 218 | notch6_indicator = notch6_start_pt; |
roryhand | 57:0c76b15cabaf | 219 | notch7_indicator = notch7_start_pt; |
roryhand | 57:0c76b15cabaf | 220 | notch8_indicator = notch8_start_pt; |
roryhand | 61:212d2db45c56 | 221 | notch_start_pts[1] = notch1_start_pt; |
roryhand | 61:212d2db45c56 | 222 | notch_start_pts[2] = notch2_start_pt; |
roryhand | 61:212d2db45c56 | 223 | notch_start_pts[3] = notch3_start_pt; |
roryhand | 61:212d2db45c56 | 224 | notch_start_pts[4] = notch4_start_pt; |
roryhand | 61:212d2db45c56 | 225 | notch_start_pts[5] = notch5_start_pt; |
roryhand | 61:212d2db45c56 | 226 | notch_start_pts[6] = notch6_start_pt; |
roryhand | 61:212d2db45c56 | 227 | notch_start_pts[7] = notch7_start_pt; |
roryhand | 61:212d2db45c56 | 228 | notch_start_pts[8] = notch8_start_pt; |
roryhand | 61:212d2db45c56 | 229 | notch_position_indicators[1] = notch1_indicator; |
roryhand | 61:212d2db45c56 | 230 | notch_position_indicators[2] = notch2_indicator; |
roryhand | 61:212d2db45c56 | 231 | notch_position_indicators[3] = notch3_indicator; |
roryhand | 61:212d2db45c56 | 232 | notch_position_indicators[4] = notch4_indicator; |
roryhand | 61:212d2db45c56 | 233 | notch_position_indicators[5] = notch5_indicator; |
roryhand | 61:212d2db45c56 | 234 | notch_position_indicators[6] = notch6_indicator; |
roryhand | 61:212d2db45c56 | 235 | notch_position_indicators[7] = notch7_indicator; |
roryhand | 61:212d2db45c56 | 236 | notch_position_indicators[8] = notch8_indicator; |
roryhand | 67:043fe0b81343 | 237 | |
roryhand | 63:a8c1971d3d42 | 238 | N1N2_start_pt = 44; |
roryhand | 63:a8c1971d3d42 | 239 | N2N3_start_pt = N1N2_start_pt + 73220; |
roryhand | 63:a8c1971d3d42 | 240 | N3N4_start_pt = N2N3_start_pt + 78164; |
roryhand | 63:a8c1971d3d42 | 241 | N4N5_start_pt = N3N4_start_pt + 59432; |
roryhand | 63:a8c1971d3d42 | 242 | N5N6_start_pt = N4N5_start_pt + 64984; |
roryhand | 63:a8c1971d3d42 | 243 | N6N7_start_pt = N5N6_start_pt + 59924; |
roryhand | 63:a8c1971d3d42 | 244 | N7N8_start_pt = N6N7_start_pt + 97874; |
roryhand | 63:a8c1971d3d42 | 245 | N8N7_start_pt = N7N8_start_pt + 63992; |
roryhand | 63:a8c1971d3d42 | 246 | N7N6_start_pt = N8N7_start_pt + 44506; |
roryhand | 63:a8c1971d3d42 | 247 | N6N5_start_pt = N7N6_start_pt + 55052; |
roryhand | 63:a8c1971d3d42 | 248 | N5N4_start_pt = N6N5_start_pt + 37038; |
roryhand | 63:a8c1971d3d42 | 249 | N4N3_start_pt = N5N4_start_pt + 49692; |
roryhand | 63:a8c1971d3d42 | 250 | N3N2_start_pt = N4N3_start_pt + 44100; |
roryhand | 63:a8c1971d3d42 | 251 | N2N1_start_pt = N3N2_start_pt + 58346; |
roryhand | 67:043fe0b81343 | 252 | |
roryhand | 67:043fe0b81343 | 253 | |
roryhand | 63:a8c1971d3d42 | 254 | notch_transitions_start_pts[1] = N1N2_start_pt; |
roryhand | 63:a8c1971d3d42 | 255 | notch_transitions_start_pts[2] = N2N3_start_pt; |
roryhand | 63:a8c1971d3d42 | 256 | notch_transitions_start_pts[3] = N3N4_start_pt; |
roryhand | 63:a8c1971d3d42 | 257 | notch_transitions_start_pts[4] = N4N5_start_pt; |
roryhand | 63:a8c1971d3d42 | 258 | notch_transitions_start_pts[5] = N5N6_start_pt; |
roryhand | 63:a8c1971d3d42 | 259 | notch_transitions_start_pts[6] = N6N7_start_pt; |
roryhand | 63:a8c1971d3d42 | 260 | notch_transitions_start_pts[7] = N7N8_start_pt; |
roryhand | 63:a8c1971d3d42 | 261 | notch_transitions_start_pts[8] = N8N7_start_pt; |
roryhand | 63:a8c1971d3d42 | 262 | notch_transitions_start_pts[9] = N7N6_start_pt; |
roryhand | 63:a8c1971d3d42 | 263 | notch_transitions_start_pts[10] = N6N5_start_pt; |
roryhand | 63:a8c1971d3d42 | 264 | notch_transitions_start_pts[11] = N5N4_start_pt; |
roryhand | 63:a8c1971d3d42 | 265 | notch_transitions_start_pts[12] = N4N3_start_pt; |
roryhand | 63:a8c1971d3d42 | 266 | notch_transitions_start_pts[13] = N3N2_start_pt; |
roryhand | 63:a8c1971d3d42 | 267 | notch_transitions_start_pts[14] = N2N1_start_pt; |
roryhand | 67:043fe0b81343 | 268 | |
roryhand | 67:043fe0b81343 | 269 | |
roryhand | 63:a8c1971d3d42 | 270 | notch_transitions_position_indicators[1] = N1N2_start_pt; |
roryhand | 63:a8c1971d3d42 | 271 | notch_transitions_position_indicators[2] = N2N3_start_pt; |
roryhand | 63:a8c1971d3d42 | 272 | notch_transitions_position_indicators[3] = N3N4_start_pt; |
roryhand | 63:a8c1971d3d42 | 273 | notch_transitions_position_indicators[4] = N4N5_start_pt; |
roryhand | 63:a8c1971d3d42 | 274 | notch_transitions_position_indicators[5] = N5N6_start_pt; |
roryhand | 63:a8c1971d3d42 | 275 | notch_transitions_position_indicators[6] = N6N7_start_pt; |
roryhand | 63:a8c1971d3d42 | 276 | notch_transitions_position_indicators[7] = N7N8_start_pt; |
roryhand | 63:a8c1971d3d42 | 277 | notch_transitions_position_indicators[8] = N8N7_start_pt; |
roryhand | 63:a8c1971d3d42 | 278 | notch_transitions_position_indicators[9] = N7N6_start_pt; |
roryhand | 63:a8c1971d3d42 | 279 | notch_transitions_position_indicators[10] = N6N5_start_pt; |
roryhand | 63:a8c1971d3d42 | 280 | notch_transitions_position_indicators[11] = N5N4_start_pt; |
roryhand | 63:a8c1971d3d42 | 281 | notch_transitions_position_indicators[12] = N4N3_start_pt; |
roryhand | 63:a8c1971d3d42 | 282 | notch_transitions_position_indicators[13] = N3N2_start_pt; |
roryhand | 63:a8c1971d3d42 | 283 | notch_transitions_position_indicators[14] = N2N1_start_pt; |
roryhand | 57:0c76b15cabaf | 284 | } |
roryhand | 57:0c76b15cabaf | 285 | }; |
roryhand | 57:0c76b15cabaf | 286 | |
roryhand | 73:a5ab93214728 | 287 | int TransitionFlag; |
roryhand | 66:edf370edd21c | 288 | void NotchUpIsr() |
roryhand | 66:edf370edd21c | 289 | { |
roryhand | 66:edf370edd21c | 290 | if(1 <= NotchingSet.Notch < 8) { |
roryhand | 66:edf370edd21c | 291 | |
roryhand | 66:edf370edd21c | 292 | NotchingSet.Notch = NotchingSet.Notch + 1; |
roryhand | 66:edf370edd21c | 293 | NotchingSet.NotchTransUp = NotchingSet.Notch + 7; |
roryhand | 66:edf370edd21c | 294 | NotchingSet.NotchDirection = 1; |
roryhand | 67:043fe0b81343 | 295 | NotchFadeIn.FadeDataInitialise(); |
roryhand | 67:043fe0b81343 | 296 | NotchFadeOut.FadeDataInitialise(); |
roryhand | 73:a5ab93214728 | 297 | TransitionFlag = 1; |
roryhand | 74:e71a7815f63d | 298 | //printf("We are in the NotchUpIsr() section \n\r"); |
roryhand | 67:043fe0b81343 | 299 | //NotchFadeOut.FadeDataInitialise; |
roryhand | 66:edf370edd21c | 300 | } |
roryhand | 66:edf370edd21c | 301 | } |
roryhand | 66:edf370edd21c | 302 | |
roryhand | 66:edf370edd21c | 303 | void NotchDownIsr() |
roryhand | 66:edf370edd21c | 304 | { |
roryhand | 66:edf370edd21c | 305 | if(1 < NotchingSet.Notch <= 8) { |
roryhand | 66:edf370edd21c | 306 | NotchingSet.Notch = NotchingSet.Notch - 1; |
roryhand | 67:043fe0b81343 | 307 | NotchingSet.NotchTransDown = NotchingSet.Notch + 15; |
roryhand | 66:edf370edd21c | 308 | NotchingSet.NotchDirection = 0; |
roryhand | 67:043fe0b81343 | 309 | NotchFadeIn.FadeDataInitialise(); |
roryhand | 67:043fe0b81343 | 310 | NotchFadeOut.FadeDataInitialise(); |
roryhand | 74:e71a7815f63d | 311 | TransitionFlag = 1; |
roryhand | 66:edf370edd21c | 312 | } |
roryhand | 66:edf370edd21c | 313 | } |
roryhand | 73:a5ab93214728 | 314 | short * data_sptr1; |
roryhand | 73:a5ab93214728 | 315 | short * data_sptr2; |
roryhand | 73:a5ab93214728 | 316 | short * data_sptr3; |
roryhand | 69:df10ee3ad523 | 317 | char *slice_buf1; |
roryhand | 69:df10ee3ad523 | 318 | char *slice_buf2; |
roryhand | 69:df10ee3ad523 | 319 | char *slice_buf3; |
roryhand | 67:043fe0b81343 | 320 | |
roryhand | 54:606a83fff291 | 321 | int OneOff = 0; |
roryhand | 38:3b4c05af5f36 | 322 | int notch_flag = 0; |
roryhand | 0:e89d7a0bfa3b | 323 | int i = 0; |
roryhand | 0:e89d7a0bfa3b | 324 | int h = 0; |
roryhand | 0:e89d7a0bfa3b | 325 | short bufflen = 1; |
roryhand | 0:e89d7a0bfa3b | 326 | int buffer[1]; |
roryhand | 1:aac37edee302 | 327 | int AudioFormat, NumChannels, SampleRate, BitsPerSample ; |
roryhand | 0:e89d7a0bfa3b | 328 | char *slice_buf; |
roryhand | 0:e89d7a0bfa3b | 329 | short *data_sptr; |
roryhand | 0:e89d7a0bfa3b | 330 | short *data_sptr_horn; |
roryhand | 0:e89d7a0bfa3b | 331 | short *data_sptr_IdleN2; |
roryhand | 0:e89d7a0bfa3b | 332 | short * data_sptr_bell; |
roryhand | 0:e89d7a0bfa3b | 333 | short * data_sptr_N2; |
roryhand | 0:e89d7a0bfa3b | 334 | short * data_sptr_Flange; |
roryhand | 0:e89d7a0bfa3b | 335 | unsigned char *data_bptr; |
roryhand | 0:e89d7a0bfa3b | 336 | int *data_wptr; |
roryhand | 0:e89d7a0bfa3b | 337 | unsigned channel; |
roryhand | 45:0e8e1f2ec5d2 | 338 | long slice, slice1, slice2, slice3, num_slices; |
roryhand | 0:e89d7a0bfa3b | 339 | int verbosity = 0; |
roryhand | 0:e89d7a0bfa3b | 340 | int verbosity2 = 0; |
roryhand | 0:e89d7a0bfa3b | 341 | int verbosity3 = 0; |
roryhand | 0:e89d7a0bfa3b | 342 | int verbosity4 = 0; |
roryhand | 0:e89d7a0bfa3b | 343 | int verbosity5 = 0; |
roryhand | 0:e89d7a0bfa3b | 344 | int interrupt_condition = 1; |
roryhand | 0:e89d7a0bfa3b | 345 | int sampling_freq = 11025; |
roryhand | 0:e89d7a0bfa3b | 346 | const int BufferLen = 2000; |
roryhand | 0:e89d7a0bfa3b | 347 | short Buffer1[BufferLen]; |
roryhand | 0:e89d7a0bfa3b | 348 | short Buffer2[BufferLen]; |
roryhand | 0:e89d7a0bfa3b | 349 | short place_hold1 = 0; |
roryhand | 0:e89d7a0bfa3b | 350 | short place_hold2 = 0; |
roryhand | 0:e89d7a0bfa3b | 351 | |
roryhand | 3:6169aeeaeeb4 | 352 | |
roryhand | 3:6169aeeaeeb4 | 353 | string FOLDER; |
roryhand | 3:6169aeeaeeb4 | 354 | string RootFolder = "/sd/mydir/SoundDecoder/"; |
roryhand | 3:6169aeeaeeb4 | 355 | string filename[25]; |
roryhand | 3:6169aeeaeeb4 | 356 | classSoundFile Sound[22]; |
roryhand | 3:6169aeeaeeb4 | 357 | |
roryhand | 0:e89d7a0bfa3b | 358 | volatile int flag1 = 1; |
roryhand | 0:e89d7a0bfa3b | 359 | volatile int flag2 = 0; |
roryhand | 0:e89d7a0bfa3b | 360 | volatile int flag3 = 1; |
roryhand | 0:e89d7a0bfa3b | 361 | volatile int flag4 = 0; |
roryhand | 0:e89d7a0bfa3b | 362 | int FLAGBUFF1 = 0; |
roryhand | 0:e89d7a0bfa3b | 363 | int FLAGBUFF2 = 0; |
roryhand | 0:e89d7a0bfa3b | 364 | int BellFlag = 0; |
roryhand | 0:e89d7a0bfa3b | 365 | int BellFlag2 = 0; |
roryhand | 0:e89d7a0bfa3b | 366 | int FadeFlag = 0; |
roryhand | 54:606a83fff291 | 367 | int BlockFlag = 0; |
roryhand | 32:6ee488c97dcc | 368 | int FileSwitchFlag = 0; |
roryhand | 0:e89d7a0bfa3b | 369 | |
roryhand | 0:e89d7a0bfa3b | 370 | |
roryhand | 0:e89d7a0bfa3b | 371 | short value[1]; |
roryhand | 59:8e7c25a915a0 | 372 | |
roryhand | 0:e89d7a0bfa3b | 373 | //long long slice_value; |
roryhand | 0:e89d7a0bfa3b | 374 | int slice_value[1]; |
roryhand | 0:e89d7a0bfa3b | 375 | |
roryhand | 0:e89d7a0bfa3b | 376 | |
roryhand | 45:0e8e1f2ec5d2 | 377 | FILE *wavfile1; |
roryhand | 45:0e8e1f2ec5d2 | 378 | FILE *wavfile2; |
roryhand | 45:0e8e1f2ec5d2 | 379 | FILE *wavfile3; |
roryhand | 45:0e8e1f2ec5d2 | 380 | |
roryhand | 45:0e8e1f2ec5d2 | 381 | classSoundFile Sound1; |
roryhand | 45:0e8e1f2ec5d2 | 382 | classSoundFile Sound2; |
roryhand | 45:0e8e1f2ec5d2 | 383 | classSoundFile Sound3; |
roryhand | 45:0e8e1f2ec5d2 | 384 | |
roryhand | 0:e89d7a0bfa3b | 385 | |
roryhand | 0:e89d7a0bfa3b | 386 | void isr() |
roryhand | 0:e89d7a0bfa3b | 387 | { |
roryhand | 54:606a83fff291 | 388 | //timer_interrupt.start(); |
roryhand | 1:aac37edee302 | 389 | if(flag1 == 0) { |
roryhand | 0:e89d7a0bfa3b | 390 | value[0] = Buffer1[place_hold1]>>4; |
roryhand | 0:e89d7a0bfa3b | 391 | i2s.write(value,1);//Send next PWM value to amp |
roryhand | 0:e89d7a0bfa3b | 392 | place_hold1 = place_hold1 + 1; |
roryhand | 1:aac37edee302 | 393 | if( (place_hold1 >= BufferLen)) { |
roryhand | 0:e89d7a0bfa3b | 394 | led2 = !led2; |
roryhand | 0:e89d7a0bfa3b | 395 | place_hold1 = 0; |
roryhand | 0:e89d7a0bfa3b | 396 | place_hold2 = 0; |
roryhand | 0:e89d7a0bfa3b | 397 | flag1 = 1; |
roryhand | 0:e89d7a0bfa3b | 398 | flag2 = 0; |
roryhand | 1:aac37edee302 | 399 | } |
roryhand | 1:aac37edee302 | 400 | } else if(flag2 == 0) { |
roryhand | 0:e89d7a0bfa3b | 401 | value[0] = Buffer2[place_hold2]>>4; |
roryhand | 0:e89d7a0bfa3b | 402 | i2s.write(value,1);//Send next PWM value to amp |
roryhand | 0:e89d7a0bfa3b | 403 | place_hold2 = place_hold2 + 1; |
roryhand | 1:aac37edee302 | 404 | if( (place_hold2 >= BufferLen) ) { |
roryhand | 0:e89d7a0bfa3b | 405 | led2 = !led2; |
roryhand | 0:e89d7a0bfa3b | 406 | place_hold1 = 0; |
roryhand | 0:e89d7a0bfa3b | 407 | place_hold2 = 0; |
roryhand | 0:e89d7a0bfa3b | 408 | flag1 = 0; |
roryhand | 1:aac37edee302 | 409 | flag2 = 1; |
roryhand | 0:e89d7a0bfa3b | 410 | FLAGBUFF2 = 0; |
roryhand | 1:aac37edee302 | 411 | } |
roryhand | 0:e89d7a0bfa3b | 412 | } |
roryhand | 54:606a83fff291 | 413 | |
roryhand | 54:606a83fff291 | 414 | //timer_interrupt.stop(); |
roryhand | 54:606a83fff291 | 415 | |
roryhand | 0:e89d7a0bfa3b | 416 | } |
roryhand | 1:aac37edee302 | 417 | |
roryhand | 38:3b4c05af5f36 | 418 | |
roryhand | 38:3b4c05af5f36 | 419 | |
roryhand | 38:3b4c05af5f36 | 420 | |
roryhand | 38:3b4c05af5f36 | 421 | |
roryhand | 0:e89d7a0bfa3b | 422 | |
roryhand | 59:8e7c25a915a0 | 423 | |
roryhand | 59:8e7c25a915a0 | 424 | |
roryhand | 59:8e7c25a915a0 | 425 | |
roryhand | 59:8e7c25a915a0 | 426 | |
roryhand | 59:8e7c25a915a0 | 427 | |
roryhand | 3:6169aeeaeeb4 | 428 | |
roryhand | 3:6169aeeaeeb4 | 429 | |
roryhand | 3:6169aeeaeeb4 | 430 | |
roryhand | 3:6169aeeaeeb4 | 431 | |
roryhand | 3:6169aeeaeeb4 | 432 | |
roryhand | 3:6169aeeaeeb4 | 433 | //function prototypes |
roryhand | 67:043fe0b81343 | 434 | //classFade FadeDataInitialise(classFade FadeData); |
roryhand | 45:0e8e1f2ec5d2 | 435 | classSoundFile ReadFileInfo(classSoundFile Sound, FILE * wav_file); |
roryhand | 3:6169aeeaeeb4 | 436 | classSoundFile LoadFileStream(classSoundFile FileInfo, string filename); |
roryhand | 3:6169aeeaeeb4 | 437 | void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo); |
roryhand | 32:6ee488c97dcc | 438 | void Play_WaveFileDual(FILE * my_wav, WAV_FILE_STRUCT FileInfo); |
roryhand | 77:e93c944ed30f | 439 | void Play_WaveFileLoop(classSoundFile Sound1, classSoundFile Sound2, FILE* wavfile1, FILE* wavfile2,classPositionIndicators Positions); |
roryhand | 0:e89d7a0bfa3b | 440 | |
roryhand | 1:aac37edee302 | 441 | int main() |
roryhand | 1:aac37edee302 | 442 | { |
roryhand | 44:a9e84d333a6a | 443 | |
roryhand | 0:e89d7a0bfa3b | 444 | NotchUp.mode(PullUp); |
roryhand | 38:3b4c05af5f36 | 445 | NotchDown.mode(PullUp); |
roryhand | 0:e89d7a0bfa3b | 446 | |
roryhand | 0:e89d7a0bfa3b | 447 | pc.printf("Beginning of program\n"); |
roryhand | 32:6ee488c97dcc | 448 | |
roryhand | 13:8e93396a27c5 | 449 | |
roryhand | 13:8e93396a27c5 | 450 | |
roryhand | 4:55fbbb049bae | 451 | |
roryhand | 25:5336e1cf38d6 | 452 | printf("Do we even get to this stupid bloody point\n\r"); |
roryhand | 0:e89d7a0bfa3b | 453 | //Populate our class instances with some data (is there an implicit way to do this?) |
roryhand | 28:6b2353fad12d | 454 | |
roryhand | 1:aac37edee302 | 455 | |
roryhand | 3:6169aeeaeeb4 | 456 | printf("hello\n\r"); |
roryhand | 0:e89d7a0bfa3b | 457 | //Set up the wolfson Audio Codec board |
roryhand | 74:e71a7815f63d | 458 | |
roryhand | 74:e71a7815f63d | 459 | |
roryhand | 0:e89d7a0bfa3b | 460 | wm8731_Config_setup(); |
roryhand | 0:e89d7a0bfa3b | 461 | //i2s audio data transfer code?? |
roryhand | 0:e89d7a0bfa3b | 462 | i2s.stereomono(I2S_STEREO); |
roryhand | 0:e89d7a0bfa3b | 463 | i2s.masterslave(I2S_MASTER); |
roryhand | 0:e89d7a0bfa3b | 464 | led3 = 1; |
roryhand | 0:e89d7a0bfa3b | 465 | led2 = 1; |
roryhand | 45:0e8e1f2ec5d2 | 466 | printf("Hello i2s has started!"); |
roryhand | 30:4a8e80b243c4 | 467 | i2s.start(); |
roryhand | 0:e89d7a0bfa3b | 468 | sampletick.attach(&isr,1.0/sampling_freq); //1/16000 |
roryhand | 73:a5ab93214728 | 469 | NotchUpTick.attach(&NotchUpIsr,10.0); |
roryhand | 67:043fe0b81343 | 470 | |
roryhand | 74:e71a7815f63d | 471 | |
roryhand | 74:e71a7815f63d | 472 | |
roryhand | 67:043fe0b81343 | 473 | NotchFadeIn.LengthSecs = 2; |
roryhand | 67:043fe0b81343 | 474 | NotchFadeOut.LengthSecs = 2; |
roryhand | 67:043fe0b81343 | 475 | |
roryhand | 67:043fe0b81343 | 476 | NotchFadeIn.FadeDataInitialise(); |
roryhand | 67:043fe0b81343 | 477 | NotchFadeOut.FadeDataInitialise(); |
roryhand | 67:043fe0b81343 | 478 | |
roryhand | 74:e71a7815f63d | 479 | |
roryhand | 58:a174e7a8f5f2 | 480 | classPositionIndicators Positions; |
roryhand | 74:e71a7815f63d | 481 | slice1 = Positions.notch_start_pts[1]; |
roryhand | 74:e71a7815f63d | 482 | |
roryhand | 74:e71a7815f63d | 483 | |
roryhand | 73:a5ab93214728 | 484 | |
roryhand | 73:a5ab93214728 | 485 | TransitionFlag = 0; |
roryhand | 73:a5ab93214728 | 486 | |
roryhand | 60:36df2997de3d | 487 | FILE* wavfile1 = fopen("/sd/mydir/SoundDecoder_second/All_eight_notches.wav","rb"); |
roryhand | 74:e71a7815f63d | 488 | FILE* wavfile2 = fopen("/sd/mydir/SoundDecoder_second/All_14_Notch_Transitions.wav","rb"); |
roryhand | 74:e71a7815f63d | 489 | |
roryhand | 60:36df2997de3d | 490 | //FILE* wavfile1 = fopen("/sd/mydir/SoundDecoder_second/01.wav","rb"); |
roryhand | 58:a174e7a8f5f2 | 491 | classSoundFile Sound1; |
roryhand | 73:a5ab93214728 | 492 | classSoundFile Sound2; |
roryhand | 73:a5ab93214728 | 493 | Sound2 = ReadFileInfo(Sound2, wavfile2); |
roryhand | 58:a174e7a8f5f2 | 494 | Sound1 = ReadFileInfo(Sound1, wavfile1); |
roryhand | 73:a5ab93214728 | 495 | NotchingSet.Notch = 1; |
roryhand | 77:e93c944ed30f | 496 | //Positions.notch_position_indicators[1] = 44; |
roryhand | 73:a5ab93214728 | 497 | fseek(wavfile1,Positions.notch_start_pts[1],SEEK_SET); |
roryhand | 73:a5ab93214728 | 498 | fseek(wavfile2,Positions.notch_transitions_start_pts[1],SEEK_SET); |
roryhand | 20:9cc7d825c07b | 499 | printf("about to play wav file\n\r"); |
roryhand | 77:e93c944ed30f | 500 | Play_WaveFileLoop(Sound1,Sound2, wavfile1,wavfile2, Positions); |
roryhand | 20:9cc7d825c07b | 501 | printf("finished playing Wav file\n\r"); |
roryhand | 54:606a83fff291 | 502 | |
roryhand | 54:606a83fff291 | 503 | |
roryhand | 31:0f8c3adf09c3 | 504 | timer_open.reset(); |
roryhand | 31:0f8c3adf09c3 | 505 | timer_open.start(); |
roryhand | 45:0e8e1f2ec5d2 | 506 | fclose(wavfile1); |
roryhand | 31:0f8c3adf09c3 | 507 | timer_open.stop(); |
roryhand | 31:0f8c3adf09c3 | 508 | printf("It took %d useconds to close file\n\r",timer_open.read_us()); |
roryhand | 54:606a83fff291 | 509 | |
roryhand | 54:606a83fff291 | 510 | |
roryhand | 54:606a83fff291 | 511 | |
roryhand | 54:606a83fff291 | 512 | |
roryhand | 9:dd9cae06b202 | 513 | /************************************PLAY WAV FILE LOOP*******************/ |
roryhand | 9:dd9cae06b202 | 514 | /************************************END OF PLAY WAV FILE LOOP*************/ |
roryhand | 13:8e93396a27c5 | 515 | |
roryhand | 13:8e93396a27c5 | 516 | |
roryhand | 1:aac37edee302 | 517 | i2s.stop(); |
roryhand | 74:e71a7815f63d | 518 | |
roryhand | 0:e89d7a0bfa3b | 519 | |
roryhand | 0:e89d7a0bfa3b | 520 | } |
roryhand | 0:e89d7a0bfa3b | 521 | |
roryhand | 0:e89d7a0bfa3b | 522 | |
roryhand | 3:6169aeeaeeb4 | 523 | |
roryhand | 3:6169aeeaeeb4 | 524 | |
roryhand | 3:6169aeeaeeb4 | 525 | |
roryhand | 3:6169aeeaeeb4 | 526 | |
roryhand | 45:0e8e1f2ec5d2 | 527 | classSoundFile ReadFileInfo(classSoundFile Sound, FILE * wav_file) |
roryhand | 0:e89d7a0bfa3b | 528 | { |
roryhand | 0:e89d7a0bfa3b | 529 | fseek(wav_file,20,SEEK_SET); |
roryhand | 22:706e86dc0d45 | 530 | printf("We have just seeked through this file\n\r"); |
roryhand | 45:0e8e1f2ec5d2 | 531 | fread(&Sound.FileInfo.FileFormat,sizeof(Sound.FileInfo.FileFormat),1,wav_file); |
roryhand | 1:aac37edee302 | 532 | //printf("wav_format.sample_rate: %d\n\r",FileInfo.FileFormat.sample_rate); |
roryhand | 1:aac37edee302 | 533 | |
roryhand | 45:0e8e1f2ec5d2 | 534 | fread(&Sound.FileInfo.FileData,sizeof(Sound.FileInfo.FileData),1,wav_file); |
roryhand | 55:5a441d3b0d57 | 535 | printf("wav_data.subchunk2_size: %d\n\r",Sound.FileInfo.FileData.subchunk2_size); |
roryhand | 45:0e8e1f2ec5d2 | 536 | Sound.FileInfo.slice_buf = ( char *)malloc(Sound.FileInfo.FileFormat.block_align); |
roryhand | 59:8e7c25a915a0 | 537 | printf("Wav File Block Align (number of bytes per sample!!: %d\n\r", Sound.FileInfo.FileFormat.block_align); |
roryhand | 45:0e8e1f2ec5d2 | 538 | fread(Sound.FileInfo.slice_buf,Sound.FileInfo.FileFormat.block_align,1,wav_file); //This isnt actually required, its just a test |
roryhand | 45:0e8e1f2ec5d2 | 539 | Sound.FileInfo.num_slices = Sound.FileInfo.FileData.subchunk2_size/Sound.FileInfo.FileFormat.block_align; |
roryhand | 1:aac37edee302 | 540 | //printf("Number of Slices: %d\n\r",FileInfo.num_slices); |
roryhand | 45:0e8e1f2ec5d2 | 541 | return Sound; |
roryhand | 0:e89d7a0bfa3b | 542 | } |
roryhand | 1:aac37edee302 | 543 | |
roryhand | 1:aac37edee302 | 544 | |
roryhand | 64:6061ffe25985 | 545 | //Function to initialise Data for classFade objects. Perhaps move this into a constructor for the class? (class still to be added) |
roryhand | 67:043fe0b81343 | 546 | /* |
roryhand | 64:6061ffe25985 | 547 | classFade FadeDataInitialise(classFade FadeData) |
roryhand | 64:6061ffe25985 | 548 | { |
roryhand | 64:6061ffe25985 | 549 | FadeData.DecayFactor = 1.3; |
roryhand | 64:6061ffe25985 | 550 | FadeData.FadeIteration = 1; |
roryhand | 64:6061ffe25985 | 551 | //FadeData.Denom = 11025*FadeData.DecayFactor; |
roryhand | 64:6061ffe25985 | 552 | FadeData.Denom = 11025*FadeData.DecayFactor; |
roryhand | 64:6061ffe25985 | 553 | FadeData.Natural_Exp = 2.7183; |
roryhand | 64:6061ffe25985 | 554 | FadeData.Length = 11025*FadeData.LengthSecs; |
roryhand | 64:6061ffe25985 | 555 | //FadeData.Natural_Exp = 2.7; |
roryhand | 64:6061ffe25985 | 556 | return FadeData; |
roryhand | 64:6061ffe25985 | 557 | } |
roryhand | 67:043fe0b81343 | 558 | */ |
roryhand | 1:aac37edee302 | 559 | |
roryhand | 1:aac37edee302 | 560 | |
roryhand | 1:aac37edee302 | 561 | |
roryhand | 0:e89d7a0bfa3b | 562 | |
roryhand | 0:e89d7a0bfa3b | 563 | void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo) |
roryhand | 0:e89d7a0bfa3b | 564 | { |
roryhand | 1:aac37edee302 | 565 | while(slice<FileInfo.num_slices) { |
roryhand | 1:aac37edee302 | 566 | fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,my_wav); |
roryhand | 1:aac37edee302 | 567 | data_sptr=(short *)FileInfo.slice_buf; // 16 bit samples |
roryhand | 1:aac37edee302 | 568 | for (channel=0; channel<FileInfo.FileFormat.num_channels; channel++) { |
roryhand | 1:aac37edee302 | 569 | if(flag1 == 1) { |
roryhand | 1:aac37edee302 | 570 | Buffer1[place_hold1] = data_sptr[channel]; |
roryhand | 1:aac37edee302 | 571 | place_hold1 = place_hold1 + 1; |
roryhand | 1:aac37edee302 | 572 | if(place_hold1 >= BufferLen) { |
roryhand | 1:aac37edee302 | 573 | while(1) { |
roryhand | 1:aac37edee302 | 574 | if(flag1 == 0) { |
roryhand | 0:e89d7a0bfa3b | 575 | |
roryhand | 1:aac37edee302 | 576 | break; |
roryhand | 0:e89d7a0bfa3b | 577 | } |
roryhand | 1:aac37edee302 | 578 | |
roryhand | 0:e89d7a0bfa3b | 579 | } |
roryhand | 1:aac37edee302 | 580 | } |
roryhand | 1:aac37edee302 | 581 | |
roryhand | 1:aac37edee302 | 582 | } else if(flag2 == 1) { |
roryhand | 1:aac37edee302 | 583 | Buffer2[place_hold2] = data_sptr[channel]; |
roryhand | 1:aac37edee302 | 584 | place_hold2 = place_hold2 + 1; |
roryhand | 1:aac37edee302 | 585 | if(place_hold2 >= BufferLen) { |
roryhand | 1:aac37edee302 | 586 | |
roryhand | 1:aac37edee302 | 587 | while(1) { |
roryhand | 1:aac37edee302 | 588 | if(flag2 == 0) { |
roryhand | 1:aac37edee302 | 589 | |
roryhand | 1:aac37edee302 | 590 | break; |
roryhand | 1:aac37edee302 | 591 | } |
roryhand | 0:e89d7a0bfa3b | 592 | } |
roryhand | 1:aac37edee302 | 593 | } |
roryhand | 0:e89d7a0bfa3b | 594 | } |
roryhand | 1:aac37edee302 | 595 | |
roryhand | 1:aac37edee302 | 596 | } |
roryhand | 1:aac37edee302 | 597 | slice = slice + 1; |
roryhand | 0:e89d7a0bfa3b | 598 | } |
roryhand | 0:e89d7a0bfa3b | 599 | } |
roryhand | 0:e89d7a0bfa3b | 600 | |
roryhand | 0:e89d7a0bfa3b | 601 | |
roryhand | 0:e89d7a0bfa3b | 602 | |
roryhand | 0:e89d7a0bfa3b | 603 | |
roryhand | 38:3b4c05af5f36 | 604 | //***************************************************************************// |
roryhand | 38:3b4c05af5f36 | 605 | |
roryhand | 38:3b4c05af5f36 | 606 | //**************************************************************************// |
roryhand | 38:3b4c05af5f36 | 607 | |
roryhand | 38:3b4c05af5f36 | 608 | |
roryhand | 38:3b4c05af5f36 | 609 | |
roryhand | 38:3b4c05af5f36 | 610 | |
roryhand | 38:3b4c05af5f36 | 611 | |
roryhand | 59:8e7c25a915a0 | 612 | |
roryhand | 44:a9e84d333a6a | 613 | |
roryhand | 77:e93c944ed30f | 614 | void Play_WaveFileLoop(classSoundFile Sound1, classSoundFile Sound2, FILE *wavfile1, FILE* wavfile2, classPositionIndicators Positions) |
roryhand | 45:0e8e1f2ec5d2 | 615 | { |
roryhand | 45:0e8e1f2ec5d2 | 616 | while(1) { //might have to change this to a while(1) loop? |
roryhand | 44:a9e84d333a6a | 617 | |
roryhand | 2:957d3b2afff4 | 618 | |
roryhand | 44:a9e84d333a6a | 619 | |
roryhand | 44:a9e84d333a6a | 620 | |
roryhand | 54:606a83fff291 | 621 | |
roryhand | 44:a9e84d333a6a | 622 | //Sound1======================================================================================= |
roryhand | 69:df10ee3ad523 | 623 | if( slice1 == (Positions.notch_start_pts[NotchingSet.Notch + 1]) ) { |
roryhand | 69:df10ee3ad523 | 624 | slice1 = Positions.notch_start_pts[NotchingSet.Notch]; |
roryhand | 69:df10ee3ad523 | 625 | fseek(wavfile1,Positions.notch_start_pts[NotchingSet.Notch],SEEK_SET); |
roryhand | 67:043fe0b81343 | 626 | } |
roryhand | 73:a5ab93214728 | 627 | if(TransitionFlag) |
roryhand | 73:a5ab93214728 | 628 | { |
roryhand | 73:a5ab93214728 | 629 | |
roryhand | 74:e71a7815f63d | 630 | //printf("TransitionFlag == 1, so now we are going to do some other processing\n\r"); |
roryhand | 73:a5ab93214728 | 631 | //NOTCH 1 |
roryhand | 75:8a71e269b890 | 632 | //OperationsTimer.reset(); |
roryhand | 75:8a71e269b890 | 633 | //OperationsTimer.start(); |
roryhand | 77:e93c944ed30f | 634 | //fpos_t position; |
roryhand | 77:e93c944ed30f | 635 | //fgetpos(wavfile1,&position); |
roryhand | 77:e93c944ed30f | 636 | //printf("Positions.notch_position_indicators[NotchingSet.Notch]: %d\n\r",Positions.notch_position_indicators[NotchingSet.Notch]); |
roryhand | 77:e93c944ed30f | 637 | fseek(wavfile1,Positions.notch_position_indicators[NotchingSet.Notch-1],Positions.notch_position_indicators[NotchingSet.Notch-1]); |
roryhand | 77:e93c944ed30f | 638 | ////fsetpos(wavfile1, &position); |
roryhand | 75:8a71e269b890 | 639 | //OperationsTimer.stop(); |
roryhand | 75:8a71e269b890 | 640 | //printf("It took %d useconds to perform fseek operation.\n\r",OperationsTimer.read_us()); |
roryhand | 74:e71a7815f63d | 641 | //printf("We have seeked through the file\n\r"); |
roryhand | 75:8a71e269b890 | 642 | |
roryhand | 75:8a71e269b890 | 643 | |
roryhand | 77:e93c944ed30f | 644 | //printf("Size of Sound1.FileInfo.FileFormat.block_align: %d\n\r",Sound1.FileInfo.FileFormat.block_align); |
roryhand | 75:8a71e269b890 | 645 | |
roryhand | 77:e93c944ed30f | 646 | /* |
roryhand | 75:8a71e269b890 | 647 | OperationsTimer.reset(); |
roryhand | 75:8a71e269b890 | 648 | OperationsTimer.start(); |
roryhand | 77:e93c944ed30f | 649 | */ |
roryhand | 78:69a0c7a5fbdf | 650 | fseek(wavfile1,Positions.notch_position_indicators[NotchingSet.Notch-1],Positions.notch_position_indicators[NotchingSet.Notch-1]); |
roryhand | 74:e71a7815f63d | 651 | fread(Sound1.FileInfo.slice_buf, Sound1.FileInfo.FileFormat.block_align,1,wavfile1); |
roryhand | 78:69a0c7a5fbdf | 652 | data_sptr1=(short *)Sound1.FileInfo.slice_buf; |
roryhand | 78:69a0c7a5fbdf | 653 | Positions.notch_position_indicators[NotchingSet.Notch-1] = Positions.notch_position_indicators[NotchingSet.Notch-1] + 2; |
roryhand | 77:e93c944ed30f | 654 | |
roryhand | 78:69a0c7a5fbdf | 655 | fseek(wavfile2,Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp],Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp]); |
roryhand | 78:69a0c7a5fbdf | 656 | fread(Sound2.FileInfo.slice_buf, Sound2.FileInfo.FileFormat.block_align,1,wavfile2); |
roryhand | 78:69a0c7a5fbdf | 657 | data_sptr2=(short *)Sound2.FileInfo.slice_buf; |
roryhand | 78:69a0c7a5fbdf | 658 | Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp] = Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp] + 2; |
roryhand | 78:69a0c7a5fbdf | 659 | |
roryhand | 78:69a0c7a5fbdf | 660 | |
roryhand | 77:e93c944ed30f | 661 | /* |
roryhand | 75:8a71e269b890 | 662 | OperationsTimer.stop(); |
roryhand | 75:8a71e269b890 | 663 | printf("It took %d useconds to perform fread operation.\n\r",OperationsTimer.read_us()); |
roryhand | 77:e93c944ed30f | 664 | */ |
roryhand | 74:e71a7815f63d | 665 | //printf("We have now read in 2 bytes of data (i.e. 1 sample)\n\r"); |
roryhand | 78:69a0c7a5fbdf | 666 | |
roryhand | 74:e71a7815f63d | 667 | //printf("We have now cast this data to a short data type\n\r"); |
roryhand | 77:e93c944ed30f | 668 | |
roryhand | 77:e93c944ed30f | 669 | |
roryhand | 78:69a0c7a5fbdf | 670 | |
roryhand | 77:e93c944ed30f | 671 | |
roryhand | 77:e93c944ed30f | 672 | |
roryhand | 74:e71a7815f63d | 673 | //printf("We have incremented up the Positions.notch_position_indicator"); |
roryhand | 72:599068243a0f | 674 | //increment up the position indicator! |
roryhand | 72:599068243a0f | 675 | |
roryhand | 73:a5ab93214728 | 676 | //NOTCH 2 |
roryhand | 77:e93c944ed30f | 677 | /* |
roryhand | 77:e93c944ed30f | 678 | fseek(wavfile1,Positions.notch_position_indicators[NotchingSet.Notch],Positions.notch_position_indicators[NotchingSet.Notch]); |
roryhand | 74:e71a7815f63d | 679 | fread(Sound1.FileInfo.slice_buf, Sound1.FileInfo.FileFormat.block_align,1,wavfile1); |
roryhand | 74:e71a7815f63d | 680 | data_sptr3=(short *)Sound1.FileInfo.slice_buf; |
roryhand | 77:e93c944ed30f | 681 | Positions.notch_position_indicators[NotchingSet.Notch] = Positions.notch_position_indicators[NotchingSet.Notch] + 2; |
roryhand | 77:e93c944ed30f | 682 | */ |
roryhand | 72:599068243a0f | 683 | //increment up the position indicator! |
roryhand | 72:599068243a0f | 684 | |
roryhand | 77:e93c944ed30f | 685 | /* |
roryhand | 69:df10ee3ad523 | 686 | if(NotchingSet.NotchDirection) |
roryhand | 69:df10ee3ad523 | 687 | |
roryhand | 69:df10ee3ad523 | 688 | { |
roryhand | 75:8a71e269b890 | 689 | //printf("Reached if(NotchingSet.NotchDirection)\n\r"); |
roryhand | 69:df10ee3ad523 | 690 | |
roryhand | 73:a5ab93214728 | 691 | //N1 N2 Transition |
roryhand | 77:e93c944ed30f | 692 | fseek(wavfile2,Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp],Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp]); |
roryhand | 74:e71a7815f63d | 693 | fread(Sound1.FileInfo.slice_buf, Sound1.FileInfo.FileFormat.block_align,1,wavfile2); |
roryhand | 77:e93c944ed30f | 694 | data_sptr2=(short *)Sound2.FileInfo.slice_buf; |
roryhand | 73:a5ab93214728 | 695 | Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp] = Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp] + 2; |
roryhand | 69:df10ee3ad523 | 696 | |
roryhand | 69:df10ee3ad523 | 697 | } else { |
roryhand | 73:a5ab93214728 | 698 | //N1 N2 Transition |
roryhand | 77:e93c944ed30f | 699 | fseek(wavfile2,Positions.notch_transitions_position_indicators[NotchingSet.NotchTransDown],Positions.notch_position_indicators[NotchingSet.NotchTransDown]); |
roryhand | 74:e71a7815f63d | 700 | fread(Sound1.FileInfo.slice_buf, Sound1.FileInfo.FileFormat.block_align,1,wavfile2); |
roryhand | 77:e93c944ed30f | 701 | data_sptr2=(short *)Sound2.FileInfo.slice_buf; |
roryhand | 73:a5ab93214728 | 702 | Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp] = Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp] + 2; |
roryhand | 69:df10ee3ad523 | 703 | |
roryhand | 69:df10ee3ad523 | 704 | } |
roryhand | 77:e93c944ed30f | 705 | */ |
roryhand | 77:e93c944ed30f | 706 | |
roryhand | 70:2b144da2c3b8 | 707 | |
roryhand | 70:2b144da2c3b8 | 708 | |
roryhand | 73:a5ab93214728 | 709 | NotchFadeOut.FadeOut(); |
roryhand | 77:e93c944ed30f | 710 | /* |
roryhand | 70:2b144da2c3b8 | 711 | if(Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp] >= (Positions.notch_transitions_start_pts[NotchingSet.NotchTransUp+1] - NotchFadeIn.Length)) |
roryhand | 70:2b144da2c3b8 | 712 | { |
roryhand | 70:2b144da2c3b8 | 713 | NotchFadeIn.FadeIn(); |
roryhand | 70:2b144da2c3b8 | 714 | if(Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp] >= Positions.notch_transitions_start_pts[NotchingSet.NotchTransUp+1]) |
roryhand | 70:2b144da2c3b8 | 715 | { |
roryhand | 73:a5ab93214728 | 716 | *Sound1.data_sptr = *data_sptr2*NotchFadeIn.FadeCoeff; |
roryhand | 73:a5ab93214728 | 717 | TransitionFlag = 0; |
roryhand | 77:e93c944ed30f | 718 | fseek(wavfile1,Positions.notch_position_indicators[NotchingSet.Notch],Positions.notch_position_indicators[NotchingSet.Notch]); |
roryhand | 70:2b144da2c3b8 | 719 | |
roryhand | 70:2b144da2c3b8 | 720 | } |
roryhand | 72:599068243a0f | 721 | else |
roryhand | 72:599068243a0f | 722 | { |
roryhand | 73:a5ab93214728 | 723 | *Sound1.data_sptr = *data_sptr1*NotchFadeOut.FadeCoeff + *data_sptr2 + *data_sptr3*NotchFadeIn.FadeCoeff; |
roryhand | 72:599068243a0f | 724 | } |
roryhand | 70:2b144da2c3b8 | 725 | |
roryhand | 70:2b144da2c3b8 | 726 | |
roryhand | 70:2b144da2c3b8 | 727 | } |
roryhand | 77:e93c944ed30f | 728 | */ |
roryhand | 77:e93c944ed30f | 729 | //else |
roryhand | 77:e93c944ed30f | 730 | //{ |
roryhand | 84:0a259e261532 | 731 | *Sound1.data_sptr = *data_sptr1;//*NotchFadeOut.FadeCoeff + *data_sptr2; |
roryhand | 78:69a0c7a5fbdf | 732 | //*Sound1.data_sptr = *data_sptr1;// + *data_sptr2; |
roryhand | 78:69a0c7a5fbdf | 733 | |
roryhand | 78:69a0c7a5fbdf | 734 | |
roryhand | 78:69a0c7a5fbdf | 735 | |
roryhand | 72:599068243a0f | 736 | //include a flag here, to hand over control. Going to get a bit complicated!!! |
roryhand | 77:e93c944ed30f | 737 | //} |
roryhand | 70:2b144da2c3b8 | 738 | |
roryhand | 70:2b144da2c3b8 | 739 | |
roryhand | 69:df10ee3ad523 | 740 | |
roryhand | 73:a5ab93214728 | 741 | |
roryhand | 73:a5ab93214728 | 742 | |
roryhand | 69:df10ee3ad523 | 743 | |
roryhand | 73:a5ab93214728 | 744 | } |
roryhand | 73:a5ab93214728 | 745 | else |
roryhand | 73:a5ab93214728 | 746 | { |
roryhand | 76:9535aedba4da | 747 | |
roryhand | 77:e93c944ed30f | 748 | /*fseek(wavfile1,Positions.notch_position_indicators[1],SEEK_SET); |
roryhand | 76:9535aedba4da | 749 | OperationsTimer.reset(); |
roryhand | 76:9535aedba4da | 750 | OperationsTimer.start(); |
roryhand | 77:e93c944ed30f | 751 | */ |
roryhand | 69:df10ee3ad523 | 752 | fread(Sound1.FileInfo.slice_buf,Sound1.FileInfo.FileFormat.block_align,1,wavfile1); |
roryhand | 77:e93c944ed30f | 753 | /*OperationsTimer.stop(); |
roryhand | 76:9535aedba4da | 754 | printf("It took %d useconds to perform fread operation.\n\r",OperationsTimer.read_us()); |
roryhand | 76:9535aedba4da | 755 | Positions.notch_position_indicators[1] = Positions.notch_position_indicators[1] + 2;//i.e. 2 bytes, per sample, for 2-byte (16-bit) data |
roryhand | 77:e93c944ed30f | 756 | */ |
roryhand | 84:0a259e261532 | 757 | data_sptr1=(short *)Sound1.FileInfo.slice_buf; |
roryhand | 84:0a259e261532 | 758 | *Sound1.data_sptr = *data_sptr1; |
roryhand | 84:0a259e261532 | 759 | //Sound1.data_sptr=(short *)Sound1.FileInfo.slice_buf; // 16 bit samples |
roryhand | 73:a5ab93214728 | 760 | |
roryhand | 73:a5ab93214728 | 761 | } |
roryhand | 44:a9e84d333a6a | 762 | //============================================================================================= |
roryhand | 44:a9e84d333a6a | 763 | |
roryhand | 67:043fe0b81343 | 764 | |
roryhand | 1:aac37edee302 | 765 | |
roryhand | 1:aac37edee302 | 766 | |
roryhand | 44:a9e84d333a6a | 767 | |
roryhand | 45:0e8e1f2ec5d2 | 768 | for (channel=0; channel<Sound1.FileInfo.FileFormat.num_channels; channel++) { |
roryhand | 45:0e8e1f2ec5d2 | 769 | switch (Sound1.FileInfo.FileFormat.sig_bps) { |
roryhand | 0:e89d7a0bfa3b | 770 | case 16: |
roryhand | 1:aac37edee302 | 771 | if(flag1 == 1) { |
roryhand | 45:0e8e1f2ec5d2 | 772 | Buffer1[place_hold1] = Sound1.data_sptr[channel]; |
roryhand | 1:aac37edee302 | 773 | place_hold1 = place_hold1 + 1; |
roryhand | 1:aac37edee302 | 774 | if(place_hold1 >= BufferLen) { |
roryhand | 1:aac37edee302 | 775 | while(1) { |
roryhand | 1:aac37edee302 | 776 | if(flag1 == 0) { |
roryhand | 1:aac37edee302 | 777 | break; |
roryhand | 1:aac37edee302 | 778 | }//if(flag1 == 0) |
roryhand | 1:aac37edee302 | 779 | |
roryhand | 1:aac37edee302 | 780 | |
roryhand | 1:aac37edee302 | 781 | }//while(1) |
roryhand | 1:aac37edee302 | 782 | }//if(place_hold1 > = BufferLen) |
roryhand | 0:e89d7a0bfa3b | 783 | |
roryhand | 1:aac37edee302 | 784 | } else if(flag2 == 1) { |
roryhand | 45:0e8e1f2ec5d2 | 785 | Buffer2[place_hold2] = Sound1.data_sptr[channel]; |
roryhand | 1:aac37edee302 | 786 | place_hold2 = place_hold2 + 1; |
roryhand | 1:aac37edee302 | 787 | if(place_hold2 >= BufferLen) { |
roryhand | 1:aac37edee302 | 788 | while(1) { |
roryhand | 1:aac37edee302 | 789 | |
roryhand | 1:aac37edee302 | 790 | if(flag2 == 0) { |
roryhand | 1:aac37edee302 | 791 | break; |
roryhand | 1:aac37edee302 | 792 | } |
roryhand | 1:aac37edee302 | 793 | } |
roryhand | 0:e89d7a0bfa3b | 794 | } |
roryhand | 1:aac37edee302 | 795 | |
roryhand | 1:aac37edee302 | 796 | } |
roryhand | 0:e89d7a0bfa3b | 797 | } |
roryhand | 0:e89d7a0bfa3b | 798 | } |
roryhand | 59:8e7c25a915a0 | 799 | slice1 = slice1 + 2;//increment up by the number of bytes per Audio data sample! Makes sense it is 2 bytes, as this is 16-bit data. |
roryhand | 45:0e8e1f2ec5d2 | 800 | slice2 = slice2 + 1; |
roryhand | 45:0e8e1f2ec5d2 | 801 | slice3 = slice3 + 1; |
roryhand | 0:e89d7a0bfa3b | 802 | } |
roryhand | 0:e89d7a0bfa3b | 803 | } |
roryhand | 0:e89d7a0bfa3b | 804 | |
roryhand | 0:e89d7a0bfa3b | 805 | |
roryhand | 0:e89d7a0bfa3b | 806 | |
roryhand | 0:e89d7a0bfa3b | 807 | |
roryhand | 0:e89d7a0bfa3b | 808 | |
roryhand | 0:e89d7a0bfa3b | 809 | |
roryhand | 59:8e7c25a915a0 | 810 |