old demo that i want to try in mbed studio

Dependencies:   mbed SDFileSystem_Copy_of_mbed_version I2S

Committer:
roryhand
Date:
Mon May 27 21:15:45 2019 +0000
Revision:
37:a563899ac0df
Parent:
36:569ec4335f92
Child:
38:3b4c05af5f36
WIP - Added in code to take logs of file names (non-interactive)

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