old demo that i want to try in mbed studio

Dependencies:   mbed SDFileSystem_Copy_of_mbed_version I2S

Committer:
roryhand
Date:
Fri Sep 27 22:33:55 2019 +0000
Revision:
62:ac63dfe15ef9
Parent:
56:3755c53ac4c6
Child:
88:76a4563ee9c7
Version to Read in all the different notch transition files and output their start and end times.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
roryhand 1:aac37edee302 1
roryhand 0:e89d7a0bfa3b 2 // 24/03/2018 update - I appear to be able to address the device and write something, as I am getting an ACK returned from the i2c write() function.
roryhand 0:e89d7a0bfa3b 3 //however if i use the write function with 4 arguments (as opposed to just 1 argument) then it doesnt work
roryhand 0:e89d7a0bfa3b 4 //only works with the 1 argument version!!!
roryhand 0:e89d7a0bfa3b 5
roryhand 0:e89d7a0bfa3b 6
roryhand 0:e89d7a0bfa3b 7 //THIS VERSION WORKED, CHANGED SOME THINGS, THEN CHANGED THEM BACK. NOW IT NO LONGER WORKS!!!!
roryhand 0:e89d7a0bfa3b 8 #include "mbed.h"
roryhand 0:e89d7a0bfa3b 9 #include "math.h"
roryhand 1:aac37edee302 10 #include "I2S.h"
roryhand 1:aac37edee302 11 #include "SDFileSystem.h"
roryhand 0:e89d7a0bfa3b 12 #include "wm8731_Config_setup.h"
roryhand 0:e89d7a0bfa3b 13 #include "WOLFSON_config_consts.h"
roryhand 54:606a83fff291 14 //#include "BlockDevice.h"
roryhand 37:a563899ac0df 15 #include <string>
roryhand 0:e89d7a0bfa3b 16 #include <stdlib.h>
roryhand 27:a378f1f937ee 17 #include <fstream>
roryhand 27:a378f1f937ee 18 #include <iostream>
roryhand 0:e89d7a0bfa3b 19 #include <vector>
roryhand 0:e89d7a0bfa3b 20 #include <string>
roryhand 0:e89d7a0bfa3b 21 #define sample_freq 11025
roryhand 1:aac37edee302 22 #pragma import __use_two_region_memory
roryhand 54:606a83fff291 23 //BlockDevice *bd = BlockDevice::get_default_instance();
roryhand 54:606a83fff291 24 //#include "LittleFileSystem.h"
roryhand 54:606a83fff291 25 //LittleFileSystem fs("fs");
roryhand 54:606a83fff291 26
roryhand 0:e89d7a0bfa3b 27 DigitalOut myled(LED1);
roryhand 0:e89d7a0bfa3b 28 DigitalOut led2(LED2);
roryhand 0:e89d7a0bfa3b 29 DigitalOut led3(LED3);
roryhand 0:e89d7a0bfa3b 30 DigitalIn NotchUp(p16);
roryhand 38:3b4c05af5f36 31 DigitalIn NotchDown(p17);//check the pin!!! Dont know if this will actually work...
roryhand 0:e89d7a0bfa3b 32 InterruptIn Horn(p16);
roryhand 0:e89d7a0bfa3b 33 Ticker sampletick;
roryhand 45:0e8e1f2ec5d2 34
roryhand 0:e89d7a0bfa3b 35 Ticker TickFadeOut;
roryhand 0:e89d7a0bfa3b 36 Timer t;
roryhand 0:e89d7a0bfa3b 37 Timer t2;
roryhand 3:6169aeeaeeb4 38 Timer NotchTimer;
roryhand 27:a378f1f937ee 39 Timer timer_open;
roryhand 0:e89d7a0bfa3b 40
roryhand 0:e89d7a0bfa3b 41 Serial pc(USBTX, USBRX); // tx, rx //FOR DEBUGGING PROGRAM USING GNU SCREEN
roryhand 0:e89d7a0bfa3b 42 DigitalOut cs(p8);
roryhand 0:e89d7a0bfa3b 43 I2S i2s(I2S_TRANSMIT, p5, p6, p7);
roryhand 0:e89d7a0bfa3b 44 SDFileSystem sd(p11, p12, p13, p8, "sd"); // the new pinout that i am using
roryhand 0:e89d7a0bfa3b 45
roryhand 0:e89d7a0bfa3b 46
roryhand 0:e89d7a0bfa3b 47 /*struct A {
roryhand 0:e89d7a0bfa3b 48 int data;
roryhand 0:e89d7a0bfa3b 49 B b;
roryhand 0:e89d7a0bfa3b 50 };*/
roryhand 0:e89d7a0bfa3b 51
roryhand 0:e89d7a0bfa3b 52
roryhand 0:e89d7a0bfa3b 53
roryhand 0:e89d7a0bfa3b 54
roryhand 0:e89d7a0bfa3b 55 class classFade
roryhand 0:e89d7a0bfa3b 56 {
roryhand 1:aac37edee302 57 public:
roryhand 1:aac37edee302 58
roryhand 0:e89d7a0bfa3b 59 float powerval;
roryhand 0:e89d7a0bfa3b 60 float FadeIteration;
roryhand 0:e89d7a0bfa3b 61 float DecayFactor;
roryhand 0:e89d7a0bfa3b 62 float Denom;
roryhand 0:e89d7a0bfa3b 63 float FadeCoeff;
roryhand 0:e89d7a0bfa3b 64 float Natural_Exp;
roryhand 0:e89d7a0bfa3b 65 int LengthSecs;
roryhand 0:e89d7a0bfa3b 66 int Length;
roryhand 1:aac37edee302 67
roryhand 0:e89d7a0bfa3b 68 //member Functions
roryhand 0:e89d7a0bfa3b 69 float FadeOut(void)
roryhand 0:e89d7a0bfa3b 70 {
roryhand 0:e89d7a0bfa3b 71 powerval = -FadeIteration/Denom;
roryhand 1:aac37edee302 72 if (FadeIteration >=Length) {
roryhand 1:aac37edee302 73 FadeCoeff = 0;
roryhand 1:aac37edee302 74
roryhand 1:aac37edee302 75 } else {
roryhand 0:e89d7a0bfa3b 76 FadeCoeff = (Length - FadeIteration)/Length;
roryhand 0:e89d7a0bfa3b 77 }
roryhand 1:aac37edee302 78 FadeIteration = FadeIteration + 1;
roryhand 1:aac37edee302 79 return FadeCoeff;
roryhand 1:aac37edee302 80
roryhand 1:aac37edee302 81 }
roryhand 1:aac37edee302 82 float FadeIn(void)
roryhand 0:e89d7a0bfa3b 83 {
roryhand 0:e89d7a0bfa3b 84 powerval = FadeIteration/Denom;
roryhand 1:aac37edee302 85 if (FadeIteration >=Length) {
roryhand 1:aac37edee302 86 FadeCoeff = 1;
roryhand 1:aac37edee302 87
roryhand 1:aac37edee302 88 } else {
roryhand 0:e89d7a0bfa3b 89 FadeCoeff = FadeIteration/Length;
roryhand 0:e89d7a0bfa3b 90 }
roryhand 0:e89d7a0bfa3b 91
roryhand 1:aac37edee302 92 FadeIteration = FadeIteration + 1;
roryhand 1:aac37edee302 93 return FadeCoeff;
roryhand 1:aac37edee302 94
roryhand 1:aac37edee302 95 }
roryhand 0:e89d7a0bfa3b 96 };
roryhand 0:e89d7a0bfa3b 97
roryhand 0:e89d7a0bfa3b 98 classFade IdleFadeOut;
roryhand 0:e89d7a0bfa3b 99 classFade N2FadeIn;
roryhand 0:e89d7a0bfa3b 100
roryhand 2:957d3b2afff4 101 classFade NotchFadeOut;
roryhand 2:957d3b2afff4 102 classFade NotchFadeIn;
roryhand 2:957d3b2afff4 103
roryhand 0:e89d7a0bfa3b 104
roryhand 0:e89d7a0bfa3b 105
roryhand 0:e89d7a0bfa3b 106
roryhand 0:e89d7a0bfa3b 107
roryhand 1:aac37edee302 108 typedef struct uFMT_STRUCT {
roryhand 1:aac37edee302 109 short comp_code;
roryhand 1:aac37edee302 110 short num_channels;
roryhand 1:aac37edee302 111 unsigned sample_rate;
roryhand 1:aac37edee302 112 unsigned avg_Bps;
roryhand 1:aac37edee302 113 short block_align;
roryhand 1:aac37edee302 114 short sig_bps;
roryhand 0:e89d7a0bfa3b 115 } FMT_STRUCT;
roryhand 0:e89d7a0bfa3b 116
roryhand 1:aac37edee302 117 typedef struct uNotch_STRUCT {
roryhand 1:aac37edee302 118 short Notch;
roryhand 1:aac37edee302 119 short NotchTransUp;
roryhand 1:aac37edee302 120 short NotchTransDown;
roryhand 1:aac37edee302 121 short NotchDirection;
roryhand 1:aac37edee302 122 } Notch_STRUCT;
roryhand 1:aac37edee302 123
roryhand 0:e89d7a0bfa3b 124 typedef struct uDATA_STRUCT {
roryhand 1:aac37edee302 125 unsigned subchunk2_ID;
roryhand 1:aac37edee302 126 unsigned subchunk2_size;
roryhand 1:aac37edee302 127 char * data_buf;
roryhand 1:aac37edee302 128 } DATA_STRUCT;
roryhand 0:e89d7a0bfa3b 129
roryhand 1:aac37edee302 130 typedef struct uWAV_FILE_STRUCT {
roryhand 1:aac37edee302 131 FILE *WavFile;
roryhand 1:aac37edee302 132 int id_number;
roryhand 1:aac37edee302 133 char *slice_buf;
roryhand 1:aac37edee302 134 int num_slices;
roryhand 1:aac37edee302 135 FMT_STRUCT FileFormat;
roryhand 1:aac37edee302 136 DATA_STRUCT FileData;
roryhand 0:e89d7a0bfa3b 137 } WAV_FILE_STRUCT;
roryhand 0:e89d7a0bfa3b 138
roryhand 0:e89d7a0bfa3b 139 /*typedef struct uWAV_FILE_STRUCT{
roryhand 1:aac37edee302 140 FILE* WavFile;
roryhand 1:aac37edee302 141
roryhand 1:aac37edee302 142
roryhand 0:e89d7a0bfa3b 143 }WAV_FILE_STRUCT;*/
roryhand 0:e89d7a0bfa3b 144 class classSoundFile
roryhand 0:e89d7a0bfa3b 145 {
roryhand 1:aac37edee302 146 public:
roryhand 1:aac37edee302 147
roryhand 44:a9e84d333a6a 148 //add a class constructor at some point in the future (perform tests in visual studio)
roryhand 1:aac37edee302 149 WAV_FILE_STRUCT FileInfo;
roryhand 2:957d3b2afff4 150 short * data_sptr;
roryhand 36:569ec4335f92 151 string file_location;
roryhand 1:aac37edee302 152 //classSoundFile(string filename);//this is the constructor
roryhand 1:aac37edee302 153 //string filename;
roryhand 0:e89d7a0bfa3b 154 };
roryhand 0:e89d7a0bfa3b 155
roryhand 1:aac37edee302 156 //class constructor;
roryhand 1:aac37edee302 157 /*classSoundFile::classSoundFile(string filename)
roryhand 1:aac37edee302 158 {
roryhand 1:aac37edee302 159 //Declare RootFolder and the directory for the appropriate file.
roryhand 1:aac37edee302 160 //How we index into filename[] from the outside of this class is another
roryhand 1:aac37edee302 161 //issue...
roryhand 1:aac37edee302 162 FileInfo.WavFile = fopen("/sd/mydir/645Engine/Startup.wav","rb");
roryhand 1:aac37edee302 163 fseek(FileInfo.WavFile,20,SEEK_SET);
roryhand 1:aac37edee302 164 fread(&FileInfo.FileFormat,sizeof(FileInfo.FileFormat),1,FileInfo.WavFile);
roryhand 1:aac37edee302 165 printf("wav_format.sample_rate: %d\n\r",FileInfo.FileFormat.sample_rate);
roryhand 1:aac37edee302 166 fread(&FileInfo.FileData,sizeof(FileInfo.FileData),1,FileInfo.WavFile);
roryhand 1:aac37edee302 167 printf("wav_data.subchunk2_size: %d\n\r",FileInfo.FileData.subchunk2_size);
roryhand 1:aac37edee302 168 FileInfo.slice_buf = ( char *)malloc(FileInfo.FileFormat.block_align);
roryhand 1:aac37edee302 169 fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,FileInfo.WavFile); //This isnt actually required, its just a test
roryhand 1:aac37edee302 170 FileInfo.num_slices = FileInfo.FileData.subchunk2_size/FileInfo.FileFormat.block_align;
roryhand 1:aac37edee302 171 }*/
roryhand 54:606a83fff291 172 int OneOff = 0;
roryhand 38:3b4c05af5f36 173 int notch_flag = 0;
roryhand 0:e89d7a0bfa3b 174 int i = 0;
roryhand 0:e89d7a0bfa3b 175 int h = 0;
roryhand 0:e89d7a0bfa3b 176 short bufflen = 1;
roryhand 0:e89d7a0bfa3b 177 int buffer[1];
roryhand 1:aac37edee302 178 int AudioFormat, NumChannels, SampleRate, BitsPerSample ;
roryhand 0:e89d7a0bfa3b 179 char *slice_buf;
roryhand 0:e89d7a0bfa3b 180 short *data_sptr;
roryhand 0:e89d7a0bfa3b 181 short *data_sptr_horn;
roryhand 0:e89d7a0bfa3b 182 short *data_sptr_IdleN2;
roryhand 0:e89d7a0bfa3b 183 short * data_sptr_bell;
roryhand 0:e89d7a0bfa3b 184 short * data_sptr_N2;
roryhand 0:e89d7a0bfa3b 185 short * data_sptr_Flange;
roryhand 0:e89d7a0bfa3b 186 unsigned char *data_bptr;
roryhand 0:e89d7a0bfa3b 187 int *data_wptr;
roryhand 0:e89d7a0bfa3b 188 unsigned channel;
roryhand 45:0e8e1f2ec5d2 189 long slice, slice1, slice2, slice3, num_slices;
roryhand 0:e89d7a0bfa3b 190 int verbosity = 0;
roryhand 0:e89d7a0bfa3b 191 int verbosity2 = 0;
roryhand 0:e89d7a0bfa3b 192 int verbosity3 = 0;
roryhand 0:e89d7a0bfa3b 193 int verbosity4 = 0;
roryhand 0:e89d7a0bfa3b 194 int verbosity5 = 0;
roryhand 0:e89d7a0bfa3b 195 int interrupt_condition = 1;
roryhand 0:e89d7a0bfa3b 196 int sampling_freq = 11025;
roryhand 0:e89d7a0bfa3b 197 const int BufferLen = 2000;
roryhand 0:e89d7a0bfa3b 198 short Buffer1[BufferLen];
roryhand 0:e89d7a0bfa3b 199 short Buffer2[BufferLen];
roryhand 0:e89d7a0bfa3b 200 short place_hold1 = 0;
roryhand 0:e89d7a0bfa3b 201 short place_hold2 = 0;
roryhand 0:e89d7a0bfa3b 202
roryhand 3:6169aeeaeeb4 203
roryhand 3:6169aeeaeeb4 204 string FOLDER;
roryhand 3:6169aeeaeeb4 205 string RootFolder = "/sd/mydir/SoundDecoder/";
roryhand 3:6169aeeaeeb4 206 string filename[25];
roryhand 3:6169aeeaeeb4 207 classSoundFile Sound[22];
roryhand 3:6169aeeaeeb4 208
roryhand 0:e89d7a0bfa3b 209 volatile int flag1 = 1;
roryhand 0:e89d7a0bfa3b 210 volatile int flag2 = 0;
roryhand 0:e89d7a0bfa3b 211 volatile int flag3 = 1;
roryhand 0:e89d7a0bfa3b 212 volatile int flag4 = 0;
roryhand 0:e89d7a0bfa3b 213 int FLAGBUFF1 = 0;
roryhand 0:e89d7a0bfa3b 214 int FLAGBUFF2 = 0;
roryhand 0:e89d7a0bfa3b 215 int BellFlag = 0;
roryhand 0:e89d7a0bfa3b 216 int BellFlag2 = 0;
roryhand 0:e89d7a0bfa3b 217 int FadeFlag = 0;
roryhand 54:606a83fff291 218 int BlockFlag = 0;
roryhand 32:6ee488c97dcc 219 int FileSwitchFlag = 0;
roryhand 0:e89d7a0bfa3b 220
roryhand 0:e89d7a0bfa3b 221
roryhand 0:e89d7a0bfa3b 222 short value[1];
roryhand 0:e89d7a0bfa3b 223 FILE *HornWav;
roryhand 0:e89d7a0bfa3b 224 FILE *edsheeran_wav;
roryhand 0:e89d7a0bfa3b 225 FILE *Startup_wav;
roryhand 0:e89d7a0bfa3b 226 FILE *IdleN2Wav;
roryhand 0:e89d7a0bfa3b 227 FILE *N2Wav;
roryhand 0:e89d7a0bfa3b 228 FILE *BellWav;
roryhand 0:e89d7a0bfa3b 229 FILE *FlangeWav;
roryhand 16:5e3420d0509b 230 FILE *HeyWav;
roryhand 0:e89d7a0bfa3b 231 //long long slice_value;
roryhand 0:e89d7a0bfa3b 232 int slice_value[1];
roryhand 0:e89d7a0bfa3b 233
roryhand 0:e89d7a0bfa3b 234
roryhand 45:0e8e1f2ec5d2 235 FILE *wavfile1;
roryhand 45:0e8e1f2ec5d2 236 FILE *wavfile2;
roryhand 45:0e8e1f2ec5d2 237 FILE *wavfile3;
roryhand 45:0e8e1f2ec5d2 238
roryhand 45:0e8e1f2ec5d2 239 classSoundFile Sound1;
roryhand 45:0e8e1f2ec5d2 240 classSoundFile Sound2;
roryhand 45:0e8e1f2ec5d2 241 classSoundFile Sound3;
roryhand 45:0e8e1f2ec5d2 242
roryhand 0:e89d7a0bfa3b 243 WAV_FILE_STRUCT WavInfo_Horn;
roryhand 0:e89d7a0bfa3b 244 WAV_FILE_STRUCT WavInfo_IdleN2;
roryhand 0:e89d7a0bfa3b 245 WAV_FILE_STRUCT WavInfo_N2;
roryhand 0:e89d7a0bfa3b 246 WAV_FILE_STRUCT WavInfo_Bell;
roryhand 0:e89d7a0bfa3b 247 WAV_FILE_STRUCT WavInfo_Flange;
roryhand 20:9cc7d825c07b 248 WAV_FILE_STRUCT WavInfo_Hey;
roryhand 32:6ee488c97dcc 249 WAV_FILE_STRUCT WavInfo_N3;
roryhand 16:5e3420d0509b 250 WAV_FILE_STRUCT WavInfo_Frustration;
roryhand 0:e89d7a0bfa3b 251 Ticker flipper;
roryhand 0:e89d7a0bfa3b 252 char * slice_buf_bell;
roryhand 0:e89d7a0bfa3b 253 char * slice_buf_ed;
roryhand 0:e89d7a0bfa3b 254 char * slice_buf_startup;
roryhand 0:e89d7a0bfa3b 255 char * slice_buf_N2;
roryhand 1:aac37edee302 256 Notch_STRUCT NotchingSet;
roryhand 0:e89d7a0bfa3b 257 //test
roryhand 0:e89d7a0bfa3b 258 //short *data_sptr_bell = 0;
roryhand 0:e89d7a0bfa3b 259 short *data_sptr_ed = 0;
roryhand 0:e89d7a0bfa3b 260 short *data_sptr_startup = 0;
roryhand 32:6ee488c97dcc 261 FILE *StartupWav;
roryhand 32:6ee488c97dcc 262 FILE *N3Wav;
roryhand 33:a75f0a30fbdc 263 int temp = 0;
roryhand 1:aac37edee302 264 void flip()
roryhand 1:aac37edee302 265 {
roryhand 0:e89d7a0bfa3b 266 led2 = !led2;
roryhand 0:e89d7a0bfa3b 267 }
roryhand 0:e89d7a0bfa3b 268
roryhand 0:e89d7a0bfa3b 269
roryhand 0:e89d7a0bfa3b 270 void isr()
roryhand 0:e89d7a0bfa3b 271 {
roryhand 54:606a83fff291 272 //timer_interrupt.start();
roryhand 1:aac37edee302 273 if(flag1 == 0) {
roryhand 0:e89d7a0bfa3b 274 value[0] = Buffer1[place_hold1]>>4;
roryhand 0:e89d7a0bfa3b 275 i2s.write(value,1);//Send next PWM value to amp
roryhand 0:e89d7a0bfa3b 276 place_hold1 = place_hold1 + 1;
roryhand 1:aac37edee302 277 if( (place_hold1 >= BufferLen)) {
roryhand 0:e89d7a0bfa3b 278 led2 = !led2;
roryhand 0:e89d7a0bfa3b 279 place_hold1 = 0;
roryhand 0:e89d7a0bfa3b 280 place_hold2 = 0;
roryhand 0:e89d7a0bfa3b 281 flag1 = 1;
roryhand 0:e89d7a0bfa3b 282 flag2 = 0;
roryhand 1:aac37edee302 283 }
roryhand 1:aac37edee302 284 } else if(flag2 == 0) {
roryhand 0:e89d7a0bfa3b 285 value[0] = Buffer2[place_hold2]>>4;
roryhand 0:e89d7a0bfa3b 286 i2s.write(value,1);//Send next PWM value to amp
roryhand 0:e89d7a0bfa3b 287 place_hold2 = place_hold2 + 1;
roryhand 1:aac37edee302 288 if( (place_hold2 >= BufferLen) ) {
roryhand 0:e89d7a0bfa3b 289 led2 = !led2;
roryhand 0:e89d7a0bfa3b 290 place_hold1 = 0;
roryhand 0:e89d7a0bfa3b 291 place_hold2 = 0;
roryhand 0:e89d7a0bfa3b 292 flag1 = 0;
roryhand 1:aac37edee302 293 flag2 = 1;
roryhand 0:e89d7a0bfa3b 294 FLAGBUFF2 = 0;
roryhand 1:aac37edee302 295 }
roryhand 0:e89d7a0bfa3b 296 }
roryhand 54:606a83fff291 297
roryhand 54:606a83fff291 298 //timer_interrupt.stop();
roryhand 54:606a83fff291 299
roryhand 0:e89d7a0bfa3b 300 }
roryhand 1:aac37edee302 301
roryhand 0:e89d7a0bfa3b 302 void horn_sound()
roryhand 0:e89d7a0bfa3b 303 {
roryhand 0:e89d7a0bfa3b 304 BellFlag = 1;
roryhand 0:e89d7a0bfa3b 305 fseek(HornWav,44,SEEK_SET);
roryhand 0:e89d7a0bfa3b 306 fseek(BellWav,44,SEEK_SET);
roryhand 0:e89d7a0bfa3b 307 fseek(FlangeWav,44,SEEK_SET);
roryhand 0:e89d7a0bfa3b 308 fseek(N2Wav,44,SEEK_SET);
roryhand 0:e89d7a0bfa3b 309 }
roryhand 0:e89d7a0bfa3b 310
roryhand 0:e89d7a0bfa3b 311
roryhand 32:6ee488c97dcc 312 void FileSwitch_isr()
roryhand 0:e89d7a0bfa3b 313 {
roryhand 32:6ee488c97dcc 314 FileSwitchFlag = 1;
roryhand 33:a75f0a30fbdc 315 temp = 1;
roryhand 33:a75f0a30fbdc 316 /*FILE* testwav = fopen("/sd/mydir/SoundDecoder_second/05.wav","rb");
roryhand 33:a75f0a30fbdc 317 if(N3Wav == NULL) {
roryhand 33:a75f0a30fbdc 318 printf("Cannot Open testwav\n\r");
roryhand 33:a75f0a30fbdc 319 }
roryhand 33:a75f0a30fbdc 320 */
roryhand 32:6ee488c97dcc 321 fseek(N3Wav,44,SEEK_SET);
roryhand 32:6ee488c97dcc 322 // fclose(StartupWav);
roryhand 0:e89d7a0bfa3b 323 }
roryhand 0:e89d7a0bfa3b 324
roryhand 0:e89d7a0bfa3b 325
roryhand 0:e89d7a0bfa3b 326 void FadeOutIsr()
roryhand 0:e89d7a0bfa3b 327 {
roryhand 1:aac37edee302 328 FadeFlag = 1;
roryhand 54:606a83fff291 329 OneOff = 1;
roryhand 54:606a83fff291 330 /*
roryhand 54:606a83fff291 331 wavfile2 = fopen("/sd/mydir/SoundDecoder_second/09.wav","rb");
roryhand 54:606a83fff291 332 if(wavfile2 == NULL) {
roryhand 54:606a83fff291 333 printf("Cannot Open wavfile2\n\r");
roryhand 54:606a83fff291 334 }
roryhand 54:606a83fff291 335 */
roryhand 54:606a83fff291 336
roryhand 54:606a83fff291 337
roryhand 54:606a83fff291 338
roryhand 54:606a83fff291 339 /*
roryhand 54:606a83fff291 340 wavfile3 = fopen("/sd/mydir/SoundDecoder_second/02.wav","rb");
roryhand 54:606a83fff291 341 if(wavfile3 == NULL) {
roryhand 54:606a83fff291 342 printf("Cannot Open wavfile3\n\r");
roryhand 54:606a83fff291 343 }
roryhand 54:606a83fff291 344 */
roryhand 54:606a83fff291 345 /*
roryhand 54:606a83fff291 346 FILE* wavfile4 = fopen("/sd/mydir/SoundDecoder_second/04.wav","rb");
roryhand 54:606a83fff291 347 if(wavfile4 == NULL) {
roryhand 54:606a83fff291 348 printf("Cannot Open wavfile3\n\r");
roryhand 54:606a83fff291 349 }
roryhand 54:606a83fff291 350 */
roryhand 54:606a83fff291 351 //fseek(wavfile2,44,SEEK_SET);
roryhand 54:606a83fff291 352 //fseek(wavfile3,44,SEEK_SET);
roryhand 54:606a83fff291 353 slice2 = 0;
roryhand 54:606a83fff291 354 slice3 = 0;
roryhand 54:606a83fff291 355 BlockFlag = 1;
roryhand 47:9334a8f54997 356 //printf("We are inside the FadeOut interrupt routine\n\r");
roryhand 1:aac37edee302 357
roryhand 0:e89d7a0bfa3b 358 }
roryhand 38:3b4c05af5f36 359
roryhand 38:3b4c05af5f36 360
roryhand 38:3b4c05af5f36 361
roryhand 38:3b4c05af5f36 362
roryhand 0:e89d7a0bfa3b 363
roryhand 3:6169aeeaeeb4 364 classFade FadeDataInitialise(classFade FadeData);
roryhand 3:6169aeeaeeb4 365
roryhand 3:6169aeeaeeb4 366
roryhand 3:6169aeeaeeb4 367
roryhand 3:6169aeeaeeb4 368
roryhand 3:6169aeeaeeb4 369
roryhand 3:6169aeeaeeb4 370 //function prototypes
roryhand 45:0e8e1f2ec5d2 371 classSoundFile ReadFileInfo(classSoundFile Sound, FILE * wav_file);
roryhand 3:6169aeeaeeb4 372 classSoundFile LoadFileStream(classSoundFile FileInfo, string filename);
roryhand 3:6169aeeaeeb4 373
roryhand 3:6169aeeaeeb4 374 float FadeOut(void);
roryhand 3:6169aeeaeeb4 375 void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo);
roryhand 32:6ee488c97dcc 376 void Play_WaveFileDual(FILE * my_wav, WAV_FILE_STRUCT FileInfo);
roryhand 3:6169aeeaeeb4 377 //void Play_WaveFileLoop(FILE * my_wav, WAV_FILE_STRUCT FileInfo);
roryhand 3:6169aeeaeeb4 378 //*********************INTERRUPT ROUTINE FOR NOTCHING***************************
roryhand 0:e89d7a0bfa3b 379
roryhand 1:aac37edee302 380 void NotchUpIsr()
roryhand 0:e89d7a0bfa3b 381 {
roryhand 1:aac37edee302 382 if(1 <= NotchingSet.Notch < 8) {
roryhand 1:aac37edee302 383
roryhand 1:aac37edee302 384 NotchingSet.Notch = NotchingSet.Notch + 1;
roryhand 1:aac37edee302 385 NotchingSet.NotchTransUp = NotchingSet.Notch + 7;
roryhand 1:aac37edee302 386 NotchingSet.NotchDirection = 1;
roryhand 3:6169aeeaeeb4 387 FadeDataInitialise(NotchFadeIn);
roryhand 3:6169aeeaeeb4 388 FadeDataInitialise(NotchFadeOut);
roryhand 1:aac37edee302 389 }
roryhand 0:e89d7a0bfa3b 390 }
roryhand 0:e89d7a0bfa3b 391
roryhand 0:e89d7a0bfa3b 392 void NotchDownIsr()
roryhand 0:e89d7a0bfa3b 393 {
roryhand 1:aac37edee302 394 if(1 < NotchingSet.Notch <= 8) {
roryhand 1:aac37edee302 395 NotchingSet.Notch = NotchingSet.Notch - 1;
roryhand 1:aac37edee302 396 NotchingSet.NotchTransDown = NotchingSet.Notch + 15;;
roryhand 1:aac37edee302 397 NotchingSet.NotchDirection = 0;
roryhand 3:6169aeeaeeb4 398 FadeDataInitialise(NotchFadeIn);
roryhand 3:6169aeeaeeb4 399 FadeDataInitialise(NotchFadeOut);
roryhand 1:aac37edee302 400 }
roryhand 1:aac37edee302 401 }
roryhand 0:e89d7a0bfa3b 402
roryhand 0:e89d7a0bfa3b 403
roryhand 3:6169aeeaeeb4 404 /**********************END OF INTERRUPT ROUTINE FOR NOTCHING*******************/
roryhand 3:6169aeeaeeb4 405
roryhand 3:6169aeeaeeb4 406
roryhand 1:aac37edee302 407
roryhand 0:e89d7a0bfa3b 408
roryhand 3:6169aeeaeeb4 409
roryhand 3:6169aeeaeeb4 410
roryhand 44:a9e84d333a6a 411 void Play_WaveFileLoop(classSoundFile Sound1, classSoundFile Sound2, classSoundFile Sound3, FILE* wavfile1,FILE* wavfile2, FILE* wavfile3);
roryhand 1:aac37edee302 412 int main()
roryhand 1:aac37edee302 413 {
roryhand 44:a9e84d333a6a 414
roryhand 0:e89d7a0bfa3b 415 NotchUp.mode(PullUp);
roryhand 38:3b4c05af5f36 416 NotchDown.mode(PullUp);
roryhand 0:e89d7a0bfa3b 417
roryhand 0:e89d7a0bfa3b 418 pc.printf("Beginning of program\n");
roryhand 32:6ee488c97dcc 419
roryhand 13:8e93396a27c5 420
roryhand 13:8e93396a27c5 421
roryhand 4:55fbbb049bae 422
roryhand 25:5336e1cf38d6 423 printf("Do we even get to this stupid bloody point\n\r");
roryhand 0:e89d7a0bfa3b 424 //Populate our class instances with some data (is there an implicit way to do this?)
roryhand 28:6b2353fad12d 425
roryhand 1:aac37edee302 426
roryhand 3:6169aeeaeeb4 427 printf("hello\n\r");
roryhand 0:e89d7a0bfa3b 428 //Set up the wolfson Audio Codec board
roryhand 0:e89d7a0bfa3b 429 wm8731_Config_setup();
roryhand 0:e89d7a0bfa3b 430 //i2s audio data transfer code??
roryhand 0:e89d7a0bfa3b 431 i2s.stereomono(I2S_STEREO);
roryhand 0:e89d7a0bfa3b 432 i2s.masterslave(I2S_MASTER);
roryhand 0:e89d7a0bfa3b 433 led3 = 1;
roryhand 0:e89d7a0bfa3b 434 led2 = 1;
roryhand 45:0e8e1f2ec5d2 435 printf("Hello i2s has started!");
roryhand 30:4a8e80b243c4 436 i2s.start();
roryhand 0:e89d7a0bfa3b 437 sampletick.attach(&isr,1.0/sampling_freq); //1/16000
roryhand 45:0e8e1f2ec5d2 438 //fileswitch_tick.attach(&FileSwitch_isr,6.0);//So we can switch between playing file 1 and file 2, including opening and closing
roryhand 45:0e8e1f2ec5d2 439 //not convinced we need this above line at the moment!!
roryhand 54:606a83fff291 440 /*
roryhand 54:606a83fff291 441 FILE* f1 = fopen("/sd/mydir/SoundDecoder_second/01.wav","rb");
roryhand 54:606a83fff291 442
roryhand 54:606a83fff291 443
roryhand 54:606a83fff291 444 if(f1 == NULL) {
roryhand 54:606a83fff291 445 printf("Cannot Open f1\n\r");
roryhand 54:606a83fff291 446 }
roryhand 54:606a83fff291 447 printf("size of file pointer: %d\n\r",sizeof(f1));
roryhand 31:0f8c3adf09c3 448
roryhand 54:606a83fff291 449 FILE* f2 = fopen("/sd/mydir/SoundDecoder_second/02.wav","rb");
roryhand 54:606a83fff291 450 if(f2 == NULL) {
roryhand 54:606a83fff291 451 printf("Cannot Open f2\n\r");
roryhand 54:606a83fff291 452 }
roryhand 54:606a83fff291 453 printf("size of file pointer: %d\n\r",sizeof(f2));
roryhand 54:606a83fff291 454 FILE* f3 = fopen("/sd/mydir/SoundDecoder_second/03.wav","rb");
roryhand 54:606a83fff291 455 if(f3 == NULL) {
roryhand 54:606a83fff291 456 printf("Cannot Open f3\n\r");
roryhand 54:606a83fff291 457 }
roryhand 54:606a83fff291 458 printf("size of file pointer: %d\n\r",sizeof(f3));
roryhand 54:606a83fff291 459
roryhand 54:606a83fff291 460 FILE* f4 = fopen("/sd/mydir/SoundDecoder_second/04.wav","rb");
roryhand 54:606a83fff291 461 if(f4 == NULL) {
roryhand 54:606a83fff291 462 printf("Cannot Open f4\n\r");
roryhand 54:606a83fff291 463 }
roryhand 54:606a83fff291 464 printf("size of file pointer: %d\n\r",sizeof(f4));
roryhand 54:606a83fff291 465 FILE* f5 = fopen("/sd/mydir/SoundDecoder_second/05.wav","rb");
roryhand 54:606a83fff291 466 if(f5 == NULL) {
roryhand 54:606a83fff291 467 printf("Cannot Open f5\n\r");
roryhand 54:606a83fff291 468 }
roryhand 54:606a83fff291 469 printf("size of file pointer: %d\n\r",sizeof(f5));
roryhand 54:606a83fff291 470 FILE* f6 = fopen("/sd/mydir/SoundDecoder_second/06.wav","rb");
roryhand 54:606a83fff291 471 if(f6 == NULL) {
roryhand 54:606a83fff291 472 printf("Cannot Open f6\n\r");
roryhand 54:606a83fff291 473 }
roryhand 54:606a83fff291 474 printf("size of file pointer: %d\n\r",sizeof(f6));
roryhand 54:606a83fff291 475 FILE* f7 = fopen("/sd/mydir/SoundDecoder_second/07.wav","rb");
roryhand 54:606a83fff291 476 if(f7 == NULL) {
roryhand 54:606a83fff291 477 printf("Cannot Open f7\n\r");
roryhand 54:606a83fff291 478 }
roryhand 54:606a83fff291 479 printf("size of file pointer: %d\n\r",sizeof(f7));
roryhand 54:606a83fff291 480 FILE* f8 = fopen("/sd/mydir/SoundDecoder_second/08.wav","rb");
roryhand 54:606a83fff291 481 if(f8 == NULL) {
roryhand 54:606a83fff291 482 printf("Cannot Open f8\n\r");
roryhand 54:606a83fff291 483 }
roryhand 54:606a83fff291 484 printf("size of file pointer: %d\n\r",sizeof(f8));
roryhand 54:606a83fff291 485 FILE* f9 = fopen("/sd/mydir/SoundDecoder_second/09.wav","rb");
roryhand 54:606a83fff291 486 if(f9 == NULL) {
roryhand 54:606a83fff291 487 printf("Cannot Open f9\n\r");
roryhand 54:606a83fff291 488 }
roryhand 54:606a83fff291 489 printf("size of file pointer: %d\n\r",sizeof(f9));
roryhand 54:606a83fff291 490 FILE* f10 = fopen("/sd/mydir/SoundDecoder_second/10.wav","rb");
roryhand 54:606a83fff291 491 if(f10 == NULL) {
roryhand 54:606a83fff291 492 printf("Cannot Open f10\n\r");
roryhand 54:606a83fff291 493 }
roryhand 54:606a83fff291 494 printf("size of file pointer: %d\n\r",sizeof(f10));
roryhand 54:606a83fff291 495 FILE* f11 = fopen("/sd/mydir/SoundDecoder_second/11.wav","rb");
roryhand 54:606a83fff291 496 if(f11 == NULL) {
roryhand 54:606a83fff291 497 printf("Cannot Open f11\n\r");
roryhand 54:606a83fff291 498 }
roryhand 54:606a83fff291 499 printf("size of file pointer: %d\n\r",sizeof(f11));
roryhand 54:606a83fff291 500 FILE* f12 = fopen("/sd/mydir/SoundDecoder_second/12.wav","rb");
roryhand 54:606a83fff291 501 if(f12 == NULL) {
roryhand 54:606a83fff291 502 printf("Cannot Open f12\n\r");
roryhand 54:606a83fff291 503 }
roryhand 54:606a83fff291 504 printf("size of file pointer: %d\n\r",sizeof(f12));
roryhand 54:606a83fff291 505 FILE* f13 = fopen("/sd/mydir/SoundDecoder_second/13.wav","rb");
roryhand 54:606a83fff291 506 if(f13 == NULL) {
roryhand 54:606a83fff291 507 printf("Cannot Open f13\n\r");
roryhand 54:606a83fff291 508 }
roryhand 54:606a83fff291 509 printf("size of file pointer: %d\n\r",sizeof(f13));
roryhand 54:606a83fff291 510 FILE* f14 = fopen("/sd/mydir/SoundDecoder_second/14.wav","rb");
roryhand 54:606a83fff291 511 if(f14 == NULL) {
roryhand 54:606a83fff291 512 printf("Cannot Open f14\n\r");
roryhand 54:606a83fff291 513 }
roryhand 54:606a83fff291 514 printf("size of file pointer: %d\n\r",sizeof(f14));
roryhand 54:606a83fff291 515 FILE* f15 = fopen("/sd/mydir/SoundDecoder_second/15.wav","rb");
roryhand 54:606a83fff291 516 if(f15 == NULL) {
roryhand 54:606a83fff291 517 printf("Cannot Open f15\n\r");
roryhand 54:606a83fff291 518 }
roryhand 54:606a83fff291 519 printf("size of file pointer: %d\n\r",sizeof(f15));
roryhand 54:606a83fff291 520 FILE* f16 = fopen("/sd/mydir/SoundDecoder_second/16.wav","rb");
roryhand 54:606a83fff291 521 if(f16 == NULL) {
roryhand 54:606a83fff291 522 printf("Cannot Open f16\n\r");
roryhand 54:606a83fff291 523 }
roryhand 54:606a83fff291 524 printf("size of file pointer: %d\n\r",sizeof(f16));
roryhand 54:606a83fff291 525 FILE* f17 = fopen("/sd/mydir/SoundDecoder_second/17.wav","rb");
roryhand 54:606a83fff291 526 if(f17 == NULL) {
roryhand 54:606a83fff291 527 printf("Cannot Open f17\n\r");
roryhand 54:606a83fff291 528 }
roryhand 54:606a83fff291 529 printf("size of file pointer: %d\n\r",sizeof(f17));
roryhand 54:606a83fff291 530 FILE* f18 = fopen("/sd/mydir/SoundDecoder_second/18.wav","rb");
roryhand 54:606a83fff291 531 if(f18 == NULL) {
roryhand 54:606a83fff291 532 printf("Cannot Open f18\n\r");
roryhand 54:606a83fff291 533 }
roryhand 54:606a83fff291 534 printf("size of file pointer: %d\n\r",sizeof(f18));
roryhand 54:606a83fff291 535 FILE* f19 = fopen("/sd/mydir/SoundDecoder_second/19.wav","rb");
roryhand 54:606a83fff291 536 if(f19 == NULL) {
roryhand 54:606a83fff291 537 printf("Cannot Open f19\n\r");
roryhand 54:606a83fff291 538 }
roryhand 54:606a83fff291 539 printf("size of file pointer: %d\n\r",sizeof(f19));
roryhand 54:606a83fff291 540 FILE* f20 = fopen("/sd/mydir/SoundDecoder_second/20.wav","rb");
roryhand 54:606a83fff291 541 if(f20 == NULL) {
roryhand 54:606a83fff291 542 printf("Cannot Open f20\n\r");
roryhand 54:606a83fff291 543 }
roryhand 54:606a83fff291 544 printf("size of file pointer: %d\n\r",sizeof(f20));
roryhand 54:606a83fff291 545 FILE* f21 = fopen("/sd/mydir/SoundDecoder_second/21.wav","rb");
roryhand 54:606a83fff291 546 if(f21 == NULL) {
roryhand 54:606a83fff291 547 printf("Cannot Open f21\n\r");
roryhand 54:606a83fff291 548 }
roryhand 54:606a83fff291 549 printf("size of file pointer: %d\n\r",sizeof(f21));
roryhand 54:606a83fff291 550 FILE* f22 = fopen("/sd/mydir/SoundDecoder_second/22.wav","rb");
roryhand 54:606a83fff291 551 if(f22 == NULL) {
roryhand 54:606a83fff291 552 printf("Cannot Open f22\n\r");
roryhand 54:606a83fff291 553 }
roryhand 54:606a83fff291 554 printf("size of file pointer: %d\n\r",sizeof(f22));
roryhand 54:606a83fff291 555 */
roryhand 56:3755c53ac4c6 556
roryhand 62:ac63dfe15ef9 557
roryhand 31:0f8c3adf09c3 558 timer_open.reset();
roryhand 32:6ee488c97dcc 559 timer_open.start();
roryhand 62:ac63dfe15ef9 560 wavfile1 = fopen("/sd/mydir/SoundDecoder_second/09.wav","rb");
roryhand 54:606a83fff291 561 if(wavfile1 == NULL) {
roryhand 45:0e8e1f2ec5d2 562 printf("Cannot Open wavfile1\n\r");
roryhand 32:6ee488c97dcc 563 }
roryhand 54:606a83fff291 564 printf("size of wavfile1 %d\n\r",sizeof(wavfile1));
roryhand 54:606a83fff291 565 timer_open.stop();
roryhand 31:0f8c3adf09c3 566 printf("It took %d useconds to open file\n\r",timer_open.read_us());
roryhand 54:606a83fff291 567 timer_open.reset();
roryhand 54:606a83fff291 568
roryhand 54:606a83fff291 569
roryhand 54:606a83fff291 570 printf("Size of wavfile 1: %d bytes\n\r",sizeof(wavfile1));
roryhand 45:0e8e1f2ec5d2 571 timer_open.start();
roryhand 62:ac63dfe15ef9 572 wavfile2 = fopen("/sd/mydir/SoundDecoder_second/10.wav","rb");
roryhand 54:606a83fff291 573 if(wavfile2 == NULL) {
roryhand 45:0e8e1f2ec5d2 574 printf("Cannot Open wavfile2\n\r");
roryhand 45:0e8e1f2ec5d2 575 }
roryhand 54:606a83fff291 576 timer_open.stop();
roryhand 45:0e8e1f2ec5d2 577 printf("It took %d useconds to open file\n\r",timer_open.read_us());
roryhand 54:606a83fff291 578 timer_open.reset();
roryhand 54:606a83fff291 579
roryhand 32:6ee488c97dcc 580 timer_open.start();
roryhand 62:ac63dfe15ef9 581 wavfile3 = fopen("/sd/mydir/SoundDecoder_second/11.wav","rb");
roryhand 54:606a83fff291 582 if(wavfile3 == NULL) {
roryhand 45:0e8e1f2ec5d2 583 printf("Cannot Open wavfile3\n\r");
roryhand 45:0e8e1f2ec5d2 584 }
roryhand 54:606a83fff291 585 timer_open.stop();
roryhand 45:0e8e1f2ec5d2 586 printf("It took %d useconds to open file\n\r",timer_open.read_us());
roryhand 54:606a83fff291 587 timer_open.reset();
roryhand 54:606a83fff291 588
roryhand 54:606a83fff291 589
roryhand 45:0e8e1f2ec5d2 590 Sound1 = ReadFileInfo(Sound1,wavfile1);
roryhand 45:0e8e1f2ec5d2 591 Sound2 = ReadFileInfo(Sound2,wavfile2);
roryhand 45:0e8e1f2ec5d2 592 Sound3 = ReadFileInfo(Sound3,wavfile3);
roryhand 55:5a441d3b0d57 593
roryhand 62:ac63dfe15ef9 594 FILE* wavfile4 = fopen("/sd/mydir/SoundDecoder_second/12.wav","rb");
roryhand 54:606a83fff291 595 if(wavfile4 == NULL) {
roryhand 54:606a83fff291 596 printf("Cannot Open wavfile4\n\r");
roryhand 54:606a83fff291 597 }
roryhand 55:5a441d3b0d57 598 classSoundFile Sound4;
roryhand 54:606a83fff291 599 Sound4 = ReadFileInfo(Sound4,wavfile4);
roryhand 55:5a441d3b0d57 600 fclose(wavfile4);
roryhand 55:5a441d3b0d57 601
roryhand 62:ac63dfe15ef9 602 FILE* wavfile5 = fopen("/sd/mydir/SoundDecoder_second/13.wav","rb");
roryhand 55:5a441d3b0d57 603 if(wavfile5 == NULL) {
roryhand 55:5a441d3b0d57 604 printf("Cannot Open wavfile5\n\r");
roryhand 55:5a441d3b0d57 605 }
roryhand 55:5a441d3b0d57 606 classSoundFile Sound5;
roryhand 55:5a441d3b0d57 607 Sound5 = ReadFileInfo(Sound5,wavfile5);
roryhand 55:5a441d3b0d57 608 fclose(wavfile5);
roryhand 55:5a441d3b0d57 609
roryhand 55:5a441d3b0d57 610
roryhand 62:ac63dfe15ef9 611 FILE* wavfile6 = fopen("/sd/mydir/SoundDecoder_second/14.wav","rb");
roryhand 55:5a441d3b0d57 612 if(wavfile6 == NULL) {
roryhand 55:5a441d3b0d57 613 printf("Cannot Open wavfile6\n\r");
roryhand 55:5a441d3b0d57 614 }
roryhand 55:5a441d3b0d57 615 classSoundFile Sound6;
roryhand 55:5a441d3b0d57 616 Sound6 = ReadFileInfo(Sound6,wavfile6);
roryhand 55:5a441d3b0d57 617 fclose(wavfile6);
roryhand 55:5a441d3b0d57 618
roryhand 55:5a441d3b0d57 619
roryhand 62:ac63dfe15ef9 620 FILE* wavfile7 = fopen("/sd/mydir/SoundDecoder_second/15.wav","rb");
roryhand 55:5a441d3b0d57 621 if(wavfile7 == NULL) {
roryhand 55:5a441d3b0d57 622 printf("Cannot Open wavfile7\n\r");
roryhand 55:5a441d3b0d57 623 }
roryhand 55:5a441d3b0d57 624 classSoundFile Sound7;
roryhand 55:5a441d3b0d57 625 Sound7 = ReadFileInfo(Sound7,wavfile7);
roryhand 55:5a441d3b0d57 626 fclose(wavfile7);
roryhand 55:5a441d3b0d57 627
roryhand 55:5a441d3b0d57 628
roryhand 62:ac63dfe15ef9 629 FILE* wavfile8 = fopen("/sd/mydir/SoundDecoder_second/16.wav","rb");
roryhand 55:5a441d3b0d57 630 if(wavfile8 == NULL) {
roryhand 55:5a441d3b0d57 631 printf("Cannot Open wavfile8\n\r");
roryhand 55:5a441d3b0d57 632 }
roryhand 55:5a441d3b0d57 633 classSoundFile Sound8;
roryhand 55:5a441d3b0d57 634 Sound8 = ReadFileInfo(Sound8,wavfile8);
roryhand 55:5a441d3b0d57 635 fclose(wavfile8);
roryhand 55:5a441d3b0d57 636
roryhand 62:ac63dfe15ef9 637
roryhand 55:5a441d3b0d57 638
roryhand 62:ac63dfe15ef9 639 FILE* wavfile9 = fopen("/sd/mydir/SoundDecoder_second/17.wav","rb");
roryhand 55:5a441d3b0d57 640 if(wavfile9 == NULL) {
roryhand 55:5a441d3b0d57 641 printf("Cannot Open wavfile9\n\r");
roryhand 55:5a441d3b0d57 642 }
roryhand 55:5a441d3b0d57 643 classSoundFile Sound9;
roryhand 55:5a441d3b0d57 644 Sound9 = ReadFileInfo(Sound9,wavfile9);
roryhand 55:5a441d3b0d57 645 fclose(wavfile9);
roryhand 55:5a441d3b0d57 646
roryhand 55:5a441d3b0d57 647
roryhand 62:ac63dfe15ef9 648 FILE* wavfile10 = fopen("/sd/mydir/SoundDecoder_second/18.wav","rb");
roryhand 55:5a441d3b0d57 649 if(wavfile10 == NULL) {
roryhand 55:5a441d3b0d57 650 printf("Cannot Open wavfile10\n\r");
roryhand 55:5a441d3b0d57 651 }
roryhand 55:5a441d3b0d57 652 classSoundFile Sound10;
roryhand 55:5a441d3b0d57 653 Sound10 = ReadFileInfo(Sound10,wavfile10);
roryhand 55:5a441d3b0d57 654 fclose(wavfile10);
roryhand 55:5a441d3b0d57 655
roryhand 55:5a441d3b0d57 656
roryhand 62:ac63dfe15ef9 657 FILE* wavfile11 = fopen("/sd/mydir/SoundDecoder_second/19.wav","rb");
roryhand 55:5a441d3b0d57 658 if(wavfile11 == NULL) {
roryhand 55:5a441d3b0d57 659 printf("Cannot Open wavfile11\n\r");
roryhand 55:5a441d3b0d57 660 }
roryhand 55:5a441d3b0d57 661 classSoundFile Sound11;
roryhand 55:5a441d3b0d57 662 Sound11 = ReadFileInfo(Sound11,wavfile11);
roryhand 55:5a441d3b0d57 663 fclose(wavfile11);
roryhand 55:5a441d3b0d57 664
roryhand 55:5a441d3b0d57 665
roryhand 62:ac63dfe15ef9 666 FILE* wavfile12 = fopen("/sd/mydir/SoundDecoder_second/20.wav","rb");
roryhand 55:5a441d3b0d57 667 if(wavfile12 == NULL) {
roryhand 55:5a441d3b0d57 668 printf("Cannot Open wavfile12\n\r");
roryhand 55:5a441d3b0d57 669 }
roryhand 55:5a441d3b0d57 670 classSoundFile Sound12;
roryhand 55:5a441d3b0d57 671 Sound12 = ReadFileInfo(Sound12,wavfile12);
roryhand 55:5a441d3b0d57 672 fclose(wavfile12);
roryhand 55:5a441d3b0d57 673
roryhand 62:ac63dfe15ef9 674 FILE* wavfile13 = fopen("/sd/mydir/SoundDecoder_second/21.wav","rb");
roryhand 55:5a441d3b0d57 675 if(wavfile13 == NULL) {
roryhand 55:5a441d3b0d57 676 printf("Cannot Open wavfile13\n\r");
roryhand 55:5a441d3b0d57 677 }
roryhand 55:5a441d3b0d57 678 classSoundFile Sound13;
roryhand 55:5a441d3b0d57 679 Sound13 = ReadFileInfo(Sound13,wavfile13);
roryhand 55:5a441d3b0d57 680 fclose(wavfile13);
roryhand 55:5a441d3b0d57 681
roryhand 55:5a441d3b0d57 682
roryhand 62:ac63dfe15ef9 683 FILE* wavfile14 = fopen("/sd/mydir/SoundDecoder_second/22.wav","rb");
roryhand 55:5a441d3b0d57 684 if(wavfile14 == NULL) {
roryhand 55:5a441d3b0d57 685 printf("Cannot Open wavfile14\n\r");
roryhand 55:5a441d3b0d57 686 }
roryhand 55:5a441d3b0d57 687 classSoundFile Sound14;
roryhand 55:5a441d3b0d57 688 Sound14 = ReadFileInfo(Sound14,wavfile14);
roryhand 55:5a441d3b0d57 689 fclose(wavfile14);
roryhand 55:5a441d3b0d57 690
roryhand 62:ac63dfe15ef9 691 /*
roryhand 55:5a441d3b0d57 692 FILE* wavfile15 = fopen("/sd/mydir/SoundDecoder_second/15.wav","rb");
roryhand 55:5a441d3b0d57 693 if(wavfile15 == NULL) {
roryhand 55:5a441d3b0d57 694 printf("Cannot Open wavfile15\n\r");
roryhand 55:5a441d3b0d57 695 }
roryhand 55:5a441d3b0d57 696 classSoundFile Sound15;
roryhand 55:5a441d3b0d57 697 Sound15 = ReadFileInfo(Sound15,wavfile15);
roryhand 55:5a441d3b0d57 698 fclose(wavfile15);
roryhand 55:5a441d3b0d57 699
roryhand 55:5a441d3b0d57 700
roryhand 55:5a441d3b0d57 701 FILE* wavfile16 = fopen("/sd/mydir/SoundDecoder_second/16.wav","rb");
roryhand 55:5a441d3b0d57 702 if(wavfile16 == NULL) {
roryhand 55:5a441d3b0d57 703 printf("Cannot Open wavfile16\n\r");
roryhand 55:5a441d3b0d57 704 }
roryhand 55:5a441d3b0d57 705 classSoundFile Sound16;
roryhand 55:5a441d3b0d57 706 Sound16 = ReadFileInfo(Sound16,wavfile16);
roryhand 55:5a441d3b0d57 707 fclose(wavfile16);
roryhand 55:5a441d3b0d57 708
roryhand 55:5a441d3b0d57 709
roryhand 55:5a441d3b0d57 710 FILE* wavfile17 = fopen("/sd/mydir/SoundDecoder_second/17.wav","rb");
roryhand 55:5a441d3b0d57 711 if(wavfile17 == NULL) {
roryhand 55:5a441d3b0d57 712 printf("Cannot Open wavfile17\n\r");
roryhand 55:5a441d3b0d57 713 }
roryhand 55:5a441d3b0d57 714 classSoundFile Sound17;
roryhand 55:5a441d3b0d57 715 Sound17 = ReadFileInfo(Sound17,wavfile17);
roryhand 55:5a441d3b0d57 716 fclose(wavfile17);
roryhand 55:5a441d3b0d57 717
roryhand 55:5a441d3b0d57 718
roryhand 55:5a441d3b0d57 719 FILE* wavfile18 = fopen("/sd/mydir/SoundDecoder_second/18.wav","rb");
roryhand 55:5a441d3b0d57 720 if(wavfile18 == NULL) {
roryhand 55:5a441d3b0d57 721 printf("Cannot Open wavfile18\n\r");
roryhand 55:5a441d3b0d57 722 }
roryhand 55:5a441d3b0d57 723 classSoundFile Sound18;
roryhand 55:5a441d3b0d57 724 Sound18 = ReadFileInfo(Sound18,wavfile18);
roryhand 55:5a441d3b0d57 725 fclose(wavfile18);
roryhand 55:5a441d3b0d57 726
roryhand 55:5a441d3b0d57 727
roryhand 55:5a441d3b0d57 728 FILE* wavfile19 = fopen("/sd/mydir/SoundDecoder_second/19.wav","rb");
roryhand 55:5a441d3b0d57 729 if(wavfile19 == NULL) {
roryhand 55:5a441d3b0d57 730 printf("Cannot Open wavfile19\n\r");
roryhand 55:5a441d3b0d57 731 }
roryhand 55:5a441d3b0d57 732 classSoundFile Sound19;
roryhand 55:5a441d3b0d57 733 Sound19 = ReadFileInfo(Sound19,wavfile19);
roryhand 55:5a441d3b0d57 734 fclose(wavfile19);
roryhand 56:3755c53ac4c6 735 */
roryhand 55:5a441d3b0d57 736
roryhand 56:3755c53ac4c6 737 //FILE* f1 = fopen("/sd/mydir/SoundDecoder_second/01.txt","rb");
roryhand 55:5a441d3b0d57 738
roryhand 56:3755c53ac4c6 739 //fprintf(f1, Sound1.FileInfo.FileData.subchunk2_size);
roryhand 55:5a441d3b0d57 740
roryhand 55:5a441d3b0d57 741
roryhand 55:5a441d3b0d57 742
roryhand 55:5a441d3b0d57 743
roryhand 13:8e93396a27c5 744
roryhand 54:606a83fff291 745 fclose(wavfile2);
roryhand 54:606a83fff291 746 fclose(wavfile3);
roryhand 47:9334a8f54997 747 NotchFadeIn.LengthSecs = 2;
roryhand 46:de390e45c2af 748 NotchFadeOut.LengthSecs = 2;
roryhand 46:de390e45c2af 749 NotchFadeIn = FadeDataInitialise(NotchFadeIn);
roryhand 46:de390e45c2af 750 NotchFadeOut = FadeDataInitialise(NotchFadeOut);
roryhand 45:0e8e1f2ec5d2 751
roryhand 45:0e8e1f2ec5d2 752
roryhand 45:0e8e1f2ec5d2 753
roryhand 45:0e8e1f2ec5d2 754 TickFadeOut.attach(&FadeOutIsr,10.0);
roryhand 45:0e8e1f2ec5d2 755
roryhand 54:606a83fff291 756
roryhand 54:606a83fff291 757 //timer_interrupt.reset();
roryhand 54:606a83fff291 758
roryhand 20:9cc7d825c07b 759 printf("about to play wav file\n\r");
roryhand 45:0e8e1f2ec5d2 760 Play_WaveFileLoop(Sound1,Sound2,Sound3,wavfile1,wavfile2,wavfile3);
roryhand 45:0e8e1f2ec5d2 761 //Play_WaveFileDual(StartupWav,WavInfo_Startup);
roryhand 20:9cc7d825c07b 762 printf("finished playing Wav file\n\r");
roryhand 54:606a83fff291 763
roryhand 54:606a83fff291 764
roryhand 31:0f8c3adf09c3 765 timer_open.reset();
roryhand 31:0f8c3adf09c3 766 timer_open.start();
roryhand 45:0e8e1f2ec5d2 767 fclose(wavfile1);
roryhand 31:0f8c3adf09c3 768 timer_open.stop();
roryhand 31:0f8c3adf09c3 769 printf("It took %d useconds to close file\n\r",timer_open.read_us());
roryhand 54:606a83fff291 770
roryhand 45:0e8e1f2ec5d2 771 timer_open.reset();
roryhand 54:606a83fff291 772 timer_open.start();
roryhand 45:0e8e1f2ec5d2 773 fclose(wavfile2);
roryhand 45:0e8e1f2ec5d2 774 timer_open.stop();
roryhand 54:606a83fff291 775 printf("It took %d useconds to close file\n\r",timer_open.read_us());
roryhand 54:606a83fff291 776
roryhand 54:606a83fff291 777
roryhand 45:0e8e1f2ec5d2 778 timer_open.reset();
roryhand 54:606a83fff291 779 timer_open.start();
roryhand 45:0e8e1f2ec5d2 780 fclose(wavfile3);
roryhand 45:0e8e1f2ec5d2 781 timer_open.stop();
roryhand 45:0e8e1f2ec5d2 782 printf("It took %d useconds to close file\n\r",timer_open.read_us());
roryhand 54:606a83fff291 783
roryhand 54:606a83fff291 784
roryhand 54:606a83fff291 785
roryhand 9:dd9cae06b202 786 /************************************PLAY WAV FILE LOOP*******************/
roryhand 20:9cc7d825c07b 787 //Play_WaveFileLoop(Sound, NotchingSet);
roryhand 9:dd9cae06b202 788 /************************************END OF PLAY WAV FILE LOOP*************/
roryhand 13:8e93396a27c5 789
roryhand 13:8e93396a27c5 790
roryhand 1:aac37edee302 791 i2s.stop();
roryhand 0:e89d7a0bfa3b 792
roryhand 0:e89d7a0bfa3b 793 }
roryhand 0:e89d7a0bfa3b 794
roryhand 0:e89d7a0bfa3b 795
roryhand 3:6169aeeaeeb4 796
roryhand 3:6169aeeaeeb4 797
roryhand 3:6169aeeaeeb4 798
roryhand 3:6169aeeaeeb4 799
roryhand 45:0e8e1f2ec5d2 800 classSoundFile ReadFileInfo(classSoundFile Sound, FILE * wav_file)
roryhand 0:e89d7a0bfa3b 801 {
roryhand 0:e89d7a0bfa3b 802 fseek(wav_file,20,SEEK_SET);
roryhand 22:706e86dc0d45 803 printf("We have just seeked through this file\n\r");
roryhand 45:0e8e1f2ec5d2 804 fread(&Sound.FileInfo.FileFormat,sizeof(Sound.FileInfo.FileFormat),1,wav_file);
roryhand 1:aac37edee302 805 //printf("wav_format.sample_rate: %d\n\r",FileInfo.FileFormat.sample_rate);
roryhand 1:aac37edee302 806
roryhand 45:0e8e1f2ec5d2 807 fread(&Sound.FileInfo.FileData,sizeof(Sound.FileInfo.FileData),1,wav_file);
roryhand 55:5a441d3b0d57 808 printf("wav_data.subchunk2_size: %d\n\r",Sound.FileInfo.FileData.subchunk2_size);
roryhand 45:0e8e1f2ec5d2 809 Sound.FileInfo.slice_buf = ( char *)malloc(Sound.FileInfo.FileFormat.block_align);
roryhand 45:0e8e1f2ec5d2 810 fread(Sound.FileInfo.slice_buf,Sound.FileInfo.FileFormat.block_align,1,wav_file); //This isnt actually required, its just a test
roryhand 45:0e8e1f2ec5d2 811 Sound.FileInfo.num_slices = Sound.FileInfo.FileData.subchunk2_size/Sound.FileInfo.FileFormat.block_align;
roryhand 1:aac37edee302 812 //printf("Number of Slices: %d\n\r",FileInfo.num_slices);
roryhand 45:0e8e1f2ec5d2 813 return Sound;
roryhand 0:e89d7a0bfa3b 814 }
roryhand 1:aac37edee302 815
roryhand 1:aac37edee302 816 classSoundFile LoadFileStream(classSoundFile Sound, string filename)
roryhand 1:aac37edee302 817 {
roryhand 1:aac37edee302 818 //Declare RootFolder and the directory for the appropriate file.
roryhand 1:aac37edee302 819 //How we index into filename[] from the outside of this class is another
roryhand 1:aac37edee302 820 //issue...
roryhand 1:aac37edee302 821 //printf("FileName: %s\n\r",filename);
roryhand 1:aac37edee302 822 //string RootFolder = "/sd/mydir/SoundDecoder/";
roryhand 1:aac37edee302 823 //string Directory = RootFolder + "01.wav";// + filename[0];
roryhand 1:aac37edee302 824 //printf("%s\n\r",Directory);
roryhand 1:aac37edee302 825 //const char* DirectoryChar = Directory.c_str();
roryhand 1:aac37edee302 826 //Sound.FileInfo.WavFile = fopen(DirectoryChar,"rb");
roryhand 1:aac37edee302 827 Sound.FileInfo.WavFile = fopen("/sd/mydir/645Engine/Startup.wav","rb");
roryhand 1:aac37edee302 828 fseek(Sound.FileInfo.WavFile,20,SEEK_SET);
roryhand 1:aac37edee302 829 fread(&Sound.FileInfo.FileFormat,sizeof(Sound.FileInfo.FileFormat),1,Sound.FileInfo.WavFile);
roryhand 1:aac37edee302 830 printf("wav_format.sample_rate: %d\n\r",Sound.FileInfo.FileFormat.sample_rate);
roryhand 1:aac37edee302 831 fread(&Sound.FileInfo.FileData,sizeof(Sound.FileInfo.FileData),1,Sound.FileInfo.WavFile);
roryhand 1:aac37edee302 832 printf("wav_data.subchunk2_size: %d\n\r",Sound.FileInfo.FileData.subchunk2_size);
roryhand 1:aac37edee302 833 Sound.FileInfo.slice_buf = ( char *)malloc(Sound.FileInfo.FileFormat.block_align);
roryhand 1:aac37edee302 834 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 835 Sound.FileInfo.num_slices = Sound.FileInfo.FileData.subchunk2_size/Sound.FileInfo.FileFormat.block_align;
roryhand 1:aac37edee302 836 printf("Number of Slices: %d\n\r",Sound.FileInfo.num_slices);
roryhand 1:aac37edee302 837 return Sound;
roryhand 1:aac37edee302 838 }
roryhand 1:aac37edee302 839
roryhand 1:aac37edee302 840
roryhand 0:e89d7a0bfa3b 841 classFade FadeDataInitialise(classFade FadeData)
roryhand 0:e89d7a0bfa3b 842 {
roryhand 1:aac37edee302 843 FadeData.DecayFactor = 1.3;
roryhand 0:e89d7a0bfa3b 844 FadeData.FadeIteration = 1;
roryhand 0:e89d7a0bfa3b 845 //FadeData.Denom = 11025*FadeData.DecayFactor;
roryhand 0:e89d7a0bfa3b 846 FadeData.Denom = 11025*FadeData.DecayFactor;
roryhand 0:e89d7a0bfa3b 847 FadeData.Natural_Exp = 2.7183;
roryhand 0:e89d7a0bfa3b 848 FadeData.Length = 11025*FadeData.LengthSecs;
roryhand 0:e89d7a0bfa3b 849 //FadeData.Natural_Exp = 2.7;
roryhand 0:e89d7a0bfa3b 850 return FadeData;
roryhand 0:e89d7a0bfa3b 851 }
roryhand 0:e89d7a0bfa3b 852
roryhand 0:e89d7a0bfa3b 853 //Playing Files Code
roryhand 46:de390e45c2af 854 /*
roryhand 45:0e8e1f2ec5d2 855 float FadeIn(void)
roryhand 0:e89d7a0bfa3b 856 {
roryhand 0:e89d7a0bfa3b 857 powervalFadeIn = FadeIterationIn/denom;
roryhand 0:e89d7a0bfa3b 858 FadeCoeffFadeIn
roryhand 1:aac37edee302 859
roryhand 1:aac37edee302 860
roryhand 45:0e8e1f2ec5d2 861 }
roryhand 45:0e8e1f2ec5d2 862 float FadeOut(void)
roryhand 0:e89d7a0bfa3b 863 {
roryhand 0:e89d7a0bfa3b 864 powerval = -FadeIteration/denom;
roryhand 0:e89d7a0bfa3b 865 FadeCoeff = pow(natural_exp,powerval);
roryhand 1:aac37edee302 866 FadeIteration = FadeIteration + 1;
roryhand 1:aac37edee302 867 return FadeCoeff;
roryhand 1:aac37edee302 868
roryhand 45:0e8e1f2ec5d2 869 }
roryhand 46:de390e45c2af 870 */
roryhand 0:e89d7a0bfa3b 871
roryhand 0:e89d7a0bfa3b 872 void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo)
roryhand 0:e89d7a0bfa3b 873 {
roryhand 1:aac37edee302 874 while(slice<FileInfo.num_slices) {
roryhand 1:aac37edee302 875 fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,my_wav);
roryhand 1:aac37edee302 876 data_sptr=(short *)FileInfo.slice_buf; // 16 bit samples
roryhand 1:aac37edee302 877 for (channel=0; channel<FileInfo.FileFormat.num_channels; channel++) {
roryhand 1:aac37edee302 878 if(flag1 == 1) {
roryhand 1:aac37edee302 879 Buffer1[place_hold1] = data_sptr[channel];
roryhand 1:aac37edee302 880 place_hold1 = place_hold1 + 1;
roryhand 1:aac37edee302 881 if(place_hold1 >= BufferLen) {
roryhand 1:aac37edee302 882 while(1) {
roryhand 1:aac37edee302 883 if(flag1 == 0) {
roryhand 0:e89d7a0bfa3b 884
roryhand 1:aac37edee302 885 break;
roryhand 0:e89d7a0bfa3b 886 }
roryhand 1:aac37edee302 887
roryhand 0:e89d7a0bfa3b 888 }
roryhand 1:aac37edee302 889 }
roryhand 1:aac37edee302 890
roryhand 1:aac37edee302 891 } else if(flag2 == 1) {
roryhand 1:aac37edee302 892 Buffer2[place_hold2] = data_sptr[channel];
roryhand 1:aac37edee302 893 place_hold2 = place_hold2 + 1;
roryhand 1:aac37edee302 894 if(place_hold2 >= BufferLen) {
roryhand 1:aac37edee302 895
roryhand 1:aac37edee302 896 while(1) {
roryhand 1:aac37edee302 897 if(flag2 == 0) {
roryhand 1:aac37edee302 898
roryhand 1:aac37edee302 899 break;
roryhand 1:aac37edee302 900 }
roryhand 0:e89d7a0bfa3b 901 }
roryhand 1:aac37edee302 902 }
roryhand 0:e89d7a0bfa3b 903 }
roryhand 1:aac37edee302 904
roryhand 1:aac37edee302 905 }
roryhand 1:aac37edee302 906 slice = slice + 1;
roryhand 0:e89d7a0bfa3b 907 }
roryhand 0:e89d7a0bfa3b 908 }
roryhand 0:e89d7a0bfa3b 909
roryhand 0:e89d7a0bfa3b 910
roryhand 0:e89d7a0bfa3b 911
roryhand 0:e89d7a0bfa3b 912
roryhand 32:6ee488c97dcc 913 void Play_WaveFileDual(FILE * my_wav, WAV_FILE_STRUCT FileInfo)
roryhand 32:6ee488c97dcc 914 {
roryhand 32:6ee488c97dcc 915 while(slice<FileInfo.num_slices) {
roryhand 32:6ee488c97dcc 916 if(FileSwitchFlag == 1) {
roryhand 35:4469b508dda3 917
roryhand 33:a75f0a30fbdc 918 if(temp == 1) {
roryhand 34:26118c8f2e48 919 printf("Does it go to this point\n\r");
roryhand 35:4469b508dda3 920 N3Wav = fopen("/sd/mydir/SoundDecoder_second/03.wav","rb");
roryhand 33:a75f0a30fbdc 921 if(N3Wav == NULL) {
roryhand 33:a75f0a30fbdc 922 printf("Cannot Open testwav\n\r");
roryhand 33:a75f0a30fbdc 923 }
roryhand 33:a75f0a30fbdc 924 fclose(StartupWav);
roryhand 33:a75f0a30fbdc 925 temp = 0;
roryhand 33:a75f0a30fbdc 926 }
roryhand 35:4469b508dda3 927 fread(WavInfo_N3.slice_buf,WavInfo_N3.FileFormat.block_align,1,N3Wav);
roryhand 35:4469b508dda3 928 data_sptr=(short*)WavInfo_N3.slice_buf;
roryhand 32:6ee488c97dcc 929 } else {
roryhand 32:6ee488c97dcc 930 fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,my_wav);
roryhand 32:6ee488c97dcc 931 data_sptr=(short *)FileInfo.slice_buf; // 16 bit samples
roryhand 32:6ee488c97dcc 932 }
roryhand 32:6ee488c97dcc 933 for (channel=0; channel<FileInfo.FileFormat.num_channels; channel++) {
roryhand 32:6ee488c97dcc 934 if(flag1 == 1) {
roryhand 32:6ee488c97dcc 935 Buffer1[place_hold1] = data_sptr[channel];
roryhand 32:6ee488c97dcc 936 place_hold1 = place_hold1 + 1;
roryhand 32:6ee488c97dcc 937 if(place_hold1 >= BufferLen) {
roryhand 32:6ee488c97dcc 938 while(1) {
roryhand 32:6ee488c97dcc 939 if(flag1 == 0) {
roryhand 0:e89d7a0bfa3b 940
roryhand 32:6ee488c97dcc 941 break;
roryhand 32:6ee488c97dcc 942 }
roryhand 32:6ee488c97dcc 943
roryhand 32:6ee488c97dcc 944 }
roryhand 32:6ee488c97dcc 945 }
roryhand 32:6ee488c97dcc 946
roryhand 32:6ee488c97dcc 947 } else if(flag2 == 1) {
roryhand 32:6ee488c97dcc 948 Buffer2[place_hold2] = data_sptr[channel];
roryhand 32:6ee488c97dcc 949 place_hold2 = place_hold2 + 1;
roryhand 32:6ee488c97dcc 950 if(place_hold2 >= BufferLen) {
roryhand 32:6ee488c97dcc 951
roryhand 32:6ee488c97dcc 952 while(1) {
roryhand 32:6ee488c97dcc 953 if(flag2 == 0) {
roryhand 32:6ee488c97dcc 954
roryhand 32:6ee488c97dcc 955 break;
roryhand 32:6ee488c97dcc 956 }
roryhand 32:6ee488c97dcc 957 }
roryhand 32:6ee488c97dcc 958 }
roryhand 32:6ee488c97dcc 959 }
roryhand 32:6ee488c97dcc 960
roryhand 32:6ee488c97dcc 961 }
roryhand 32:6ee488c97dcc 962 slice = slice + 1;
roryhand 32:6ee488c97dcc 963 }
roryhand 32:6ee488c97dcc 964 }
roryhand 0:e89d7a0bfa3b 965
roryhand 38:3b4c05af5f36 966 //***************************************************************************//
roryhand 38:3b4c05af5f36 967
roryhand 38:3b4c05af5f36 968 //**************************************************************************//
roryhand 38:3b4c05af5f36 969
roryhand 38:3b4c05af5f36 970
roryhand 38:3b4c05af5f36 971
roryhand 38:3b4c05af5f36 972
roryhand 38:3b4c05af5f36 973
roryhand 1:aac37edee302 974
roryhand 44:a9e84d333a6a 975
roryhand 45:0e8e1f2ec5d2 976 void Play_WaveFileLoop(classSoundFile Sound1, classSoundFile Sound2, classSoundFile Sound3, FILE *wavfile1, FILE *wavfile2, FILE *wavfile3)
roryhand 45:0e8e1f2ec5d2 977 {
roryhand 45:0e8e1f2ec5d2 978 while(1) { //might have to change this to a while(1) loop?
roryhand 45:0e8e1f2ec5d2 979 //New format!! This should be (roughly) the way that this is done, with the new structures and classes
roryhand 44:a9e84d333a6a 980
roryhand 45:0e8e1f2ec5d2 981 //Block 1 of code. We need to pass in 3x classSoundFile objects, and 3x FILE* pointer objects.
roryhand 45:0e8e1f2ec5d2 982 //This will allow us to switch between the 3 different files (using "cross-fades") as needed.
roryhand 45:0e8e1f2ec5d2 983 /*Remember that these will need to be global varaibles to work properly*/
roryhand 45:0e8e1f2ec5d2 984
roryhand 45:0e8e1f2ec5d2 985
roryhand 2:957d3b2afff4 986 //make sure we are reading in the correct "notch" here
roryhand 2:957d3b2afff4 987
roryhand 44:a9e84d333a6a 988
roryhand 44:a9e84d333a6a 989
roryhand 54:606a83fff291 990 /*Block1*/
roryhand 54:606a83fff291 991 /*Read in data for current sound files. We only have 3 active engine noises at a time.
roryhand 54:606a83fff291 992 When it becomes time to transition up again, we then flip to the opposite block, and perform
roryhand 54:606a83fff291 993 the opposite operation.*/
roryhand 54:606a83fff291 994
roryhand 54:606a83fff291 995
roryhand 54:606a83fff291 996 if(BlockFlag == 0) {
roryhand 44:a9e84d333a6a 997 //Sound1=======================================================================================
roryhand 44:a9e84d333a6a 998 if( slice1 == (Sound1.FileInfo.num_slices-1) ) {
roryhand 44:a9e84d333a6a 999 slice1 = 0;
roryhand 44:a9e84d333a6a 1000 fseek(wavfile1,44,SEEK_SET);
roryhand 2:957d3b2afff4 1001 }
roryhand 47:9334a8f54997 1002 if(feof(wavfile1)) {
roryhand 47:9334a8f54997 1003 fseek(wavfile1,44,SEEK_SET);
roryhand 47:9334a8f54997 1004 }
roryhand 44:a9e84d333a6a 1005 fread(Sound1.FileInfo.slice_buf,Sound1.FileInfo.FileFormat.block_align,1,wavfile1);
roryhand 44:a9e84d333a6a 1006 Sound1.data_sptr=(short *)Sound1.FileInfo.slice_buf; // 16 bit samples
roryhand 44:a9e84d333a6a 1007 //=============================================================================================
roryhand 54:606a83fff291 1008 }
roryhand 44:a9e84d333a6a 1009
roryhand 54:606a83fff291 1010 else if(BlockFlag == 1) {
roryhand 44:a9e84d333a6a 1011
roryhand 44:a9e84d333a6a 1012
roryhand 44:a9e84d333a6a 1013
roryhand 44:a9e84d333a6a 1014
roryhand 44:a9e84d333a6a 1015 /*Block2*/
roryhand 3:6169aeeaeeb4 1016
roryhand 2:957d3b2afff4 1017 //Read in data for current (i.e. now the previous notch, according to the index!!)
roryhand 2:957d3b2afff4 1018 //We might not need this code here...as its probably done somewhere else??
roryhand 44:a9e84d333a6a 1019 //fread(Sounds[NotchingSet.Notch-1].FileInfo.slice_buf,Sounds[NotchingSet.Notch-1].FileInfo.FileFormat.block_align,1,Sounds[NotchingSet.Notch-1].FileInfo.WavFile);
roryhand 44:a9e84d333a6a 1020 //Sounds[NotchingSet.Notch-1].data_sptr = (short *)Sounds[NotchingSet.Notch-1].FileInfo.slice_buf;
roryhand 44:a9e84d333a6a 1021 //We are now performing this section above.
roryhand 3:6169aeeaeeb4 1022
roryhand 47:9334a8f54997 1023
roryhand 54:606a83fff291 1024 if(FadeFlag) {
roryhand 54:606a83fff291 1025 if( slice1 == (Sound1.FileInfo.num_slices-1) ) {
roryhand 54:606a83fff291 1026 slice1 = 0;
roryhand 54:606a83fff291 1027 fseek(wavfile1,44,SEEK_SET);
roryhand 54:606a83fff291 1028 }
roryhand 54:606a83fff291 1029 if(OneOff == 1) {
roryhand 47:9334a8f54997 1030
roryhand 47:9334a8f54997 1031
roryhand 54:606a83fff291 1032 wavfile2 = fopen("/sd/mydir/SoundDecoder_second/09.wav","rb");
roryhand 54:606a83fff291 1033 if(wavfile2 == NULL) {
roryhand 54:606a83fff291 1034 printf("Cannot Open wavfile2\n\r");
roryhand 54:606a83fff291 1035 }
roryhand 54:606a83fff291 1036
roryhand 54:606a83fff291 1037 wavfile3 = fopen("/sd/mydir/SoundDecoder_second/02.wav","rb");
roryhand 54:606a83fff291 1038 if(wavfile3 == NULL) {
roryhand 54:606a83fff291 1039 printf("Cannot Open wavfile3\n\r");
roryhand 54:606a83fff291 1040 }
roryhand 54:606a83fff291 1041 fseek(wavfile2,44,SEEK_SET);
roryhand 54:606a83fff291 1042 fseek(wavfile3,44,SEEK_SET);
roryhand 54:606a83fff291 1043 /*
roryhand 54:606a83fff291 1044 FILE* wavfile4 = fopen("/sd/mydir/SoundDecoder_second/04.wav","rb");
roryhand 54:606a83fff291 1045 if(wavfile4 == NULL) {
roryhand 54:606a83fff291 1046 printf("Cannot Open wavfile3\n\r");
roryhand 54:606a83fff291 1047 }
roryhand 54:606a83fff291 1048 */
roryhand 54:606a83fff291 1049 OneOff = 0;
roryhand 54:606a83fff291 1050 }
roryhand 54:606a83fff291 1051
roryhand 54:606a83fff291 1052 fread(Sound1.FileInfo.slice_buf,Sound1.FileInfo.FileFormat.block_align,1,wavfile1);
roryhand 54:606a83fff291 1053 Sound1.data_sptr=(short *)Sound1.FileInfo.slice_buf; // 16 bit samples
roryhand 54:606a83fff291 1054
roryhand 54:606a83fff291 1055 //Sound2=======================================================================================
roryhand 54:606a83fff291 1056 fread(Sound2.FileInfo.slice_buf,Sound2.FileInfo.FileFormat.block_align,1,wavfile2);
roryhand 54:606a83fff291 1057 Sound2.data_sptr=(short *)Sound2.FileInfo.slice_buf; // 16 bit samples
roryhand 54:606a83fff291 1058 //=============================================================================================
roryhand 2:957d3b2afff4 1059
roryhand 45:0e8e1f2ec5d2 1060
roryhand 3:6169aeeaeeb4 1061
roryhand 54:606a83fff291 1062 //Sound3=======================================================================================
roryhand 54:606a83fff291 1063 fread(Sound3.FileInfo.slice_buf,Sound3.FileInfo.FileFormat.block_align,1,wavfile3);
roryhand 54:606a83fff291 1064 Sound3.data_sptr=(short *)Sound3.FileInfo.slice_buf; // 16 bit samples
roryhand 54:606a83fff291 1065 //=============================================================================================
roryhand 54:606a83fff291 1066
roryhand 54:606a83fff291 1067 //require this to get the fadeout coefficient for Sound1.
roryhand 54:606a83fff291 1068 NotchFadeOut.FadeCoeff = NotchFadeOut.FadeOut();//compute new FadeOut Coeff value
roryhand 54:606a83fff291 1069
roryhand 54:606a83fff291 1070
roryhand 54:606a83fff291 1071
roryhand 54:606a83fff291 1072 if( ((Sound2.FileInfo.FileData.subchunk2_size) - NotchFadeIn.Length - 2*11025) <= (ftell(wavfile2) + 44)) {
roryhand 2:957d3b2afff4 1073
roryhand 44:a9e84d333a6a 1074
roryhand 54:606a83fff291 1075 //required for calculating the fade In coefficient for Sound3
roryhand 54:606a83fff291 1076 NotchFadeIn.FadeCoeff = NotchFadeIn.FadeIn();
roryhand 3:6169aeeaeeb4 1077
roryhand 54:606a83fff291 1078 //Read In the next Notch
roryhand 44:a9e84d333a6a 1079
roryhand 54:606a83fff291 1080 /*
roryhand 54:606a83fff291 1081 fread(Sounds[NotchingSet.Notch].FileInfo.slice_buf,Sounds[NotchingSet.Notch].FileInfo.FileFormat.block_align,1,Sounds[NotchingSet.Notch].FileInfo.WavFile);
roryhand 54:606a83fff291 1082 Sounds[NotchingSet.Notch].data_sptr = (short *)Sounds[NotchingSet.Notch].FileInfo.slice_buf;
roryhand 54:606a83fff291 1083 */
roryhand 54:606a83fff291 1084 //no longer require the above section as we are reading in data for Sound3 (above, at beginning of function).
roryhand 54:606a83fff291 1085
roryhand 54:606a83fff291 1086 if( (ftell(wavfile2) + 44) >= Sound2.FileInfo.FileData.subchunk2_size ) {
roryhand 2:957d3b2afff4 1087
roryhand 54:606a83fff291 1088 //need to explicitly test if this notation/syntax works for pointers....
roryhand 54:606a83fff291 1089 /*Was this ever tested?? no idea...
roryhand 54:606a83fff291 1090 If not then we need to pass in the 3 different "data_sptr" variables in separately, and not tied to a specific class
roryhand 54:606a83fff291 1091 or structure.*/
roryhand 54:606a83fff291 1092 *Sound1.data_sptr = *Sound3.data_sptr*NotchFadeIn.FadeCoeff;//Sound 3 by itself.
roryhand 54:606a83fff291 1093 //fclose(wavfile2);
roryhand 54:606a83fff291 1094 //fclose(wavfile1);
roryhand 54:606a83fff291 1095 } else {
roryhand 54:606a83fff291 1096 *Sound1.data_sptr = *Sound1.data_sptr*NotchFadeOut.FadeCoeff + *Sound2.data_sptr + *Sound3.data_sptr*NotchFadeIn.FadeCoeff;//Sounds 1, 2 and 3 Cross-fade.
roryhand 54:606a83fff291 1097 //probably later on redesign this to work with flags - that way it may be a little easier to debug any issues.
roryhand 54:606a83fff291 1098 }
roryhand 3:6169aeeaeeb4 1099
roryhand 2:957d3b2afff4 1100 } else {
roryhand 54:606a83fff291 1101 *Sound1.data_sptr = *Sound1.data_sptr*NotchFadeOut.FadeCoeff + *Sound2.data_sptr;//Sound1 and Sound 2 cross fade
roryhand 2:957d3b2afff4 1102 }
roryhand 2:957d3b2afff4 1103
roryhand 2:957d3b2afff4 1104 }
roryhand 2:957d3b2afff4 1105
roryhand 54:606a83fff291 1106
roryhand 54:606a83fff291 1107 /********************END OF DATA ASSIGNMENT SECTION*************************************************/
roryhand 54:606a83fff291 1108
roryhand 1:aac37edee302 1109 }
roryhand 1:aac37edee302 1110
roryhand 1:aac37edee302 1111
roryhand 44:a9e84d333a6a 1112
roryhand 44:a9e84d333a6a 1113 /**********************************************************************************************************/
roryhand 44:a9e84d333a6a 1114 /****************************DATA OUTPUT SECTION***********************************************************/
roryhand 44:a9e84d333a6a 1115 /**********************************************************************************************************/
roryhand 45:0e8e1f2ec5d2 1116 for (channel=0; channel<Sound1.FileInfo.FileFormat.num_channels; channel++) {
roryhand 45:0e8e1f2ec5d2 1117 switch (Sound1.FileInfo.FileFormat.sig_bps) {
roryhand 0:e89d7a0bfa3b 1118 case 16:
roryhand 1:aac37edee302 1119 if(flag1 == 1) {
roryhand 45:0e8e1f2ec5d2 1120 Buffer1[place_hold1] = Sound1.data_sptr[channel];
roryhand 1:aac37edee302 1121 place_hold1 = place_hold1 + 1;
roryhand 1:aac37edee302 1122 if(place_hold1 >= BufferLen) {
roryhand 1:aac37edee302 1123 while(1) {
roryhand 1:aac37edee302 1124 if(flag1 == 0) {
roryhand 1:aac37edee302 1125 break;
roryhand 1:aac37edee302 1126 }//if(flag1 == 0)
roryhand 1:aac37edee302 1127
roryhand 1:aac37edee302 1128
roryhand 1:aac37edee302 1129 }//while(1)
roryhand 1:aac37edee302 1130 }//if(place_hold1 > = BufferLen)
roryhand 0:e89d7a0bfa3b 1131
roryhand 1:aac37edee302 1132 } else if(flag2 == 1) {
roryhand 45:0e8e1f2ec5d2 1133 Buffer2[place_hold2] = Sound1.data_sptr[channel];
roryhand 1:aac37edee302 1134 place_hold2 = place_hold2 + 1;
roryhand 1:aac37edee302 1135 if(place_hold2 >= BufferLen) {
roryhand 1:aac37edee302 1136 while(1) {
roryhand 1:aac37edee302 1137
roryhand 1:aac37edee302 1138 if(flag2 == 0) {
roryhand 1:aac37edee302 1139 break;
roryhand 1:aac37edee302 1140 }
roryhand 1:aac37edee302 1141 }
roryhand 0:e89d7a0bfa3b 1142 }
roryhand 1:aac37edee302 1143
roryhand 1:aac37edee302 1144 }
roryhand 0:e89d7a0bfa3b 1145 }
roryhand 0:e89d7a0bfa3b 1146 }
roryhand 45:0e8e1f2ec5d2 1147 slice1 = slice1 + 1;
roryhand 45:0e8e1f2ec5d2 1148 slice2 = slice2 + 1;
roryhand 45:0e8e1f2ec5d2 1149 slice3 = slice3 + 1;
roryhand 0:e89d7a0bfa3b 1150 }
roryhand 0:e89d7a0bfa3b 1151 }
roryhand 0:e89d7a0bfa3b 1152
roryhand 0:e89d7a0bfa3b 1153
roryhand 0:e89d7a0bfa3b 1154
roryhand 0:e89d7a0bfa3b 1155
roryhand 0:e89d7a0bfa3b 1156
roryhand 0:e89d7a0bfa3b 1157
roryhand 0:e89d7a0bfa3b 1158
roryhand 9:dd9cae06b202 1159