old demo that i want to try in mbed studio

Dependencies:   mbed SDFileSystem_Copy_of_mbed_version I2S

Committer:
roryhand
Date:
Mon Apr 22 12:54:34 2019 +0000
Revision:
25:5336e1cf38d6
Parent:
24:a60d1c3db09d
Child:
26:82a31e2bafd0
Cannot open more than 4 extra files at once (on top of all the other ones.  no actual explanation.  Doesn't appear to be related to file name)

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