old demo that i want to try in mbed studio

Dependencies:   mbed SDFileSystem_Copy_of_mbed_version I2S

Committer:
roryhand
Date:
Sat Sep 07 14:57:31 2019 +0000
Revision:
41:5dca752e6c40
Parent:
40:ba34990514fa
Child:
42:f481dcabdc34
Last version to contain any mention of Vectors.  Will be doing this another way after conv with Tristan

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