old demo that i want to try in mbed studio

Dependencies:   mbed SDFileSystem_Copy_of_mbed_version I2S

Committer:
roryhand
Date:
Mon Apr 22 11:53:32 2019 +0000
Revision:
22:706e86dc0d45
Parent:
21:1aacd67d19c1
Child:
23:49c10427a1cd
Current version that doesn't use vectors when reading in strings from Directory stream

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 0:e89d7a0bfa3b 14 #include <stdlib.h>
roryhand 0:e89d7a0bfa3b 15 #include <vector>
roryhand 0:e89d7a0bfa3b 16 #include <string>
roryhand 0:e89d7a0bfa3b 17 #define sample_freq 11025
roryhand 1:aac37edee302 18 #pragma import __use_two_region_memory
roryhand 0:e89d7a0bfa3b 19 DigitalOut myled(LED1);
roryhand 0:e89d7a0bfa3b 20 DigitalOut led2(LED2);
roryhand 0:e89d7a0bfa3b 21 DigitalOut led3(LED3);
roryhand 0:e89d7a0bfa3b 22 DigitalIn NotchUp(p16);
roryhand 0:e89d7a0bfa3b 23 InterruptIn Horn(p16);
roryhand 0:e89d7a0bfa3b 24 Ticker sampletick;
roryhand 0:e89d7a0bfa3b 25 Ticker BellTick;
roryhand 0:e89d7a0bfa3b 26 Ticker EdTick;
roryhand 0:e89d7a0bfa3b 27 Ticker TickFadeOut;
roryhand 3:6169aeeaeeb4 28 Ticker TestTick;
roryhand 0:e89d7a0bfa3b 29 Timer t;
roryhand 0:e89d7a0bfa3b 30 Timer t2;
roryhand 3:6169aeeaeeb4 31 Timer NotchTimer;
roryhand 0:e89d7a0bfa3b 32
roryhand 22:706e86dc0d45 33 vector <string> VectorFilenames;
roryhand 22:706e86dc0d45 34
roryhand 0:e89d7a0bfa3b 35 Serial pc(USBTX, USBRX); // tx, rx //FOR DEBUGGING PROGRAM USING GNU SCREEN
roryhand 0:e89d7a0bfa3b 36 DigitalOut cs(p8);
roryhand 0:e89d7a0bfa3b 37 I2S i2s(I2S_TRANSMIT, p5, p6, p7);
roryhand 0:e89d7a0bfa3b 38 SDFileSystem sd(p11, p12, p13, p8, "sd"); // the new pinout that i am using
roryhand 0:e89d7a0bfa3b 39
roryhand 0:e89d7a0bfa3b 40
roryhand 0:e89d7a0bfa3b 41 /*struct A {
roryhand 0:e89d7a0bfa3b 42 int data;
roryhand 0:e89d7a0bfa3b 43 B b;
roryhand 0:e89d7a0bfa3b 44 };*/
roryhand 0:e89d7a0bfa3b 45
roryhand 0:e89d7a0bfa3b 46
roryhand 0:e89d7a0bfa3b 47
roryhand 0:e89d7a0bfa3b 48
roryhand 0:e89d7a0bfa3b 49 class classFade
roryhand 0:e89d7a0bfa3b 50 {
roryhand 1:aac37edee302 51 public:
roryhand 1:aac37edee302 52
roryhand 0:e89d7a0bfa3b 53 float powerval;
roryhand 0:e89d7a0bfa3b 54 float FadeIteration;
roryhand 0:e89d7a0bfa3b 55 float DecayFactor;
roryhand 0:e89d7a0bfa3b 56 float Denom;
roryhand 0:e89d7a0bfa3b 57 float FadeCoeff;
roryhand 0:e89d7a0bfa3b 58 float Natural_Exp;
roryhand 0:e89d7a0bfa3b 59 int LengthSecs;
roryhand 0:e89d7a0bfa3b 60 int Length;
roryhand 1:aac37edee302 61
roryhand 0:e89d7a0bfa3b 62 //member Functions
roryhand 0:e89d7a0bfa3b 63 float FadeOut(void)
roryhand 0:e89d7a0bfa3b 64 {
roryhand 0:e89d7a0bfa3b 65 powerval = -FadeIteration/Denom;
roryhand 1:aac37edee302 66 if (FadeIteration >=Length) {
roryhand 1:aac37edee302 67 FadeCoeff = 0;
roryhand 1:aac37edee302 68
roryhand 1:aac37edee302 69 } else {
roryhand 0:e89d7a0bfa3b 70 FadeCoeff = (Length - FadeIteration)/Length;
roryhand 0:e89d7a0bfa3b 71 }
roryhand 1:aac37edee302 72 FadeIteration = FadeIteration + 1;
roryhand 1:aac37edee302 73 return FadeCoeff;
roryhand 1:aac37edee302 74
roryhand 1:aac37edee302 75 }
roryhand 1:aac37edee302 76 float FadeIn(void)
roryhand 0:e89d7a0bfa3b 77 {
roryhand 0:e89d7a0bfa3b 78 powerval = FadeIteration/Denom;
roryhand 1:aac37edee302 79 if (FadeIteration >=Length) {
roryhand 1:aac37edee302 80 FadeCoeff = 1;
roryhand 1:aac37edee302 81
roryhand 1:aac37edee302 82 } else {
roryhand 0:e89d7a0bfa3b 83 FadeCoeff = FadeIteration/Length;
roryhand 0:e89d7a0bfa3b 84 }
roryhand 0:e89d7a0bfa3b 85
roryhand 1:aac37edee302 86 FadeIteration = FadeIteration + 1;
roryhand 1:aac37edee302 87 return FadeCoeff;
roryhand 1:aac37edee302 88
roryhand 1:aac37edee302 89 }
roryhand 0:e89d7a0bfa3b 90 };
roryhand 0:e89d7a0bfa3b 91
roryhand 0:e89d7a0bfa3b 92 classFade IdleFadeOut;
roryhand 0:e89d7a0bfa3b 93 classFade N2FadeIn;
roryhand 0:e89d7a0bfa3b 94
roryhand 2:957d3b2afff4 95 classFade NotchFadeOut;
roryhand 2:957d3b2afff4 96 classFade NotchFadeIn;
roryhand 2:957d3b2afff4 97
roryhand 0:e89d7a0bfa3b 98
roryhand 0:e89d7a0bfa3b 99
roryhand 0:e89d7a0bfa3b 100
roryhand 0:e89d7a0bfa3b 101
roryhand 1:aac37edee302 102 typedef struct uFMT_STRUCT {
roryhand 1:aac37edee302 103 short comp_code;
roryhand 1:aac37edee302 104 short num_channels;
roryhand 1:aac37edee302 105 unsigned sample_rate;
roryhand 1:aac37edee302 106 unsigned avg_Bps;
roryhand 1:aac37edee302 107 short block_align;
roryhand 1:aac37edee302 108 short sig_bps;
roryhand 0:e89d7a0bfa3b 109 } FMT_STRUCT;
roryhand 0:e89d7a0bfa3b 110
roryhand 1:aac37edee302 111 typedef struct uNotch_STRUCT {
roryhand 1:aac37edee302 112 short Notch;
roryhand 1:aac37edee302 113 short NotchTransUp;
roryhand 1:aac37edee302 114 short NotchTransDown;
roryhand 1:aac37edee302 115 short NotchDirection;
roryhand 1:aac37edee302 116 } Notch_STRUCT;
roryhand 1:aac37edee302 117
roryhand 0:e89d7a0bfa3b 118 typedef struct uDATA_STRUCT {
roryhand 1:aac37edee302 119 unsigned subchunk2_ID;
roryhand 1:aac37edee302 120 unsigned subchunk2_size;
roryhand 1:aac37edee302 121 char * data_buf;
roryhand 1:aac37edee302 122 } DATA_STRUCT;
roryhand 0:e89d7a0bfa3b 123
roryhand 1:aac37edee302 124 typedef struct uWAV_FILE_STRUCT {
roryhand 1:aac37edee302 125 FILE *WavFile;
roryhand 1:aac37edee302 126 int id_number;
roryhand 1:aac37edee302 127 char *slice_buf;
roryhand 1:aac37edee302 128 int num_slices;
roryhand 1:aac37edee302 129 FMT_STRUCT FileFormat;
roryhand 1:aac37edee302 130 DATA_STRUCT FileData;
roryhand 0:e89d7a0bfa3b 131 } WAV_FILE_STRUCT;
roryhand 0:e89d7a0bfa3b 132
roryhand 0:e89d7a0bfa3b 133 /*typedef struct uWAV_FILE_STRUCT{
roryhand 1:aac37edee302 134 FILE* WavFile;
roryhand 1:aac37edee302 135
roryhand 1:aac37edee302 136
roryhand 0:e89d7a0bfa3b 137 }WAV_FILE_STRUCT;*/
roryhand 0:e89d7a0bfa3b 138 class classSoundFile
roryhand 0:e89d7a0bfa3b 139 {
roryhand 1:aac37edee302 140 public:
roryhand 1:aac37edee302 141
roryhand 1:aac37edee302 142 //add a class constructor
roryhand 1:aac37edee302 143 WAV_FILE_STRUCT FileInfo;
roryhand 2:957d3b2afff4 144 short * data_sptr;
roryhand 1:aac37edee302 145 //classSoundFile(string filename);//this is the constructor
roryhand 1:aac37edee302 146 //string filename;
roryhand 0:e89d7a0bfa3b 147 };
roryhand 0:e89d7a0bfa3b 148
roryhand 1:aac37edee302 149 //class constructor;
roryhand 1:aac37edee302 150 /*classSoundFile::classSoundFile(string filename)
roryhand 1:aac37edee302 151 {
roryhand 1:aac37edee302 152 //Declare RootFolder and the directory for the appropriate file.
roryhand 1:aac37edee302 153 //How we index into filename[] from the outside of this class is another
roryhand 1:aac37edee302 154 //issue...
roryhand 1:aac37edee302 155 FileInfo.WavFile = fopen("/sd/mydir/645Engine/Startup.wav","rb");
roryhand 1:aac37edee302 156 fseek(FileInfo.WavFile,20,SEEK_SET);
roryhand 1:aac37edee302 157 fread(&FileInfo.FileFormat,sizeof(FileInfo.FileFormat),1,FileInfo.WavFile);
roryhand 1:aac37edee302 158 printf("wav_format.sample_rate: %d\n\r",FileInfo.FileFormat.sample_rate);
roryhand 1:aac37edee302 159 fread(&FileInfo.FileData,sizeof(FileInfo.FileData),1,FileInfo.WavFile);
roryhand 1:aac37edee302 160 printf("wav_data.subchunk2_size: %d\n\r",FileInfo.FileData.subchunk2_size);
roryhand 1:aac37edee302 161 FileInfo.slice_buf = ( char *)malloc(FileInfo.FileFormat.block_align);
roryhand 1:aac37edee302 162 fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,FileInfo.WavFile); //This isnt actually required, its just a test
roryhand 1:aac37edee302 163 FileInfo.num_slices = FileInfo.FileData.subchunk2_size/FileInfo.FileFormat.block_align;
roryhand 1:aac37edee302 164 }*/
roryhand 1:aac37edee302 165
roryhand 0:e89d7a0bfa3b 166
roryhand 0:e89d7a0bfa3b 167 int i = 0;
roryhand 0:e89d7a0bfa3b 168 int h = 0;
roryhand 0:e89d7a0bfa3b 169 short bufflen = 1;
roryhand 0:e89d7a0bfa3b 170 int buffer[1];
roryhand 1:aac37edee302 171 int AudioFormat, NumChannels, SampleRate, BitsPerSample ;
roryhand 0:e89d7a0bfa3b 172 char *slice_buf;
roryhand 0:e89d7a0bfa3b 173 short *data_sptr;
roryhand 0:e89d7a0bfa3b 174 short *data_sptr_horn;
roryhand 0:e89d7a0bfa3b 175 short *data_sptr_IdleN2;
roryhand 0:e89d7a0bfa3b 176 short * data_sptr_bell;
roryhand 0:e89d7a0bfa3b 177 short * data_sptr_N2;
roryhand 0:e89d7a0bfa3b 178 short * data_sptr_Flange;
roryhand 0:e89d7a0bfa3b 179 unsigned char *data_bptr;
roryhand 0:e89d7a0bfa3b 180 int *data_wptr;
roryhand 0:e89d7a0bfa3b 181 unsigned channel;
roryhand 0:e89d7a0bfa3b 182 long slice, num_slices;
roryhand 0:e89d7a0bfa3b 183 int verbosity = 0;
roryhand 0:e89d7a0bfa3b 184 int verbosity2 = 0;
roryhand 0:e89d7a0bfa3b 185 int verbosity3 = 0;
roryhand 0:e89d7a0bfa3b 186 int verbosity4 = 0;
roryhand 0:e89d7a0bfa3b 187 int verbosity5 = 0;
roryhand 0:e89d7a0bfa3b 188 int interrupt_condition = 1;
roryhand 0:e89d7a0bfa3b 189 int sampling_freq = 11025;
roryhand 0:e89d7a0bfa3b 190 const int BufferLen = 2000;
roryhand 0:e89d7a0bfa3b 191 short Buffer1[BufferLen];
roryhand 0:e89d7a0bfa3b 192 short Buffer2[BufferLen];
roryhand 0:e89d7a0bfa3b 193 short place_hold1 = 0;
roryhand 0:e89d7a0bfa3b 194 short place_hold2 = 0;
roryhand 0:e89d7a0bfa3b 195
roryhand 3:6169aeeaeeb4 196
roryhand 3:6169aeeaeeb4 197 string FOLDER;
roryhand 3:6169aeeaeeb4 198 string RootFolder = "/sd/mydir/SoundDecoder/";
roryhand 3:6169aeeaeeb4 199 string filename[25];
roryhand 3:6169aeeaeeb4 200 classSoundFile Sound[22];
roryhand 3:6169aeeaeeb4 201
roryhand 0:e89d7a0bfa3b 202 volatile int flag1 = 1;
roryhand 0:e89d7a0bfa3b 203 volatile int flag2 = 0;
roryhand 0:e89d7a0bfa3b 204 volatile int flag3 = 1;
roryhand 0:e89d7a0bfa3b 205 volatile int flag4 = 0;
roryhand 0:e89d7a0bfa3b 206 int FLAGBUFF1 = 0;
roryhand 0:e89d7a0bfa3b 207 int FLAGBUFF2 = 0;
roryhand 0:e89d7a0bfa3b 208 int BellFlag = 0;
roryhand 0:e89d7a0bfa3b 209 int BellFlag2 = 0;
roryhand 0:e89d7a0bfa3b 210 int FadeFlag = 0;
roryhand 0:e89d7a0bfa3b 211 int DualEngineFlag = 0;
roryhand 0:e89d7a0bfa3b 212
roryhand 0:e89d7a0bfa3b 213
roryhand 0:e89d7a0bfa3b 214 short value[1];
roryhand 0:e89d7a0bfa3b 215 FILE *HornWav;
roryhand 0:e89d7a0bfa3b 216 FILE *edsheeran_wav;
roryhand 0:e89d7a0bfa3b 217 FILE *Startup_wav;
roryhand 0:e89d7a0bfa3b 218 FILE *IdleN2Wav;
roryhand 0:e89d7a0bfa3b 219 FILE *N2Wav;
roryhand 0:e89d7a0bfa3b 220 FILE *BellWav;
roryhand 0:e89d7a0bfa3b 221 FILE *FlangeWav;
roryhand 16:5e3420d0509b 222 FILE *HeyWav;
roryhand 0:e89d7a0bfa3b 223 //long long slice_value;
roryhand 0:e89d7a0bfa3b 224 int slice_value[1];
roryhand 0:e89d7a0bfa3b 225
roryhand 0:e89d7a0bfa3b 226
roryhand 0:e89d7a0bfa3b 227 WAV_FILE_STRUCT WavInfo_Horn;
roryhand 0:e89d7a0bfa3b 228 WAV_FILE_STRUCT WavInfo_IdleN2;
roryhand 0:e89d7a0bfa3b 229 WAV_FILE_STRUCT WavInfo_N2;
roryhand 0:e89d7a0bfa3b 230 WAV_FILE_STRUCT WavInfo_Bell;
roryhand 0:e89d7a0bfa3b 231 WAV_FILE_STRUCT WavInfo_Flange;
roryhand 20:9cc7d825c07b 232 WAV_FILE_STRUCT WavInfo_Hey;
roryhand 16:5e3420d0509b 233 WAV_FILE_STRUCT WavInfo_Frustration;
roryhand 0:e89d7a0bfa3b 234 Ticker flipper;
roryhand 0:e89d7a0bfa3b 235 char * slice_buf_bell;
roryhand 0:e89d7a0bfa3b 236 char * slice_buf_ed;
roryhand 0:e89d7a0bfa3b 237 char * slice_buf_startup;
roryhand 0:e89d7a0bfa3b 238 char * slice_buf_N2;
roryhand 1:aac37edee302 239 Notch_STRUCT NotchingSet;
roryhand 0:e89d7a0bfa3b 240 //test
roryhand 0:e89d7a0bfa3b 241 //short *data_sptr_bell = 0;
roryhand 0:e89d7a0bfa3b 242 short *data_sptr_ed = 0;
roryhand 0:e89d7a0bfa3b 243 short *data_sptr_startup = 0;
roryhand 1:aac37edee302 244 void flip()
roryhand 1:aac37edee302 245 {
roryhand 0:e89d7a0bfa3b 246 led2 = !led2;
roryhand 0:e89d7a0bfa3b 247 }
roryhand 0:e89d7a0bfa3b 248
roryhand 0:e89d7a0bfa3b 249
roryhand 0:e89d7a0bfa3b 250 void isr()
roryhand 0:e89d7a0bfa3b 251 {
roryhand 1:aac37edee302 252 if(flag1 == 0) {
roryhand 0:e89d7a0bfa3b 253 value[0] = Buffer1[place_hold1]>>4;
roryhand 0:e89d7a0bfa3b 254 i2s.write(value,1);//Send next PWM value to amp
roryhand 0:e89d7a0bfa3b 255 place_hold1 = place_hold1 + 1;
roryhand 1:aac37edee302 256 if( (place_hold1 >= BufferLen)) {
roryhand 0:e89d7a0bfa3b 257 led2 = !led2;
roryhand 0:e89d7a0bfa3b 258 place_hold1 = 0;
roryhand 0:e89d7a0bfa3b 259 place_hold2 = 0;
roryhand 0:e89d7a0bfa3b 260 flag1 = 1;
roryhand 0:e89d7a0bfa3b 261 flag2 = 0;
roryhand 1:aac37edee302 262 }
roryhand 1:aac37edee302 263 } else if(flag2 == 0) {
roryhand 0:e89d7a0bfa3b 264 value[0] = Buffer2[place_hold2]>>4;
roryhand 0:e89d7a0bfa3b 265 i2s.write(value,1);//Send next PWM value to amp
roryhand 0:e89d7a0bfa3b 266 place_hold2 = place_hold2 + 1;
roryhand 1:aac37edee302 267 if( (place_hold2 >= BufferLen) ) {
roryhand 0:e89d7a0bfa3b 268 led2 = !led2;
roryhand 0:e89d7a0bfa3b 269 place_hold1 = 0;
roryhand 0:e89d7a0bfa3b 270 place_hold2 = 0;
roryhand 0:e89d7a0bfa3b 271 flag1 = 0;
roryhand 1:aac37edee302 272 flag2 = 1;
roryhand 0:e89d7a0bfa3b 273 FLAGBUFF2 = 0;
roryhand 1:aac37edee302 274 }
roryhand 0:e89d7a0bfa3b 275 }
roryhand 0:e89d7a0bfa3b 276 }
roryhand 1:aac37edee302 277
roryhand 0:e89d7a0bfa3b 278 void horn_sound()
roryhand 0:e89d7a0bfa3b 279 {
roryhand 0:e89d7a0bfa3b 280 BellFlag = 1;
roryhand 0:e89d7a0bfa3b 281 fseek(HornWav,44,SEEK_SET);
roryhand 0:e89d7a0bfa3b 282 fseek(BellWav,44,SEEK_SET);
roryhand 0:e89d7a0bfa3b 283 fseek(FlangeWav,44,SEEK_SET);
roryhand 0:e89d7a0bfa3b 284 fseek(N2Wav,44,SEEK_SET);
roryhand 0:e89d7a0bfa3b 285 }
roryhand 0:e89d7a0bfa3b 286
roryhand 0:e89d7a0bfa3b 287
roryhand 0:e89d7a0bfa3b 288 void N2SoundIsr()
roryhand 0:e89d7a0bfa3b 289 {
roryhand 0:e89d7a0bfa3b 290 DualEngineFlag = 1;
roryhand 0:e89d7a0bfa3b 291 fseek(N2Wav,44,SEEK_SET);
roryhand 0:e89d7a0bfa3b 292 fseek(HornWav,44,SEEK_SET);
roryhand 0:e89d7a0bfa3b 293 //TickFadeOut.detach(&N2SoundIsr);//,5.0);
roryhand 0:e89d7a0bfa3b 294 }
roryhand 0:e89d7a0bfa3b 295
roryhand 0:e89d7a0bfa3b 296
roryhand 0:e89d7a0bfa3b 297 void FadeOutIsr()
roryhand 0:e89d7a0bfa3b 298 {
roryhand 1:aac37edee302 299 FadeFlag = 1;
roryhand 1:aac37edee302 300 fseek(IdleN2Wav,44,SEEK_SET);
roryhand 1:aac37edee302 301 fseek(N2Wav,44,SEEK_SET);
roryhand 1:aac37edee302 302 fseek(HornWav,44,SEEK_SET);
roryhand 0:e89d7a0bfa3b 303 fseek(FlangeWav,44,SEEK_SET);
roryhand 1:aac37edee302 304
roryhand 0:e89d7a0bfa3b 305 }
roryhand 0:e89d7a0bfa3b 306
roryhand 3:6169aeeaeeb4 307 classFade FadeDataInitialise(classFade FadeData);
roryhand 3:6169aeeaeeb4 308
roryhand 3:6169aeeaeeb4 309
roryhand 3:6169aeeaeeb4 310
roryhand 3:6169aeeaeeb4 311
roryhand 3:6169aeeaeeb4 312
roryhand 3:6169aeeaeeb4 313 //function prototypes
roryhand 3:6169aeeaeeb4 314 WAV_FILE_STRUCT ReadFileInfo(WAV_FILE_STRUCT FileInfo, FILE * wav_file);
roryhand 3:6169aeeaeeb4 315 classSoundFile LoadFileStream(classSoundFile FileInfo, string filename);
roryhand 3:6169aeeaeeb4 316
roryhand 3:6169aeeaeeb4 317 float FadeOut(void);
roryhand 3:6169aeeaeeb4 318 void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo);
roryhand 3:6169aeeaeeb4 319 //void Play_WaveFileLoop(FILE * my_wav, WAV_FILE_STRUCT FileInfo);
roryhand 3:6169aeeaeeb4 320 //*********************INTERRUPT ROUTINE FOR NOTCHING***************************
roryhand 0:e89d7a0bfa3b 321
roryhand 1:aac37edee302 322 void NotchUpIsr()
roryhand 0:e89d7a0bfa3b 323 {
roryhand 1:aac37edee302 324 if(1 <= NotchingSet.Notch < 8) {
roryhand 1:aac37edee302 325
roryhand 1:aac37edee302 326 NotchingSet.Notch = NotchingSet.Notch + 1;
roryhand 1:aac37edee302 327 NotchingSet.NotchTransUp = NotchingSet.Notch + 7;
roryhand 1:aac37edee302 328 NotchingSet.NotchDirection = 1;
roryhand 3:6169aeeaeeb4 329 FadeDataInitialise(NotchFadeIn);
roryhand 3:6169aeeaeeb4 330 FadeDataInitialise(NotchFadeOut);
roryhand 1:aac37edee302 331 }
roryhand 0:e89d7a0bfa3b 332 }
roryhand 0:e89d7a0bfa3b 333
roryhand 0:e89d7a0bfa3b 334 void NotchDownIsr()
roryhand 0:e89d7a0bfa3b 335 {
roryhand 1:aac37edee302 336 if(1 < NotchingSet.Notch <= 8) {
roryhand 1:aac37edee302 337 NotchingSet.Notch = NotchingSet.Notch - 1;
roryhand 1:aac37edee302 338 NotchingSet.NotchTransDown = NotchingSet.Notch + 15;;
roryhand 1:aac37edee302 339 NotchingSet.NotchDirection = 0;
roryhand 3:6169aeeaeeb4 340 FadeDataInitialise(NotchFadeIn);
roryhand 3:6169aeeaeeb4 341 FadeDataInitialise(NotchFadeOut);
roryhand 1:aac37edee302 342 }
roryhand 1:aac37edee302 343 }
roryhand 0:e89d7a0bfa3b 344
roryhand 0:e89d7a0bfa3b 345
roryhand 3:6169aeeaeeb4 346 /**********************END OF INTERRUPT ROUTINE FOR NOTCHING*******************/
roryhand 3:6169aeeaeeb4 347
roryhand 3:6169aeeaeeb4 348
roryhand 1:aac37edee302 349
roryhand 0:e89d7a0bfa3b 350
roryhand 3:6169aeeaeeb4 351
roryhand 3:6169aeeaeeb4 352
roryhand 9:dd9cae06b202 353 void Play_WaveFileLoop(classSoundFile Sounds[], Notch_STRUCT NotchingSet);
roryhand 1:aac37edee302 354 int main()
roryhand 1:aac37edee302 355 {
roryhand 0:e89d7a0bfa3b 356 //LocalFileSystem local("local");
roryhand 0:e89d7a0bfa3b 357 NotchUp.mode(PullUp);
roryhand 0:e89d7a0bfa3b 358
roryhand 0:e89d7a0bfa3b 359
roryhand 0:e89d7a0bfa3b 360 //classSoundFile Sounds[4];
roryhand 1:aac37edee302 361 /* for(int iii = 0; iii < 3; iii ++)
roryhand 1:aac37edee302 362 {
roryhand 1:aac37edee302 363 Sounds[iii].setX(iii);
roryhand 1:aac37edee302 364 }*/
roryhand 0:e89d7a0bfa3b 365 WAV_FILE_STRUCT WavInfo_Startup;
roryhand 0:e89d7a0bfa3b 366 WAV_FILE_STRUCT WavInfo_Idle;
roryhand 0:e89d7a0bfa3b 367
roryhand 0:e89d7a0bfa3b 368 pc.printf("Beginning of program\n");
roryhand 0:e89d7a0bfa3b 369 FILE *StartupWav;
roryhand 0:e89d7a0bfa3b 370 FILE *IdleWav;
roryhand 1:aac37edee302 371
roryhand 3:6169aeeaeeb4 372
roryhand 0:e89d7a0bfa3b 373 DIR *dir;
roryhand 22:706e86dc0d45 374 struct dirent *ent;
roryhand 0:e89d7a0bfa3b 375 int iterator = 0;
roryhand 13:8e93396a27c5 376
roryhand 13:8e93396a27c5 377
roryhand 13:8e93396a27c5 378
roryhand 13:8e93396a27c5 379
roryhand 3:6169aeeaeeb4 380 printf("Directory is about to be opened? Still dont really Get this concept\n\r");
roryhand 3:6169aeeaeeb4 381 //if i try to open folder SoundDecoder2, it gets stuck after file 13... WHY
roryhand 3:6169aeeaeeb4 382 if ((dir = opendir ("/sd/mydir/SoundDecoder_second")) != NULL) {
roryhand 1:aac37edee302 383
roryhand 0:e89d7a0bfa3b 384 // print all the files and directories within directory
roryhand 1:aac37edee302 385 while ((ent = readdir (dir)) != NULL) {
roryhand 3:6169aeeaeeb4 386 //printf("%s\r\n",string(ent->d_name));
roryhand 3:6169aeeaeeb4 387 filename[iterator] = (ent->d_name);
roryhand 22:706e86dc0d45 388 printf("Filename: %s\n\r",filename[iterator].c_str());
roryhand 0:e89d7a0bfa3b 389 //printf("%s\r\n",filename[iterator]);
roryhand 0:e89d7a0bfa3b 390 iterator = iterator + 1;
roryhand 0:e89d7a0bfa3b 391 //printf("%s\r\n", ent->d_name);
roryhand 1:aac37edee302 392 //filenames.push_back(string(dirp->d_name));
roryhand 0:e89d7a0bfa3b 393 }
roryhand 0:e89d7a0bfa3b 394 closedir (dir);
roryhand 1:aac37edee302 395 }
roryhand 4:55fbbb049bae 396 /*
roryhand 3:6169aeeaeeb4 397 printf("Now printing all the files");
roryhand 3:6169aeeaeeb4 398 for(iterator = 0; iterator < 21; iterator ++) {
roryhand 1:aac37edee302 399 printf("All the Files: %s\r\n",filename[iterator]);
roryhand 1:aac37edee302 400 //printf("All the Files: %s\r\n",ent[iterator]);
roryhand 1:aac37edee302 401 }
roryhand 4:55fbbb049bae 402 */
roryhand 13:8e93396a27c5 403
roryhand 1:aac37edee302 404 //strcat(RootFolder,qdfilename[0]);
roryhand 3:6169aeeaeeb4 405 //string folder = RootFolder + filename[9];
roryhand 3:6169aeeaeeb4 406 //printf("Folder: %s\n\r",folder);
roryhand 1:aac37edee302 407
roryhand 1:aac37edee302 408
roryhand 0:e89d7a0bfa3b 409 //printf("Files and Folders contained here: %d\n\r",readdir(dp));
roryhand 1:aac37edee302 410
roryhand 1:aac37edee302 411
roryhand 9:dd9cae06b202 412 StartupWav = fopen("/sd/mydir/Startup.wav","rb");
roryhand 3:6169aeeaeeb4 413 //const char* folder2 = folder.c_str();
roryhand 1:aac37edee302 414
roryhand 1:aac37edee302 415
roryhand 1:aac37edee302 416 string FileName;
roryhand 1:aac37edee302 417 //vector <classSoundFile> Sound (27);
roryhand 3:6169aeeaeeb4 418 const char* FOLDER;
roryhand 13:8e93396a27c5 419
roryhand 13:8e93396a27c5 420 /*
roryhand 13:8e93396a27c5 421 WAV_FILE_STRUCT MyNewWav;
roryhand 13:8e93396a27c5 422
roryhand 13:8e93396a27c5 423 string folder;
roryhand 9:dd9cae06b202 424
roryhand 13:8e93396a27c5 425 for(int aaa = 0;aaa < 21; aaa ++ )
roryhand 13:8e93396a27c5 426 {
roryhand 13:8e93396a27c5 427 folder = RootFolder + filename[aaa];
roryhand 13:8e93396a27c5 428 FOLDER = folder.c_str();
roryhand 13:8e93396a27c5 429 Sound[aaa].FileInfo.WavFile = fopen(FOLDER,"rb");
roryhand 13:8e93396a27c5 430 //MyNewWav.WavFile = fopen("/sd/mydir/Startup.wav","rb");
roryhand 13:8e93396a27c5 431 printf("we opened This file %d\n\r",aaa);
roryhand 9:dd9cae06b202 432
roryhand 13:8e93396a27c5 433 /*
roryhand 13:8e93396a27c5 434 printf("Size of FILE* %d\n\r ",sizeof(Sound[aaa].FileInfo.WavFile));
roryhand 13:8e93396a27c5 435 fseek(Sound[aaa].FileInfo.WavFile,20,SEEK_SET);
roryhand 13:8e93396a27c5 436 fread(&Sound[aaa].FileInfo.FileFormat,sizeof(Sound[aaa].FileInfo.FileFormat),1,Sound[aaa].FileInfo.WavFile);
roryhand 13:8e93396a27c5 437 fread(&Sound[aaa].FileInfo.FileData,sizeof(Sound[aaa].FileInfo.FileData),1,Sound[aaa].FileInfo.WavFile);
roryhand 13:8e93396a27c5 438 */
roryhand 13:8e93396a27c5 439
roryhand 13:8e93396a27c5 440
roryhand 9:dd9cae06b202 441 //fseek(Sound[aaa].FileInfo.WavFile,20,SEEK_SET);
roryhand 9:dd9cae06b202 442
roryhand 9:dd9cae06b202 443 //fseek(MyNewWav.WavFile,20,SEEK_SET);
roryhand 9:dd9cae06b202 444 //fread(&WavInfo_Horn.FileFormat,sizeof(WavInfo_Horn.FileFormat),1,MyNewWav.WavFile);
roryhand 13:8e93396a27c5 445 /*
roryhand 13:8e93396a27c5 446 fread(&Sound[aaa].FileInfo.FileData,sizeof(Sound[aaa].FileInfo.FileData),1,Sound[aaa].FileInfo.WavFile);
roryhand 9:dd9cae06b202 447
roryhand 7:131ac4231c46 448 Sound[aaa].FileInfo.slice_buf = ( char *)malloc(Sound[aaa].FileInfo.FileFormat.block_align);
roryhand 7:131ac4231c46 449 fread(Sound[aaa].FileInfo.slice_buf,Sound[aaa].FileInfo.FileFormat.block_align,1,Sound[aaa].FileInfo.WavFile); //This isnt actually required, its just a test
roryhand 7:131ac4231c46 450 Sound[aaa].FileInfo.num_slices = Sound[aaa].FileInfo.FileData.subchunk2_size/Sound[aaa].FileInfo.FileFormat.block_align;
roryhand 13:8e93396a27c5 451 */
roryhand 8:c2faf06e7240 452
roryhand 13:8e93396a27c5 453 /*
roryhand 13:8e93396a27c5 454 Sound[aaa].FileInfo.slice_buf = ( char *)malloc(Sound[aaa].FileInfo.FileFormat.block_align);
roryhand 13:8e93396a27c5 455 fread(Sound[aaa].FileInfo.slice_buf,Sound[aaa].FileInfo.FileFormat.block_align,1,Sound[aaa].FileInfo.WavFile); //This isnt actually required, its just a test
roryhand 13:8e93396a27c5 456 Sound[aaa].FileInfo.num_slices = Sound[aaa].FileInfo.FileData.subchunk2_size/Sound[aaa].FileInfo.FileFormat.block_align;
roryhand 13:8e93396a27c5 457
roryhand 13:8e93396a27c5 458
roryhand 13:8e93396a27c5 459 }
roryhand 13:8e93396a27c5 460 */
roryhand 13:8e93396a27c5 461
roryhand 10:ce38f2e9e80e 462 int aaa = 0;
roryhand 10:ce38f2e9e80e 463 string folder = RootFolder + filename[0];
roryhand 10:ce38f2e9e80e 464 FOLDER = folder.c_str();
roryhand 12:e386150cefd3 465 WAV_FILE_STRUCT WavStruct0;
roryhand 12:e386150cefd3 466 WAV_FILE_STRUCT WavStruct1;
roryhand 12:e386150cefd3 467 WAV_FILE_STRUCT WavStruct2;
roryhand 12:e386150cefd3 468 WAV_FILE_STRUCT WavStruct3;
roryhand 12:e386150cefd3 469 WAV_FILE_STRUCT WavStruct4;
roryhand 12:e386150cefd3 470 WAV_FILE_STRUCT WavStruct5;
roryhand 12:e386150cefd3 471 WAV_FILE_STRUCT WavStruct6;
roryhand 12:e386150cefd3 472 WAV_FILE_STRUCT WavStruct7;
roryhand 12:e386150cefd3 473 WAV_FILE_STRUCT WavStruct8;
roryhand 12:e386150cefd3 474 WAV_FILE_STRUCT WavStruct9;
roryhand 12:e386150cefd3 475 WAV_FILE_STRUCT WavStruct10;
roryhand 12:e386150cefd3 476 WAV_FILE_STRUCT WavStruct11;
roryhand 12:e386150cefd3 477 WAV_FILE_STRUCT WavStruct12;
roryhand 12:e386150cefd3 478 WAV_FILE_STRUCT WavStruct13;
roryhand 12:e386150cefd3 479 WAV_FILE_STRUCT WavStruct14;
roryhand 12:e386150cefd3 480 WAV_FILE_STRUCT WavStruct15;
roryhand 12:e386150cefd3 481 WAV_FILE_STRUCT WavStruct16;
roryhand 12:e386150cefd3 482 WAV_FILE_STRUCT WavStruct17;
roryhand 12:e386150cefd3 483 WAV_FILE_STRUCT WavStruct18;
roryhand 12:e386150cefd3 484 WAV_FILE_STRUCT WavStruct19;
roryhand 12:e386150cefd3 485 WAV_FILE_STRUCT WavStruct20;
roryhand 12:e386150cefd3 486 WAV_FILE_STRUCT WavStruct21;
roryhand 12:e386150cefd3 487 WAV_FILE_STRUCT WavStruct22;
roryhand 12:e386150cefd3 488 //WavStruct0.WavFile = fopen(FOLDER,"rb");
roryhand 12:e386150cefd3 489 FILE* mywav0 = fopen(FOLDER,"rb");
roryhand 10:ce38f2e9e80e 490 printf("we opened This file %d\n\r",aaa);
roryhand 10:ce38f2e9e80e 491 aaa = aaa+1;
roryhand 13:8e93396a27c5 492
roryhand 13:8e93396a27c5 493
roryhand 10:ce38f2e9e80e 494 folder = RootFolder + filename[1];
roryhand 10:ce38f2e9e80e 495 FOLDER = folder.c_str();
roryhand 12:e386150cefd3 496 FILE* mywav1 = fopen(FOLDER,"rb");
roryhand 13:8e93396a27c5 497
roryhand 10:ce38f2e9e80e 498 printf("we opened This file %d\n\r",aaa);
roryhand 13:8e93396a27c5 499
roryhand 13:8e93396a27c5 500 printf("Size of WavStruct1: %d\n\r",sizeof(WavStruct1));
roryhand 13:8e93396a27c5 501 aaa = aaa+1;
roryhand 13:8e93396a27c5 502
roryhand 10:ce38f2e9e80e 503 folder = RootFolder + filename[2];
roryhand 13:8e93396a27c5 504 FOLDER = folder.c_str();
roryhand 12:e386150cefd3 505 FILE* mywav2 = fopen(FOLDER,"rb");
roryhand 13:8e93396a27c5 506
roryhand 13:8e93396a27c5 507
roryhand 10:ce38f2e9e80e 508 printf("we opened This file %d\n\r",aaa);
roryhand 13:8e93396a27c5 509
roryhand 13:8e93396a27c5 510
roryhand 13:8e93396a27c5 511
roryhand 13:8e93396a27c5 512
roryhand 13:8e93396a27c5 513
roryhand 13:8e93396a27c5 514 aaa = aaa+1;
roryhand 13:8e93396a27c5 515
roryhand 22:706e86dc0d45 516 /*folder = RootFolder + filename[3];
roryhand 13:8e93396a27c5 517 FOLDER = folder.c_str();
roryhand 13:8e93396a27c5 518 FILE* mywav3 = fopen(FOLDER,"rb");
roryhand 22:706e86dc0d45 519 if(mywav3 == NULL){
roryhand 22:706e86dc0d45 520 printf("CANNOT OPEN mywav 3\n\r");
roryhand 22:706e86dc0d45 521 }
roryhand 13:8e93396a27c5 522
roryhand 22:706e86dc0d45 523 printf("we opened This file %d\n\r",aaa);*/
roryhand 13:8e93396a27c5 524
roryhand 13:8e93396a27c5 525
roryhand 12:e386150cefd3 526
roryhand 12:e386150cefd3 527
roryhand 12:e386150cefd3 528
roryhand 10:ce38f2e9e80e 529 aaa = aaa+1;
roryhand 13:8e93396a27c5 530
roryhand 22:706e86dc0d45 531 string folder4 = RootFolder + filename[4].c_str();
roryhand 22:706e86dc0d45 532 printf("filename[4]: %s\n\r", filename[4].c_str());
roryhand 22:706e86dc0d45 533 FOLDER = folder4.c_str();
roryhand 22:706e86dc0d45 534 FILE * mywav4 = fopen(FOLDER,"rb");
roryhand 22:706e86dc0d45 535 //FILE* mywav4 = fopen("sd/mydir/SoundDecoder_second/07.wav","rb");
roryhand 22:706e86dc0d45 536 if(mywav4 == NULL){
roryhand 22:706e86dc0d45 537 printf("Cannot Open mywav4\n\r");
roryhand 22:706e86dc0d45 538 }
roryhand 13:8e93396a27c5 539
roryhand 10:ce38f2e9e80e 540 printf("we opened This file %d\n\r",aaa);
roryhand 11:34136ff82179 541
roryhand 13:8e93396a27c5 542
roryhand 13:8e93396a27c5 543
roryhand 13:8e93396a27c5 544
roryhand 13:8e93396a27c5 545
roryhand 13:8e93396a27c5 546 aaa = aaa+1;
roryhand 12:e386150cefd3 547
roryhand 13:8e93396a27c5 548 folder = RootFolder + filename[5];
roryhand 13:8e93396a27c5 549 FOLDER = folder.c_str();
roryhand 22:706e86dc0d45 550 printf("filename[5]: %s\n\r", filename[5]);
roryhand 13:8e93396a27c5 551 FILE* mywav5 = fopen(FOLDER,"rb");
roryhand 13:8e93396a27c5 552
roryhand 10:ce38f2e9e80e 553 printf("we opened This file %d\n\r",aaa);
roryhand 22:706e86dc0d45 554 if(mywav5 == NULL){
roryhand 22:706e86dc0d45 555 printf("Cannot Open mywav5\n\r");
roryhand 22:706e86dc0d45 556 }
roryhand 12:e386150cefd3 557
roryhand 11:34136ff82179 558
roryhand 10:ce38f2e9e80e 559 aaa = aaa+1;
roryhand 13:8e93396a27c5 560
roryhand 10:ce38f2e9e80e 561 folder = RootFolder + filename[6];
roryhand 13:8e93396a27c5 562 FOLDER = folder.c_str();
roryhand 12:e386150cefd3 563 FILE* mywav6 = fopen(FOLDER,"rb");
roryhand 13:8e93396a27c5 564
roryhand 10:ce38f2e9e80e 565 printf("we opened This file %d\n\r",aaa);
roryhand 12:e386150cefd3 566
roryhand 13:8e93396a27c5 567 aaa = aaa+1;
roryhand 13:8e93396a27c5 568
roryhand 13:8e93396a27c5 569 folder = RootFolder + filename[7];
roryhand 13:8e93396a27c5 570 FOLDER = folder.c_str();
roryhand 13:8e93396a27c5 571 FILE* mywav7 = fopen(FOLDER,"rb");
roryhand 12:e386150cefd3 572
roryhand 13:8e93396a27c5 573 printf("we opened This file %d\n\r",aaa);
roryhand 13:8e93396a27c5 574
roryhand 13:8e93396a27c5 575
roryhand 13:8e93396a27c5 576
roryhand 13:8e93396a27c5 577
roryhand 10:ce38f2e9e80e 578 aaa = aaa+1;
roryhand 13:8e93396a27c5 579
roryhand 10:ce38f2e9e80e 580 folder = RootFolder + filename[8];
roryhand 13:8e93396a27c5 581 FOLDER = folder.c_str();
roryhand 13:8e93396a27c5 582 FILE* mywav8 = fopen(FOLDER,"rb");
roryhand 13:8e93396a27c5 583
roryhand 10:ce38f2e9e80e 584 printf("we opened This file %d\n\r",aaa);
roryhand 13:8e93396a27c5 585
roryhand 12:e386150cefd3 586
roryhand 11:34136ff82179 587
roryhand 10:ce38f2e9e80e 588 aaa = aaa+1;
roryhand 13:8e93396a27c5 589
roryhand 10:ce38f2e9e80e 590 folder = RootFolder + filename[9];
roryhand 13:8e93396a27c5 591 FOLDER = folder.c_str();
roryhand 13:8e93396a27c5 592 FILE* mywav9 = fopen(FOLDER,"rb");
roryhand 13:8e93396a27c5 593
roryhand 10:ce38f2e9e80e 594 printf("we opened This file %d\n\r",aaa);
roryhand 13:8e93396a27c5 595
roryhand 13:8e93396a27c5 596
roryhand 10:ce38f2e9e80e 597 aaa = aaa+1;
roryhand 13:8e93396a27c5 598
roryhand 10:ce38f2e9e80e 599 folder = RootFolder + filename[10];
roryhand 13:8e93396a27c5 600 FOLDER = folder.c_str();
roryhand 13:8e93396a27c5 601 FILE* mywav10 = fopen(FOLDER,"rb");
roryhand 13:8e93396a27c5 602
roryhand 10:ce38f2e9e80e 603 printf("we opened This file %d\n\r",aaa);
roryhand 11:34136ff82179 604
roryhand 13:8e93396a27c5 605
roryhand 11:34136ff82179 606
roryhand 10:ce38f2e9e80e 607 aaa = aaa+1;
roryhand 13:8e93396a27c5 608
roryhand 10:ce38f2e9e80e 609 folder = RootFolder + filename[11];
roryhand 10:ce38f2e9e80e 610 FOLDER = folder.c_str();
roryhand 13:8e93396a27c5 611 FILE* mywav11 = fopen(FOLDER,"rb");
roryhand 13:8e93396a27c5 612
roryhand 10:ce38f2e9e80e 613 printf("we opened This file %d\n\r",aaa);
roryhand 13:8e93396a27c5 614
roryhand 13:8e93396a27c5 615
roryhand 10:ce38f2e9e80e 616 aaa = aaa+1;
roryhand 13:8e93396a27c5 617
roryhand 10:ce38f2e9e80e 618 folder = RootFolder + filename[12];
roryhand 10:ce38f2e9e80e 619 FOLDER = folder.c_str();
roryhand 13:8e93396a27c5 620 FILE* mywav12 = fopen(FOLDER,"rb");
roryhand 13:8e93396a27c5 621
roryhand 10:ce38f2e9e80e 622 printf("we opened This file %d\n\r",aaa);
roryhand 11:34136ff82179 623
roryhand 13:8e93396a27c5 624
roryhand 13:8e93396a27c5 625
roryhand 13:8e93396a27c5 626 aaa = aaa+1;
roryhand 13:8e93396a27c5 627
roryhand 13:8e93396a27c5 628 folder = RootFolder + filename[13];
roryhand 13:8e93396a27c5 629 FOLDER = folder.c_str();
roryhand 13:8e93396a27c5 630 FILE* mywav13 = fopen(FOLDER,"rb");
roryhand 13:8e93396a27c5 631
roryhand 13:8e93396a27c5 632 printf("we opened This file %d\n\r",aaa);
roryhand 13:8e93396a27c5 633
roryhand 13:8e93396a27c5 634
roryhand 11:34136ff82179 635
roryhand 10:ce38f2e9e80e 636 aaa = aaa+1;
roryhand 13:8e93396a27c5 637
roryhand 10:ce38f2e9e80e 638 folder = RootFolder + filename[14];
roryhand 13:8e93396a27c5 639 FOLDER = folder.c_str();
roryhand 13:8e93396a27c5 640 FILE* mywav14 = fopen(FOLDER,"rb");
roryhand 13:8e93396a27c5 641
roryhand 10:ce38f2e9e80e 642 printf("we opened This file %d\n\r",aaa);
roryhand 13:8e93396a27c5 643
roryhand 13:8e93396a27c5 644
roryhand 13:8e93396a27c5 645
roryhand 10:ce38f2e9e80e 646 aaa = aaa+1;
roryhand 22:706e86dc0d45 647 /*
roryhand 10:ce38f2e9e80e 648 folder = RootFolder + filename[15];
roryhand 13:8e93396a27c5 649 FOLDER = folder.c_str();
roryhand 13:8e93396a27c5 650 FILE* mywav15 = fopen(FOLDER,"rb");
roryhand 13:8e93396a27c5 651
roryhand 10:ce38f2e9e80e 652 printf("we opened This file %d\n\r",aaa);
roryhand 13:8e93396a27c5 653
roryhand 13:8e93396a27c5 654
roryhand 13:8e93396a27c5 655
roryhand 10:ce38f2e9e80e 656 aaa = aaa+1;
roryhand 13:8e93396a27c5 657
roryhand 10:ce38f2e9e80e 658 folder = RootFolder + filename[16];
roryhand 13:8e93396a27c5 659 FOLDER = folder.c_str();
roryhand 13:8e93396a27c5 660 FILE* mywav16 = fopen(FOLDER,"rb");
roryhand 13:8e93396a27c5 661
roryhand 10:ce38f2e9e80e 662 printf("we opened This file %d\n\r",aaa);
roryhand 13:8e93396a27c5 663
roryhand 13:8e93396a27c5 664
roryhand 13:8e93396a27c5 665
roryhand 10:ce38f2e9e80e 666 aaa = aaa+1;
roryhand 13:8e93396a27c5 667
roryhand 10:ce38f2e9e80e 668 folder = RootFolder + filename[17];
roryhand 13:8e93396a27c5 669 FOLDER = folder.c_str();
roryhand 13:8e93396a27c5 670 FILE* mywav17 = fopen(FOLDER,"rb");
roryhand 13:8e93396a27c5 671
roryhand 10:ce38f2e9e80e 672 printf("we opened This file %d\n\r",aaa);
roryhand 13:8e93396a27c5 673
roryhand 13:8e93396a27c5 674
roryhand 13:8e93396a27c5 675
roryhand 10:ce38f2e9e80e 676 aaa = aaa+1;
roryhand 13:8e93396a27c5 677
roryhand 10:ce38f2e9e80e 678 folder = RootFolder + filename[18];
roryhand 13:8e93396a27c5 679 FOLDER = folder.c_str();
roryhand 13:8e93396a27c5 680 FILE* mywav18 = fopen(FOLDER,"rb");
roryhand 13:8e93396a27c5 681
roryhand 10:ce38f2e9e80e 682 printf("we opened This file %d\n\r",aaa);
roryhand 13:8e93396a27c5 683
roryhand 13:8e93396a27c5 684
roryhand 13:8e93396a27c5 685
roryhand 13:8e93396a27c5 686 printf("We performed all ReadFileInfo Operations!\n\r");
roryhand 10:ce38f2e9e80e 687 aaa = aaa+1;
roryhand 22:706e86dc0d45 688 */
roryhand 1:aac37edee302 689
roryhand 1:aac37edee302 690 printf("DO WE GET PAST THE ALLOCATION POINT\n\r");
roryhand 1:aac37edee302 691
roryhand 1:aac37edee302 692
roryhand 1:aac37edee302 693
roryhand 1:aac37edee302 694
roryhand 1:aac37edee302 695
roryhand 13:8e93396a27c5 696 /*
roryhand 1:aac37edee302 697 StartupWav = fopen("/sd/mydir/645Engine/Startup.wav","rb");
roryhand 0:e89d7a0bfa3b 698 IdleWav = fopen("/sd/mydir/645Engine/N2_11k_minus10dB.wav","rb");
roryhand 0:e89d7a0bfa3b 699 IdleN2Wav = fopen("/sd/mydir/645Engine/N2N3_11k_minus10dB.wav","rb");
roryhand 0:e89d7a0bfa3b 700 HornWav = fopen("/sd/mydir/645Engine/K3H_1_A_short_quiet.wav","rb");
roryhand 0:e89d7a0bfa3b 701 N2Wav = fopen("/sd/mydir/645Engine/N3_11k_minus11dB.wav","rb");
roryhand 0:e89d7a0bfa3b 702 BellWav = fopen("/sd/mydir/645Engine/EMD_BRONZE_BELL_1_11k_minus10dB.wav","rb");
roryhand 0:e89d7a0bfa3b 703 FlangeWav = fopen("/sd/mydir/645Engine/EX_FlangeJoint1_11k_minus12dB.wav","rb");
roryhand 13:8e93396a27c5 704
roryhand 13:8e93396a27c5 705
roryhand 13:8e93396a27c5 706
roryhand 1:aac37edee302 707
roryhand 0:e89d7a0bfa3b 708 WavInfo_Startup = ReadFileInfo(WavInfo_Startup, StartupWav);
roryhand 1:aac37edee302 709 printf("WavInfo_Startup Size: %d\n\r",sizeof(WavInfo_Startup));
roryhand 0:e89d7a0bfa3b 710 WavInfo_Idle = ReadFileInfo(WavInfo_Idle, IdleWav);
roryhand 0:e89d7a0bfa3b 711 WavInfo_Horn = ReadFileInfo(WavInfo_Horn, HornWav);
roryhand 0:e89d7a0bfa3b 712 WavInfo_IdleN2 = ReadFileInfo(WavInfo_IdleN2, IdleN2Wav);
roryhand 0:e89d7a0bfa3b 713 WavInfo_N2 = ReadFileInfo(WavInfo_N2, N2Wav);
roryhand 0:e89d7a0bfa3b 714 WavInfo_Bell = ReadFileInfo(WavInfo_Bell, BellWav);
roryhand 0:e89d7a0bfa3b 715 WavInfo_Flange = ReadFileInfo(WavInfo_Flange, FlangeWav);
roryhand 13:8e93396a27c5 716 */
roryhand 13:8e93396a27c5 717
roryhand 21:1aacd67d19c1 718 WavStruct0 = ReadFileInfo(WavStruct0,mywav0);
roryhand 21:1aacd67d19c1 719 WavStruct1 = ReadFileInfo(WavStruct1,mywav1);
roryhand 21:1aacd67d19c1 720 WavStruct2 = ReadFileInfo(WavStruct2,mywav2);
roryhand 22:706e86dc0d45 721 //WavStruct3 = ReadFileInfo(WavStruct3,mywav3);
roryhand 22:706e86dc0d45 722 /*WavStruct4 = ReadFileInfo(WavStruct4,mywav4);
roryhand 21:1aacd67d19c1 723 WavStruct5 = ReadFileInfo(WavStruct5,mywav5);
roryhand 21:1aacd67d19c1 724 WavStruct6 = ReadFileInfo(WavStruct6,mywav6);
roryhand 21:1aacd67d19c1 725 WavStruct7 = ReadFileInfo(WavStruct7,mywav7);
roryhand 21:1aacd67d19c1 726 WavStruct8 = ReadFileInfo(WavStruct8,mywav8);
roryhand 21:1aacd67d19c1 727 WavStruct9 = ReadFileInfo(WavStruct9,mywav9);
roryhand 21:1aacd67d19c1 728 WavStruct10 = ReadFileInfo(WavStruct10,mywav10);
roryhand 21:1aacd67d19c1 729 WavStruct11 = ReadFileInfo(WavStruct11,mywav11);
roryhand 21:1aacd67d19c1 730 WavStruct12 = ReadFileInfo(WavStruct12,mywav12);
roryhand 21:1aacd67d19c1 731 WavStruct13 = ReadFileInfo(WavStruct13,mywav13);
roryhand 21:1aacd67d19c1 732 WavStruct14 = ReadFileInfo(WavStruct14,mywav14);
roryhand 21:1aacd67d19c1 733 WavStruct15 = ReadFileInfo(WavStruct15,mywav15);
roryhand 21:1aacd67d19c1 734 WavStruct16 = ReadFileInfo(WavStruct16,mywav16);
roryhand 21:1aacd67d19c1 735 WavStruct17 = ReadFileInfo(WavStruct17,mywav17);
roryhand 21:1aacd67d19c1 736 WavStruct18 = ReadFileInfo(WavStruct18,mywav18);*/
roryhand 21:1aacd67d19c1 737
roryhand 21:1aacd67d19c1 738
roryhand 13:8e93396a27c5 739 printf("About to Start ReadFileInfo Operations\n\r");
roryhand 13:8e93396a27c5 740
roryhand 14:cc555d14e3f8 741
roryhand 13:8e93396a27c5 742 StartupWav = fopen("/sd/mydir/645Engine/Startup.wav","rb");
roryhand 13:8e93396a27c5 743 IdleWav = fopen("/sd/mydir/645Engine/N2_11k_minus10dB.wav","rb");
roryhand 13:8e93396a27c5 744 IdleN2Wav = fopen("/sd/mydir/645Engine/N2N3_11k_minus10dB.wav","rb");
roryhand 13:8e93396a27c5 745 HornWav = fopen("/sd/mydir/645Engine/K3H_1_A_short_quiet.wav","rb");
roryhand 13:8e93396a27c5 746 N2Wav = fopen("/sd/mydir/645Engine/N3_11k_minus11dB.wav","rb");
roryhand 13:8e93396a27c5 747 BellWav = fopen("/sd/mydir/645Engine/EMD_BRONZE_BELL_1_11k_minus10dB.wav","rb");
roryhand 20:9cc7d825c07b 748 //FlangeWav = fopen("/sd/mydir/645Engine/EX_FlangeJoint1_11k_minus12dB.wav","rb");
roryhand 16:5e3420d0509b 749
roryhand 20:9cc7d825c07b 750 HeyWav = fopen("/sd/mydir/645Engine/EX_FlangeJoint1_11k_minus12dB.wav","rb");
roryhand 16:5e3420d0509b 751 //HeyWav = fopen("/sd/mydir/edsheeran.wav","rb");
roryhand 13:8e93396a27c5 752
roryhand 13:8e93396a27c5 753
roryhand 13:8e93396a27c5 754
roryhand 13:8e93396a27c5 755 WavInfo_Startup = ReadFileInfo(WavInfo_Startup, StartupWav);
roryhand 17:832eb9a75c05 756 //printf("WavInfo_Startup Size: %d\n\r",sizeof(WavInfo_Startup));
roryhand 13:8e93396a27c5 757 WavInfo_Idle = ReadFileInfo(WavInfo_Idle, IdleWav);
roryhand 13:8e93396a27c5 758 WavInfo_Horn = ReadFileInfo(WavInfo_Horn, HornWav);
roryhand 13:8e93396a27c5 759 WavInfo_IdleN2 = ReadFileInfo(WavInfo_IdleN2, IdleN2Wav);
roryhand 13:8e93396a27c5 760 WavInfo_N2 = ReadFileInfo(WavInfo_N2, N2Wav);
roryhand 13:8e93396a27c5 761 WavInfo_Bell = ReadFileInfo(WavInfo_Bell, BellWav);
roryhand 22:706e86dc0d45 762 printf("About to Read HeyWav\n\r");
roryhand 22:706e86dc0d45 763 printf("SizeOf mywav4: %d\n\r",sizeof(mywav4));
roryhand 22:706e86dc0d45 764 fseek(mywav4,1,SEEK_SET);
roryhand 22:706e86dc0d45 765 WavInfo_Flange = ReadFileInfo(WavInfo_Flange, HeyWav);
roryhand 20:9cc7d825c07b 766 //WavInfo_Hey = ReadFileInfo(WavInfo_Hey,HeyWav);
roryhand 16:5e3420d0509b 767 //WAV_FILE_STRUCT WavInfo_Frustration;
roryhand 16:5e3420d0509b 768 //FILE* FrustrationWav = fopen("/sd/mydir/645Engine/EX_FlangeJoint1_11k_minus12dB.wav","rb");
roryhand 17:832eb9a75c05 769 //WAV_FILE_STRUCT WavInfo_Hey;
roryhand 20:9cc7d825c07b 770 WavInfo_Hey = ReadFileInfo(WavInfo_Hey,HeyWav);
roryhand 16:5e3420d0509b 771 //FlangeWav - this one works.
roryhand 16:5e3420d0509b 772 //HeyWav - this one doesn't. Despite the fact they reference teh exact same file.
roryhand 16:5e3420d0509b 773 //WavInfo_Bell = ReadFileInfo(WavInfo_Bell,HeyWav);
roryhand 16:5e3420d0509b 774 //WavInfo_Frustration = ReadFileInfo(WavInfo_Frustration,FlangeWav);
roryhand 17:832eb9a75c05 775 //printf("Frustration\n\r");
roryhand 13:8e93396a27c5 776
roryhand 13:8e93396a27c5 777
roryhand 4:55fbbb049bae 778
roryhand 14:cc555d14e3f8 779 printf("Do we even get to this stupid bloody point\n\r");
roryhand 0:e89d7a0bfa3b 780 //Populate our class instances with some data (is there an implicit way to do this?)
roryhand 0:e89d7a0bfa3b 781 N2FadeIn.LengthSecs = 4;
roryhand 0:e89d7a0bfa3b 782 IdleFadeOut.LengthSecs = 2;
roryhand 0:e89d7a0bfa3b 783 N2FadeIn = FadeDataInitialise(N2FadeIn);
roryhand 0:e89d7a0bfa3b 784 IdleFadeOut = FadeDataInitialise(IdleFadeOut);
roryhand 1:aac37edee302 785
roryhand 3:6169aeeaeeb4 786 printf("hello\n\r");
roryhand 0:e89d7a0bfa3b 787 //Set up the wolfson Audio Codec board
roryhand 0:e89d7a0bfa3b 788 wm8731_Config_setup();
roryhand 0:e89d7a0bfa3b 789 //i2s audio data transfer code??
roryhand 0:e89d7a0bfa3b 790 i2s.stereomono(I2S_STEREO);
roryhand 0:e89d7a0bfa3b 791 i2s.masterslave(I2S_MASTER);
roryhand 0:e89d7a0bfa3b 792 led3 = 1;
roryhand 0:e89d7a0bfa3b 793 led2 = 1;
roryhand 13:8e93396a27c5 794
roryhand 0:e89d7a0bfa3b 795 sampletick.attach(&isr,1.0/sampling_freq); //1/16000
roryhand 0:e89d7a0bfa3b 796 //TickFadeOut.attach(&FadeOutIsr,10.0);
roryhand 3:6169aeeaeeb4 797 printf("SamplingFreq: %d\n\r",sampling_freq);
roryhand 0:e89d7a0bfa3b 798 i2s.start();
roryhand 3:6169aeeaeeb4 799 printf("Hello i2s has starrted!!");
roryhand 0:e89d7a0bfa3b 800 Horn.rise(&FadeOutIsr);
roryhand 0:e89d7a0bfa3b 801 slice = 0;
roryhand 0:e89d7a0bfa3b 802 fseek(IdleN2Wav,44,SEEK_SET);
roryhand 0:e89d7a0bfa3b 803 //Play_WaveFile(IdleN2Wav,WavInfo_IdleN2);
roryhand 0:e89d7a0bfa3b 804 //Play_WaveFile(N2Wav,WavInfo_N2);
roryhand 0:e89d7a0bfa3b 805 t.reset();
roryhand 0:e89d7a0bfa3b 806 t.start();
roryhand 0:e89d7a0bfa3b 807 N2FadeIn.FadeCoeff = N2FadeIn.FadeOut();
roryhand 0:e89d7a0bfa3b 808 t.stop();
roryhand 0:e89d7a0bfa3b 809 printf("Time to Calcualte Fade Coeff: %d\n\r",t.read_us());
roryhand 0:e89d7a0bfa3b 810 t.reset();
roryhand 1:aac37edee302 811
roryhand 0:e89d7a0bfa3b 812 fseek(IdleN2Wav,44,SEEK_SET);
roryhand 0:e89d7a0bfa3b 813 t.start();
roryhand 1:aac37edee302 814 fread(WavInfo_IdleN2.slice_buf,WavInfo_IdleN2.FileFormat.block_align,1,IdleN2Wav);
roryhand 0:e89d7a0bfa3b 815 data_sptr_IdleN2 = (short *)WavInfo_IdleN2.slice_buf;
roryhand 0:e89d7a0bfa3b 816 t.stop();
roryhand 0:e89d7a0bfa3b 817 printf("Time to Read in a slice: %dus\n\r",t.read_us());
roryhand 0:e89d7a0bfa3b 818 t.reset();
roryhand 1:aac37edee302 819
roryhand 0:e89d7a0bfa3b 820 printf("point to start sound: %d\n\r",((WavInfo_IdleN2.FileData.subchunk2_size) - N2FadeIn.Length));
roryhand 0:e89d7a0bfa3b 821 printf("Size of Data: %d\n\r",WavInfo_IdleN2.FileData.subchunk2_size);
roryhand 1:aac37edee302 822
roryhand 20:9cc7d825c07b 823 fseek(HeyWav,44,SEEK_SET);
roryhand 13:8e93396a27c5 824
roryhand 20:9cc7d825c07b 825 printf("about to play wav file\n\r");
roryhand 20:9cc7d825c07b 826 Play_WaveFile(HeyWav,WavInfo_Hey);
roryhand 20:9cc7d825c07b 827 printf("finished playing Wav file\n\r");
roryhand 9:dd9cae06b202 828 /************************************PLAY WAV FILE LOOP*******************/
roryhand 20:9cc7d825c07b 829 //Play_WaveFileLoop(Sound, NotchingSet);
roryhand 9:dd9cae06b202 830 /************************************END OF PLAY WAV FILE LOOP*************/
roryhand 13:8e93396a27c5 831
roryhand 13:8e93396a27c5 832
roryhand 13:8e93396a27c5 833
roryhand 9:dd9cae06b202 834
roryhand 3:6169aeeaeeb4 835
roryhand 0:e89d7a0bfa3b 836 fseek(IdleN2Wav,44,SEEK_SET);//reset for use in the Loop code
roryhand 0:e89d7a0bfa3b 837 slice = 0;
roryhand 0:e89d7a0bfa3b 838 fseek(IdleWav,44,SEEK_SET);
roryhand 3:6169aeeaeeb4 839 NotchingSet.Notch = 1;
roryhand 1:aac37edee302 840 //Play_WaveFileLoop(IdleWav, WavInfo_Idle);
roryhand 1:aac37edee302 841
roryhand 1:aac37edee302 842 i2s.stop();
roryhand 0:e89d7a0bfa3b 843
roryhand 0:e89d7a0bfa3b 844 }
roryhand 0:e89d7a0bfa3b 845
roryhand 0:e89d7a0bfa3b 846
roryhand 3:6169aeeaeeb4 847
roryhand 3:6169aeeaeeb4 848
roryhand 3:6169aeeaeeb4 849
roryhand 3:6169aeeaeeb4 850
roryhand 0:e89d7a0bfa3b 851 WAV_FILE_STRUCT ReadFileInfo(WAV_FILE_STRUCT FileInfo, FILE * wav_file)
roryhand 0:e89d7a0bfa3b 852 {
roryhand 0:e89d7a0bfa3b 853 fseek(wav_file,20,SEEK_SET);
roryhand 22:706e86dc0d45 854 printf("We have just seeked through this file\n\r");
roryhand 0:e89d7a0bfa3b 855 fread(&FileInfo.FileFormat,sizeof(FileInfo.FileFormat),1,wav_file);
roryhand 1:aac37edee302 856 //printf("wav_format.sample_rate: %d\n\r",FileInfo.FileFormat.sample_rate);
roryhand 1:aac37edee302 857
roryhand 0:e89d7a0bfa3b 858 fread(&FileInfo.FileData,sizeof(FileInfo.FileData),1,wav_file);
roryhand 1:aac37edee302 859 //printf("wav_data.subchunk2_size: %d\n\r",FileInfo.FileData.subchunk2_size);
roryhand 0:e89d7a0bfa3b 860 FileInfo.slice_buf = ( char *)malloc(FileInfo.FileFormat.block_align);
roryhand 0:e89d7a0bfa3b 861 fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,wav_file); //This isnt actually required, its just a test
roryhand 1:aac37edee302 862 FileInfo.num_slices = FileInfo.FileData.subchunk2_size/FileInfo.FileFormat.block_align;
roryhand 1:aac37edee302 863 //printf("Number of Slices: %d\n\r",FileInfo.num_slices);
roryhand 1:aac37edee302 864 return FileInfo;
roryhand 0:e89d7a0bfa3b 865 }
roryhand 1:aac37edee302 866
roryhand 1:aac37edee302 867 classSoundFile LoadFileStream(classSoundFile Sound, string filename)
roryhand 1:aac37edee302 868 {
roryhand 1:aac37edee302 869 //Declare RootFolder and the directory for the appropriate file.
roryhand 1:aac37edee302 870 //How we index into filename[] from the outside of this class is another
roryhand 1:aac37edee302 871 //issue...
roryhand 1:aac37edee302 872 //printf("FileName: %s\n\r",filename);
roryhand 1:aac37edee302 873 //string RootFolder = "/sd/mydir/SoundDecoder/";
roryhand 1:aac37edee302 874 //string Directory = RootFolder + "01.wav";// + filename[0];
roryhand 1:aac37edee302 875 //printf("%s\n\r",Directory);
roryhand 1:aac37edee302 876 //const char* DirectoryChar = Directory.c_str();
roryhand 1:aac37edee302 877 //Sound.FileInfo.WavFile = fopen(DirectoryChar,"rb");
roryhand 1:aac37edee302 878 Sound.FileInfo.WavFile = fopen("/sd/mydir/645Engine/Startup.wav","rb");
roryhand 1:aac37edee302 879 fseek(Sound.FileInfo.WavFile,20,SEEK_SET);
roryhand 1:aac37edee302 880 fread(&Sound.FileInfo.FileFormat,sizeof(Sound.FileInfo.FileFormat),1,Sound.FileInfo.WavFile);
roryhand 1:aac37edee302 881 printf("wav_format.sample_rate: %d\n\r",Sound.FileInfo.FileFormat.sample_rate);
roryhand 1:aac37edee302 882 fread(&Sound.FileInfo.FileData,sizeof(Sound.FileInfo.FileData),1,Sound.FileInfo.WavFile);
roryhand 1:aac37edee302 883 printf("wav_data.subchunk2_size: %d\n\r",Sound.FileInfo.FileData.subchunk2_size);
roryhand 1:aac37edee302 884 Sound.FileInfo.slice_buf = ( char *)malloc(Sound.FileInfo.FileFormat.block_align);
roryhand 1:aac37edee302 885 fread(Sound.FileInfo.slice_buf,Sound.FileInfo.FileFormat.block_align,1,Sound.FileInfo.WavFile); //This isnt actually required, its just a test
roryhand 1:aac37edee302 886 Sound.FileInfo.num_slices = Sound.FileInfo.FileData.subchunk2_size/Sound.FileInfo.FileFormat.block_align;
roryhand 1:aac37edee302 887 printf("Number of Slices: %d\n\r",Sound.FileInfo.num_slices);
roryhand 1:aac37edee302 888 return Sound;
roryhand 1:aac37edee302 889 }
roryhand 1:aac37edee302 890
roryhand 1:aac37edee302 891
roryhand 0:e89d7a0bfa3b 892 classFade FadeDataInitialise(classFade FadeData)
roryhand 0:e89d7a0bfa3b 893 {
roryhand 1:aac37edee302 894 FadeData.DecayFactor = 1.3;
roryhand 0:e89d7a0bfa3b 895 FadeData.FadeIteration = 1;
roryhand 0:e89d7a0bfa3b 896 //FadeData.Denom = 11025*FadeData.DecayFactor;
roryhand 0:e89d7a0bfa3b 897 FadeData.Denom = 11025*FadeData.DecayFactor;
roryhand 0:e89d7a0bfa3b 898 FadeData.Natural_Exp = 2.7183;
roryhand 0:e89d7a0bfa3b 899 FadeData.Length = 11025*FadeData.LengthSecs;
roryhand 0:e89d7a0bfa3b 900 //FadeData.Natural_Exp = 2.7;
roryhand 0:e89d7a0bfa3b 901 return FadeData;
roryhand 0:e89d7a0bfa3b 902 }
roryhand 0:e89d7a0bfa3b 903
roryhand 0:e89d7a0bfa3b 904 //Playing Files Code
roryhand 0:e89d7a0bfa3b 905 /*float FadeIn(void)
roryhand 0:e89d7a0bfa3b 906 {
roryhand 0:e89d7a0bfa3b 907 powervalFadeIn = FadeIterationIn/denom;
roryhand 0:e89d7a0bfa3b 908 FadeCoeffFadeIn
roryhand 1:aac37edee302 909
roryhand 1:aac37edee302 910
roryhand 0:e89d7a0bfa3b 911 }*/
roryhand 0:e89d7a0bfa3b 912 /*float FadeOut(void)
roryhand 0:e89d7a0bfa3b 913 {
roryhand 0:e89d7a0bfa3b 914 powerval = -FadeIteration/denom;
roryhand 0:e89d7a0bfa3b 915 FadeCoeff = pow(natural_exp,powerval);
roryhand 1:aac37edee302 916 FadeIteration = FadeIteration + 1;
roryhand 1:aac37edee302 917 return FadeCoeff;
roryhand 1:aac37edee302 918
roryhand 0:e89d7a0bfa3b 919 }*/
roryhand 0:e89d7a0bfa3b 920
roryhand 0:e89d7a0bfa3b 921
roryhand 0:e89d7a0bfa3b 922 void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo)
roryhand 0:e89d7a0bfa3b 923 {
roryhand 1:aac37edee302 924 while(slice<FileInfo.num_slices) {
roryhand 1:aac37edee302 925 fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,my_wav);
roryhand 1:aac37edee302 926 data_sptr=(short *)FileInfo.slice_buf; // 16 bit samples
roryhand 1:aac37edee302 927 for (channel=0; channel<FileInfo.FileFormat.num_channels; channel++) {
roryhand 1:aac37edee302 928 if(flag1 == 1) {
roryhand 1:aac37edee302 929 Buffer1[place_hold1] = data_sptr[channel];
roryhand 1:aac37edee302 930 place_hold1 = place_hold1 + 1;
roryhand 1:aac37edee302 931 if(place_hold1 >= BufferLen) {
roryhand 1:aac37edee302 932 while(1) {
roryhand 1:aac37edee302 933 if(flag1 == 0) {
roryhand 0:e89d7a0bfa3b 934
roryhand 1:aac37edee302 935 break;
roryhand 0:e89d7a0bfa3b 936 }
roryhand 1:aac37edee302 937
roryhand 0:e89d7a0bfa3b 938 }
roryhand 1:aac37edee302 939 }
roryhand 1:aac37edee302 940
roryhand 1:aac37edee302 941 } else if(flag2 == 1) {
roryhand 1:aac37edee302 942 Buffer2[place_hold2] = data_sptr[channel];
roryhand 1:aac37edee302 943 place_hold2 = place_hold2 + 1;
roryhand 1:aac37edee302 944 if(place_hold2 >= BufferLen) {
roryhand 1:aac37edee302 945
roryhand 1:aac37edee302 946 while(1) {
roryhand 1:aac37edee302 947 if(flag2 == 0) {
roryhand 1:aac37edee302 948
roryhand 1:aac37edee302 949 break;
roryhand 1:aac37edee302 950 }
roryhand 0:e89d7a0bfa3b 951 }
roryhand 1:aac37edee302 952 }
roryhand 0:e89d7a0bfa3b 953 }
roryhand 1:aac37edee302 954
roryhand 1:aac37edee302 955 }
roryhand 1:aac37edee302 956 slice = slice + 1;
roryhand 0:e89d7a0bfa3b 957 }
roryhand 0:e89d7a0bfa3b 958 }
roryhand 0:e89d7a0bfa3b 959
roryhand 0:e89d7a0bfa3b 960
roryhand 0:e89d7a0bfa3b 961
roryhand 0:e89d7a0bfa3b 962
roryhand 0:e89d7a0bfa3b 963
roryhand 0:e89d7a0bfa3b 964
roryhand 2:957d3b2afff4 965 //void Play_WaveFileLoop(FILE * my_wav, WAV_FILE_STRUCT FileInfo)//(classSoundFile Sounds)
roryhand 9:dd9cae06b202 966
roryhand 9:dd9cae06b202 967 void Play_WaveFileLoop(classSoundFile Sounds[], Notch_STRUCT NotchingSet)
roryhand 0:e89d7a0bfa3b 968 {
roryhand 1:aac37edee302 969 while(1) { //might have to change this to a while(1) loop?
roryhand 1:aac37edee302 970 //New format!! This should be (roughly) the way that this is done, with the new structures and classes
roryhand 1:aac37edee302 971 ////fread(Sound[Notch].FileData.slice_buf,Sound[Notch].FileFormat.block_align,1,Sound[notch].WavFile);
roryhand 1:aac37edee302 972 //data_sptr=(short *)Sound[Notch].FileInfo.slice_buf;
roryhand 1:aac37edee302 973
roryhand 0:e89d7a0bfa3b 974
roryhand 2:957d3b2afff4 975 if( slice == (Sounds[NotchingSet.Notch].FileInfo.num_slices-1) ) {
roryhand 1:aac37edee302 976 slice = 0;
roryhand 2:957d3b2afff4 977 fseek(Sounds[NotchingSet.Notch].FileInfo.WavFile,44,SEEK_SET);
roryhand 1:aac37edee302 978 }
roryhand 1:aac37edee302 979
roryhand 2:957d3b2afff4 980 //fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,my_wav);
roryhand 2:957d3b2afff4 981 data_sptr=(short *)Sounds[NotchingSet.Notch].FileInfo.slice_buf; // 16 bit samples
roryhand 2:957d3b2afff4 982 //make sure we are reading in the correct "notch" here
roryhand 2:957d3b2afff4 983
roryhand 2:957d3b2afff4 984 if(FadeFlag) {
roryhand 2:957d3b2afff4 985 if(feof(Sounds[NotchingSet.Notch].FileInfo.WavFile)) {
roryhand 2:957d3b2afff4 986 fseek(Sounds[NotchingSet.Notch].FileInfo.WavFile,44,SEEK_SET);
roryhand 2:957d3b2afff4 987 }
roryhand 3:6169aeeaeeb4 988
roryhand 2:957d3b2afff4 989 //Read in data for current (i.e. now the previous notch, according to the index!!)
roryhand 2:957d3b2afff4 990 //We might not need this code here...as its probably done somewhere else??
roryhand 2:957d3b2afff4 991 fread(Sounds[NotchingSet.Notch-1].FileInfo.slice_buf,Sounds[NotchingSet.Notch-1].FileInfo.FileFormat.block_align,1,Sounds[NotchingSet.Notch-1].FileInfo.WavFile);
roryhand 2:957d3b2afff4 992 Sounds[NotchingSet.Notch-1].data_sptr = (short *)Sounds[NotchingSet.Notch-1].FileInfo.slice_buf;
roryhand 3:6169aeeaeeb4 993
roryhand 2:957d3b2afff4 994 NotchFadeOut.FadeCoeff = NotchFadeOut.FadeOut();//compute new FadeOut Coeff value
roryhand 2:957d3b2afff4 995
roryhand 2:957d3b2afff4 996 //Read in the notch transition file for transitioning up
roryhand 2:957d3b2afff4 997 fread(Sounds[NotchingSet.NotchTransUp].FileInfo.slice_buf,Sounds[NotchingSet.NotchTransUp].FileInfo.FileFormat.block_align,1,Sounds[NotchingSet.NotchTransUp].FileInfo.WavFile);
roryhand 2:957d3b2afff4 998 Sounds[NotchingSet.NotchTransUp].data_sptr = (short*)Sounds[NotchingSet.NotchTransUp].FileInfo.slice_buf;
roryhand 3:6169aeeaeeb4 999
roryhand 2:957d3b2afff4 1000 if( ((Sounds[NotchingSet.NotchTransUp].FileInfo.FileData.subchunk2_size) - NotchFadeIn.Length - 2*11025) <= (ftell(Sounds[NotchingSet.NotchTransUp].FileInfo.WavFile) + 44))
roryhand 2:957d3b2afff4 1001 //if( (WavInfo_IdleN2.FileData.subchunk2_size)/8 <=ftell(IdleN2Wav) )
roryhand 2:957d3b2afff4 1002 {
roryhand 2:957d3b2afff4 1003
roryhand 2:957d3b2afff4 1004 NotchFadeIn.FadeCoeff = NotchFadeIn.FadeIn();
roryhand 3:6169aeeaeeb4 1005
roryhand 2:957d3b2afff4 1006 //Read In the next Notch
roryhand 2:957d3b2afff4 1007 fread(Sounds[NotchingSet.Notch].FileInfo.slice_buf,Sounds[NotchingSet.Notch].FileInfo.FileFormat.block_align,1,Sounds[NotchingSet.Notch].FileInfo.WavFile);
roryhand 2:957d3b2afff4 1008 Sounds[NotchingSet.Notch].data_sptr = (short *)Sounds[NotchingSet.Notch].FileInfo.slice_buf;
roryhand 2:957d3b2afff4 1009
roryhand 2:957d3b2afff4 1010 if( (ftell(Sounds[NotchingSet.NotchTransUp].FileInfo.WavFile) + 44) >= Sounds[NotchingSet.NotchTransUp].FileInfo.FileData.subchunk2_size ) {
roryhand 3:6169aeeaeeb4 1011
roryhand 2:957d3b2afff4 1012 //need to explicitly test if this notation/syntax works for pointers....
roryhand 2:957d3b2afff4 1013 *Sounds[NotchingSet.Notch].data_sptr = *Sounds[NotchingSet.Notch].data_sptr*NotchFadeIn.FadeCoeff;
roryhand 2:957d3b2afff4 1014 } else {
roryhand 2:957d3b2afff4 1015 *Sounds[NotchingSet.Notch-1].data_sptr = *Sounds[NotchingSet.Notch - 1].data_sptr*NotchFadeOut.FadeCoeff + *Sounds[NotchingSet.NotchTransUp].data_sptr + *Sounds[NotchingSet.Notch].data_sptr*NotchFadeIn.FadeCoeff;// + *data_sptr_N2;
roryhand 2:957d3b2afff4 1016 }
roryhand 2:957d3b2afff4 1017
roryhand 2:957d3b2afff4 1018 } else {
roryhand 2:957d3b2afff4 1019 *Sounds[NotchingSet.Notch-1].data_sptr = *Sounds[NotchingSet.Notch-1].data_sptr*NotchFadeOut.FadeCoeff + *Sounds[NotchingSet.NotchTransUp].data_sptr;
roryhand 2:957d3b2afff4 1020 }
roryhand 2:957d3b2afff4 1021
roryhand 1:aac37edee302 1022 }
roryhand 1:aac37edee302 1023
roryhand 1:aac37edee302 1024
roryhand 3:6169aeeaeeb4 1025 /********************END OF DATA ASSIGNMENT SECTION*************************************************/
roryhand 9:dd9cae06b202 1026
roryhand 2:957d3b2afff4 1027 for (channel=0; channel<Sounds[NotchingSet.Notch].FileInfo.FileFormat.num_channels; channel++) {
roryhand 2:957d3b2afff4 1028 switch (Sounds[NotchingSet.Notch].FileInfo.FileFormat.sig_bps) {
roryhand 0:e89d7a0bfa3b 1029 case 16:
roryhand 1:aac37edee302 1030 if(flag1 == 1) {
roryhand 2:957d3b2afff4 1031 Buffer1[place_hold1] = Sounds[NotchingSet.Notch].data_sptr[channel];
roryhand 1:aac37edee302 1032 place_hold1 = place_hold1 + 1;
roryhand 1:aac37edee302 1033 if(place_hold1 >= BufferLen) {
roryhand 1:aac37edee302 1034 while(1) {
roryhand 1:aac37edee302 1035 if(flag1 == 0) {
roryhand 1:aac37edee302 1036 break;
roryhand 1:aac37edee302 1037 }//if(flag1 == 0)
roryhand 1:aac37edee302 1038
roryhand 1:aac37edee302 1039
roryhand 1:aac37edee302 1040 }//while(1)
roryhand 1:aac37edee302 1041 }//if(place_hold1 > = BufferLen)
roryhand 0:e89d7a0bfa3b 1042
roryhand 1:aac37edee302 1043 } else if(flag2 == 1) {
roryhand 2:957d3b2afff4 1044 Buffer2[place_hold2] = Sounds[NotchingSet.Notch].data_sptr[channel];
roryhand 1:aac37edee302 1045 place_hold2 = place_hold2 + 1;
roryhand 1:aac37edee302 1046 if(place_hold2 >= BufferLen) {
roryhand 1:aac37edee302 1047 while(1) {
roryhand 1:aac37edee302 1048
roryhand 1:aac37edee302 1049 if(flag2 == 0) {
roryhand 1:aac37edee302 1050 break;
roryhand 1:aac37edee302 1051 }
roryhand 1:aac37edee302 1052 }
roryhand 0:e89d7a0bfa3b 1053 }
roryhand 1:aac37edee302 1054
roryhand 1:aac37edee302 1055 }
roryhand 0:e89d7a0bfa3b 1056 }
roryhand 0:e89d7a0bfa3b 1057 }
roryhand 0:e89d7a0bfa3b 1058 slice = slice + 1;
roryhand 0:e89d7a0bfa3b 1059 }
roryhand 0:e89d7a0bfa3b 1060 }
roryhand 0:e89d7a0bfa3b 1061
roryhand 0:e89d7a0bfa3b 1062
roryhand 0:e89d7a0bfa3b 1063
roryhand 0:e89d7a0bfa3b 1064
roryhand 0:e89d7a0bfa3b 1065
roryhand 0:e89d7a0bfa3b 1066
roryhand 0:e89d7a0bfa3b 1067
roryhand 9:dd9cae06b202 1068