old demo that i want to try in mbed studio

Dependencies:   mbed SDFileSystem_Copy_of_mbed_version I2S

Committer:
roryhand
Date:
Mon May 27 19:44:22 2019 +0000
Revision:
36:569ec4335f92
Parent:
35:4469b508dda3
Child:
37:a563899ac0df
WIP - just changing classSoundFile

Who changed what in which revision?

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