old demo that i want to try in mbed studio

Dependencies:   mbed SDFileSystem_Copy_of_mbed_version I2S

Committer:
roryhand
Date:
Mon Sep 23 21:09:51 2019 +0000
Revision:
55:5a441d3b0d57
Parent:
54:606a83fff291
Child:
56:3755c53ac4c6
WIP - trying to read in sizes of data, so as we know whereabouts our file position indicators will need to go to, when all the sound is amalgamated into one huge file

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 31:0f8c3adf09c3 556 timer_open.reset();
roryhand 32:6ee488c97dcc 557 timer_open.start();
roryhand 55:5a441d3b0d57 558 wavfile1 = fopen("/sd/mydir/SoundDecoder_second/01.wav","rb");
roryhand 54:606a83fff291 559 if(wavfile1 == NULL) {
roryhand 45:0e8e1f2ec5d2 560 printf("Cannot Open wavfile1\n\r");
roryhand 32:6ee488c97dcc 561 }
roryhand 54:606a83fff291 562 printf("size of wavfile1 %d\n\r",sizeof(wavfile1));
roryhand 54:606a83fff291 563 timer_open.stop();
roryhand 31:0f8c3adf09c3 564 printf("It took %d useconds to open file\n\r",timer_open.read_us());
roryhand 54:606a83fff291 565 timer_open.reset();
roryhand 54:606a83fff291 566
roryhand 54:606a83fff291 567
roryhand 54:606a83fff291 568 printf("Size of wavfile 1: %d bytes\n\r",sizeof(wavfile1));
roryhand 45:0e8e1f2ec5d2 569 timer_open.start();
roryhand 47:9334a8f54997 570 wavfile2 = fopen("/sd/mydir/SoundDecoder_second/09.wav","rb");
roryhand 54:606a83fff291 571 if(wavfile2 == NULL) {
roryhand 45:0e8e1f2ec5d2 572 printf("Cannot Open wavfile2\n\r");
roryhand 45:0e8e1f2ec5d2 573 }
roryhand 54:606a83fff291 574 timer_open.stop();
roryhand 45:0e8e1f2ec5d2 575 printf("It took %d useconds to open file\n\r",timer_open.read_us());
roryhand 54:606a83fff291 576 timer_open.reset();
roryhand 54:606a83fff291 577
roryhand 32:6ee488c97dcc 578 timer_open.start();
roryhand 47:9334a8f54997 579 wavfile3 = fopen("/sd/mydir/SoundDecoder_second/02.wav","rb");
roryhand 54:606a83fff291 580 if(wavfile3 == NULL) {
roryhand 45:0e8e1f2ec5d2 581 printf("Cannot Open wavfile3\n\r");
roryhand 45:0e8e1f2ec5d2 582 }
roryhand 54:606a83fff291 583 timer_open.stop();
roryhand 45:0e8e1f2ec5d2 584 printf("It took %d useconds to open file\n\r",timer_open.read_us());
roryhand 54:606a83fff291 585 timer_open.reset();
roryhand 54:606a83fff291 586
roryhand 54:606a83fff291 587
roryhand 45:0e8e1f2ec5d2 588 Sound1 = ReadFileInfo(Sound1,wavfile1);
roryhand 45:0e8e1f2ec5d2 589 Sound2 = ReadFileInfo(Sound2,wavfile2);
roryhand 45:0e8e1f2ec5d2 590 Sound3 = ReadFileInfo(Sound3,wavfile3);
roryhand 55:5a441d3b0d57 591
roryhand 54:606a83fff291 592 FILE* wavfile4 = fopen("/sd/mydir/SoundDecoder_second/04.wav","rb");
roryhand 54:606a83fff291 593 if(wavfile4 == NULL) {
roryhand 54:606a83fff291 594 printf("Cannot Open wavfile4\n\r");
roryhand 54:606a83fff291 595 }
roryhand 55:5a441d3b0d57 596 classSoundFile Sound4;
roryhand 54:606a83fff291 597 Sound4 = ReadFileInfo(Sound4,wavfile4);
roryhand 55:5a441d3b0d57 598 fclose(wavfile4);
roryhand 55:5a441d3b0d57 599
roryhand 55:5a441d3b0d57 600 FILE* wavfile5 = fopen("/sd/mydir/SoundDecoder_second/05.wav","rb");
roryhand 55:5a441d3b0d57 601 if(wavfile5 == NULL) {
roryhand 55:5a441d3b0d57 602 printf("Cannot Open wavfile5\n\r");
roryhand 55:5a441d3b0d57 603 }
roryhand 55:5a441d3b0d57 604 classSoundFile Sound5;
roryhand 55:5a441d3b0d57 605 Sound5 = ReadFileInfo(Sound5,wavfile5);
roryhand 55:5a441d3b0d57 606 fclose(wavfile5);
roryhand 55:5a441d3b0d57 607
roryhand 55:5a441d3b0d57 608
roryhand 55:5a441d3b0d57 609 FILE* wavfile6 = fopen("/sd/mydir/SoundDecoder_second/06.wav","rb");
roryhand 55:5a441d3b0d57 610 if(wavfile6 == NULL) {
roryhand 55:5a441d3b0d57 611 printf("Cannot Open wavfile6\n\r");
roryhand 55:5a441d3b0d57 612 }
roryhand 55:5a441d3b0d57 613 classSoundFile Sound6;
roryhand 55:5a441d3b0d57 614 Sound6 = ReadFileInfo(Sound6,wavfile6);
roryhand 55:5a441d3b0d57 615 fclose(wavfile6);
roryhand 55:5a441d3b0d57 616
roryhand 55:5a441d3b0d57 617
roryhand 55:5a441d3b0d57 618 FILE* wavfile7 = fopen("/sd/mydir/SoundDecoder_second/07.wav","rb");
roryhand 55:5a441d3b0d57 619 if(wavfile7 == NULL) {
roryhand 55:5a441d3b0d57 620 printf("Cannot Open wavfile7\n\r");
roryhand 55:5a441d3b0d57 621 }
roryhand 55:5a441d3b0d57 622 classSoundFile Sound7;
roryhand 55:5a441d3b0d57 623 Sound7 = ReadFileInfo(Sound7,wavfile7);
roryhand 55:5a441d3b0d57 624 fclose(wavfile7);
roryhand 55:5a441d3b0d57 625
roryhand 55:5a441d3b0d57 626
roryhand 55:5a441d3b0d57 627 FILE* wavfile8 = fopen("/sd/mydir/SoundDecoder_second/08.wav","rb");
roryhand 55:5a441d3b0d57 628 if(wavfile8 == NULL) {
roryhand 55:5a441d3b0d57 629 printf("Cannot Open wavfile8\n\r");
roryhand 55:5a441d3b0d57 630 }
roryhand 55:5a441d3b0d57 631 classSoundFile Sound8;
roryhand 55:5a441d3b0d57 632 Sound8 = ReadFileInfo(Sound8,wavfile8);
roryhand 55:5a441d3b0d57 633 fclose(wavfile8);
roryhand 55:5a441d3b0d57 634
roryhand 55:5a441d3b0d57 635
roryhand 55:5a441d3b0d57 636
roryhand 55:5a441d3b0d57 637 FILE* wavfile9 = fopen("/sd/mydir/SoundDecoder_second/09.wav","rb");
roryhand 55:5a441d3b0d57 638 if(wavfile9 == NULL) {
roryhand 55:5a441d3b0d57 639 printf("Cannot Open wavfile9\n\r");
roryhand 55:5a441d3b0d57 640 }
roryhand 55:5a441d3b0d57 641 classSoundFile Sound9;
roryhand 55:5a441d3b0d57 642 Sound9 = ReadFileInfo(Sound9,wavfile9);
roryhand 55:5a441d3b0d57 643 fclose(wavfile9);
roryhand 55:5a441d3b0d57 644
roryhand 55:5a441d3b0d57 645
roryhand 55:5a441d3b0d57 646 FILE* wavfile10 = fopen("/sd/mydir/SoundDecoder_second/10.wav","rb");
roryhand 55:5a441d3b0d57 647 if(wavfile10 == NULL) {
roryhand 55:5a441d3b0d57 648 printf("Cannot Open wavfile10\n\r");
roryhand 55:5a441d3b0d57 649 }
roryhand 55:5a441d3b0d57 650 classSoundFile Sound10;
roryhand 55:5a441d3b0d57 651 Sound10 = ReadFileInfo(Sound10,wavfile10);
roryhand 55:5a441d3b0d57 652 fclose(wavfile10);
roryhand 55:5a441d3b0d57 653
roryhand 55:5a441d3b0d57 654
roryhand 55:5a441d3b0d57 655 FILE* wavfile11 = fopen("/sd/mydir/SoundDecoder_second/11.wav","rb");
roryhand 55:5a441d3b0d57 656 if(wavfile11 == NULL) {
roryhand 55:5a441d3b0d57 657 printf("Cannot Open wavfile11\n\r");
roryhand 55:5a441d3b0d57 658 }
roryhand 55:5a441d3b0d57 659 classSoundFile Sound11;
roryhand 55:5a441d3b0d57 660 Sound11 = ReadFileInfo(Sound11,wavfile11);
roryhand 55:5a441d3b0d57 661 fclose(wavfile11);
roryhand 55:5a441d3b0d57 662
roryhand 55:5a441d3b0d57 663
roryhand 55:5a441d3b0d57 664 FILE* wavfile12 = fopen("/sd/mydir/SoundDecoder_second/12.wav","rb");
roryhand 55:5a441d3b0d57 665 if(wavfile12 == NULL) {
roryhand 55:5a441d3b0d57 666 printf("Cannot Open wavfile12\n\r");
roryhand 55:5a441d3b0d57 667 }
roryhand 55:5a441d3b0d57 668 classSoundFile Sound12;
roryhand 55:5a441d3b0d57 669 Sound12 = ReadFileInfo(Sound12,wavfile12);
roryhand 55:5a441d3b0d57 670 fclose(wavfile12);
roryhand 55:5a441d3b0d57 671
roryhand 55:5a441d3b0d57 672 FILE* wavfile13 = fopen("/sd/mydir/SoundDecoder_second/13.wav","rb");
roryhand 55:5a441d3b0d57 673 if(wavfile13 == NULL) {
roryhand 55:5a441d3b0d57 674 printf("Cannot Open wavfile13\n\r");
roryhand 55:5a441d3b0d57 675 }
roryhand 55:5a441d3b0d57 676 classSoundFile Sound13;
roryhand 55:5a441d3b0d57 677 Sound13 = ReadFileInfo(Sound13,wavfile13);
roryhand 55:5a441d3b0d57 678 fclose(wavfile13);
roryhand 55:5a441d3b0d57 679
roryhand 55:5a441d3b0d57 680
roryhand 55:5a441d3b0d57 681 FILE* wavfile14 = fopen("/sd/mydir/SoundDecoder_second/14.wav","rb");
roryhand 55:5a441d3b0d57 682 if(wavfile14 == NULL) {
roryhand 55:5a441d3b0d57 683 printf("Cannot Open wavfile14\n\r");
roryhand 55:5a441d3b0d57 684 }
roryhand 55:5a441d3b0d57 685 classSoundFile Sound14;
roryhand 55:5a441d3b0d57 686 Sound14 = ReadFileInfo(Sound14,wavfile14);
roryhand 55:5a441d3b0d57 687 fclose(wavfile14);
roryhand 55:5a441d3b0d57 688
roryhand 55:5a441d3b0d57 689
roryhand 55:5a441d3b0d57 690 FILE* wavfile15 = fopen("/sd/mydir/SoundDecoder_second/15.wav","rb");
roryhand 55:5a441d3b0d57 691 if(wavfile15 == NULL) {
roryhand 55:5a441d3b0d57 692 printf("Cannot Open wavfile15\n\r");
roryhand 55:5a441d3b0d57 693 }
roryhand 55:5a441d3b0d57 694 classSoundFile Sound15;
roryhand 55:5a441d3b0d57 695 Sound15 = ReadFileInfo(Sound15,wavfile15);
roryhand 55:5a441d3b0d57 696 fclose(wavfile15);
roryhand 55:5a441d3b0d57 697
roryhand 55:5a441d3b0d57 698
roryhand 55:5a441d3b0d57 699 FILE* wavfile16 = fopen("/sd/mydir/SoundDecoder_second/16.wav","rb");
roryhand 55:5a441d3b0d57 700 if(wavfile16 == NULL) {
roryhand 55:5a441d3b0d57 701 printf("Cannot Open wavfile16\n\r");
roryhand 55:5a441d3b0d57 702 }
roryhand 55:5a441d3b0d57 703 classSoundFile Sound16;
roryhand 55:5a441d3b0d57 704 Sound16 = ReadFileInfo(Sound16,wavfile16);
roryhand 55:5a441d3b0d57 705 fclose(wavfile16);
roryhand 55:5a441d3b0d57 706
roryhand 55:5a441d3b0d57 707
roryhand 55:5a441d3b0d57 708 FILE* wavfile17 = fopen("/sd/mydir/SoundDecoder_second/17.wav","rb");
roryhand 55:5a441d3b0d57 709 if(wavfile17 == NULL) {
roryhand 55:5a441d3b0d57 710 printf("Cannot Open wavfile17\n\r");
roryhand 55:5a441d3b0d57 711 }
roryhand 55:5a441d3b0d57 712 classSoundFile Sound17;
roryhand 55:5a441d3b0d57 713 Sound17 = ReadFileInfo(Sound17,wavfile17);
roryhand 55:5a441d3b0d57 714 fclose(wavfile17);
roryhand 55:5a441d3b0d57 715
roryhand 55:5a441d3b0d57 716
roryhand 55:5a441d3b0d57 717 FILE* wavfile18 = fopen("/sd/mydir/SoundDecoder_second/18.wav","rb");
roryhand 55:5a441d3b0d57 718 if(wavfile18 == NULL) {
roryhand 55:5a441d3b0d57 719 printf("Cannot Open wavfile18\n\r");
roryhand 55:5a441d3b0d57 720 }
roryhand 55:5a441d3b0d57 721 classSoundFile Sound18;
roryhand 55:5a441d3b0d57 722 Sound18 = ReadFileInfo(Sound18,wavfile18);
roryhand 55:5a441d3b0d57 723 fclose(wavfile18);
roryhand 55:5a441d3b0d57 724
roryhand 55:5a441d3b0d57 725
roryhand 55:5a441d3b0d57 726 FILE* wavfile19 = fopen("/sd/mydir/SoundDecoder_second/19.wav","rb");
roryhand 55:5a441d3b0d57 727 if(wavfile19 == NULL) {
roryhand 55:5a441d3b0d57 728 printf("Cannot Open wavfile19\n\r");
roryhand 55:5a441d3b0d57 729 }
roryhand 55:5a441d3b0d57 730 classSoundFile Sound19;
roryhand 55:5a441d3b0d57 731 Sound19 = ReadFileInfo(Sound19,wavfile19);
roryhand 55:5a441d3b0d57 732 fclose(wavfile19);
roryhand 55:5a441d3b0d57 733
roryhand 55:5a441d3b0d57 734 FILE* f1 = fopen("/sd/mydir/SoundDecoder_second/01.txt","rb");
roryhand 55:5a441d3b0d57 735
roryhand 55:5a441d3b0d57 736 fprintf(f1, Sound1.FileInfo.FileData.subchunk2_size);
roryhand 55:5a441d3b0d57 737
roryhand 55:5a441d3b0d57 738
roryhand 55:5a441d3b0d57 739
roryhand 55:5a441d3b0d57 740
roryhand 13:8e93396a27c5 741
roryhand 54:606a83fff291 742 fclose(wavfile2);
roryhand 54:606a83fff291 743 fclose(wavfile3);
roryhand 47:9334a8f54997 744 NotchFadeIn.LengthSecs = 2;
roryhand 46:de390e45c2af 745 NotchFadeOut.LengthSecs = 2;
roryhand 46:de390e45c2af 746 NotchFadeIn = FadeDataInitialise(NotchFadeIn);
roryhand 46:de390e45c2af 747 NotchFadeOut = FadeDataInitialise(NotchFadeOut);
roryhand 45:0e8e1f2ec5d2 748
roryhand 45:0e8e1f2ec5d2 749
roryhand 45:0e8e1f2ec5d2 750
roryhand 45:0e8e1f2ec5d2 751 TickFadeOut.attach(&FadeOutIsr,10.0);
roryhand 45:0e8e1f2ec5d2 752
roryhand 54:606a83fff291 753
roryhand 54:606a83fff291 754 //timer_interrupt.reset();
roryhand 54:606a83fff291 755
roryhand 20:9cc7d825c07b 756 printf("about to play wav file\n\r");
roryhand 45:0e8e1f2ec5d2 757 Play_WaveFileLoop(Sound1,Sound2,Sound3,wavfile1,wavfile2,wavfile3);
roryhand 45:0e8e1f2ec5d2 758 //Play_WaveFileDual(StartupWav,WavInfo_Startup);
roryhand 20:9cc7d825c07b 759 printf("finished playing Wav file\n\r");
roryhand 54:606a83fff291 760
roryhand 54:606a83fff291 761
roryhand 31:0f8c3adf09c3 762 timer_open.reset();
roryhand 31:0f8c3adf09c3 763 timer_open.start();
roryhand 45:0e8e1f2ec5d2 764 fclose(wavfile1);
roryhand 31:0f8c3adf09c3 765 timer_open.stop();
roryhand 31:0f8c3adf09c3 766 printf("It took %d useconds to close file\n\r",timer_open.read_us());
roryhand 54:606a83fff291 767
roryhand 45:0e8e1f2ec5d2 768 timer_open.reset();
roryhand 54:606a83fff291 769 timer_open.start();
roryhand 45:0e8e1f2ec5d2 770 fclose(wavfile2);
roryhand 45:0e8e1f2ec5d2 771 timer_open.stop();
roryhand 54:606a83fff291 772 printf("It took %d useconds to close file\n\r",timer_open.read_us());
roryhand 54:606a83fff291 773
roryhand 54:606a83fff291 774
roryhand 45:0e8e1f2ec5d2 775 timer_open.reset();
roryhand 54:606a83fff291 776 timer_open.start();
roryhand 45:0e8e1f2ec5d2 777 fclose(wavfile3);
roryhand 45:0e8e1f2ec5d2 778 timer_open.stop();
roryhand 45:0e8e1f2ec5d2 779 printf("It took %d useconds to close file\n\r",timer_open.read_us());
roryhand 54:606a83fff291 780
roryhand 54:606a83fff291 781
roryhand 54:606a83fff291 782
roryhand 9:dd9cae06b202 783 /************************************PLAY WAV FILE LOOP*******************/
roryhand 20:9cc7d825c07b 784 //Play_WaveFileLoop(Sound, NotchingSet);
roryhand 9:dd9cae06b202 785 /************************************END OF PLAY WAV FILE LOOP*************/
roryhand 13:8e93396a27c5 786
roryhand 13:8e93396a27c5 787
roryhand 1:aac37edee302 788 i2s.stop();
roryhand 0:e89d7a0bfa3b 789
roryhand 0:e89d7a0bfa3b 790 }
roryhand 0:e89d7a0bfa3b 791
roryhand 0:e89d7a0bfa3b 792
roryhand 3:6169aeeaeeb4 793
roryhand 3:6169aeeaeeb4 794
roryhand 3:6169aeeaeeb4 795
roryhand 3:6169aeeaeeb4 796
roryhand 45:0e8e1f2ec5d2 797 classSoundFile ReadFileInfo(classSoundFile Sound, FILE * wav_file)
roryhand 0:e89d7a0bfa3b 798 {
roryhand 0:e89d7a0bfa3b 799 fseek(wav_file,20,SEEK_SET);
roryhand 22:706e86dc0d45 800 printf("We have just seeked through this file\n\r");
roryhand 45:0e8e1f2ec5d2 801 fread(&Sound.FileInfo.FileFormat,sizeof(Sound.FileInfo.FileFormat),1,wav_file);
roryhand 1:aac37edee302 802 //printf("wav_format.sample_rate: %d\n\r",FileInfo.FileFormat.sample_rate);
roryhand 1:aac37edee302 803
roryhand 45:0e8e1f2ec5d2 804 fread(&Sound.FileInfo.FileData,sizeof(Sound.FileInfo.FileData),1,wav_file);
roryhand 55:5a441d3b0d57 805 printf("wav_data.subchunk2_size: %d\n\r",Sound.FileInfo.FileData.subchunk2_size);
roryhand 45:0e8e1f2ec5d2 806 Sound.FileInfo.slice_buf = ( char *)malloc(Sound.FileInfo.FileFormat.block_align);
roryhand 45:0e8e1f2ec5d2 807 fread(Sound.FileInfo.slice_buf,Sound.FileInfo.FileFormat.block_align,1,wav_file); //This isnt actually required, its just a test
roryhand 45:0e8e1f2ec5d2 808 Sound.FileInfo.num_slices = Sound.FileInfo.FileData.subchunk2_size/Sound.FileInfo.FileFormat.block_align;
roryhand 1:aac37edee302 809 //printf("Number of Slices: %d\n\r",FileInfo.num_slices);
roryhand 45:0e8e1f2ec5d2 810 return Sound;
roryhand 0:e89d7a0bfa3b 811 }
roryhand 1:aac37edee302 812
roryhand 1:aac37edee302 813 classSoundFile LoadFileStream(classSoundFile Sound, string filename)
roryhand 1:aac37edee302 814 {
roryhand 1:aac37edee302 815 //Declare RootFolder and the directory for the appropriate file.
roryhand 1:aac37edee302 816 //How we index into filename[] from the outside of this class is another
roryhand 1:aac37edee302 817 //issue...
roryhand 1:aac37edee302 818 //printf("FileName: %s\n\r",filename);
roryhand 1:aac37edee302 819 //string RootFolder = "/sd/mydir/SoundDecoder/";
roryhand 1:aac37edee302 820 //string Directory = RootFolder + "01.wav";// + filename[0];
roryhand 1:aac37edee302 821 //printf("%s\n\r",Directory);
roryhand 1:aac37edee302 822 //const char* DirectoryChar = Directory.c_str();
roryhand 1:aac37edee302 823 //Sound.FileInfo.WavFile = fopen(DirectoryChar,"rb");
roryhand 1:aac37edee302 824 Sound.FileInfo.WavFile = fopen("/sd/mydir/645Engine/Startup.wav","rb");
roryhand 1:aac37edee302 825 fseek(Sound.FileInfo.WavFile,20,SEEK_SET);
roryhand 1:aac37edee302 826 fread(&Sound.FileInfo.FileFormat,sizeof(Sound.FileInfo.FileFormat),1,Sound.FileInfo.WavFile);
roryhand 1:aac37edee302 827 printf("wav_format.sample_rate: %d\n\r",Sound.FileInfo.FileFormat.sample_rate);
roryhand 1:aac37edee302 828 fread(&Sound.FileInfo.FileData,sizeof(Sound.FileInfo.FileData),1,Sound.FileInfo.WavFile);
roryhand 1:aac37edee302 829 printf("wav_data.subchunk2_size: %d\n\r",Sound.FileInfo.FileData.subchunk2_size);
roryhand 1:aac37edee302 830 Sound.FileInfo.slice_buf = ( char *)malloc(Sound.FileInfo.FileFormat.block_align);
roryhand 1:aac37edee302 831 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 832 Sound.FileInfo.num_slices = Sound.FileInfo.FileData.subchunk2_size/Sound.FileInfo.FileFormat.block_align;
roryhand 1:aac37edee302 833 printf("Number of Slices: %d\n\r",Sound.FileInfo.num_slices);
roryhand 1:aac37edee302 834 return Sound;
roryhand 1:aac37edee302 835 }
roryhand 1:aac37edee302 836
roryhand 1:aac37edee302 837
roryhand 0:e89d7a0bfa3b 838 classFade FadeDataInitialise(classFade FadeData)
roryhand 0:e89d7a0bfa3b 839 {
roryhand 1:aac37edee302 840 FadeData.DecayFactor = 1.3;
roryhand 0:e89d7a0bfa3b 841 FadeData.FadeIteration = 1;
roryhand 0:e89d7a0bfa3b 842 //FadeData.Denom = 11025*FadeData.DecayFactor;
roryhand 0:e89d7a0bfa3b 843 FadeData.Denom = 11025*FadeData.DecayFactor;
roryhand 0:e89d7a0bfa3b 844 FadeData.Natural_Exp = 2.7183;
roryhand 0:e89d7a0bfa3b 845 FadeData.Length = 11025*FadeData.LengthSecs;
roryhand 0:e89d7a0bfa3b 846 //FadeData.Natural_Exp = 2.7;
roryhand 0:e89d7a0bfa3b 847 return FadeData;
roryhand 0:e89d7a0bfa3b 848 }
roryhand 0:e89d7a0bfa3b 849
roryhand 0:e89d7a0bfa3b 850 //Playing Files Code
roryhand 46:de390e45c2af 851 /*
roryhand 45:0e8e1f2ec5d2 852 float FadeIn(void)
roryhand 0:e89d7a0bfa3b 853 {
roryhand 0:e89d7a0bfa3b 854 powervalFadeIn = FadeIterationIn/denom;
roryhand 0:e89d7a0bfa3b 855 FadeCoeffFadeIn
roryhand 1:aac37edee302 856
roryhand 1:aac37edee302 857
roryhand 45:0e8e1f2ec5d2 858 }
roryhand 45:0e8e1f2ec5d2 859 float FadeOut(void)
roryhand 0:e89d7a0bfa3b 860 {
roryhand 0:e89d7a0bfa3b 861 powerval = -FadeIteration/denom;
roryhand 0:e89d7a0bfa3b 862 FadeCoeff = pow(natural_exp,powerval);
roryhand 1:aac37edee302 863 FadeIteration = FadeIteration + 1;
roryhand 1:aac37edee302 864 return FadeCoeff;
roryhand 1:aac37edee302 865
roryhand 45:0e8e1f2ec5d2 866 }
roryhand 46:de390e45c2af 867 */
roryhand 0:e89d7a0bfa3b 868
roryhand 0:e89d7a0bfa3b 869 void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo)
roryhand 0:e89d7a0bfa3b 870 {
roryhand 1:aac37edee302 871 while(slice<FileInfo.num_slices) {
roryhand 1:aac37edee302 872 fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,my_wav);
roryhand 1:aac37edee302 873 data_sptr=(short *)FileInfo.slice_buf; // 16 bit samples
roryhand 1:aac37edee302 874 for (channel=0; channel<FileInfo.FileFormat.num_channels; channel++) {
roryhand 1:aac37edee302 875 if(flag1 == 1) {
roryhand 1:aac37edee302 876 Buffer1[place_hold1] = data_sptr[channel];
roryhand 1:aac37edee302 877 place_hold1 = place_hold1 + 1;
roryhand 1:aac37edee302 878 if(place_hold1 >= BufferLen) {
roryhand 1:aac37edee302 879 while(1) {
roryhand 1:aac37edee302 880 if(flag1 == 0) {
roryhand 0:e89d7a0bfa3b 881
roryhand 1:aac37edee302 882 break;
roryhand 0:e89d7a0bfa3b 883 }
roryhand 1:aac37edee302 884
roryhand 0:e89d7a0bfa3b 885 }
roryhand 1:aac37edee302 886 }
roryhand 1:aac37edee302 887
roryhand 1:aac37edee302 888 } else if(flag2 == 1) {
roryhand 1:aac37edee302 889 Buffer2[place_hold2] = data_sptr[channel];
roryhand 1:aac37edee302 890 place_hold2 = place_hold2 + 1;
roryhand 1:aac37edee302 891 if(place_hold2 >= BufferLen) {
roryhand 1:aac37edee302 892
roryhand 1:aac37edee302 893 while(1) {
roryhand 1:aac37edee302 894 if(flag2 == 0) {
roryhand 1:aac37edee302 895
roryhand 1:aac37edee302 896 break;
roryhand 1:aac37edee302 897 }
roryhand 0:e89d7a0bfa3b 898 }
roryhand 1:aac37edee302 899 }
roryhand 0:e89d7a0bfa3b 900 }
roryhand 1:aac37edee302 901
roryhand 1:aac37edee302 902 }
roryhand 1:aac37edee302 903 slice = slice + 1;
roryhand 0:e89d7a0bfa3b 904 }
roryhand 0:e89d7a0bfa3b 905 }
roryhand 0:e89d7a0bfa3b 906
roryhand 0:e89d7a0bfa3b 907
roryhand 0:e89d7a0bfa3b 908
roryhand 0:e89d7a0bfa3b 909
roryhand 32:6ee488c97dcc 910 void Play_WaveFileDual(FILE * my_wav, WAV_FILE_STRUCT FileInfo)
roryhand 32:6ee488c97dcc 911 {
roryhand 32:6ee488c97dcc 912 while(slice<FileInfo.num_slices) {
roryhand 32:6ee488c97dcc 913 if(FileSwitchFlag == 1) {
roryhand 35:4469b508dda3 914
roryhand 33:a75f0a30fbdc 915 if(temp == 1) {
roryhand 34:26118c8f2e48 916 printf("Does it go to this point\n\r");
roryhand 35:4469b508dda3 917 N3Wav = fopen("/sd/mydir/SoundDecoder_second/03.wav","rb");
roryhand 33:a75f0a30fbdc 918 if(N3Wav == NULL) {
roryhand 33:a75f0a30fbdc 919 printf("Cannot Open testwav\n\r");
roryhand 33:a75f0a30fbdc 920 }
roryhand 33:a75f0a30fbdc 921 fclose(StartupWav);
roryhand 33:a75f0a30fbdc 922 temp = 0;
roryhand 33:a75f0a30fbdc 923 }
roryhand 35:4469b508dda3 924 fread(WavInfo_N3.slice_buf,WavInfo_N3.FileFormat.block_align,1,N3Wav);
roryhand 35:4469b508dda3 925 data_sptr=(short*)WavInfo_N3.slice_buf;
roryhand 32:6ee488c97dcc 926 } else {
roryhand 32:6ee488c97dcc 927 fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,my_wav);
roryhand 32:6ee488c97dcc 928 data_sptr=(short *)FileInfo.slice_buf; // 16 bit samples
roryhand 32:6ee488c97dcc 929 }
roryhand 32:6ee488c97dcc 930 for (channel=0; channel<FileInfo.FileFormat.num_channels; channel++) {
roryhand 32:6ee488c97dcc 931 if(flag1 == 1) {
roryhand 32:6ee488c97dcc 932 Buffer1[place_hold1] = data_sptr[channel];
roryhand 32:6ee488c97dcc 933 place_hold1 = place_hold1 + 1;
roryhand 32:6ee488c97dcc 934 if(place_hold1 >= BufferLen) {
roryhand 32:6ee488c97dcc 935 while(1) {
roryhand 32:6ee488c97dcc 936 if(flag1 == 0) {
roryhand 0:e89d7a0bfa3b 937
roryhand 32:6ee488c97dcc 938 break;
roryhand 32:6ee488c97dcc 939 }
roryhand 32:6ee488c97dcc 940
roryhand 32:6ee488c97dcc 941 }
roryhand 32:6ee488c97dcc 942 }
roryhand 32:6ee488c97dcc 943
roryhand 32:6ee488c97dcc 944 } else if(flag2 == 1) {
roryhand 32:6ee488c97dcc 945 Buffer2[place_hold2] = data_sptr[channel];
roryhand 32:6ee488c97dcc 946 place_hold2 = place_hold2 + 1;
roryhand 32:6ee488c97dcc 947 if(place_hold2 >= BufferLen) {
roryhand 32:6ee488c97dcc 948
roryhand 32:6ee488c97dcc 949 while(1) {
roryhand 32:6ee488c97dcc 950 if(flag2 == 0) {
roryhand 32:6ee488c97dcc 951
roryhand 32:6ee488c97dcc 952 break;
roryhand 32:6ee488c97dcc 953 }
roryhand 32:6ee488c97dcc 954 }
roryhand 32:6ee488c97dcc 955 }
roryhand 32:6ee488c97dcc 956 }
roryhand 32:6ee488c97dcc 957
roryhand 32:6ee488c97dcc 958 }
roryhand 32:6ee488c97dcc 959 slice = slice + 1;
roryhand 32:6ee488c97dcc 960 }
roryhand 32:6ee488c97dcc 961 }
roryhand 0:e89d7a0bfa3b 962
roryhand 38:3b4c05af5f36 963 //***************************************************************************//
roryhand 38:3b4c05af5f36 964
roryhand 38:3b4c05af5f36 965 //**************************************************************************//
roryhand 38:3b4c05af5f36 966
roryhand 38:3b4c05af5f36 967
roryhand 38:3b4c05af5f36 968
roryhand 38:3b4c05af5f36 969
roryhand 38:3b4c05af5f36 970
roryhand 1:aac37edee302 971
roryhand 44:a9e84d333a6a 972
roryhand 45:0e8e1f2ec5d2 973 void Play_WaveFileLoop(classSoundFile Sound1, classSoundFile Sound2, classSoundFile Sound3, FILE *wavfile1, FILE *wavfile2, FILE *wavfile3)
roryhand 45:0e8e1f2ec5d2 974 {
roryhand 45:0e8e1f2ec5d2 975 while(1) { //might have to change this to a while(1) loop?
roryhand 45:0e8e1f2ec5d2 976 //New format!! This should be (roughly) the way that this is done, with the new structures and classes
roryhand 44:a9e84d333a6a 977
roryhand 45:0e8e1f2ec5d2 978 //Block 1 of code. We need to pass in 3x classSoundFile objects, and 3x FILE* pointer objects.
roryhand 45:0e8e1f2ec5d2 979 //This will allow us to switch between the 3 different files (using "cross-fades") as needed.
roryhand 45:0e8e1f2ec5d2 980 /*Remember that these will need to be global varaibles to work properly*/
roryhand 45:0e8e1f2ec5d2 981
roryhand 45:0e8e1f2ec5d2 982
roryhand 2:957d3b2afff4 983 //make sure we are reading in the correct "notch" here
roryhand 2:957d3b2afff4 984
roryhand 44:a9e84d333a6a 985
roryhand 44:a9e84d333a6a 986
roryhand 54:606a83fff291 987 /*Block1*/
roryhand 54:606a83fff291 988 /*Read in data for current sound files. We only have 3 active engine noises at a time.
roryhand 54:606a83fff291 989 When it becomes time to transition up again, we then flip to the opposite block, and perform
roryhand 54:606a83fff291 990 the opposite operation.*/
roryhand 54:606a83fff291 991
roryhand 54:606a83fff291 992
roryhand 54:606a83fff291 993 if(BlockFlag == 0) {
roryhand 44:a9e84d333a6a 994 //Sound1=======================================================================================
roryhand 44:a9e84d333a6a 995 if( slice1 == (Sound1.FileInfo.num_slices-1) ) {
roryhand 44:a9e84d333a6a 996 slice1 = 0;
roryhand 44:a9e84d333a6a 997 fseek(wavfile1,44,SEEK_SET);
roryhand 2:957d3b2afff4 998 }
roryhand 47:9334a8f54997 999 if(feof(wavfile1)) {
roryhand 47:9334a8f54997 1000 fseek(wavfile1,44,SEEK_SET);
roryhand 47:9334a8f54997 1001 }
roryhand 44:a9e84d333a6a 1002 fread(Sound1.FileInfo.slice_buf,Sound1.FileInfo.FileFormat.block_align,1,wavfile1);
roryhand 44:a9e84d333a6a 1003 Sound1.data_sptr=(short *)Sound1.FileInfo.slice_buf; // 16 bit samples
roryhand 44:a9e84d333a6a 1004 //=============================================================================================
roryhand 54:606a83fff291 1005 }
roryhand 44:a9e84d333a6a 1006
roryhand 54:606a83fff291 1007 else if(BlockFlag == 1) {
roryhand 44:a9e84d333a6a 1008
roryhand 44:a9e84d333a6a 1009
roryhand 44:a9e84d333a6a 1010
roryhand 44:a9e84d333a6a 1011
roryhand 44:a9e84d333a6a 1012 /*Block2*/
roryhand 3:6169aeeaeeb4 1013
roryhand 2:957d3b2afff4 1014 //Read in data for current (i.e. now the previous notch, according to the index!!)
roryhand 2:957d3b2afff4 1015 //We might not need this code here...as its probably done somewhere else??
roryhand 44:a9e84d333a6a 1016 //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 1017 //Sounds[NotchingSet.Notch-1].data_sptr = (short *)Sounds[NotchingSet.Notch-1].FileInfo.slice_buf;
roryhand 44:a9e84d333a6a 1018 //We are now performing this section above.
roryhand 3:6169aeeaeeb4 1019
roryhand 47:9334a8f54997 1020
roryhand 54:606a83fff291 1021 if(FadeFlag) {
roryhand 54:606a83fff291 1022 if( slice1 == (Sound1.FileInfo.num_slices-1) ) {
roryhand 54:606a83fff291 1023 slice1 = 0;
roryhand 54:606a83fff291 1024 fseek(wavfile1,44,SEEK_SET);
roryhand 54:606a83fff291 1025 }
roryhand 54:606a83fff291 1026 if(OneOff == 1) {
roryhand 47:9334a8f54997 1027
roryhand 47:9334a8f54997 1028
roryhand 54:606a83fff291 1029 wavfile2 = fopen("/sd/mydir/SoundDecoder_second/09.wav","rb");
roryhand 54:606a83fff291 1030 if(wavfile2 == NULL) {
roryhand 54:606a83fff291 1031 printf("Cannot Open wavfile2\n\r");
roryhand 54:606a83fff291 1032 }
roryhand 54:606a83fff291 1033
roryhand 54:606a83fff291 1034 wavfile3 = fopen("/sd/mydir/SoundDecoder_second/02.wav","rb");
roryhand 54:606a83fff291 1035 if(wavfile3 == NULL) {
roryhand 54:606a83fff291 1036 printf("Cannot Open wavfile3\n\r");
roryhand 54:606a83fff291 1037 }
roryhand 54:606a83fff291 1038 fseek(wavfile2,44,SEEK_SET);
roryhand 54:606a83fff291 1039 fseek(wavfile3,44,SEEK_SET);
roryhand 54:606a83fff291 1040 /*
roryhand 54:606a83fff291 1041 FILE* wavfile4 = fopen("/sd/mydir/SoundDecoder_second/04.wav","rb");
roryhand 54:606a83fff291 1042 if(wavfile4 == NULL) {
roryhand 54:606a83fff291 1043 printf("Cannot Open wavfile3\n\r");
roryhand 54:606a83fff291 1044 }
roryhand 54:606a83fff291 1045 */
roryhand 54:606a83fff291 1046 OneOff = 0;
roryhand 54:606a83fff291 1047 }
roryhand 54:606a83fff291 1048
roryhand 54:606a83fff291 1049 fread(Sound1.FileInfo.slice_buf,Sound1.FileInfo.FileFormat.block_align,1,wavfile1);
roryhand 54:606a83fff291 1050 Sound1.data_sptr=(short *)Sound1.FileInfo.slice_buf; // 16 bit samples
roryhand 54:606a83fff291 1051
roryhand 54:606a83fff291 1052 //Sound2=======================================================================================
roryhand 54:606a83fff291 1053 fread(Sound2.FileInfo.slice_buf,Sound2.FileInfo.FileFormat.block_align,1,wavfile2);
roryhand 54:606a83fff291 1054 Sound2.data_sptr=(short *)Sound2.FileInfo.slice_buf; // 16 bit samples
roryhand 54:606a83fff291 1055 //=============================================================================================
roryhand 2:957d3b2afff4 1056
roryhand 45:0e8e1f2ec5d2 1057
roryhand 3:6169aeeaeeb4 1058
roryhand 54:606a83fff291 1059 //Sound3=======================================================================================
roryhand 54:606a83fff291 1060 fread(Sound3.FileInfo.slice_buf,Sound3.FileInfo.FileFormat.block_align,1,wavfile3);
roryhand 54:606a83fff291 1061 Sound3.data_sptr=(short *)Sound3.FileInfo.slice_buf; // 16 bit samples
roryhand 54:606a83fff291 1062 //=============================================================================================
roryhand 54:606a83fff291 1063
roryhand 54:606a83fff291 1064 //require this to get the fadeout coefficient for Sound1.
roryhand 54:606a83fff291 1065 NotchFadeOut.FadeCoeff = NotchFadeOut.FadeOut();//compute new FadeOut Coeff value
roryhand 54:606a83fff291 1066
roryhand 54:606a83fff291 1067
roryhand 54:606a83fff291 1068
roryhand 54:606a83fff291 1069 if( ((Sound2.FileInfo.FileData.subchunk2_size) - NotchFadeIn.Length - 2*11025) <= (ftell(wavfile2) + 44)) {
roryhand 2:957d3b2afff4 1070
roryhand 44:a9e84d333a6a 1071
roryhand 54:606a83fff291 1072 //required for calculating the fade In coefficient for Sound3
roryhand 54:606a83fff291 1073 NotchFadeIn.FadeCoeff = NotchFadeIn.FadeIn();
roryhand 3:6169aeeaeeb4 1074
roryhand 54:606a83fff291 1075 //Read In the next Notch
roryhand 44:a9e84d333a6a 1076
roryhand 54:606a83fff291 1077 /*
roryhand 54:606a83fff291 1078 fread(Sounds[NotchingSet.Notch].FileInfo.slice_buf,Sounds[NotchingSet.Notch].FileInfo.FileFormat.block_align,1,Sounds[NotchingSet.Notch].FileInfo.WavFile);
roryhand 54:606a83fff291 1079 Sounds[NotchingSet.Notch].data_sptr = (short *)Sounds[NotchingSet.Notch].FileInfo.slice_buf;
roryhand 54:606a83fff291 1080 */
roryhand 54:606a83fff291 1081 //no longer require the above section as we are reading in data for Sound3 (above, at beginning of function).
roryhand 54:606a83fff291 1082
roryhand 54:606a83fff291 1083 if( (ftell(wavfile2) + 44) >= Sound2.FileInfo.FileData.subchunk2_size ) {
roryhand 2:957d3b2afff4 1084
roryhand 54:606a83fff291 1085 //need to explicitly test if this notation/syntax works for pointers....
roryhand 54:606a83fff291 1086 /*Was this ever tested?? no idea...
roryhand 54:606a83fff291 1087 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 1088 or structure.*/
roryhand 54:606a83fff291 1089 *Sound1.data_sptr = *Sound3.data_sptr*NotchFadeIn.FadeCoeff;//Sound 3 by itself.
roryhand 54:606a83fff291 1090 //fclose(wavfile2);
roryhand 54:606a83fff291 1091 //fclose(wavfile1);
roryhand 54:606a83fff291 1092 } else {
roryhand 54:606a83fff291 1093 *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 1094 //probably later on redesign this to work with flags - that way it may be a little easier to debug any issues.
roryhand 54:606a83fff291 1095 }
roryhand 3:6169aeeaeeb4 1096
roryhand 2:957d3b2afff4 1097 } else {
roryhand 54:606a83fff291 1098 *Sound1.data_sptr = *Sound1.data_sptr*NotchFadeOut.FadeCoeff + *Sound2.data_sptr;//Sound1 and Sound 2 cross fade
roryhand 2:957d3b2afff4 1099 }
roryhand 2:957d3b2afff4 1100
roryhand 2:957d3b2afff4 1101 }
roryhand 2:957d3b2afff4 1102
roryhand 54:606a83fff291 1103
roryhand 54:606a83fff291 1104 /********************END OF DATA ASSIGNMENT SECTION*************************************************/
roryhand 54:606a83fff291 1105
roryhand 1:aac37edee302 1106 }
roryhand 1:aac37edee302 1107
roryhand 1:aac37edee302 1108
roryhand 44:a9e84d333a6a 1109
roryhand 44:a9e84d333a6a 1110 /**********************************************************************************************************/
roryhand 44:a9e84d333a6a 1111 /****************************DATA OUTPUT SECTION***********************************************************/
roryhand 44:a9e84d333a6a 1112 /**********************************************************************************************************/
roryhand 45:0e8e1f2ec5d2 1113 for (channel=0; channel<Sound1.FileInfo.FileFormat.num_channels; channel++) {
roryhand 45:0e8e1f2ec5d2 1114 switch (Sound1.FileInfo.FileFormat.sig_bps) {
roryhand 0:e89d7a0bfa3b 1115 case 16:
roryhand 1:aac37edee302 1116 if(flag1 == 1) {
roryhand 45:0e8e1f2ec5d2 1117 Buffer1[place_hold1] = Sound1.data_sptr[channel];
roryhand 1:aac37edee302 1118 place_hold1 = place_hold1 + 1;
roryhand 1:aac37edee302 1119 if(place_hold1 >= BufferLen) {
roryhand 1:aac37edee302 1120 while(1) {
roryhand 1:aac37edee302 1121 if(flag1 == 0) {
roryhand 1:aac37edee302 1122 break;
roryhand 1:aac37edee302 1123 }//if(flag1 == 0)
roryhand 1:aac37edee302 1124
roryhand 1:aac37edee302 1125
roryhand 1:aac37edee302 1126 }//while(1)
roryhand 1:aac37edee302 1127 }//if(place_hold1 > = BufferLen)
roryhand 0:e89d7a0bfa3b 1128
roryhand 1:aac37edee302 1129 } else if(flag2 == 1) {
roryhand 45:0e8e1f2ec5d2 1130 Buffer2[place_hold2] = Sound1.data_sptr[channel];
roryhand 1:aac37edee302 1131 place_hold2 = place_hold2 + 1;
roryhand 1:aac37edee302 1132 if(place_hold2 >= BufferLen) {
roryhand 1:aac37edee302 1133 while(1) {
roryhand 1:aac37edee302 1134
roryhand 1:aac37edee302 1135 if(flag2 == 0) {
roryhand 1:aac37edee302 1136 break;
roryhand 1:aac37edee302 1137 }
roryhand 1:aac37edee302 1138 }
roryhand 0:e89d7a0bfa3b 1139 }
roryhand 1:aac37edee302 1140
roryhand 1:aac37edee302 1141 }
roryhand 0:e89d7a0bfa3b 1142 }
roryhand 0:e89d7a0bfa3b 1143 }
roryhand 45:0e8e1f2ec5d2 1144 slice1 = slice1 + 1;
roryhand 45:0e8e1f2ec5d2 1145 slice2 = slice2 + 1;
roryhand 45:0e8e1f2ec5d2 1146 slice3 = slice3 + 1;
roryhand 0:e89d7a0bfa3b 1147 }
roryhand 0:e89d7a0bfa3b 1148 }
roryhand 0:e89d7a0bfa3b 1149
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 9:dd9cae06b202 1156