old demo that i want to try in mbed studio
Dependencies: mbed SDFileSystem_Copy_of_mbed_version I2S
NotchingDemo.cpp@66:edf370edd21c, 2019-09-29 (annotated)
- Committer:
- roryhand
- Date:
- Sun Sep 29 20:00:41 2019 +0000
- Branch:
- LargeFile_Tests
- Revision:
- 66:edf370edd21c
- Parent:
- 65:8b6a4e307941
- Child:
- 67:043fe0b81343
WIP - NotchUpIsr() and NotchDownIsr() copied from another commit.
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 | 65:8b6a4e307941 | 46 | class classFade |
| roryhand | 65:8b6a4e307941 | 47 | { |
| roryhand | 65:8b6a4e307941 | 48 | public: |
| roryhand | 65:8b6a4e307941 | 49 | |
| roryhand | 65:8b6a4e307941 | 50 | float powerval; |
| roryhand | 65:8b6a4e307941 | 51 | float FadeIteration; |
| roryhand | 65:8b6a4e307941 | 52 | float DecayFactor; |
| roryhand | 65:8b6a4e307941 | 53 | float Denom; |
| roryhand | 65:8b6a4e307941 | 54 | float FadeCoeff; |
| roryhand | 65:8b6a4e307941 | 55 | float Natural_Exp; |
| roryhand | 65:8b6a4e307941 | 56 | int LengthSecs; |
| roryhand | 65:8b6a4e307941 | 57 | int Length; |
| roryhand | 65:8b6a4e307941 | 58 | |
| roryhand | 65:8b6a4e307941 | 59 | //member Functions |
| roryhand | 65:8b6a4e307941 | 60 | float FadeOut(void) |
| roryhand | 65:8b6a4e307941 | 61 | { |
| roryhand | 65:8b6a4e307941 | 62 | powerval = -FadeIteration/Denom; |
| roryhand | 65:8b6a4e307941 | 63 | if (FadeIteration >=Length) { |
| roryhand | 65:8b6a4e307941 | 64 | FadeCoeff = 0; |
| roryhand | 65:8b6a4e307941 | 65 | |
| roryhand | 65:8b6a4e307941 | 66 | } else { |
| roryhand | 65:8b6a4e307941 | 67 | FadeCoeff = (Length - FadeIteration)/Length; |
| roryhand | 65:8b6a4e307941 | 68 | } |
| roryhand | 65:8b6a4e307941 | 69 | FadeIteration = FadeIteration + 1; |
| roryhand | 65:8b6a4e307941 | 70 | return FadeCoeff; |
| roryhand | 65:8b6a4e307941 | 71 | |
| roryhand | 65:8b6a4e307941 | 72 | } |
| roryhand | 65:8b6a4e307941 | 73 | float FadeIn(void) |
| roryhand | 65:8b6a4e307941 | 74 | { |
| roryhand | 65:8b6a4e307941 | 75 | powerval = FadeIteration/Denom; |
| roryhand | 65:8b6a4e307941 | 76 | if (FadeIteration >=Length) { |
| roryhand | 65:8b6a4e307941 | 77 | FadeCoeff = 1; |
| roryhand | 65:8b6a4e307941 | 78 | |
| roryhand | 65:8b6a4e307941 | 79 | } else { |
| roryhand | 65:8b6a4e307941 | 80 | FadeCoeff = FadeIteration/Length; |
| roryhand | 65:8b6a4e307941 | 81 | } |
| roryhand | 65:8b6a4e307941 | 82 | |
| roryhand | 65:8b6a4e307941 | 83 | FadeIteration = FadeIteration + 1; |
| roryhand | 65:8b6a4e307941 | 84 | return FadeCoeff; |
| roryhand | 65:8b6a4e307941 | 85 | |
| roryhand | 65:8b6a4e307941 | 86 | } |
| roryhand | 65:8b6a4e307941 | 87 | }; |
| roryhand | 65:8b6a4e307941 | 88 | |
| roryhand | 65:8b6a4e307941 | 89 | |
| roryhand | 1:aac37edee302 | 90 | typedef struct uFMT_STRUCT { |
| roryhand | 1:aac37edee302 | 91 | short comp_code; |
| roryhand | 1:aac37edee302 | 92 | short num_channels; |
| roryhand | 1:aac37edee302 | 93 | unsigned sample_rate; |
| roryhand | 1:aac37edee302 | 94 | unsigned avg_Bps; |
| roryhand | 1:aac37edee302 | 95 | short block_align; |
| roryhand | 1:aac37edee302 | 96 | short sig_bps; |
| roryhand | 0:e89d7a0bfa3b | 97 | } FMT_STRUCT; |
| roryhand | 0:e89d7a0bfa3b | 98 | |
| roryhand | 1:aac37edee302 | 99 | typedef struct uNotch_STRUCT { |
| roryhand | 1:aac37edee302 | 100 | short Notch; |
| roryhand | 1:aac37edee302 | 101 | short NotchTransUp; |
| roryhand | 1:aac37edee302 | 102 | short NotchTransDown; |
| roryhand | 1:aac37edee302 | 103 | short NotchDirection; |
| roryhand | 1:aac37edee302 | 104 | } Notch_STRUCT; |
| roryhand | 1:aac37edee302 | 105 | |
| roryhand | 0:e89d7a0bfa3b | 106 | typedef struct uDATA_STRUCT { |
| roryhand | 1:aac37edee302 | 107 | unsigned subchunk2_ID; |
| roryhand | 1:aac37edee302 | 108 | unsigned subchunk2_size; |
| roryhand | 1:aac37edee302 | 109 | char * data_buf; |
| roryhand | 1:aac37edee302 | 110 | } DATA_STRUCT; |
| roryhand | 0:e89d7a0bfa3b | 111 | |
| roryhand | 1:aac37edee302 | 112 | typedef struct uWAV_FILE_STRUCT { |
| roryhand | 1:aac37edee302 | 113 | FILE *WavFile; |
| roryhand | 1:aac37edee302 | 114 | int id_number; |
| roryhand | 1:aac37edee302 | 115 | char *slice_buf; |
| roryhand | 1:aac37edee302 | 116 | int num_slices; |
| roryhand | 1:aac37edee302 | 117 | FMT_STRUCT FileFormat; |
| roryhand | 1:aac37edee302 | 118 | DATA_STRUCT FileData; |
| roryhand | 0:e89d7a0bfa3b | 119 | } WAV_FILE_STRUCT; |
| roryhand | 0:e89d7a0bfa3b | 120 | |
| roryhand | 0:e89d7a0bfa3b | 121 | /*typedef struct uWAV_FILE_STRUCT{ |
| roryhand | 1:aac37edee302 | 122 | FILE* WavFile; |
| roryhand | 1:aac37edee302 | 123 | |
| roryhand | 1:aac37edee302 | 124 | |
| roryhand | 0:e89d7a0bfa3b | 125 | }WAV_FILE_STRUCT;*/ |
| roryhand | 59:8e7c25a915a0 | 126 | |
| roryhand | 59:8e7c25a915a0 | 127 | |
| roryhand | 59:8e7c25a915a0 | 128 | |
| roryhand | 59:8e7c25a915a0 | 129 | |
| roryhand | 59:8e7c25a915a0 | 130 | |
| roryhand | 59:8e7c25a915a0 | 131 | class classSoundFile |
| roryhand | 59:8e7c25a915a0 | 132 | { |
| roryhand | 59:8e7c25a915a0 | 133 | public: |
| roryhand | 59:8e7c25a915a0 | 134 | |
| roryhand | 59:8e7c25a915a0 | 135 | //add a class constructor at some point in the future (perform tests in visual studio) |
| roryhand | 59:8e7c25a915a0 | 136 | WAV_FILE_STRUCT FileInfo; |
| roryhand | 59:8e7c25a915a0 | 137 | short * data_sptr; |
| roryhand | 59:8e7c25a915a0 | 138 | string file_location; |
| roryhand | 59:8e7c25a915a0 | 139 | //classSoundFile(string filename);//this is the constructor |
| roryhand | 59:8e7c25a915a0 | 140 | //string filename; |
| roryhand | 59:8e7c25a915a0 | 141 | }; |
| roryhand | 58:a174e7a8f5f2 | 142 | class classPositionIndicators |
| roryhand | 57:0c76b15cabaf | 143 | { |
| roryhand | 57:0c76b15cabaf | 144 | public: |
| roryhand | 57:0c76b15cabaf | 145 | int notch1_indicator, notch2_indicator, notch3_indicator, notch4_indicator; |
| roryhand | 57:0c76b15cabaf | 146 | int notch5_indicator, notch6_indicator, notch7_indicator, notch8_indicator; |
| roryhand | 57:0c76b15cabaf | 147 | int notch1_start_pt, notch2_start_pt, notch3_start_pt, notch4_start_pt; |
| roryhand | 57:0c76b15cabaf | 148 | int notch5_start_pt, notch6_start_pt, notch7_start_pt, notch8_start_pt; |
| roryhand | 63:a8c1971d3d42 | 149 | int N1N2_start_pt, N2N3_start_pt, N3N4_start_pt, N4N5_start_pt, N5N6_start_pt; |
| roryhand | 63:a8c1971d3d42 | 150 | int N6N7_start_pt, N7N8_start_pt, N8N7_start_pt, N7N6_start_pt, N6N5_start_pt; |
| roryhand | 63:a8c1971d3d42 | 151 | int N5N4_start_pt, N4N3_start_pt, N3N2_start_pt, N2N1_start_pt; |
| roryhand | 63:a8c1971d3d42 | 152 | |
| roryhand | 61:212d2db45c56 | 153 | int notch_start_pts [9]; |
| roryhand | 61:212d2db45c56 | 154 | int notch_position_indicators[9]; |
| roryhand | 61:212d2db45c56 | 155 | int notch_transitions_start_pts[15]; |
| roryhand | 61:212d2db45c56 | 156 | int notch_transitions_position_indicators[15]; |
| roryhand | 61:212d2db45c56 | 157 | int auxiliary_start_pts[5]; |
| roryhand | 61:212d2db45c56 | 158 | int auxiliary_position_indicators[5]; |
| roryhand | 58:a174e7a8f5f2 | 159 | classPositionIndicators() |
| roryhand | 57:0c76b15cabaf | 160 | { |
| roryhand | 57:0c76b15cabaf | 161 | notch1_start_pt = 44; |
| roryhand | 57:0c76b15cabaf | 162 | notch2_start_pt = 220884+44; |
| roryhand | 57:0c76b15cabaf | 163 | notch3_start_pt = notch2_start_pt+217698; |
| roryhand | 57:0c76b15cabaf | 164 | notch4_start_pt = notch3_start_pt + 193060; |
| roryhand | 57:0c76b15cabaf | 165 | notch5_start_pt = notch4_start_pt + 92010; |
| roryhand | 57:0c76b15cabaf | 166 | notch6_start_pt = notch5_start_pt + 216642; |
| roryhand | 57:0c76b15cabaf | 167 | notch7_start_pt = notch6_start_pt + 250316; |
| roryhand | 61:212d2db45c56 | 168 | notch8_start_pt = notch7_start_pt + 150152; |
| roryhand | 57:0c76b15cabaf | 169 | notch1_indicator = notch1_start_pt; |
| roryhand | 57:0c76b15cabaf | 170 | notch2_indicator = notch2_start_pt; |
| roryhand | 57:0c76b15cabaf | 171 | notch3_indicator = notch3_start_pt; |
| roryhand | 57:0c76b15cabaf | 172 | notch4_indicator = notch4_start_pt; |
| roryhand | 57:0c76b15cabaf | 173 | notch5_indicator = notch5_start_pt; |
| roryhand | 57:0c76b15cabaf | 174 | notch6_indicator = notch6_start_pt; |
| roryhand | 57:0c76b15cabaf | 175 | notch7_indicator = notch7_start_pt; |
| roryhand | 57:0c76b15cabaf | 176 | notch8_indicator = notch8_start_pt; |
| roryhand | 61:212d2db45c56 | 177 | notch_start_pts[1] = notch1_start_pt; |
| roryhand | 61:212d2db45c56 | 178 | notch_start_pts[2] = notch2_start_pt; |
| roryhand | 61:212d2db45c56 | 179 | notch_start_pts[3] = notch3_start_pt; |
| roryhand | 61:212d2db45c56 | 180 | notch_start_pts[4] = notch4_start_pt; |
| roryhand | 61:212d2db45c56 | 181 | notch_start_pts[5] = notch5_start_pt; |
| roryhand | 61:212d2db45c56 | 182 | notch_start_pts[6] = notch6_start_pt; |
| roryhand | 61:212d2db45c56 | 183 | notch_start_pts[7] = notch7_start_pt; |
| roryhand | 61:212d2db45c56 | 184 | notch_start_pts[8] = notch8_start_pt; |
| roryhand | 61:212d2db45c56 | 185 | notch_position_indicators[1] = notch1_indicator; |
| roryhand | 61:212d2db45c56 | 186 | notch_position_indicators[2] = notch2_indicator; |
| roryhand | 61:212d2db45c56 | 187 | notch_position_indicators[3] = notch3_indicator; |
| roryhand | 61:212d2db45c56 | 188 | notch_position_indicators[4] = notch4_indicator; |
| roryhand | 61:212d2db45c56 | 189 | notch_position_indicators[5] = notch5_indicator; |
| roryhand | 61:212d2db45c56 | 190 | notch_position_indicators[6] = notch6_indicator; |
| roryhand | 61:212d2db45c56 | 191 | notch_position_indicators[7] = notch7_indicator; |
| roryhand | 61:212d2db45c56 | 192 | notch_position_indicators[8] = notch8_indicator; |
| roryhand | 63:a8c1971d3d42 | 193 | |
| roryhand | 63:a8c1971d3d42 | 194 | N1N2_start_pt = 44; |
| roryhand | 63:a8c1971d3d42 | 195 | N2N3_start_pt = N1N2_start_pt + 73220; |
| roryhand | 63:a8c1971d3d42 | 196 | N3N4_start_pt = N2N3_start_pt + 78164; |
| roryhand | 63:a8c1971d3d42 | 197 | N4N5_start_pt = N3N4_start_pt + 59432; |
| roryhand | 63:a8c1971d3d42 | 198 | N5N6_start_pt = N4N5_start_pt + 64984; |
| roryhand | 63:a8c1971d3d42 | 199 | N6N7_start_pt = N5N6_start_pt + 59924; |
| roryhand | 63:a8c1971d3d42 | 200 | N7N8_start_pt = N6N7_start_pt + 97874; |
| roryhand | 63:a8c1971d3d42 | 201 | N8N7_start_pt = N7N8_start_pt + 63992; |
| roryhand | 63:a8c1971d3d42 | 202 | N7N6_start_pt = N8N7_start_pt + 44506; |
| roryhand | 63:a8c1971d3d42 | 203 | N6N5_start_pt = N7N6_start_pt + 55052; |
| roryhand | 63:a8c1971d3d42 | 204 | N5N4_start_pt = N6N5_start_pt + 37038; |
| roryhand | 63:a8c1971d3d42 | 205 | N4N3_start_pt = N5N4_start_pt + 49692; |
| roryhand | 63:a8c1971d3d42 | 206 | N3N2_start_pt = N4N3_start_pt + 44100; |
| roryhand | 63:a8c1971d3d42 | 207 | N2N1_start_pt = N3N2_start_pt + 58346; |
| roryhand | 63:a8c1971d3d42 | 208 | |
| roryhand | 63:a8c1971d3d42 | 209 | |
| roryhand | 63:a8c1971d3d42 | 210 | notch_transitions_start_pts[1] = N1N2_start_pt; |
| roryhand | 63:a8c1971d3d42 | 211 | notch_transitions_start_pts[2] = N2N3_start_pt; |
| roryhand | 63:a8c1971d3d42 | 212 | notch_transitions_start_pts[3] = N3N4_start_pt; |
| roryhand | 63:a8c1971d3d42 | 213 | notch_transitions_start_pts[4] = N4N5_start_pt; |
| roryhand | 63:a8c1971d3d42 | 214 | notch_transitions_start_pts[5] = N5N6_start_pt; |
| roryhand | 63:a8c1971d3d42 | 215 | notch_transitions_start_pts[6] = N6N7_start_pt; |
| roryhand | 63:a8c1971d3d42 | 216 | notch_transitions_start_pts[7] = N7N8_start_pt; |
| roryhand | 63:a8c1971d3d42 | 217 | notch_transitions_start_pts[8] = N8N7_start_pt; |
| roryhand | 63:a8c1971d3d42 | 218 | notch_transitions_start_pts[9] = N7N6_start_pt; |
| roryhand | 63:a8c1971d3d42 | 219 | notch_transitions_start_pts[10] = N6N5_start_pt; |
| roryhand | 63:a8c1971d3d42 | 220 | notch_transitions_start_pts[11] = N5N4_start_pt; |
| roryhand | 63:a8c1971d3d42 | 221 | notch_transitions_start_pts[12] = N4N3_start_pt; |
| roryhand | 63:a8c1971d3d42 | 222 | notch_transitions_start_pts[13] = N3N2_start_pt; |
| roryhand | 63:a8c1971d3d42 | 223 | notch_transitions_start_pts[14] = N2N1_start_pt; |
| roryhand | 63:a8c1971d3d42 | 224 | |
| roryhand | 63:a8c1971d3d42 | 225 | |
| roryhand | 63:a8c1971d3d42 | 226 | notch_transitions_position_indicators[1] = N1N2_start_pt; |
| roryhand | 63:a8c1971d3d42 | 227 | notch_transitions_position_indicators[2] = N2N3_start_pt; |
| roryhand | 63:a8c1971d3d42 | 228 | notch_transitions_position_indicators[3] = N3N4_start_pt; |
| roryhand | 63:a8c1971d3d42 | 229 | notch_transitions_position_indicators[4] = N4N5_start_pt; |
| roryhand | 63:a8c1971d3d42 | 230 | notch_transitions_position_indicators[5] = N5N6_start_pt; |
| roryhand | 63:a8c1971d3d42 | 231 | notch_transitions_position_indicators[6] = N6N7_start_pt; |
| roryhand | 63:a8c1971d3d42 | 232 | notch_transitions_position_indicators[7] = N7N8_start_pt; |
| roryhand | 63:a8c1971d3d42 | 233 | notch_transitions_position_indicators[8] = N8N7_start_pt; |
| roryhand | 63:a8c1971d3d42 | 234 | notch_transitions_position_indicators[9] = N7N6_start_pt; |
| roryhand | 63:a8c1971d3d42 | 235 | notch_transitions_position_indicators[10] = N6N5_start_pt; |
| roryhand | 63:a8c1971d3d42 | 236 | notch_transitions_position_indicators[11] = N5N4_start_pt; |
| roryhand | 63:a8c1971d3d42 | 237 | notch_transitions_position_indicators[12] = N4N3_start_pt; |
| roryhand | 63:a8c1971d3d42 | 238 | notch_transitions_position_indicators[13] = N3N2_start_pt; |
| roryhand | 63:a8c1971d3d42 | 239 | notch_transitions_position_indicators[14] = N2N1_start_pt; |
| roryhand | 57:0c76b15cabaf | 240 | } |
| roryhand | 57:0c76b15cabaf | 241 | }; |
| roryhand | 57:0c76b15cabaf | 242 | |
| roryhand | 66:edf370edd21c | 243 | |
| roryhand | 66:edf370edd21c | 244 | void NotchUpIsr() |
| roryhand | 66:edf370edd21c | 245 | { |
| roryhand | 66:edf370edd21c | 246 | if(1 <= NotchingSet.Notch < 8) { |
| roryhand | 66:edf370edd21c | 247 | |
| roryhand | 66:edf370edd21c | 248 | NotchingSet.Notch = NotchingSet.Notch + 1; |
| roryhand | 66:edf370edd21c | 249 | NotchingSet.NotchTransUp = NotchingSet.Notch + 7; |
| roryhand | 66:edf370edd21c | 250 | NotchingSet.NotchDirection = 1; |
| roryhand | 66:edf370edd21c | 251 | FadeDataInitialise(NotchFadeIn); |
| roryhand | 66:edf370edd21c | 252 | FadeDataInitialise(NotchFadeOut); |
| roryhand | 66:edf370edd21c | 253 | } |
| roryhand | 66:edf370edd21c | 254 | } |
| roryhand | 66:edf370edd21c | 255 | |
| roryhand | 66:edf370edd21c | 256 | void NotchDownIsr() |
| roryhand | 66:edf370edd21c | 257 | { |
| roryhand | 66:edf370edd21c | 258 | if(1 < NotchingSet.Notch <= 8) { |
| roryhand | 66:edf370edd21c | 259 | NotchingSet.Notch = NotchingSet.Notch - 1; |
| roryhand | 66:edf370edd21c | 260 | NotchingSet.NotchTransDown = NotchingSet.Notch + 15;; |
| roryhand | 66:edf370edd21c | 261 | NotchingSet.NotchDirection = 0; |
| roryhand | 66:edf370edd21c | 262 | FadeDataInitialise(NotchFadeIn); |
| roryhand | 66:edf370edd21c | 263 | FadeDataInitialise(NotchFadeOut); |
| roryhand | 66:edf370edd21c | 264 | } |
| roryhand | 66:edf370edd21c | 265 | } |
| roryhand | 54:606a83fff291 | 266 | int OneOff = 0; |
| roryhand | 38:3b4c05af5f36 | 267 | int notch_flag = 0; |
| roryhand | 0:e89d7a0bfa3b | 268 | int i = 0; |
| roryhand | 0:e89d7a0bfa3b | 269 | int h = 0; |
| roryhand | 0:e89d7a0bfa3b | 270 | short bufflen = 1; |
| roryhand | 0:e89d7a0bfa3b | 271 | int buffer[1]; |
| roryhand | 1:aac37edee302 | 272 | int AudioFormat, NumChannels, SampleRate, BitsPerSample ; |
| roryhand | 0:e89d7a0bfa3b | 273 | char *slice_buf; |
| roryhand | 0:e89d7a0bfa3b | 274 | short *data_sptr; |
| roryhand | 0:e89d7a0bfa3b | 275 | short *data_sptr_horn; |
| roryhand | 0:e89d7a0bfa3b | 276 | short *data_sptr_IdleN2; |
| roryhand | 0:e89d7a0bfa3b | 277 | short * data_sptr_bell; |
| roryhand | 0:e89d7a0bfa3b | 278 | short * data_sptr_N2; |
| roryhand | 0:e89d7a0bfa3b | 279 | short * data_sptr_Flange; |
| roryhand | 0:e89d7a0bfa3b | 280 | unsigned char *data_bptr; |
| roryhand | 0:e89d7a0bfa3b | 281 | int *data_wptr; |
| roryhand | 0:e89d7a0bfa3b | 282 | unsigned channel; |
| roryhand | 45:0e8e1f2ec5d2 | 283 | long slice, slice1, slice2, slice3, num_slices; |
| roryhand | 0:e89d7a0bfa3b | 284 | int verbosity = 0; |
| roryhand | 0:e89d7a0bfa3b | 285 | int verbosity2 = 0; |
| roryhand | 0:e89d7a0bfa3b | 286 | int verbosity3 = 0; |
| roryhand | 0:e89d7a0bfa3b | 287 | int verbosity4 = 0; |
| roryhand | 0:e89d7a0bfa3b | 288 | int verbosity5 = 0; |
| roryhand | 0:e89d7a0bfa3b | 289 | int interrupt_condition = 1; |
| roryhand | 0:e89d7a0bfa3b | 290 | int sampling_freq = 11025; |
| roryhand | 0:e89d7a0bfa3b | 291 | const int BufferLen = 2000; |
| roryhand | 0:e89d7a0bfa3b | 292 | short Buffer1[BufferLen]; |
| roryhand | 0:e89d7a0bfa3b | 293 | short Buffer2[BufferLen]; |
| roryhand | 0:e89d7a0bfa3b | 294 | short place_hold1 = 0; |
| roryhand | 0:e89d7a0bfa3b | 295 | short place_hold2 = 0; |
| roryhand | 0:e89d7a0bfa3b | 296 | |
| roryhand | 3:6169aeeaeeb4 | 297 | |
| roryhand | 3:6169aeeaeeb4 | 298 | string FOLDER; |
| roryhand | 3:6169aeeaeeb4 | 299 | string RootFolder = "/sd/mydir/SoundDecoder/"; |
| roryhand | 3:6169aeeaeeb4 | 300 | string filename[25]; |
| roryhand | 3:6169aeeaeeb4 | 301 | classSoundFile Sound[22]; |
| roryhand | 3:6169aeeaeeb4 | 302 | |
| roryhand | 0:e89d7a0bfa3b | 303 | volatile int flag1 = 1; |
| roryhand | 0:e89d7a0bfa3b | 304 | volatile int flag2 = 0; |
| roryhand | 0:e89d7a0bfa3b | 305 | volatile int flag3 = 1; |
| roryhand | 0:e89d7a0bfa3b | 306 | volatile int flag4 = 0; |
| roryhand | 0:e89d7a0bfa3b | 307 | int FLAGBUFF1 = 0; |
| roryhand | 0:e89d7a0bfa3b | 308 | int FLAGBUFF2 = 0; |
| roryhand | 0:e89d7a0bfa3b | 309 | int BellFlag = 0; |
| roryhand | 0:e89d7a0bfa3b | 310 | int BellFlag2 = 0; |
| roryhand | 0:e89d7a0bfa3b | 311 | int FadeFlag = 0; |
| roryhand | 54:606a83fff291 | 312 | int BlockFlag = 0; |
| roryhand | 32:6ee488c97dcc | 313 | int FileSwitchFlag = 0; |
| roryhand | 0:e89d7a0bfa3b | 314 | |
| roryhand | 0:e89d7a0bfa3b | 315 | |
| roryhand | 0:e89d7a0bfa3b | 316 | short value[1]; |
| roryhand | 59:8e7c25a915a0 | 317 | |
| roryhand | 0:e89d7a0bfa3b | 318 | //long long slice_value; |
| roryhand | 0:e89d7a0bfa3b | 319 | int slice_value[1]; |
| roryhand | 0:e89d7a0bfa3b | 320 | |
| roryhand | 0:e89d7a0bfa3b | 321 | |
| roryhand | 45:0e8e1f2ec5d2 | 322 | FILE *wavfile1; |
| roryhand | 45:0e8e1f2ec5d2 | 323 | FILE *wavfile2; |
| roryhand | 45:0e8e1f2ec5d2 | 324 | FILE *wavfile3; |
| roryhand | 45:0e8e1f2ec5d2 | 325 | |
| roryhand | 45:0e8e1f2ec5d2 | 326 | classSoundFile Sound1; |
| roryhand | 45:0e8e1f2ec5d2 | 327 | classSoundFile Sound2; |
| roryhand | 45:0e8e1f2ec5d2 | 328 | classSoundFile Sound3; |
| roryhand | 45:0e8e1f2ec5d2 | 329 | |
| roryhand | 0:e89d7a0bfa3b | 330 | |
| roryhand | 0:e89d7a0bfa3b | 331 | void isr() |
| roryhand | 0:e89d7a0bfa3b | 332 | { |
| roryhand | 54:606a83fff291 | 333 | //timer_interrupt.start(); |
| roryhand | 1:aac37edee302 | 334 | if(flag1 == 0) { |
| roryhand | 0:e89d7a0bfa3b | 335 | value[0] = Buffer1[place_hold1]>>4; |
| roryhand | 0:e89d7a0bfa3b | 336 | i2s.write(value,1);//Send next PWM value to amp |
| roryhand | 0:e89d7a0bfa3b | 337 | place_hold1 = place_hold1 + 1; |
| roryhand | 1:aac37edee302 | 338 | if( (place_hold1 >= BufferLen)) { |
| roryhand | 0:e89d7a0bfa3b | 339 | led2 = !led2; |
| roryhand | 0:e89d7a0bfa3b | 340 | place_hold1 = 0; |
| roryhand | 0:e89d7a0bfa3b | 341 | place_hold2 = 0; |
| roryhand | 0:e89d7a0bfa3b | 342 | flag1 = 1; |
| roryhand | 0:e89d7a0bfa3b | 343 | flag2 = 0; |
| roryhand | 1:aac37edee302 | 344 | } |
| roryhand | 1:aac37edee302 | 345 | } else if(flag2 == 0) { |
| roryhand | 0:e89d7a0bfa3b | 346 | value[0] = Buffer2[place_hold2]>>4; |
| roryhand | 0:e89d7a0bfa3b | 347 | i2s.write(value,1);//Send next PWM value to amp |
| roryhand | 0:e89d7a0bfa3b | 348 | place_hold2 = place_hold2 + 1; |
| roryhand | 1:aac37edee302 | 349 | if( (place_hold2 >= BufferLen) ) { |
| roryhand | 0:e89d7a0bfa3b | 350 | led2 = !led2; |
| roryhand | 0:e89d7a0bfa3b | 351 | place_hold1 = 0; |
| roryhand | 0:e89d7a0bfa3b | 352 | place_hold2 = 0; |
| roryhand | 0:e89d7a0bfa3b | 353 | flag1 = 0; |
| roryhand | 1:aac37edee302 | 354 | flag2 = 1; |
| roryhand | 0:e89d7a0bfa3b | 355 | FLAGBUFF2 = 0; |
| roryhand | 1:aac37edee302 | 356 | } |
| roryhand | 0:e89d7a0bfa3b | 357 | } |
| roryhand | 54:606a83fff291 | 358 | |
| roryhand | 54:606a83fff291 | 359 | //timer_interrupt.stop(); |
| roryhand | 54:606a83fff291 | 360 | |
| roryhand | 0:e89d7a0bfa3b | 361 | } |
| roryhand | 1:aac37edee302 | 362 | |
| roryhand | 38:3b4c05af5f36 | 363 | |
| roryhand | 38:3b4c05af5f36 | 364 | |
| roryhand | 38:3b4c05af5f36 | 365 | |
| roryhand | 38:3b4c05af5f36 | 366 | |
| roryhand | 0:e89d7a0bfa3b | 367 | |
| roryhand | 59:8e7c25a915a0 | 368 | |
| roryhand | 59:8e7c25a915a0 | 369 | |
| roryhand | 59:8e7c25a915a0 | 370 | |
| roryhand | 59:8e7c25a915a0 | 371 | |
| roryhand | 59:8e7c25a915a0 | 372 | |
| roryhand | 3:6169aeeaeeb4 | 373 | |
| roryhand | 3:6169aeeaeeb4 | 374 | |
| roryhand | 3:6169aeeaeeb4 | 375 | |
| roryhand | 3:6169aeeaeeb4 | 376 | |
| roryhand | 3:6169aeeaeeb4 | 377 | |
| roryhand | 3:6169aeeaeeb4 | 378 | //function prototypes |
| roryhand | 45:0e8e1f2ec5d2 | 379 | classSoundFile ReadFileInfo(classSoundFile Sound, FILE * wav_file); |
| roryhand | 3:6169aeeaeeb4 | 380 | classSoundFile LoadFileStream(classSoundFile FileInfo, string filename); |
| roryhand | 3:6169aeeaeeb4 | 381 | void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo); |
| roryhand | 32:6ee488c97dcc | 382 | void Play_WaveFileDual(FILE * my_wav, WAV_FILE_STRUCT FileInfo); |
| roryhand | 59:8e7c25a915a0 | 383 | void Play_WaveFileLoop(classSoundFile Sound1, FILE* wavfile1,classPositionIndicators Positions); |
| roryhand | 0:e89d7a0bfa3b | 384 | |
| roryhand | 1:aac37edee302 | 385 | int main() |
| roryhand | 1:aac37edee302 | 386 | { |
| roryhand | 44:a9e84d333a6a | 387 | |
| roryhand | 0:e89d7a0bfa3b | 388 | NotchUp.mode(PullUp); |
| roryhand | 38:3b4c05af5f36 | 389 | NotchDown.mode(PullUp); |
| roryhand | 0:e89d7a0bfa3b | 390 | |
| roryhand | 0:e89d7a0bfa3b | 391 | pc.printf("Beginning of program\n"); |
| roryhand | 32:6ee488c97dcc | 392 | |
| roryhand | 13:8e93396a27c5 | 393 | |
| roryhand | 13:8e93396a27c5 | 394 | |
| roryhand | 4:55fbbb049bae | 395 | |
| roryhand | 25:5336e1cf38d6 | 396 | printf("Do we even get to this stupid bloody point\n\r"); |
| roryhand | 0:e89d7a0bfa3b | 397 | //Populate our class instances with some data (is there an implicit way to do this?) |
| roryhand | 28:6b2353fad12d | 398 | |
| roryhand | 1:aac37edee302 | 399 | |
| roryhand | 3:6169aeeaeeb4 | 400 | printf("hello\n\r"); |
| roryhand | 0:e89d7a0bfa3b | 401 | //Set up the wolfson Audio Codec board |
| roryhand | 0:e89d7a0bfa3b | 402 | wm8731_Config_setup(); |
| roryhand | 0:e89d7a0bfa3b | 403 | //i2s audio data transfer code?? |
| roryhand | 0:e89d7a0bfa3b | 404 | i2s.stereomono(I2S_STEREO); |
| roryhand | 0:e89d7a0bfa3b | 405 | i2s.masterslave(I2S_MASTER); |
| roryhand | 0:e89d7a0bfa3b | 406 | led3 = 1; |
| roryhand | 0:e89d7a0bfa3b | 407 | led2 = 1; |
| roryhand | 45:0e8e1f2ec5d2 | 408 | printf("Hello i2s has started!"); |
| roryhand | 30:4a8e80b243c4 | 409 | i2s.start(); |
| roryhand | 0:e89d7a0bfa3b | 410 | sampletick.attach(&isr,1.0/sampling_freq); //1/16000 |
| roryhand | 54:606a83fff291 | 411 | |
| roryhand | 58:a174e7a8f5f2 | 412 | classPositionIndicators Positions; |
| roryhand | 61:212d2db45c56 | 413 | slice1 = Positions.notch7_start_pt; |
| roryhand | 60:36df2997de3d | 414 | FILE* wavfile1 = fopen("/sd/mydir/SoundDecoder_second/All_eight_notches.wav","rb"); |
| roryhand | 60:36df2997de3d | 415 | //FILE* wavfile1 = fopen("/sd/mydir/SoundDecoder_second/01.wav","rb"); |
| roryhand | 58:a174e7a8f5f2 | 416 | classSoundFile Sound1; |
| roryhand | 58:a174e7a8f5f2 | 417 | Sound1 = ReadFileInfo(Sound1, wavfile1); |
| roryhand | 61:212d2db45c56 | 418 | fseek(wavfile1,Positions.notch7_start_pt,SEEK_SET); |
| roryhand | 20:9cc7d825c07b | 419 | printf("about to play wav file\n\r"); |
| roryhand | 59:8e7c25a915a0 | 420 | Play_WaveFileLoop(Sound1,wavfile1,Positions); |
| roryhand | 20:9cc7d825c07b | 421 | printf("finished playing Wav file\n\r"); |
| roryhand | 54:606a83fff291 | 422 | |
| roryhand | 54:606a83fff291 | 423 | |
| roryhand | 31:0f8c3adf09c3 | 424 | timer_open.reset(); |
| roryhand | 31:0f8c3adf09c3 | 425 | timer_open.start(); |
| roryhand | 45:0e8e1f2ec5d2 | 426 | fclose(wavfile1); |
| roryhand | 31:0f8c3adf09c3 | 427 | timer_open.stop(); |
| roryhand | 31:0f8c3adf09c3 | 428 | printf("It took %d useconds to close file\n\r",timer_open.read_us()); |
| roryhand | 54:606a83fff291 | 429 | |
| roryhand | 54:606a83fff291 | 430 | |
| roryhand | 54:606a83fff291 | 431 | |
| roryhand | 54:606a83fff291 | 432 | |
| roryhand | 9:dd9cae06b202 | 433 | /************************************PLAY WAV FILE LOOP*******************/ |
| roryhand | 9:dd9cae06b202 | 434 | /************************************END OF PLAY WAV FILE LOOP*************/ |
| roryhand | 13:8e93396a27c5 | 435 | |
| roryhand | 13:8e93396a27c5 | 436 | |
| roryhand | 1:aac37edee302 | 437 | i2s.stop(); |
| roryhand | 0:e89d7a0bfa3b | 438 | |
| roryhand | 0:e89d7a0bfa3b | 439 | } |
| roryhand | 0:e89d7a0bfa3b | 440 | |
| roryhand | 0:e89d7a0bfa3b | 441 | |
| roryhand | 3:6169aeeaeeb4 | 442 | |
| roryhand | 3:6169aeeaeeb4 | 443 | |
| roryhand | 3:6169aeeaeeb4 | 444 | |
| roryhand | 3:6169aeeaeeb4 | 445 | |
| roryhand | 45:0e8e1f2ec5d2 | 446 | classSoundFile ReadFileInfo(classSoundFile Sound, FILE * wav_file) |
| roryhand | 0:e89d7a0bfa3b | 447 | { |
| roryhand | 0:e89d7a0bfa3b | 448 | fseek(wav_file,20,SEEK_SET); |
| roryhand | 22:706e86dc0d45 | 449 | printf("We have just seeked through this file\n\r"); |
| roryhand | 45:0e8e1f2ec5d2 | 450 | fread(&Sound.FileInfo.FileFormat,sizeof(Sound.FileInfo.FileFormat),1,wav_file); |
| roryhand | 1:aac37edee302 | 451 | //printf("wav_format.sample_rate: %d\n\r",FileInfo.FileFormat.sample_rate); |
| roryhand | 1:aac37edee302 | 452 | |
| roryhand | 45:0e8e1f2ec5d2 | 453 | fread(&Sound.FileInfo.FileData,sizeof(Sound.FileInfo.FileData),1,wav_file); |
| roryhand | 55:5a441d3b0d57 | 454 | printf("wav_data.subchunk2_size: %d\n\r",Sound.FileInfo.FileData.subchunk2_size); |
| roryhand | 45:0e8e1f2ec5d2 | 455 | Sound.FileInfo.slice_buf = ( char *)malloc(Sound.FileInfo.FileFormat.block_align); |
| roryhand | 59:8e7c25a915a0 | 456 | printf("Wav File Block Align (number of bytes per sample!!: %d\n\r", Sound.FileInfo.FileFormat.block_align); |
| roryhand | 45:0e8e1f2ec5d2 | 457 | fread(Sound.FileInfo.slice_buf,Sound.FileInfo.FileFormat.block_align,1,wav_file); //This isnt actually required, its just a test |
| roryhand | 45:0e8e1f2ec5d2 | 458 | Sound.FileInfo.num_slices = Sound.FileInfo.FileData.subchunk2_size/Sound.FileInfo.FileFormat.block_align; |
| roryhand | 1:aac37edee302 | 459 | //printf("Number of Slices: %d\n\r",FileInfo.num_slices); |
| roryhand | 45:0e8e1f2ec5d2 | 460 | return Sound; |
| roryhand | 0:e89d7a0bfa3b | 461 | } |
| roryhand | 1:aac37edee302 | 462 | |
| roryhand | 1:aac37edee302 | 463 | |
| roryhand | 64:6061ffe25985 | 464 | //Function to initialise Data for classFade objects. Perhaps move this into a constructor for the class? (class still to be added) |
| roryhand | 64:6061ffe25985 | 465 | classFade FadeDataInitialise(classFade FadeData) |
| roryhand | 64:6061ffe25985 | 466 | { |
| roryhand | 64:6061ffe25985 | 467 | FadeData.DecayFactor = 1.3; |
| roryhand | 64:6061ffe25985 | 468 | FadeData.FadeIteration = 1; |
| roryhand | 64:6061ffe25985 | 469 | //FadeData.Denom = 11025*FadeData.DecayFactor; |
| roryhand | 64:6061ffe25985 | 470 | FadeData.Denom = 11025*FadeData.DecayFactor; |
| roryhand | 64:6061ffe25985 | 471 | FadeData.Natural_Exp = 2.7183; |
| roryhand | 64:6061ffe25985 | 472 | FadeData.Length = 11025*FadeData.LengthSecs; |
| roryhand | 64:6061ffe25985 | 473 | //FadeData.Natural_Exp = 2.7; |
| roryhand | 64:6061ffe25985 | 474 | return FadeData; |
| roryhand | 64:6061ffe25985 | 475 | } |
| roryhand | 1:aac37edee302 | 476 | |
| roryhand | 1:aac37edee302 | 477 | |
| roryhand | 1:aac37edee302 | 478 | |
| roryhand | 0:e89d7a0bfa3b | 479 | |
| roryhand | 0:e89d7a0bfa3b | 480 | void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo) |
| roryhand | 0:e89d7a0bfa3b | 481 | { |
| roryhand | 1:aac37edee302 | 482 | while(slice<FileInfo.num_slices) { |
| roryhand | 1:aac37edee302 | 483 | fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,my_wav); |
| roryhand | 1:aac37edee302 | 484 | data_sptr=(short *)FileInfo.slice_buf; // 16 bit samples |
| roryhand | 1:aac37edee302 | 485 | for (channel=0; channel<FileInfo.FileFormat.num_channels; channel++) { |
| roryhand | 1:aac37edee302 | 486 | if(flag1 == 1) { |
| roryhand | 1:aac37edee302 | 487 | Buffer1[place_hold1] = data_sptr[channel]; |
| roryhand | 1:aac37edee302 | 488 | place_hold1 = place_hold1 + 1; |
| roryhand | 1:aac37edee302 | 489 | if(place_hold1 >= BufferLen) { |
| roryhand | 1:aac37edee302 | 490 | while(1) { |
| roryhand | 1:aac37edee302 | 491 | if(flag1 == 0) { |
| roryhand | 0:e89d7a0bfa3b | 492 | |
| roryhand | 1:aac37edee302 | 493 | break; |
| roryhand | 0:e89d7a0bfa3b | 494 | } |
| roryhand | 1:aac37edee302 | 495 | |
| roryhand | 0:e89d7a0bfa3b | 496 | } |
| roryhand | 1:aac37edee302 | 497 | } |
| roryhand | 1:aac37edee302 | 498 | |
| roryhand | 1:aac37edee302 | 499 | } else if(flag2 == 1) { |
| roryhand | 1:aac37edee302 | 500 | Buffer2[place_hold2] = data_sptr[channel]; |
| roryhand | 1:aac37edee302 | 501 | place_hold2 = place_hold2 + 1; |
| roryhand | 1:aac37edee302 | 502 | if(place_hold2 >= BufferLen) { |
| roryhand | 1:aac37edee302 | 503 | |
| roryhand | 1:aac37edee302 | 504 | while(1) { |
| roryhand | 1:aac37edee302 | 505 | if(flag2 == 0) { |
| roryhand | 1:aac37edee302 | 506 | |
| roryhand | 1:aac37edee302 | 507 | break; |
| roryhand | 1:aac37edee302 | 508 | } |
| roryhand | 0:e89d7a0bfa3b | 509 | } |
| roryhand | 1:aac37edee302 | 510 | } |
| roryhand | 0:e89d7a0bfa3b | 511 | } |
| roryhand | 1:aac37edee302 | 512 | |
| roryhand | 1:aac37edee302 | 513 | } |
| roryhand | 1:aac37edee302 | 514 | slice = slice + 1; |
| roryhand | 0:e89d7a0bfa3b | 515 | } |
| roryhand | 0:e89d7a0bfa3b | 516 | } |
| roryhand | 0:e89d7a0bfa3b | 517 | |
| roryhand | 0:e89d7a0bfa3b | 518 | |
| roryhand | 0:e89d7a0bfa3b | 519 | |
| roryhand | 0:e89d7a0bfa3b | 520 | |
| roryhand | 38:3b4c05af5f36 | 521 | //***************************************************************************// |
| roryhand | 38:3b4c05af5f36 | 522 | |
| roryhand | 38:3b4c05af5f36 | 523 | //**************************************************************************// |
| roryhand | 38:3b4c05af5f36 | 524 | |
| roryhand | 38:3b4c05af5f36 | 525 | |
| roryhand | 38:3b4c05af5f36 | 526 | |
| roryhand | 38:3b4c05af5f36 | 527 | |
| roryhand | 38:3b4c05af5f36 | 528 | |
| roryhand | 59:8e7c25a915a0 | 529 | |
| roryhand | 44:a9e84d333a6a | 530 | |
| roryhand | 57:0c76b15cabaf | 531 | void Play_WaveFileLoop(classSoundFile Sound1, FILE *wavfile1, classPositionIndicators Positions) |
| roryhand | 45:0e8e1f2ec5d2 | 532 | { |
| roryhand | 45:0e8e1f2ec5d2 | 533 | while(1) { //might have to change this to a while(1) loop? |
| roryhand | 44:a9e84d333a6a | 534 | |
| roryhand | 2:957d3b2afff4 | 535 | |
| roryhand | 44:a9e84d333a6a | 536 | |
| roryhand | 44:a9e84d333a6a | 537 | |
| roryhand | 54:606a83fff291 | 538 | |
| roryhand | 44:a9e84d333a6a | 539 | //Sound1======================================================================================= |
| roryhand | 61:212d2db45c56 | 540 | if( slice1 == (Positions.notch8_start_pt) ) { |
| roryhand | 61:212d2db45c56 | 541 | slice1 = Positions.notch7_start_pt; |
| roryhand | 61:212d2db45c56 | 542 | fseek(wavfile1,Positions.notch7_start_pt,SEEK_SET); |
| roryhand | 2:957d3b2afff4 | 543 | } |
| roryhand | 57:0c76b15cabaf | 544 | |
| roryhand | 44:a9e84d333a6a | 545 | fread(Sound1.FileInfo.slice_buf,Sound1.FileInfo.FileFormat.block_align,1,wavfile1); |
| roryhand | 44:a9e84d333a6a | 546 | Sound1.data_sptr=(short *)Sound1.FileInfo.slice_buf; // 16 bit samples |
| roryhand | 44:a9e84d333a6a | 547 | //============================================================================================= |
| roryhand | 44:a9e84d333a6a | 548 | |
| roryhand | 58:a174e7a8f5f2 | 549 | |
| roryhand | 1:aac37edee302 | 550 | |
| roryhand | 1:aac37edee302 | 551 | |
| roryhand | 44:a9e84d333a6a | 552 | |
| roryhand | 45:0e8e1f2ec5d2 | 553 | for (channel=0; channel<Sound1.FileInfo.FileFormat.num_channels; channel++) { |
| roryhand | 45:0e8e1f2ec5d2 | 554 | switch (Sound1.FileInfo.FileFormat.sig_bps) { |
| roryhand | 0:e89d7a0bfa3b | 555 | case 16: |
| roryhand | 1:aac37edee302 | 556 | if(flag1 == 1) { |
| roryhand | 45:0e8e1f2ec5d2 | 557 | Buffer1[place_hold1] = Sound1.data_sptr[channel]; |
| roryhand | 1:aac37edee302 | 558 | place_hold1 = place_hold1 + 1; |
| roryhand | 1:aac37edee302 | 559 | if(place_hold1 >= BufferLen) { |
| roryhand | 1:aac37edee302 | 560 | while(1) { |
| roryhand | 1:aac37edee302 | 561 | if(flag1 == 0) { |
| roryhand | 1:aac37edee302 | 562 | break; |
| roryhand | 1:aac37edee302 | 563 | }//if(flag1 == 0) |
| roryhand | 1:aac37edee302 | 564 | |
| roryhand | 1:aac37edee302 | 565 | |
| roryhand | 1:aac37edee302 | 566 | }//while(1) |
| roryhand | 1:aac37edee302 | 567 | }//if(place_hold1 > = BufferLen) |
| roryhand | 0:e89d7a0bfa3b | 568 | |
| roryhand | 1:aac37edee302 | 569 | } else if(flag2 == 1) { |
| roryhand | 45:0e8e1f2ec5d2 | 570 | Buffer2[place_hold2] = Sound1.data_sptr[channel]; |
| roryhand | 1:aac37edee302 | 571 | place_hold2 = place_hold2 + 1; |
| roryhand | 1:aac37edee302 | 572 | if(place_hold2 >= BufferLen) { |
| roryhand | 1:aac37edee302 | 573 | while(1) { |
| roryhand | 1:aac37edee302 | 574 | |
| roryhand | 1:aac37edee302 | 575 | if(flag2 == 0) { |
| roryhand | 1:aac37edee302 | 576 | break; |
| roryhand | 1:aac37edee302 | 577 | } |
| roryhand | 1:aac37edee302 | 578 | } |
| roryhand | 0:e89d7a0bfa3b | 579 | } |
| roryhand | 1:aac37edee302 | 580 | |
| roryhand | 1:aac37edee302 | 581 | } |
| roryhand | 0:e89d7a0bfa3b | 582 | } |
| roryhand | 0:e89d7a0bfa3b | 583 | } |
| roryhand | 59:8e7c25a915a0 | 584 | 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 | 585 | slice2 = slice2 + 1; |
| roryhand | 45:0e8e1f2ec5d2 | 586 | slice3 = slice3 + 1; |
| roryhand | 0:e89d7a0bfa3b | 587 | } |
| roryhand | 0:e89d7a0bfa3b | 588 | } |
| roryhand | 0:e89d7a0bfa3b | 589 | |
| roryhand | 0:e89d7a0bfa3b | 590 | |
| roryhand | 0:e89d7a0bfa3b | 591 | |
| roryhand | 0:e89d7a0bfa3b | 592 | |
| roryhand | 0:e89d7a0bfa3b | 593 | |
| roryhand | 0:e89d7a0bfa3b | 594 | |
| roryhand | 59:8e7c25a915a0 | 595 | |
| roryhand | 59:8e7c25a915a0 | 596 |