old demo that i want to try in mbed studio

Dependencies:   mbed SDFileSystem_Copy_of_mbed_version I2S

Committer:
roryhand
Date:
Tue Oct 01 20:40:43 2019 +0000
Branch:
LargeFile_Tests
Revision:
79:00cc7799407f
Parent:
78:69a0c7a5fbdf
Child:
80:9c70dc3fc16b
WIP - the issue i am getting here does not make any logical sense.  Once I have assigned a variable, it should not make any difference if i change the variable i assigned it to

Who changed what in which revision?

UserRevisionLine numberNew 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 79:00cc7799407f 298 /*
roryhand 79:00cc7799407f 299 if(SoundFlag == 1) {
roryhand 79:00cc7799407f 300 SoundFlag = 3;
roryhand 79:00cc7799407f 301 } else {
roryhand 79:00cc7799407f 302
roryhand 79:00cc7799407f 303
roryhand 79:00cc7799407f 304 SoundFlag = 1;
roryhand 79:00cc7799407f 305 }
roryhand 79:00cc7799407f 306 */
roryhand 74:e71a7815f63d 307 //printf("We are in the NotchUpIsr() section \n\r");
roryhand 67:043fe0b81343 308 //NotchFadeOut.FadeDataInitialise;
roryhand 66:edf370edd21c 309 }
roryhand 66:edf370edd21c 310 }
roryhand 66:edf370edd21c 311
roryhand 66:edf370edd21c 312 void NotchDownIsr()
roryhand 66:edf370edd21c 313 {
roryhand 66:edf370edd21c 314 if(1 < NotchingSet.Notch <= 8) {
roryhand 66:edf370edd21c 315 NotchingSet.Notch = NotchingSet.Notch - 1;
roryhand 67:043fe0b81343 316 NotchingSet.NotchTransDown = NotchingSet.Notch + 15;
roryhand 66:edf370edd21c 317 NotchingSet.NotchDirection = 0;
roryhand 67:043fe0b81343 318 NotchFadeIn.FadeDataInitialise();
roryhand 67:043fe0b81343 319 NotchFadeOut.FadeDataInitialise();
roryhand 74:e71a7815f63d 320 TransitionFlag = 1;
roryhand 66:edf370edd21c 321 }
roryhand 66:edf370edd21c 322 }
roryhand 73:a5ab93214728 323 short * data_sptr1;
roryhand 73:a5ab93214728 324 short * data_sptr2;
roryhand 73:a5ab93214728 325 short * data_sptr3;
roryhand 69:df10ee3ad523 326 char *slice_buf1;
roryhand 69:df10ee3ad523 327 char *slice_buf2;
roryhand 69:df10ee3ad523 328 char *slice_buf3;
roryhand 67:043fe0b81343 329
roryhand 54:606a83fff291 330 int OneOff = 0;
roryhand 38:3b4c05af5f36 331 int notch_flag = 0;
roryhand 0:e89d7a0bfa3b 332 int i = 0;
roryhand 0:e89d7a0bfa3b 333 int h = 0;
roryhand 0:e89d7a0bfa3b 334 short bufflen = 1;
roryhand 0:e89d7a0bfa3b 335 int buffer[1];
roryhand 1:aac37edee302 336 int AudioFormat, NumChannels, SampleRate, BitsPerSample ;
roryhand 0:e89d7a0bfa3b 337 char *slice_buf;
roryhand 0:e89d7a0bfa3b 338 short *data_sptr;
roryhand 0:e89d7a0bfa3b 339 short *data_sptr_horn;
roryhand 0:e89d7a0bfa3b 340 short *data_sptr_IdleN2;
roryhand 0:e89d7a0bfa3b 341 short * data_sptr_bell;
roryhand 0:e89d7a0bfa3b 342 short * data_sptr_N2;
roryhand 0:e89d7a0bfa3b 343 short * data_sptr_Flange;
roryhand 0:e89d7a0bfa3b 344 unsigned char *data_bptr;
roryhand 0:e89d7a0bfa3b 345 int *data_wptr;
roryhand 0:e89d7a0bfa3b 346 unsigned channel;
roryhand 45:0e8e1f2ec5d2 347 long slice, slice1, slice2, slice3, num_slices;
roryhand 0:e89d7a0bfa3b 348 int verbosity = 0;
roryhand 0:e89d7a0bfa3b 349 int verbosity2 = 0;
roryhand 0:e89d7a0bfa3b 350 int verbosity3 = 0;
roryhand 0:e89d7a0bfa3b 351 int verbosity4 = 0;
roryhand 0:e89d7a0bfa3b 352 int verbosity5 = 0;
roryhand 0:e89d7a0bfa3b 353 int interrupt_condition = 1;
roryhand 0:e89d7a0bfa3b 354 int sampling_freq = 11025;
roryhand 0:e89d7a0bfa3b 355 const int BufferLen = 2000;
roryhand 0:e89d7a0bfa3b 356 short Buffer1[BufferLen];
roryhand 0:e89d7a0bfa3b 357 short Buffer2[BufferLen];
roryhand 0:e89d7a0bfa3b 358 short place_hold1 = 0;
roryhand 0:e89d7a0bfa3b 359 short place_hold2 = 0;
roryhand 0:e89d7a0bfa3b 360
roryhand 3:6169aeeaeeb4 361
roryhand 3:6169aeeaeeb4 362 string FOLDER;
roryhand 3:6169aeeaeeb4 363 string RootFolder = "/sd/mydir/SoundDecoder/";
roryhand 3:6169aeeaeeb4 364 string filename[25];
roryhand 3:6169aeeaeeb4 365 classSoundFile Sound[22];
roryhand 3:6169aeeaeeb4 366
roryhand 0:e89d7a0bfa3b 367 volatile int flag1 = 1;
roryhand 0:e89d7a0bfa3b 368 volatile int flag2 = 0;
roryhand 0:e89d7a0bfa3b 369 volatile int flag3 = 1;
roryhand 0:e89d7a0bfa3b 370 volatile int flag4 = 0;
roryhand 0:e89d7a0bfa3b 371 int FLAGBUFF1 = 0;
roryhand 0:e89d7a0bfa3b 372 int FLAGBUFF2 = 0;
roryhand 0:e89d7a0bfa3b 373 int BellFlag = 0;
roryhand 0:e89d7a0bfa3b 374 int BellFlag2 = 0;
roryhand 0:e89d7a0bfa3b 375 int FadeFlag = 0;
roryhand 54:606a83fff291 376 int BlockFlag = 0;
roryhand 32:6ee488c97dcc 377 int FileSwitchFlag = 0;
roryhand 0:e89d7a0bfa3b 378
roryhand 0:e89d7a0bfa3b 379
roryhand 0:e89d7a0bfa3b 380 short value[1];
roryhand 59:8e7c25a915a0 381
roryhand 0:e89d7a0bfa3b 382 //long long slice_value;
roryhand 0:e89d7a0bfa3b 383 int slice_value[1];
roryhand 0:e89d7a0bfa3b 384
roryhand 0:e89d7a0bfa3b 385
roryhand 45:0e8e1f2ec5d2 386 FILE *wavfile1;
roryhand 45:0e8e1f2ec5d2 387 FILE *wavfile2;
roryhand 45:0e8e1f2ec5d2 388 FILE *wavfile3;
roryhand 45:0e8e1f2ec5d2 389
roryhand 45:0e8e1f2ec5d2 390 classSoundFile Sound1;
roryhand 45:0e8e1f2ec5d2 391 classSoundFile Sound2;
roryhand 45:0e8e1f2ec5d2 392 classSoundFile Sound3;
roryhand 45:0e8e1f2ec5d2 393
roryhand 0:e89d7a0bfa3b 394
roryhand 0:e89d7a0bfa3b 395 void isr()
roryhand 0:e89d7a0bfa3b 396 {
roryhand 54:606a83fff291 397 //timer_interrupt.start();
roryhand 1:aac37edee302 398 if(flag1 == 0) {
roryhand 0:e89d7a0bfa3b 399 value[0] = Buffer1[place_hold1]>>4;
roryhand 0:e89d7a0bfa3b 400 i2s.write(value,1);//Send next PWM value to amp
roryhand 0:e89d7a0bfa3b 401 place_hold1 = place_hold1 + 1;
roryhand 1:aac37edee302 402 if( (place_hold1 >= BufferLen)) {
roryhand 0:e89d7a0bfa3b 403 led2 = !led2;
roryhand 0:e89d7a0bfa3b 404 place_hold1 = 0;
roryhand 0:e89d7a0bfa3b 405 place_hold2 = 0;
roryhand 0:e89d7a0bfa3b 406 flag1 = 1;
roryhand 0:e89d7a0bfa3b 407 flag2 = 0;
roryhand 1:aac37edee302 408 }
roryhand 1:aac37edee302 409 } else if(flag2 == 0) {
roryhand 0:e89d7a0bfa3b 410 value[0] = Buffer2[place_hold2]>>4;
roryhand 0:e89d7a0bfa3b 411 i2s.write(value,1);//Send next PWM value to amp
roryhand 0:e89d7a0bfa3b 412 place_hold2 = place_hold2 + 1;
roryhand 1:aac37edee302 413 if( (place_hold2 >= BufferLen) ) {
roryhand 0:e89d7a0bfa3b 414 led2 = !led2;
roryhand 0:e89d7a0bfa3b 415 place_hold1 = 0;
roryhand 0:e89d7a0bfa3b 416 place_hold2 = 0;
roryhand 0:e89d7a0bfa3b 417 flag1 = 0;
roryhand 1:aac37edee302 418 flag2 = 1;
roryhand 0:e89d7a0bfa3b 419 FLAGBUFF2 = 0;
roryhand 1:aac37edee302 420 }
roryhand 0:e89d7a0bfa3b 421 }
roryhand 54:606a83fff291 422
roryhand 54:606a83fff291 423 //timer_interrupt.stop();
roryhand 54:606a83fff291 424
roryhand 0:e89d7a0bfa3b 425 }
roryhand 1:aac37edee302 426
roryhand 38:3b4c05af5f36 427
roryhand 38:3b4c05af5f36 428
roryhand 38:3b4c05af5f36 429
roryhand 38:3b4c05af5f36 430
roryhand 0:e89d7a0bfa3b 431
roryhand 59:8e7c25a915a0 432
roryhand 59:8e7c25a915a0 433
roryhand 59:8e7c25a915a0 434
roryhand 59:8e7c25a915a0 435
roryhand 59:8e7c25a915a0 436
roryhand 3:6169aeeaeeb4 437
roryhand 3:6169aeeaeeb4 438
roryhand 3:6169aeeaeeb4 439
roryhand 3:6169aeeaeeb4 440
roryhand 3:6169aeeaeeb4 441
roryhand 3:6169aeeaeeb4 442 //function prototypes
roryhand 67:043fe0b81343 443 //classFade FadeDataInitialise(classFade FadeData);
roryhand 45:0e8e1f2ec5d2 444 classSoundFile ReadFileInfo(classSoundFile Sound, FILE * wav_file);
roryhand 3:6169aeeaeeb4 445 classSoundFile LoadFileStream(classSoundFile FileInfo, string filename);
roryhand 3:6169aeeaeeb4 446 void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo);
roryhand 32:6ee488c97dcc 447 void Play_WaveFileDual(FILE * my_wav, WAV_FILE_STRUCT FileInfo);
roryhand 79:00cc7799407f 448 void Play_WaveFileLoop(classSoundFile Sound1, classSoundFile Sound2, classSoundFile Sound3, FILE* wavfile1, FILE* wavfile2,classPositionIndicators Positions);
roryhand 0:e89d7a0bfa3b 449
roryhand 1:aac37edee302 450 int main()
roryhand 1:aac37edee302 451 {
roryhand 44:a9e84d333a6a 452
roryhand 0:e89d7a0bfa3b 453 NotchUp.mode(PullUp);
roryhand 38:3b4c05af5f36 454 NotchDown.mode(PullUp);
roryhand 0:e89d7a0bfa3b 455
roryhand 0:e89d7a0bfa3b 456 pc.printf("Beginning of program\n");
roryhand 32:6ee488c97dcc 457
roryhand 13:8e93396a27c5 458
roryhand 13:8e93396a27c5 459
roryhand 4:55fbbb049bae 460
roryhand 25:5336e1cf38d6 461 printf("Do we even get to this stupid bloody point\n\r");
roryhand 0:e89d7a0bfa3b 462 //Populate our class instances with some data (is there an implicit way to do this?)
roryhand 28:6b2353fad12d 463
roryhand 1:aac37edee302 464
roryhand 3:6169aeeaeeb4 465 printf("hello\n\r");
roryhand 0:e89d7a0bfa3b 466 //Set up the wolfson Audio Codec board
roryhand 79:00cc7799407f 467
roryhand 79:00cc7799407f 468
roryhand 0:e89d7a0bfa3b 469 wm8731_Config_setup();
roryhand 0:e89d7a0bfa3b 470 //i2s audio data transfer code??
roryhand 0:e89d7a0bfa3b 471 i2s.stereomono(I2S_STEREO);
roryhand 0:e89d7a0bfa3b 472 i2s.masterslave(I2S_MASTER);
roryhand 0:e89d7a0bfa3b 473 led3 = 1;
roryhand 0:e89d7a0bfa3b 474 led2 = 1;
roryhand 45:0e8e1f2ec5d2 475 printf("Hello i2s has started!");
roryhand 30:4a8e80b243c4 476 i2s.start();
roryhand 0:e89d7a0bfa3b 477 sampletick.attach(&isr,1.0/sampling_freq); //1/16000
roryhand 79:00cc7799407f 478 NotchUpTick.attach(&NotchUpIsr,8.0);
roryhand 67:043fe0b81343 479
roryhand 74:e71a7815f63d 480
roryhand 74:e71a7815f63d 481
roryhand 67:043fe0b81343 482 NotchFadeIn.LengthSecs = 2;
roryhand 67:043fe0b81343 483 NotchFadeOut.LengthSecs = 2;
roryhand 67:043fe0b81343 484
roryhand 67:043fe0b81343 485 NotchFadeIn.FadeDataInitialise();
roryhand 67:043fe0b81343 486 NotchFadeOut.FadeDataInitialise();
roryhand 67:043fe0b81343 487
roryhand 74:e71a7815f63d 488
roryhand 58:a174e7a8f5f2 489 classPositionIndicators Positions;
roryhand 74:e71a7815f63d 490 slice1 = Positions.notch_start_pts[1];
roryhand 79:00cc7799407f 491
roryhand 79:00cc7799407f 492
roryhand 79:00cc7799407f 493
roryhand 73:a5ab93214728 494 TransitionFlag = 0;
roryhand 79:00cc7799407f 495
roryhand 60:36df2997de3d 496 FILE* wavfile1 = fopen("/sd/mydir/SoundDecoder_second/All_eight_notches.wav","rb");
roryhand 74:e71a7815f63d 497 FILE* wavfile2 = fopen("/sd/mydir/SoundDecoder_second/All_14_Notch_Transitions.wav","rb");
roryhand 79:00cc7799407f 498 FILE* wavfile3 = fopen("/sd/mydir/SoundDecoder_second/All_eight_notches.wav","rb");
roryhand 60:36df2997de3d 499 //FILE* wavfile1 = fopen("/sd/mydir/SoundDecoder_second/01.wav","rb");
roryhand 58:a174e7a8f5f2 500 classSoundFile Sound1;
roryhand 73:a5ab93214728 501 classSoundFile Sound2;
roryhand 79:00cc7799407f 502 Sound3 = ReadFileInfo(Sound1, wavfile3);
roryhand 73:a5ab93214728 503 Sound2 = ReadFileInfo(Sound2, wavfile2);
roryhand 58:a174e7a8f5f2 504 Sound1 = ReadFileInfo(Sound1, wavfile1);
roryhand 73:a5ab93214728 505 NotchingSet.Notch = 1;
roryhand 77:e93c944ed30f 506 //Positions.notch_position_indicators[1] = 44;
roryhand 73:a5ab93214728 507 fseek(wavfile1,Positions.notch_start_pts[1],SEEK_SET);
roryhand 73:a5ab93214728 508 fseek(wavfile2,Positions.notch_transitions_start_pts[1],SEEK_SET);
roryhand 79:00cc7799407f 509 fseek(wavfile3,Positions.notch_transitions_start_pts[2],Positions.notch_transitions_start_pts[2]);
roryhand 20:9cc7d825c07b 510 printf("about to play wav file\n\r");
roryhand 79:00cc7799407f 511 Play_WaveFileLoop(Sound1,Sound2, Sound3, wavfile1,wavfile2, Positions);
roryhand 20:9cc7d825c07b 512 printf("finished playing Wav file\n\r");
roryhand 54:606a83fff291 513
roryhand 54:606a83fff291 514
roryhand 31:0f8c3adf09c3 515 timer_open.reset();
roryhand 31:0f8c3adf09c3 516 timer_open.start();
roryhand 45:0e8e1f2ec5d2 517 fclose(wavfile1);
roryhand 31:0f8c3adf09c3 518 timer_open.stop();
roryhand 31:0f8c3adf09c3 519 printf("It took %d useconds to close file\n\r",timer_open.read_us());
roryhand 54:606a83fff291 520
roryhand 54:606a83fff291 521
roryhand 54:606a83fff291 522
roryhand 54:606a83fff291 523
roryhand 9:dd9cae06b202 524 /************************************PLAY WAV FILE LOOP*******************/
roryhand 9:dd9cae06b202 525 /************************************END OF PLAY WAV FILE LOOP*************/
roryhand 13:8e93396a27c5 526
roryhand 13:8e93396a27c5 527
roryhand 1:aac37edee302 528 i2s.stop();
roryhand 79:00cc7799407f 529
roryhand 0:e89d7a0bfa3b 530
roryhand 0:e89d7a0bfa3b 531 }
roryhand 0:e89d7a0bfa3b 532
roryhand 0:e89d7a0bfa3b 533
roryhand 3:6169aeeaeeb4 534
roryhand 3:6169aeeaeeb4 535
roryhand 3:6169aeeaeeb4 536
roryhand 3:6169aeeaeeb4 537
roryhand 45:0e8e1f2ec5d2 538 classSoundFile ReadFileInfo(classSoundFile Sound, FILE * wav_file)
roryhand 0:e89d7a0bfa3b 539 {
roryhand 0:e89d7a0bfa3b 540 fseek(wav_file,20,SEEK_SET);
roryhand 22:706e86dc0d45 541 printf("We have just seeked through this file\n\r");
roryhand 45:0e8e1f2ec5d2 542 fread(&Sound.FileInfo.FileFormat,sizeof(Sound.FileInfo.FileFormat),1,wav_file);
roryhand 1:aac37edee302 543 //printf("wav_format.sample_rate: %d\n\r",FileInfo.FileFormat.sample_rate);
roryhand 1:aac37edee302 544
roryhand 45:0e8e1f2ec5d2 545 fread(&Sound.FileInfo.FileData,sizeof(Sound.FileInfo.FileData),1,wav_file);
roryhand 55:5a441d3b0d57 546 printf("wav_data.subchunk2_size: %d\n\r",Sound.FileInfo.FileData.subchunk2_size);
roryhand 45:0e8e1f2ec5d2 547 Sound.FileInfo.slice_buf = ( char *)malloc(Sound.FileInfo.FileFormat.block_align);
roryhand 59:8e7c25a915a0 548 printf("Wav File Block Align (number of bytes per sample!!: %d\n\r", Sound.FileInfo.FileFormat.block_align);
roryhand 45:0e8e1f2ec5d2 549 fread(Sound.FileInfo.slice_buf,Sound.FileInfo.FileFormat.block_align,1,wav_file); //This isnt actually required, its just a test
roryhand 45:0e8e1f2ec5d2 550 Sound.FileInfo.num_slices = Sound.FileInfo.FileData.subchunk2_size/Sound.FileInfo.FileFormat.block_align;
roryhand 1:aac37edee302 551 //printf("Number of Slices: %d\n\r",FileInfo.num_slices);
roryhand 45:0e8e1f2ec5d2 552 return Sound;
roryhand 0:e89d7a0bfa3b 553 }
roryhand 1:aac37edee302 554
roryhand 1:aac37edee302 555
roryhand 64:6061ffe25985 556 //Function to initialise Data for classFade objects. Perhaps move this into a constructor for the class? (class still to be added)
roryhand 67:043fe0b81343 557 /*
roryhand 64:6061ffe25985 558 classFade FadeDataInitialise(classFade FadeData)
roryhand 64:6061ffe25985 559 {
roryhand 64:6061ffe25985 560 FadeData.DecayFactor = 1.3;
roryhand 64:6061ffe25985 561 FadeData.FadeIteration = 1;
roryhand 64:6061ffe25985 562 //FadeData.Denom = 11025*FadeData.DecayFactor;
roryhand 64:6061ffe25985 563 FadeData.Denom = 11025*FadeData.DecayFactor;
roryhand 64:6061ffe25985 564 FadeData.Natural_Exp = 2.7183;
roryhand 64:6061ffe25985 565 FadeData.Length = 11025*FadeData.LengthSecs;
roryhand 64:6061ffe25985 566 //FadeData.Natural_Exp = 2.7;
roryhand 64:6061ffe25985 567 return FadeData;
roryhand 64:6061ffe25985 568 }
roryhand 67:043fe0b81343 569 */
roryhand 1:aac37edee302 570
roryhand 1:aac37edee302 571
roryhand 1:aac37edee302 572
roryhand 0:e89d7a0bfa3b 573
roryhand 0:e89d7a0bfa3b 574 void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo)
roryhand 0:e89d7a0bfa3b 575 {
roryhand 1:aac37edee302 576 while(slice<FileInfo.num_slices) {
roryhand 1:aac37edee302 577 fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,my_wav);
roryhand 1:aac37edee302 578 data_sptr=(short *)FileInfo.slice_buf; // 16 bit samples
roryhand 1:aac37edee302 579 for (channel=0; channel<FileInfo.FileFormat.num_channels; channel++) {
roryhand 1:aac37edee302 580 if(flag1 == 1) {
roryhand 1:aac37edee302 581 Buffer1[place_hold1] = data_sptr[channel];
roryhand 1:aac37edee302 582 place_hold1 = place_hold1 + 1;
roryhand 1:aac37edee302 583 if(place_hold1 >= BufferLen) {
roryhand 1:aac37edee302 584 while(1) {
roryhand 1:aac37edee302 585 if(flag1 == 0) {
roryhand 0:e89d7a0bfa3b 586
roryhand 1:aac37edee302 587 break;
roryhand 0:e89d7a0bfa3b 588 }
roryhand 1:aac37edee302 589
roryhand 0:e89d7a0bfa3b 590 }
roryhand 1:aac37edee302 591 }
roryhand 1:aac37edee302 592
roryhand 1:aac37edee302 593 } else if(flag2 == 1) {
roryhand 1:aac37edee302 594 Buffer2[place_hold2] = data_sptr[channel];
roryhand 1:aac37edee302 595 place_hold2 = place_hold2 + 1;
roryhand 1:aac37edee302 596 if(place_hold2 >= BufferLen) {
roryhand 1:aac37edee302 597
roryhand 1:aac37edee302 598 while(1) {
roryhand 1:aac37edee302 599 if(flag2 == 0) {
roryhand 1:aac37edee302 600
roryhand 1:aac37edee302 601 break;
roryhand 1:aac37edee302 602 }
roryhand 0:e89d7a0bfa3b 603 }
roryhand 1:aac37edee302 604 }
roryhand 0:e89d7a0bfa3b 605 }
roryhand 1:aac37edee302 606
roryhand 1:aac37edee302 607 }
roryhand 1:aac37edee302 608 slice = slice + 1;
roryhand 0:e89d7a0bfa3b 609 }
roryhand 0:e89d7a0bfa3b 610 }
roryhand 0:e89d7a0bfa3b 611
roryhand 0:e89d7a0bfa3b 612
roryhand 0:e89d7a0bfa3b 613
roryhand 0:e89d7a0bfa3b 614
roryhand 38:3b4c05af5f36 615 //***************************************************************************//
roryhand 38:3b4c05af5f36 616
roryhand 38:3b4c05af5f36 617 //**************************************************************************//
roryhand 38:3b4c05af5f36 618
roryhand 38:3b4c05af5f36 619
roryhand 38:3b4c05af5f36 620
roryhand 38:3b4c05af5f36 621
roryhand 38:3b4c05af5f36 622
roryhand 59:8e7c25a915a0 623
roryhand 44:a9e84d333a6a 624
roryhand 79:00cc7799407f 625 void Play_WaveFileLoop(classSoundFile Sound1, classSoundFile Sound2, classSoundFile Sound3, FILE *wavfile1, FILE* wavfile2, classPositionIndicators Positions)
roryhand 45:0e8e1f2ec5d2 626 {
roryhand 45:0e8e1f2ec5d2 627 while(1) { //might have to change this to a while(1) loop?
roryhand 44:a9e84d333a6a 628
roryhand 2:957d3b2afff4 629
roryhand 44:a9e84d333a6a 630
roryhand 44:a9e84d333a6a 631
roryhand 54:606a83fff291 632
roryhand 44:a9e84d333a6a 633 //Sound1=======================================================================================
roryhand 69:df10ee3ad523 634 if( slice1 == (Positions.notch_start_pts[NotchingSet.Notch + 1]) ) {
roryhand 69:df10ee3ad523 635 slice1 = Positions.notch_start_pts[NotchingSet.Notch];
roryhand 69:df10ee3ad523 636 fseek(wavfile1,Positions.notch_start_pts[NotchingSet.Notch],SEEK_SET);
roryhand 67:043fe0b81343 637 }
roryhand 79:00cc7799407f 638 if(TransitionFlag) {
roryhand 79:00cc7799407f 639
roryhand 74:e71a7815f63d 640 //printf("TransitionFlag == 1, so now we are going to do some other processing\n\r");
roryhand 73:a5ab93214728 641 //NOTCH 1
roryhand 75:8a71e269b890 642 //OperationsTimer.reset();
roryhand 75:8a71e269b890 643 //OperationsTimer.start();
roryhand 77:e93c944ed30f 644 //fpos_t position;
roryhand 77:e93c944ed30f 645 //fgetpos(wavfile1,&position);
roryhand 77:e93c944ed30f 646 //printf("Positions.notch_position_indicators[NotchingSet.Notch]: %d\n\r",Positions.notch_position_indicators[NotchingSet.Notch]);
roryhand 77:e93c944ed30f 647 fseek(wavfile1,Positions.notch_position_indicators[NotchingSet.Notch-1],Positions.notch_position_indicators[NotchingSet.Notch-1]);
roryhand 77:e93c944ed30f 648 ////fsetpos(wavfile1, &position);
roryhand 75:8a71e269b890 649 //OperationsTimer.stop();
roryhand 75:8a71e269b890 650 //printf("It took %d useconds to perform fseek operation.\n\r",OperationsTimer.read_us());
roryhand 74:e71a7815f63d 651 //printf("We have seeked through the file\n\r");
roryhand 79:00cc7799407f 652
roryhand 79:00cc7799407f 653
roryhand 77:e93c944ed30f 654 //printf("Size of Sound1.FileInfo.FileFormat.block_align: %d\n\r",Sound1.FileInfo.FileFormat.block_align);
roryhand 79:00cc7799407f 655
roryhand 77:e93c944ed30f 656 /*
roryhand 75:8a71e269b890 657 OperationsTimer.reset();
roryhand 75:8a71e269b890 658 OperationsTimer.start();
roryhand 77:e93c944ed30f 659 */
roryhand 79:00cc7799407f 660
roryhand 78:69a0c7a5fbdf 661 fseek(wavfile1,Positions.notch_position_indicators[NotchingSet.Notch-1],Positions.notch_position_indicators[NotchingSet.Notch-1]);
roryhand 74:e71a7815f63d 662 fread(Sound1.FileInfo.slice_buf, Sound1.FileInfo.FileFormat.block_align,1,wavfile1);
roryhand 78:69a0c7a5fbdf 663 data_sptr1=(short *)Sound1.FileInfo.slice_buf;
roryhand 78:69a0c7a5fbdf 664 Positions.notch_position_indicators[NotchingSet.Notch-1] = Positions.notch_position_indicators[NotchingSet.Notch-1] + 2;
roryhand 79:00cc7799407f 665
roryhand 78:69a0c7a5fbdf 666
roryhand 79:00cc7799407f 667
roryhand 77:e93c944ed30f 668 /*
roryhand 75:8a71e269b890 669 OperationsTimer.stop();
roryhand 75:8a71e269b890 670 printf("It took %d useconds to perform fread operation.\n\r",OperationsTimer.read_us());
roryhand 77:e93c944ed30f 671 */
roryhand 74:e71a7815f63d 672 //printf("We have now read in 2 bytes of data (i.e. 1 sample)\n\r");
roryhand 78:69a0c7a5fbdf 673
roryhand 74:e71a7815f63d 674 //printf("We have now cast this data to a short data type\n\r");
roryhand 79:00cc7799407f 675
roryhand 79:00cc7799407f 676
roryhand 78:69a0c7a5fbdf 677
roryhand 79:00cc7799407f 678
roryhand 79:00cc7799407f 679
roryhand 74:e71a7815f63d 680 //printf("We have incremented up the Positions.notch_position_indicator");
roryhand 72:599068243a0f 681 //increment up the position indicator!
roryhand 79:00cc7799407f 682
roryhand 73:a5ab93214728 683 //NOTCH 2
roryhand 77:e93c944ed30f 684 /*
roryhand 77:e93c944ed30f 685 fseek(wavfile1,Positions.notch_position_indicators[NotchingSet.Notch],Positions.notch_position_indicators[NotchingSet.Notch]);
roryhand 79:00cc7799407f 686 fread(Sound3.FileInfo.slice_buf, Sound3.FileInfo.FileFormat.block_align,1,wavfile1);
roryhand 79:00cc7799407f 687 data_sptr3=(short *)Sound3.FileInfo.slice_buf;
roryhand 77:e93c944ed30f 688 Positions.notch_position_indicators[NotchingSet.Notch] = Positions.notch_position_indicators[NotchingSet.Notch] + 2;
roryhand 77:e93c944ed30f 689 */
roryhand 72:599068243a0f 690 //increment up the position indicator!
roryhand 79:00cc7799407f 691
roryhand 79:00cc7799407f 692
roryhand 69:df10ee3ad523 693 if(NotchingSet.NotchDirection)
roryhand 69:df10ee3ad523 694
roryhand 69:df10ee3ad523 695 {
roryhand 75:8a71e269b890 696 //printf("Reached if(NotchingSet.NotchDirection)\n\r");
roryhand 69:df10ee3ad523 697
roryhand 73:a5ab93214728 698 //N1 N2 Transition
roryhand 77:e93c944ed30f 699 fseek(wavfile2,Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp],Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp]);
roryhand 74:e71a7815f63d 700 fread(Sound1.FileInfo.slice_buf, Sound1.FileInfo.FileFormat.block_align,1,wavfile2);
roryhand 79:00cc7799407f 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 } else {
roryhand 73:a5ab93214728 705 //N1 N2 Transition
roryhand 77:e93c944ed30f 706 fseek(wavfile2,Positions.notch_transitions_position_indicators[NotchingSet.NotchTransDown],Positions.notch_position_indicators[NotchingSet.NotchTransDown]);
roryhand 79:00cc7799407f 707 fread(Sound2.FileInfo.slice_buf, Sound2.FileInfo.FileFormat.block_align,1,wavfile2);
roryhand 77:e93c944ed30f 708 data_sptr2=(short *)Sound2.FileInfo.slice_buf;
roryhand 73:a5ab93214728 709 Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp] = Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp] + 2;
roryhand 69:df10ee3ad523 710
roryhand 69:df10ee3ad523 711 }
roryhand 79:00cc7799407f 712
roryhand 79:00cc7799407f 713
roryhand 79:00cc7799407f 714
roryhand 79:00cc7799407f 715
roryhand 73:a5ab93214728 716 NotchFadeOut.FadeOut();
roryhand 77:e93c944ed30f 717 /*
roryhand 70:2b144da2c3b8 718 if(Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp] >= (Positions.notch_transitions_start_pts[NotchingSet.NotchTransUp+1] - NotchFadeIn.Length))
roryhand 70:2b144da2c3b8 719 {
roryhand 70:2b144da2c3b8 720 NotchFadeIn.FadeIn();
roryhand 70:2b144da2c3b8 721 if(Positions.notch_transitions_position_indicators[NotchingSet.NotchTransUp] >= Positions.notch_transitions_start_pts[NotchingSet.NotchTransUp+1])
roryhand 70:2b144da2c3b8 722 {
roryhand 73:a5ab93214728 723 *Sound1.data_sptr = *data_sptr2*NotchFadeIn.FadeCoeff;
roryhand 73:a5ab93214728 724 TransitionFlag = 0;
roryhand 77:e93c944ed30f 725 fseek(wavfile1,Positions.notch_position_indicators[NotchingSet.Notch],Positions.notch_position_indicators[NotchingSet.Notch]);
roryhand 79:00cc7799407f 726
roryhand 79:00cc7799407f 727 }
roryhand 72:599068243a0f 728 else
roryhand 72:599068243a0f 729 {
roryhand 79:00cc7799407f 730 *Sound1.data_sptr = *data_sptr1*NotchFadeOut.FadeCoeff + *data_sptr2 + *data_sptr3*NotchFadeIn.FadeCoeff;
roryhand 72:599068243a0f 731 }
roryhand 79:00cc7799407f 732
roryhand 79:00cc7799407f 733
roryhand 70:2b144da2c3b8 734 }
roryhand 77:e93c944ed30f 735 */
roryhand 79:00cc7799407f 736
roryhand 77:e93c944ed30f 737 //else
roryhand 77:e93c944ed30f 738 //{
roryhand 79:00cc7799407f 739 *Sound1.data_sptr = *data_sptr1;//*NotchFadeOut.FadeCoeff;// + *data_sptr2;
roryhand 79:00cc7799407f 740 //*Sound1.data_sptr = *data_sptr1;// + *data_sptr2;
roryhand 79:00cc7799407f 741
roryhand 79:00cc7799407f 742
roryhand 79:00cc7799407f 743
roryhand 79:00cc7799407f 744 //include a flag here, to hand over control. Going to get a bit complicated!!!
roryhand 77:e93c944ed30f 745 //}
roryhand 79:00cc7799407f 746
roryhand 79:00cc7799407f 747
roryhand 79:00cc7799407f 748
roryhand 69:df10ee3ad523 749
roryhand 79:00cc7799407f 750
roryhand 69:df10ee3ad523 751
roryhand 79:00cc7799407f 752 } else {
roryhand 79:00cc7799407f 753
roryhand 77:e93c944ed30f 754 /*fseek(wavfile1,Positions.notch_position_indicators[1],SEEK_SET);
roryhand 76:9535aedba4da 755 OperationsTimer.reset();
roryhand 76:9535aedba4da 756 OperationsTimer.start();
roryhand 77:e93c944ed30f 757 */
roryhand 69:df10ee3ad523 758 fread(Sound1.FileInfo.slice_buf,Sound1.FileInfo.FileFormat.block_align,1,wavfile1);
roryhand 77:e93c944ed30f 759 /*OperationsTimer.stop();
roryhand 76:9535aedba4da 760 printf("It took %d useconds to perform fread operation.\n\r",OperationsTimer.read_us());
roryhand 76:9535aedba4da 761 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 762 */
roryhand 69:df10ee3ad523 763 Sound1.data_sptr=(short *)Sound1.FileInfo.slice_buf; // 16 bit samples
roryhand 79:00cc7799407f 764
roryhand 79:00cc7799407f 765 }
roryhand 44:a9e84d333a6a 766 //=============================================================================================
roryhand 44:a9e84d333a6a 767
roryhand 67:043fe0b81343 768
roryhand 1:aac37edee302 769
roryhand 1:aac37edee302 770
roryhand 44:a9e84d333a6a 771
roryhand 45:0e8e1f2ec5d2 772 for (channel=0; channel<Sound1.FileInfo.FileFormat.num_channels; channel++) {
roryhand 45:0e8e1f2ec5d2 773 switch (Sound1.FileInfo.FileFormat.sig_bps) {
roryhand 0:e89d7a0bfa3b 774 case 16:
roryhand 1:aac37edee302 775 if(flag1 == 1) {
roryhand 45:0e8e1f2ec5d2 776 Buffer1[place_hold1] = Sound1.data_sptr[channel];
roryhand 1:aac37edee302 777 place_hold1 = place_hold1 + 1;
roryhand 1:aac37edee302 778 if(place_hold1 >= BufferLen) {
roryhand 1:aac37edee302 779 while(1) {
roryhand 1:aac37edee302 780 if(flag1 == 0) {
roryhand 1:aac37edee302 781 break;
roryhand 1:aac37edee302 782 }//if(flag1 == 0)
roryhand 1:aac37edee302 783
roryhand 1:aac37edee302 784
roryhand 1:aac37edee302 785 }//while(1)
roryhand 1:aac37edee302 786 }//if(place_hold1 > = BufferLen)
roryhand 0:e89d7a0bfa3b 787
roryhand 1:aac37edee302 788 } else if(flag2 == 1) {
roryhand 45:0e8e1f2ec5d2 789 Buffer2[place_hold2] = Sound1.data_sptr[channel];
roryhand 1:aac37edee302 790 place_hold2 = place_hold2 + 1;
roryhand 1:aac37edee302 791 if(place_hold2 >= BufferLen) {
roryhand 1:aac37edee302 792 while(1) {
roryhand 1:aac37edee302 793
roryhand 1:aac37edee302 794 if(flag2 == 0) {
roryhand 1:aac37edee302 795 break;
roryhand 1:aac37edee302 796 }
roryhand 1:aac37edee302 797 }
roryhand 0:e89d7a0bfa3b 798 }
roryhand 1:aac37edee302 799
roryhand 1:aac37edee302 800 }
roryhand 0:e89d7a0bfa3b 801 }
roryhand 0:e89d7a0bfa3b 802 }
roryhand 59:8e7c25a915a0 803 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 804 slice2 = slice2 + 1;
roryhand 45:0e8e1f2ec5d2 805 slice3 = slice3 + 1;
roryhand 0:e89d7a0bfa3b 806 }
roryhand 0:e89d7a0bfa3b 807 }
roryhand 0:e89d7a0bfa3b 808
roryhand 0:e89d7a0bfa3b 809
roryhand 0:e89d7a0bfa3b 810
roryhand 0:e89d7a0bfa3b 811
roryhand 0:e89d7a0bfa3b 812
roryhand 0:e89d7a0bfa3b 813
roryhand 59:8e7c25a915a0 814