old demo that i want to try in mbed studio

Dependencies:   mbed SDFileSystem_Copy_of_mbed_version I2S

Committer:
roryhand
Date:
Wed Feb 27 20:11:41 2019 +0000
Revision:
1:aac37edee302
Parent:
0:e89d7a0bfa3b
Child:
2:957d3b2afff4
Version that can read in the files.  Now need to set up the entire demo (i.e. change PlayLoop Fnc)

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 0:e89d7a0bfa3b 15 #include <vector>
roryhand 0:e89d7a0bfa3b 16 #include <string>
roryhand 0:e89d7a0bfa3b 17 #define sample_freq 11025
roryhand 1:aac37edee302 18 #pragma import __use_two_region_memory
roryhand 0:e89d7a0bfa3b 19 DigitalOut myled(LED1);
roryhand 0:e89d7a0bfa3b 20 DigitalOut led2(LED2);
roryhand 0:e89d7a0bfa3b 21 DigitalOut led3(LED3);
roryhand 0:e89d7a0bfa3b 22 DigitalIn NotchUp(p16);
roryhand 0:e89d7a0bfa3b 23 InterruptIn Horn(p16);
roryhand 0:e89d7a0bfa3b 24 Ticker sampletick;
roryhand 0:e89d7a0bfa3b 25 Ticker BellTick;
roryhand 0:e89d7a0bfa3b 26 Ticker EdTick;
roryhand 0:e89d7a0bfa3b 27 Ticker TickFadeOut;
roryhand 0:e89d7a0bfa3b 28 Timer t;
roryhand 0:e89d7a0bfa3b 29 Timer t2;
roryhand 0:e89d7a0bfa3b 30
roryhand 0:e89d7a0bfa3b 31 Serial pc(USBTX, USBRX); // tx, rx //FOR DEBUGGING PROGRAM USING GNU SCREEN
roryhand 0:e89d7a0bfa3b 32 DigitalOut cs(p8);
roryhand 0:e89d7a0bfa3b 33 I2S i2s(I2S_TRANSMIT, p5, p6, p7);
roryhand 0:e89d7a0bfa3b 34 SDFileSystem sd(p11, p12, p13, p8, "sd"); // the new pinout that i am using
roryhand 0:e89d7a0bfa3b 35
roryhand 0:e89d7a0bfa3b 36
roryhand 0:e89d7a0bfa3b 37 /*struct A {
roryhand 0:e89d7a0bfa3b 38 int data;
roryhand 0:e89d7a0bfa3b 39 B b;
roryhand 0:e89d7a0bfa3b 40 };*/
roryhand 0:e89d7a0bfa3b 41
roryhand 0:e89d7a0bfa3b 42
roryhand 0:e89d7a0bfa3b 43
roryhand 0:e89d7a0bfa3b 44
roryhand 0:e89d7a0bfa3b 45 class classFade
roryhand 0:e89d7a0bfa3b 46 {
roryhand 1:aac37edee302 47 public:
roryhand 1:aac37edee302 48
roryhand 0:e89d7a0bfa3b 49 float powerval;
roryhand 0:e89d7a0bfa3b 50 float FadeIteration;
roryhand 0:e89d7a0bfa3b 51 float DecayFactor;
roryhand 0:e89d7a0bfa3b 52 float Denom;
roryhand 0:e89d7a0bfa3b 53 float FadeCoeff;
roryhand 0:e89d7a0bfa3b 54 float Natural_Exp;
roryhand 0:e89d7a0bfa3b 55 int LengthSecs;
roryhand 0:e89d7a0bfa3b 56 int Length;
roryhand 1:aac37edee302 57
roryhand 0:e89d7a0bfa3b 58 //member Functions
roryhand 0:e89d7a0bfa3b 59 float FadeOut(void)
roryhand 0:e89d7a0bfa3b 60 {
roryhand 0:e89d7a0bfa3b 61 powerval = -FadeIteration/Denom;
roryhand 1:aac37edee302 62 if (FadeIteration >=Length) {
roryhand 1:aac37edee302 63 FadeCoeff = 0;
roryhand 1:aac37edee302 64
roryhand 1:aac37edee302 65 } else {
roryhand 0:e89d7a0bfa3b 66 FadeCoeff = (Length - FadeIteration)/Length;
roryhand 0:e89d7a0bfa3b 67 }
roryhand 1:aac37edee302 68 FadeIteration = FadeIteration + 1;
roryhand 1:aac37edee302 69 return FadeCoeff;
roryhand 1:aac37edee302 70
roryhand 1:aac37edee302 71 }
roryhand 1:aac37edee302 72 float FadeIn(void)
roryhand 0:e89d7a0bfa3b 73 {
roryhand 0:e89d7a0bfa3b 74 powerval = FadeIteration/Denom;
roryhand 1:aac37edee302 75 if (FadeIteration >=Length) {
roryhand 1:aac37edee302 76 FadeCoeff = 1;
roryhand 1:aac37edee302 77
roryhand 1:aac37edee302 78 } else {
roryhand 0:e89d7a0bfa3b 79 FadeCoeff = FadeIteration/Length;
roryhand 0:e89d7a0bfa3b 80 }
roryhand 0:e89d7a0bfa3b 81
roryhand 1:aac37edee302 82 FadeIteration = FadeIteration + 1;
roryhand 1:aac37edee302 83 return FadeCoeff;
roryhand 1:aac37edee302 84
roryhand 1:aac37edee302 85 }
roryhand 0:e89d7a0bfa3b 86 };
roryhand 0:e89d7a0bfa3b 87
roryhand 0:e89d7a0bfa3b 88 classFade IdleFadeOut;
roryhand 0:e89d7a0bfa3b 89 classFade N2FadeIn;
roryhand 0:e89d7a0bfa3b 90
roryhand 0:e89d7a0bfa3b 91
roryhand 0:e89d7a0bfa3b 92
roryhand 0:e89d7a0bfa3b 93
roryhand 0:e89d7a0bfa3b 94
roryhand 1:aac37edee302 95 typedef struct uFMT_STRUCT {
roryhand 1:aac37edee302 96 short comp_code;
roryhand 1:aac37edee302 97 short num_channels;
roryhand 1:aac37edee302 98 unsigned sample_rate;
roryhand 1:aac37edee302 99 unsigned avg_Bps;
roryhand 1:aac37edee302 100 short block_align;
roryhand 1:aac37edee302 101 short sig_bps;
roryhand 0:e89d7a0bfa3b 102 } FMT_STRUCT;
roryhand 0:e89d7a0bfa3b 103
roryhand 1:aac37edee302 104 typedef struct uNotch_STRUCT {
roryhand 1:aac37edee302 105 short Notch;
roryhand 1:aac37edee302 106 short NotchTransUp;
roryhand 1:aac37edee302 107 short NotchTransDown;
roryhand 1:aac37edee302 108 short NotchDirection;
roryhand 1:aac37edee302 109 } Notch_STRUCT;
roryhand 1:aac37edee302 110
roryhand 0:e89d7a0bfa3b 111 typedef struct uDATA_STRUCT {
roryhand 1:aac37edee302 112 unsigned subchunk2_ID;
roryhand 1:aac37edee302 113 unsigned subchunk2_size;
roryhand 1:aac37edee302 114 char * data_buf;
roryhand 1:aac37edee302 115 } DATA_STRUCT;
roryhand 0:e89d7a0bfa3b 116
roryhand 1:aac37edee302 117 typedef struct uWAV_FILE_STRUCT {
roryhand 1:aac37edee302 118 FILE *WavFile;
roryhand 1:aac37edee302 119 int id_number;
roryhand 1:aac37edee302 120 char *slice_buf;
roryhand 1:aac37edee302 121 int num_slices;
roryhand 1:aac37edee302 122 FMT_STRUCT FileFormat;
roryhand 1:aac37edee302 123 DATA_STRUCT FileData;
roryhand 0:e89d7a0bfa3b 124 } WAV_FILE_STRUCT;
roryhand 0:e89d7a0bfa3b 125
roryhand 0:e89d7a0bfa3b 126 /*typedef struct uWAV_FILE_STRUCT{
roryhand 1:aac37edee302 127 FILE* WavFile;
roryhand 1:aac37edee302 128
roryhand 1:aac37edee302 129
roryhand 0:e89d7a0bfa3b 130 }WAV_FILE_STRUCT;*/
roryhand 0:e89d7a0bfa3b 131 class classSoundFile
roryhand 0:e89d7a0bfa3b 132 {
roryhand 1:aac37edee302 133 public:
roryhand 1:aac37edee302 134
roryhand 1:aac37edee302 135 //add a class constructor
roryhand 1:aac37edee302 136
roryhand 1:aac37edee302 137 WAV_FILE_STRUCT FileInfo;
roryhand 1:aac37edee302 138 //classSoundFile(string filename);//this is the constructor
roryhand 1:aac37edee302 139 //string filename;
roryhand 0:e89d7a0bfa3b 140 };
roryhand 0:e89d7a0bfa3b 141
roryhand 1:aac37edee302 142 //class constructor;
roryhand 1:aac37edee302 143 /*classSoundFile::classSoundFile(string filename)
roryhand 1:aac37edee302 144 {
roryhand 1:aac37edee302 145 //Declare RootFolder and the directory for the appropriate file.
roryhand 1:aac37edee302 146 //How we index into filename[] from the outside of this class is another
roryhand 1:aac37edee302 147 //issue...
roryhand 1:aac37edee302 148 FileInfo.WavFile = fopen("/sd/mydir/645Engine/Startup.wav","rb");
roryhand 1:aac37edee302 149 fseek(FileInfo.WavFile,20,SEEK_SET);
roryhand 1:aac37edee302 150 fread(&FileInfo.FileFormat,sizeof(FileInfo.FileFormat),1,FileInfo.WavFile);
roryhand 1:aac37edee302 151 printf("wav_format.sample_rate: %d\n\r",FileInfo.FileFormat.sample_rate);
roryhand 1:aac37edee302 152 fread(&FileInfo.FileData,sizeof(FileInfo.FileData),1,FileInfo.WavFile);
roryhand 1:aac37edee302 153 printf("wav_data.subchunk2_size: %d\n\r",FileInfo.FileData.subchunk2_size);
roryhand 1:aac37edee302 154 FileInfo.slice_buf = ( char *)malloc(FileInfo.FileFormat.block_align);
roryhand 1:aac37edee302 155 fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,FileInfo.WavFile); //This isnt actually required, its just a test
roryhand 1:aac37edee302 156 FileInfo.num_slices = FileInfo.FileData.subchunk2_size/FileInfo.FileFormat.block_align;
roryhand 1:aac37edee302 157 }*/
roryhand 1:aac37edee302 158
roryhand 0:e89d7a0bfa3b 159
roryhand 0:e89d7a0bfa3b 160 int i = 0;
roryhand 0:e89d7a0bfa3b 161 int h = 0;
roryhand 0:e89d7a0bfa3b 162 short bufflen = 1;
roryhand 0:e89d7a0bfa3b 163 int buffer[1];
roryhand 1:aac37edee302 164 int AudioFormat, NumChannels, SampleRate, BitsPerSample ;
roryhand 0:e89d7a0bfa3b 165 char *slice_buf;
roryhand 0:e89d7a0bfa3b 166 short *data_sptr;
roryhand 0:e89d7a0bfa3b 167 short *data_sptr_horn;
roryhand 0:e89d7a0bfa3b 168 short *data_sptr_IdleN2;
roryhand 0:e89d7a0bfa3b 169 short * data_sptr_bell;
roryhand 0:e89d7a0bfa3b 170 short * data_sptr_N2;
roryhand 0:e89d7a0bfa3b 171 short * data_sptr_Flange;
roryhand 0:e89d7a0bfa3b 172 unsigned char *data_bptr;
roryhand 0:e89d7a0bfa3b 173 int *data_wptr;
roryhand 0:e89d7a0bfa3b 174 unsigned channel;
roryhand 0:e89d7a0bfa3b 175 long slice, num_slices;
roryhand 0:e89d7a0bfa3b 176 int verbosity = 0;
roryhand 0:e89d7a0bfa3b 177 int verbosity2 = 0;
roryhand 0:e89d7a0bfa3b 178 int verbosity3 = 0;
roryhand 0:e89d7a0bfa3b 179 int verbosity4 = 0;
roryhand 0:e89d7a0bfa3b 180 int verbosity5 = 0;
roryhand 0:e89d7a0bfa3b 181 int interrupt_condition = 1;
roryhand 0:e89d7a0bfa3b 182 int sampling_freq = 11025;
roryhand 0:e89d7a0bfa3b 183 const int BufferLen = 2000;
roryhand 0:e89d7a0bfa3b 184 short Buffer1[BufferLen];
roryhand 0:e89d7a0bfa3b 185 short Buffer2[BufferLen];
roryhand 0:e89d7a0bfa3b 186 short place_hold1 = 0;
roryhand 0:e89d7a0bfa3b 187 short place_hold2 = 0;
roryhand 0:e89d7a0bfa3b 188
roryhand 0:e89d7a0bfa3b 189 volatile int flag1 = 1;
roryhand 0:e89d7a0bfa3b 190 volatile int flag2 = 0;
roryhand 0:e89d7a0bfa3b 191 volatile int flag3 = 1;
roryhand 0:e89d7a0bfa3b 192 volatile int flag4 = 0;
roryhand 0:e89d7a0bfa3b 193 int FLAGBUFF1 = 0;
roryhand 0:e89d7a0bfa3b 194 int FLAGBUFF2 = 0;
roryhand 0:e89d7a0bfa3b 195 int BellFlag = 0;
roryhand 0:e89d7a0bfa3b 196 int BellFlag2 = 0;
roryhand 0:e89d7a0bfa3b 197 int FadeFlag = 0;
roryhand 0:e89d7a0bfa3b 198 int DualEngineFlag = 0;
roryhand 0:e89d7a0bfa3b 199
roryhand 0:e89d7a0bfa3b 200
roryhand 0:e89d7a0bfa3b 201 short value[1];
roryhand 0:e89d7a0bfa3b 202 FILE *HornWav;
roryhand 0:e89d7a0bfa3b 203 FILE *edsheeran_wav;
roryhand 0:e89d7a0bfa3b 204 FILE *Startup_wav;
roryhand 0:e89d7a0bfa3b 205 FILE *IdleN2Wav;
roryhand 0:e89d7a0bfa3b 206 FILE *N2Wav;
roryhand 0:e89d7a0bfa3b 207 FILE *BellWav;
roryhand 0:e89d7a0bfa3b 208 FILE *FlangeWav;
roryhand 0:e89d7a0bfa3b 209 //long long slice_value;
roryhand 0:e89d7a0bfa3b 210 int slice_value[1];
roryhand 0:e89d7a0bfa3b 211
roryhand 0:e89d7a0bfa3b 212
roryhand 0:e89d7a0bfa3b 213 WAV_FILE_STRUCT WavInfo_Horn;
roryhand 0:e89d7a0bfa3b 214 WAV_FILE_STRUCT WavInfo_IdleN2;
roryhand 0:e89d7a0bfa3b 215 WAV_FILE_STRUCT WavInfo_N2;
roryhand 0:e89d7a0bfa3b 216 WAV_FILE_STRUCT WavInfo_Bell;
roryhand 0:e89d7a0bfa3b 217 WAV_FILE_STRUCT WavInfo_Flange;
roryhand 0:e89d7a0bfa3b 218 Ticker flipper;
roryhand 0:e89d7a0bfa3b 219 char * slice_buf_bell;
roryhand 0:e89d7a0bfa3b 220 char * slice_buf_ed;
roryhand 0:e89d7a0bfa3b 221 char * slice_buf_startup;
roryhand 0:e89d7a0bfa3b 222 char * slice_buf_N2;
roryhand 1:aac37edee302 223 Notch_STRUCT NotchingSet;
roryhand 0:e89d7a0bfa3b 224 //test
roryhand 0:e89d7a0bfa3b 225 //short *data_sptr_bell = 0;
roryhand 0:e89d7a0bfa3b 226 short *data_sptr_ed = 0;
roryhand 0:e89d7a0bfa3b 227 short *data_sptr_startup = 0;
roryhand 1:aac37edee302 228 void flip()
roryhand 1:aac37edee302 229 {
roryhand 0:e89d7a0bfa3b 230 led2 = !led2;
roryhand 0:e89d7a0bfa3b 231 }
roryhand 0:e89d7a0bfa3b 232
roryhand 0:e89d7a0bfa3b 233
roryhand 0:e89d7a0bfa3b 234 void isr()
roryhand 0:e89d7a0bfa3b 235 {
roryhand 1:aac37edee302 236 if(flag1 == 0) {
roryhand 0:e89d7a0bfa3b 237 value[0] = Buffer1[place_hold1]>>4;
roryhand 0:e89d7a0bfa3b 238 i2s.write(value,1);//Send next PWM value to amp
roryhand 0:e89d7a0bfa3b 239 place_hold1 = place_hold1 + 1;
roryhand 1:aac37edee302 240 if( (place_hold1 >= BufferLen)) {
roryhand 0:e89d7a0bfa3b 241 led2 = !led2;
roryhand 0:e89d7a0bfa3b 242 place_hold1 = 0;
roryhand 0:e89d7a0bfa3b 243 place_hold2 = 0;
roryhand 0:e89d7a0bfa3b 244 flag1 = 1;
roryhand 0:e89d7a0bfa3b 245 flag2 = 0;
roryhand 1:aac37edee302 246 }
roryhand 1:aac37edee302 247 } else if(flag2 == 0) {
roryhand 0:e89d7a0bfa3b 248 value[0] = Buffer2[place_hold2]>>4;
roryhand 0:e89d7a0bfa3b 249 i2s.write(value,1);//Send next PWM value to amp
roryhand 0:e89d7a0bfa3b 250 place_hold2 = place_hold2 + 1;
roryhand 1:aac37edee302 251 if( (place_hold2 >= BufferLen) ) {
roryhand 0:e89d7a0bfa3b 252 led2 = !led2;
roryhand 0:e89d7a0bfa3b 253 place_hold1 = 0;
roryhand 0:e89d7a0bfa3b 254 place_hold2 = 0;
roryhand 0:e89d7a0bfa3b 255 flag1 = 0;
roryhand 1:aac37edee302 256 flag2 = 1;
roryhand 0:e89d7a0bfa3b 257 FLAGBUFF2 = 0;
roryhand 1:aac37edee302 258 }
roryhand 0:e89d7a0bfa3b 259 }
roryhand 0:e89d7a0bfa3b 260 }
roryhand 1:aac37edee302 261
roryhand 0:e89d7a0bfa3b 262 void horn_sound()
roryhand 0:e89d7a0bfa3b 263 {
roryhand 0:e89d7a0bfa3b 264 BellFlag = 1;
roryhand 0:e89d7a0bfa3b 265 fseek(HornWav,44,SEEK_SET);
roryhand 0:e89d7a0bfa3b 266 fseek(BellWav,44,SEEK_SET);
roryhand 0:e89d7a0bfa3b 267 fseek(FlangeWav,44,SEEK_SET);
roryhand 0:e89d7a0bfa3b 268 fseek(N2Wav,44,SEEK_SET);
roryhand 0:e89d7a0bfa3b 269 }
roryhand 0:e89d7a0bfa3b 270
roryhand 0:e89d7a0bfa3b 271
roryhand 0:e89d7a0bfa3b 272 void N2SoundIsr()
roryhand 0:e89d7a0bfa3b 273 {
roryhand 0:e89d7a0bfa3b 274 DualEngineFlag = 1;
roryhand 0:e89d7a0bfa3b 275 fseek(N2Wav,44,SEEK_SET);
roryhand 0:e89d7a0bfa3b 276 fseek(HornWav,44,SEEK_SET);
roryhand 0:e89d7a0bfa3b 277 //TickFadeOut.detach(&N2SoundIsr);//,5.0);
roryhand 0:e89d7a0bfa3b 278 }
roryhand 0:e89d7a0bfa3b 279
roryhand 0:e89d7a0bfa3b 280
roryhand 0:e89d7a0bfa3b 281 void FadeOutIsr()
roryhand 0:e89d7a0bfa3b 282 {
roryhand 1:aac37edee302 283 FadeFlag = 1;
roryhand 1:aac37edee302 284 fseek(IdleN2Wav,44,SEEK_SET);
roryhand 1:aac37edee302 285 fseek(N2Wav,44,SEEK_SET);
roryhand 1:aac37edee302 286 fseek(HornWav,44,SEEK_SET);
roryhand 0:e89d7a0bfa3b 287 fseek(FlangeWav,44,SEEK_SET);
roryhand 1:aac37edee302 288
roryhand 0:e89d7a0bfa3b 289 }
roryhand 0:e89d7a0bfa3b 290
roryhand 0:e89d7a0bfa3b 291
roryhand 1:aac37edee302 292 void NotchUpIsr()
roryhand 0:e89d7a0bfa3b 293 {
roryhand 1:aac37edee302 294 if(1 <= NotchingSet.Notch < 8) {
roryhand 1:aac37edee302 295
roryhand 1:aac37edee302 296 NotchingSet.Notch = NotchingSet.Notch + 1;
roryhand 1:aac37edee302 297 NotchingSet.NotchTransUp = NotchingSet.Notch + 7;
roryhand 1:aac37edee302 298
roryhand 1:aac37edee302 299 NotchingSet.NotchDirection = 1;
roryhand 1:aac37edee302 300 }
roryhand 0:e89d7a0bfa3b 301 }
roryhand 0:e89d7a0bfa3b 302
roryhand 0:e89d7a0bfa3b 303 void NotchDownIsr()
roryhand 0:e89d7a0bfa3b 304 {
roryhand 1:aac37edee302 305 if(1 < NotchingSet.Notch <= 8) {
roryhand 1:aac37edee302 306 NotchingSet.Notch = NotchingSet.Notch - 1;
roryhand 1:aac37edee302 307 NotchingSet.NotchTransDown = NotchingSet.Notch + 15;;
roryhand 1:aac37edee302 308 NotchingSet.NotchDirection = 0;
roryhand 1:aac37edee302 309 }
roryhand 1:aac37edee302 310 }
roryhand 0:e89d7a0bfa3b 311
roryhand 0:e89d7a0bfa3b 312
roryhand 1:aac37edee302 313
roryhand 0:e89d7a0bfa3b 314
roryhand 0:e89d7a0bfa3b 315 //function prototypes
roryhand 0:e89d7a0bfa3b 316 WAV_FILE_STRUCT ReadFileInfo(WAV_FILE_STRUCT FileInfo, FILE * wav_file);
roryhand 1:aac37edee302 317 classSoundFile LoadFileStream(classSoundFile FileInfo, string filename);
roryhand 0:e89d7a0bfa3b 318 classFade FadeDataInitialise(classFade FadeData);
roryhand 0:e89d7a0bfa3b 319 float FadeOut(void);
roryhand 0:e89d7a0bfa3b 320 void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo);
roryhand 0:e89d7a0bfa3b 321 void Play_WaveFileLoop(FILE * my_wav, WAV_FILE_STRUCT FileInfo);
roryhand 1:aac37edee302 322 int main()
roryhand 1:aac37edee302 323 {
roryhand 0:e89d7a0bfa3b 324 //LocalFileSystem local("local");
roryhand 0:e89d7a0bfa3b 325 NotchUp.mode(PullUp);
roryhand 0:e89d7a0bfa3b 326
roryhand 0:e89d7a0bfa3b 327
roryhand 0:e89d7a0bfa3b 328 //classSoundFile Sounds[4];
roryhand 1:aac37edee302 329 /* for(int iii = 0; iii < 3; iii ++)
roryhand 1:aac37edee302 330 {
roryhand 1:aac37edee302 331 Sounds[iii].setX(iii);
roryhand 1:aac37edee302 332 }*/
roryhand 0:e89d7a0bfa3b 333 WAV_FILE_STRUCT WavInfo_Startup;
roryhand 0:e89d7a0bfa3b 334 WAV_FILE_STRUCT WavInfo_Idle;
roryhand 0:e89d7a0bfa3b 335
roryhand 0:e89d7a0bfa3b 336 pc.printf("Beginning of program\n");
roryhand 0:e89d7a0bfa3b 337 FILE *StartupWav;
roryhand 0:e89d7a0bfa3b 338 FILE *IdleWav;
roryhand 1:aac37edee302 339
roryhand 1:aac37edee302 340 char * RootFolder = "/sd/mydir/SoundDecoder/";
roryhand 0:e89d7a0bfa3b 341 DIR *dir;
roryhand 0:e89d7a0bfa3b 342 dirent *ent;
roryhand 0:e89d7a0bfa3b 343 int iterator = 0;
roryhand 0:e89d7a0bfa3b 344 string filename[10];
roryhand 1:aac37edee302 345 if ((dir = opendir ("/sd/mydir/SoundDecoder")) != NULL) {
roryhand 1:aac37edee302 346
roryhand 0:e89d7a0bfa3b 347 // print all the files and directories within directory
roryhand 1:aac37edee302 348 while ((ent = readdir (dir)) != NULL) {
roryhand 0:e89d7a0bfa3b 349 printf("%s\r\n",string(ent->d_name));
roryhand 0:e89d7a0bfa3b 350 filename[iterator] = string(ent->d_name);
roryhand 1:aac37edee302 351
roryhand 0:e89d7a0bfa3b 352 //printf("%s\r\n",filename[iterator]);
roryhand 0:e89d7a0bfa3b 353 iterator = iterator + 1;
roryhand 0:e89d7a0bfa3b 354 //printf("%s\r\n", ent->d_name);
roryhand 1:aac37edee302 355 //filenames.push_back(string(dirp->d_name));
roryhand 0:e89d7a0bfa3b 356 }
roryhand 0:e89d7a0bfa3b 357 closedir (dir);
roryhand 1:aac37edee302 358 }
roryhand 1:aac37edee302 359 for(iterator = 0; iterator < 10; iterator ++) {
roryhand 1:aac37edee302 360 printf("All the Files: %s\r\n",filename[iterator]);
roryhand 1:aac37edee302 361 //printf("All the Files: %s\r\n",ent[iterator]);
roryhand 1:aac37edee302 362 }
roryhand 1:aac37edee302 363 //strcat(RootFolder,qdfilename[0]);
roryhand 1:aac37edee302 364 string folder = RootFolder + filename[9];
roryhand 1:aac37edee302 365 printf("Folder: %s\n\r",folder);
roryhand 1:aac37edee302 366
roryhand 1:aac37edee302 367
roryhand 0:e89d7a0bfa3b 368 //printf("Files and Folders contained here: %d\n\r",readdir(dp));
roryhand 1:aac37edee302 369
roryhand 1:aac37edee302 370
roryhand 0:e89d7a0bfa3b 371 //StartupWav = fopen("/sd/mydir/Startup.wav","rb");
roryhand 0:e89d7a0bfa3b 372 const char* folder2 = folder.c_str();
roryhand 1:aac37edee302 373
roryhand 1:aac37edee302 374
roryhand 1:aac37edee302 375 string FileName;
roryhand 1:aac37edee302 376 //vector <classSoundFile> Sound (27);
roryhand 1:aac37edee302 377 classSoundFile Sound[22];
roryhand 1:aac37edee302 378 for(int iii = 0; iii < 21; iii++) {
roryhand 1:aac37edee302 379 //Sound[0].FileInfo;
roryhand 1:aac37edee302 380 string folder = RootFolder + filename[3];
roryhand 1:aac37edee302 381 printf("Whole File Thing: %s\n\r",folder);
roryhand 1:aac37edee302 382 Sound[iii].FileInfo.WavFile = fopen("/sd/mydir/645Engine/Startup.wav","rb");
roryhand 1:aac37edee302 383 printf("Size of FILE* %d\n\r ",sizeof(Sound[iii].FileInfo.WavFile));
roryhand 1:aac37edee302 384 fseek(Sound[iii].FileInfo.WavFile,20,SEEK_SET);
roryhand 1:aac37edee302 385 fread(&Sound[iii].FileInfo.FileFormat,sizeof(Sound[iii].FileInfo.FileFormat),1,Sound[iii].FileInfo.WavFile);
roryhand 1:aac37edee302 386 //printf("wav_format.sample_rate: %d\n\r",Sound[iii].FileInfo.FileFormat.sample_rate);
roryhand 1:aac37edee302 387 fread(&Sound[iii].FileInfo.FileData,sizeof(Sound[iii].FileInfo.FileData),1,Sound[iii].FileInfo.WavFile);
roryhand 1:aac37edee302 388 //printf("wav_data.subchunk2_size: %d\n\r",Sound[iii].FileInfo.FileData.subchunk2_size);
roryhand 1:aac37edee302 389 Sound[iii].FileInfo.slice_buf = ( char *)malloc(Sound[iii].FileInfo.FileFormat.block_align);
roryhand 1:aac37edee302 390 fread(Sound[iii].FileInfo.slice_buf,Sound[iii].FileInfo.FileFormat.block_align,1,Sound[iii].FileInfo.WavFile); //This isnt actually required, its just a test
roryhand 1:aac37edee302 391 Sound[iii].FileInfo.num_slices = Sound[iii].FileInfo.FileData.subchunk2_size/Sound[iii].FileInfo.FileFormat.block_align;
roryhand 1:aac37edee302 392 //printf("Number of Slices: %d\n\r",Sound[iii].FileInfo.num_slices);
roryhand 1:aac37edee302 393 printf("Iteration: %d\n\r",iii);
roryhand 1:aac37edee302 394 printf("SizeOf Sound[iii] %d\n\r",sizeof(Sound[iii]));
roryhand 1:aac37edee302 395 printf("SizeOf Sound[iii].FileInfo.FileFormat %d\n\r",sizeof(Sound[iii].FileInfo.FileFormat));
roryhand 1:aac37edee302 396 printf("SizeOf Sound[iii].FileInfo.FileFormat %d\n\r",sizeof(Sound[iii].FileInfo.FileData));
roryhand 1:aac37edee302 397 printf("SizeOf Sound[iii].FileInfo.FileFormat %d\n\r",sizeof(Sound[iii].FileInfo.WavFile));
roryhand 1:aac37edee302 398 printf("SizeOf Sound[iii].FileInfo.FileFormat %d\n\r",sizeof(Sound[iii].FileInfo.id_number));
roryhand 1:aac37edee302 399 printf("SizeOf Sound[iii].FileInfo.FileFormat %d\n\r",sizeof(Sound[iii].FileInfo.slice_buf));
roryhand 1:aac37edee302 400 printf("SizeOf Sound[iii].FileInfo.FileFormat %d\n\r",sizeof(Sound[iii].FileInfo.num_slices));
roryhand 1:aac37edee302 401 fclose(Sound[iii].FileInfo.WavFile);//close the file stream. We will only reopen the file when we need to do it. Hopefully this should also free the memory...
roryhand 1:aac37edee302 402
roryhand 1:aac37edee302 403 /*
roryhand 1:aac37edee302 404 FILE *WavFile;
roryhand 1:aac37edee302 405 int id_number;
roryhand 1:aac37edee302 406 char *slice_buf;
roryhand 1:aac37edee302 407 int num_slices;
roryhand 1:aac37edee302 408 */
roryhand 1:aac37edee302 409 //Sounds[iii] = LoadFileStream(Sounds[iii],FileName);
roryhand 0:e89d7a0bfa3b 410 }
roryhand 1:aac37edee302 411 //We still experience the exact same memory issue
roryhand 1:aac37edee302 412 //classSoundFile Sounds[10] = {classSoundFile(FileName),classSoundFile(FileName), classSoundFile(FileName),classSoundFile(FileName),classSoundFile(FileName),classSoundFile(FileName),classSoundFile(FileName), classSoundFile(FileName),classSoundFile(FileName),classSoundFile(FileName)};
roryhand 1:aac37edee302 413
roryhand 1:aac37edee302 414 //classSoundFile Sounds[27];
roryhand 1:aac37edee302 415 /* for(int iii = 0; iii < 6; iii++)
roryhand 1:aac37edee302 416 {
roryhand 1:aac37edee302 417 FileName = filename[0];
roryhand 1:aac37edee302 418 string teststring = "test string";
roryhand 1:aac37edee302 419 //printf("Before calling fnc: 2%s\n\r",FileName);
roryhand 1:aac37edee302 420 classSoundFile Sound(FileName);
roryhand 1:aac37edee302 421 Sounds[iii] = Sound;
roryhand 1:aac37edee302 422 printf("HELLO!\n\r");
roryhand 1:aac37edee302 423 }*/
roryhand 1:aac37edee302 424 printf("DO WE GET PAST THE ALLOCATION POINT\n\r");
roryhand 1:aac37edee302 425
roryhand 1:aac37edee302 426
roryhand 1:aac37edee302 427
roryhand 1:aac37edee302 428
roryhand 1:aac37edee302 429
roryhand 1:aac37edee302 430
roryhand 1:aac37edee302 431 StartupWav = fopen("/sd/mydir/645Engine/Startup.wav","rb");
roryhand 0:e89d7a0bfa3b 432 IdleWav = fopen("/sd/mydir/645Engine/N2_11k_minus10dB.wav","rb");
roryhand 0:e89d7a0bfa3b 433 IdleN2Wav = fopen("/sd/mydir/645Engine/N2N3_11k_minus10dB.wav","rb");
roryhand 0:e89d7a0bfa3b 434 HornWav = fopen("/sd/mydir/645Engine/K3H_1_A_short_quiet.wav","rb");
roryhand 0:e89d7a0bfa3b 435 N2Wav = fopen("/sd/mydir/645Engine/N3_11k_minus11dB.wav","rb");
roryhand 0:e89d7a0bfa3b 436 BellWav = fopen("/sd/mydir/645Engine/EMD_BRONZE_BELL_1_11k_minus10dB.wav","rb");
roryhand 0:e89d7a0bfa3b 437 FlangeWav = fopen("/sd/mydir/645Engine/EX_FlangeJoint1_11k_minus12dB.wav","rb");
roryhand 1:aac37edee302 438
roryhand 1:aac37edee302 439
roryhand 0:e89d7a0bfa3b 440 WavInfo_Startup = ReadFileInfo(WavInfo_Startup, StartupWav);
roryhand 1:aac37edee302 441 printf("WavInfo_Startup Size: %d\n\r",sizeof(WavInfo_Startup));
roryhand 0:e89d7a0bfa3b 442 WavInfo_Idle = ReadFileInfo(WavInfo_Idle, IdleWav);
roryhand 0:e89d7a0bfa3b 443 WavInfo_Horn = ReadFileInfo(WavInfo_Horn, HornWav);
roryhand 0:e89d7a0bfa3b 444 WavInfo_IdleN2 = ReadFileInfo(WavInfo_IdleN2, IdleN2Wav);
roryhand 0:e89d7a0bfa3b 445 WavInfo_N2 = ReadFileInfo(WavInfo_N2, N2Wav);
roryhand 0:e89d7a0bfa3b 446 WavInfo_Bell = ReadFileInfo(WavInfo_Bell, BellWav);
roryhand 0:e89d7a0bfa3b 447 WavInfo_Flange = ReadFileInfo(WavInfo_Flange, FlangeWav);
roryhand 1:aac37edee302 448
roryhand 1:aac37edee302 449
roryhand 0:e89d7a0bfa3b 450 //Populate our class instances with some data (is there an implicit way to do this?)
roryhand 0:e89d7a0bfa3b 451 N2FadeIn.LengthSecs = 4;
roryhand 0:e89d7a0bfa3b 452 IdleFadeOut.LengthSecs = 2;
roryhand 0:e89d7a0bfa3b 453 N2FadeIn = FadeDataInitialise(N2FadeIn);
roryhand 0:e89d7a0bfa3b 454 IdleFadeOut = FadeDataInitialise(IdleFadeOut);
roryhand 1:aac37edee302 455
roryhand 1:aac37edee302 456
roryhand 0:e89d7a0bfa3b 457 //Set up the wolfson Audio Codec board
roryhand 0:e89d7a0bfa3b 458 wm8731_Config_setup();
roryhand 0:e89d7a0bfa3b 459 //i2s audio data transfer code??
roryhand 0:e89d7a0bfa3b 460 i2s.stereomono(I2S_STEREO);
roryhand 0:e89d7a0bfa3b 461 i2s.masterslave(I2S_MASTER);
roryhand 0:e89d7a0bfa3b 462 led3 = 1;
roryhand 0:e89d7a0bfa3b 463 led2 = 1;
roryhand 0:e89d7a0bfa3b 464 sampletick.attach(&isr,1.0/sampling_freq); //1/16000
roryhand 0:e89d7a0bfa3b 465 //TickFadeOut.attach(&FadeOutIsr,10.0);
roryhand 0:e89d7a0bfa3b 466 i2s.start();
roryhand 0:e89d7a0bfa3b 467 Horn.rise(&FadeOutIsr);
roryhand 0:e89d7a0bfa3b 468 slice = 0;
roryhand 0:e89d7a0bfa3b 469 fseek(IdleN2Wav,44,SEEK_SET);
roryhand 0:e89d7a0bfa3b 470 //Play_WaveFile(IdleN2Wav,WavInfo_IdleN2);
roryhand 0:e89d7a0bfa3b 471 //Play_WaveFile(N2Wav,WavInfo_N2);
roryhand 0:e89d7a0bfa3b 472 t.reset();
roryhand 0:e89d7a0bfa3b 473 t.start();
roryhand 0:e89d7a0bfa3b 474 N2FadeIn.FadeCoeff = N2FadeIn.FadeOut();
roryhand 0:e89d7a0bfa3b 475 t.stop();
roryhand 0:e89d7a0bfa3b 476 printf("Time to Calcualte Fade Coeff: %d\n\r",t.read_us());
roryhand 0:e89d7a0bfa3b 477 t.reset();
roryhand 1:aac37edee302 478
roryhand 0:e89d7a0bfa3b 479 fseek(IdleN2Wav,44,SEEK_SET);
roryhand 0:e89d7a0bfa3b 480 t.start();
roryhand 1:aac37edee302 481 fread(WavInfo_IdleN2.slice_buf,WavInfo_IdleN2.FileFormat.block_align,1,IdleN2Wav);
roryhand 0:e89d7a0bfa3b 482 data_sptr_IdleN2 = (short *)WavInfo_IdleN2.slice_buf;
roryhand 0:e89d7a0bfa3b 483 t.stop();
roryhand 0:e89d7a0bfa3b 484 printf("Time to Read in a slice: %dus\n\r",t.read_us());
roryhand 0:e89d7a0bfa3b 485 t.reset();
roryhand 1:aac37edee302 486
roryhand 0:e89d7a0bfa3b 487 printf("point to start sound: %d\n\r",((WavInfo_IdleN2.FileData.subchunk2_size) - N2FadeIn.Length));
roryhand 0:e89d7a0bfa3b 488 printf("Size of Data: %d\n\r",WavInfo_IdleN2.FileData.subchunk2_size);
roryhand 1:aac37edee302 489
roryhand 0:e89d7a0bfa3b 490 fseek(FlangeWav,44,SEEK_SET);
roryhand 0:e89d7a0bfa3b 491 Play_WaveFile(StartupWav,WavInfo_Startup);
roryhand 0:e89d7a0bfa3b 492 fseek(IdleN2Wav,44,SEEK_SET);//reset for use in the Loop code
roryhand 0:e89d7a0bfa3b 493 slice = 0;
roryhand 0:e89d7a0bfa3b 494 fseek(IdleWav,44,SEEK_SET);
roryhand 1:aac37edee302 495 //Play_WaveFileLoop(IdleWav, WavInfo_Idle);
roryhand 1:aac37edee302 496
roryhand 1:aac37edee302 497 i2s.stop();
roryhand 0:e89d7a0bfa3b 498
roryhand 0:e89d7a0bfa3b 499 }
roryhand 0:e89d7a0bfa3b 500
roryhand 0:e89d7a0bfa3b 501
roryhand 0:e89d7a0bfa3b 502 WAV_FILE_STRUCT ReadFileInfo(WAV_FILE_STRUCT FileInfo, FILE * wav_file)
roryhand 0:e89d7a0bfa3b 503 {
roryhand 0:e89d7a0bfa3b 504 fseek(wav_file,20,SEEK_SET);
roryhand 0:e89d7a0bfa3b 505 fread(&FileInfo.FileFormat,sizeof(FileInfo.FileFormat),1,wav_file);
roryhand 1:aac37edee302 506 //printf("wav_format.sample_rate: %d\n\r",FileInfo.FileFormat.sample_rate);
roryhand 1:aac37edee302 507
roryhand 0:e89d7a0bfa3b 508 fread(&FileInfo.FileData,sizeof(FileInfo.FileData),1,wav_file);
roryhand 1:aac37edee302 509 //printf("wav_data.subchunk2_size: %d\n\r",FileInfo.FileData.subchunk2_size);
roryhand 0:e89d7a0bfa3b 510 FileInfo.slice_buf = ( char *)malloc(FileInfo.FileFormat.block_align);
roryhand 0:e89d7a0bfa3b 511 fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,wav_file); //This isnt actually required, its just a test
roryhand 1:aac37edee302 512 FileInfo.num_slices = FileInfo.FileData.subchunk2_size/FileInfo.FileFormat.block_align;
roryhand 1:aac37edee302 513 //printf("Number of Slices: %d\n\r",FileInfo.num_slices);
roryhand 1:aac37edee302 514 return FileInfo;
roryhand 0:e89d7a0bfa3b 515 }
roryhand 1:aac37edee302 516
roryhand 1:aac37edee302 517 classSoundFile LoadFileStream(classSoundFile Sound, string filename)
roryhand 1:aac37edee302 518 {
roryhand 1:aac37edee302 519 //Declare RootFolder and the directory for the appropriate file.
roryhand 1:aac37edee302 520 //How we index into filename[] from the outside of this class is another
roryhand 1:aac37edee302 521 //issue...
roryhand 1:aac37edee302 522 //printf("FileName: %s\n\r",filename);
roryhand 1:aac37edee302 523 //string RootFolder = "/sd/mydir/SoundDecoder/";
roryhand 1:aac37edee302 524 //string Directory = RootFolder + "01.wav";// + filename[0];
roryhand 1:aac37edee302 525 //printf("%s\n\r",Directory);
roryhand 1:aac37edee302 526 //const char* DirectoryChar = Directory.c_str();
roryhand 1:aac37edee302 527 //Sound.FileInfo.WavFile = fopen(DirectoryChar,"rb");
roryhand 1:aac37edee302 528 Sound.FileInfo.WavFile = fopen("/sd/mydir/645Engine/Startup.wav","rb");
roryhand 1:aac37edee302 529 fseek(Sound.FileInfo.WavFile,20,SEEK_SET);
roryhand 1:aac37edee302 530 fread(&Sound.FileInfo.FileFormat,sizeof(Sound.FileInfo.FileFormat),1,Sound.FileInfo.WavFile);
roryhand 1:aac37edee302 531 printf("wav_format.sample_rate: %d\n\r",Sound.FileInfo.FileFormat.sample_rate);
roryhand 1:aac37edee302 532 fread(&Sound.FileInfo.FileData,sizeof(Sound.FileInfo.FileData),1,Sound.FileInfo.WavFile);
roryhand 1:aac37edee302 533 printf("wav_data.subchunk2_size: %d\n\r",Sound.FileInfo.FileData.subchunk2_size);
roryhand 1:aac37edee302 534 Sound.FileInfo.slice_buf = ( char *)malloc(Sound.FileInfo.FileFormat.block_align);
roryhand 1:aac37edee302 535 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 536 Sound.FileInfo.num_slices = Sound.FileInfo.FileData.subchunk2_size/Sound.FileInfo.FileFormat.block_align;
roryhand 1:aac37edee302 537 printf("Number of Slices: %d\n\r",Sound.FileInfo.num_slices);
roryhand 1:aac37edee302 538 return Sound;
roryhand 1:aac37edee302 539 }
roryhand 1:aac37edee302 540
roryhand 1:aac37edee302 541
roryhand 0:e89d7a0bfa3b 542 classFade FadeDataInitialise(classFade FadeData)
roryhand 0:e89d7a0bfa3b 543 {
roryhand 1:aac37edee302 544 FadeData.DecayFactor = 1.3;
roryhand 0:e89d7a0bfa3b 545 FadeData.FadeIteration = 1;
roryhand 0:e89d7a0bfa3b 546 //FadeData.Denom = 11025*FadeData.DecayFactor;
roryhand 0:e89d7a0bfa3b 547 FadeData.Denom = 11025*FadeData.DecayFactor;
roryhand 0:e89d7a0bfa3b 548 FadeData.Natural_Exp = 2.7183;
roryhand 0:e89d7a0bfa3b 549 FadeData.Length = 11025*FadeData.LengthSecs;
roryhand 0:e89d7a0bfa3b 550 //FadeData.Natural_Exp = 2.7;
roryhand 0:e89d7a0bfa3b 551 return FadeData;
roryhand 0:e89d7a0bfa3b 552 }
roryhand 0:e89d7a0bfa3b 553
roryhand 0:e89d7a0bfa3b 554 //Playing Files Code
roryhand 0:e89d7a0bfa3b 555 /*float FadeIn(void)
roryhand 0:e89d7a0bfa3b 556 {
roryhand 0:e89d7a0bfa3b 557 powervalFadeIn = FadeIterationIn/denom;
roryhand 0:e89d7a0bfa3b 558 FadeCoeffFadeIn
roryhand 1:aac37edee302 559
roryhand 1:aac37edee302 560
roryhand 0:e89d7a0bfa3b 561 }*/
roryhand 0:e89d7a0bfa3b 562 /*float FadeOut(void)
roryhand 0:e89d7a0bfa3b 563 {
roryhand 0:e89d7a0bfa3b 564 powerval = -FadeIteration/denom;
roryhand 0:e89d7a0bfa3b 565 FadeCoeff = pow(natural_exp,powerval);
roryhand 1:aac37edee302 566 FadeIteration = FadeIteration + 1;
roryhand 1:aac37edee302 567 return FadeCoeff;
roryhand 1:aac37edee302 568
roryhand 0:e89d7a0bfa3b 569 }*/
roryhand 0:e89d7a0bfa3b 570
roryhand 0:e89d7a0bfa3b 571
roryhand 0:e89d7a0bfa3b 572 void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo)
roryhand 0:e89d7a0bfa3b 573 {
roryhand 1:aac37edee302 574 while(slice<FileInfo.num_slices) {
roryhand 1:aac37edee302 575 fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,my_wav);
roryhand 1:aac37edee302 576 data_sptr=(short *)FileInfo.slice_buf; // 16 bit samples
roryhand 1:aac37edee302 577 for (channel=0; channel<FileInfo.FileFormat.num_channels; channel++) {
roryhand 1:aac37edee302 578 if(flag1 == 1) {
roryhand 1:aac37edee302 579 Buffer1[place_hold1] = data_sptr[channel];
roryhand 1:aac37edee302 580 place_hold1 = place_hold1 + 1;
roryhand 1:aac37edee302 581 if(place_hold1 >= BufferLen) {
roryhand 1:aac37edee302 582 while(1) {
roryhand 1:aac37edee302 583 if(flag1 == 0) {
roryhand 0:e89d7a0bfa3b 584
roryhand 1:aac37edee302 585 break;
roryhand 0:e89d7a0bfa3b 586 }
roryhand 1:aac37edee302 587
roryhand 0:e89d7a0bfa3b 588 }
roryhand 1:aac37edee302 589 }
roryhand 1:aac37edee302 590
roryhand 1:aac37edee302 591 } else if(flag2 == 1) {
roryhand 1:aac37edee302 592 Buffer2[place_hold2] = data_sptr[channel];
roryhand 1:aac37edee302 593 place_hold2 = place_hold2 + 1;
roryhand 1:aac37edee302 594 if(place_hold2 >= BufferLen) {
roryhand 1:aac37edee302 595
roryhand 1:aac37edee302 596 while(1) {
roryhand 1:aac37edee302 597 if(flag2 == 0) {
roryhand 1:aac37edee302 598
roryhand 1:aac37edee302 599 break;
roryhand 1:aac37edee302 600 }
roryhand 0:e89d7a0bfa3b 601 }
roryhand 1:aac37edee302 602 }
roryhand 0:e89d7a0bfa3b 603 }
roryhand 1:aac37edee302 604
roryhand 1:aac37edee302 605 }
roryhand 1:aac37edee302 606 slice = slice + 1;
roryhand 0:e89d7a0bfa3b 607 }
roryhand 0:e89d7a0bfa3b 608 }
roryhand 0:e89d7a0bfa3b 609
roryhand 0:e89d7a0bfa3b 610
roryhand 0:e89d7a0bfa3b 611
roryhand 0:e89d7a0bfa3b 612
roryhand 0:e89d7a0bfa3b 613
roryhand 0:e89d7a0bfa3b 614
roryhand 0:e89d7a0bfa3b 615 void Play_WaveFileLoop(FILE * my_wav, WAV_FILE_STRUCT FileInfo)//(classSoundFile Sounds)
roryhand 1:aac37edee302 616 //void Play_WaveFileLoop(classSoundFiles NotchSounds, classSoundFiles NotchTransitionSounds, classSoundFiles AdditSounds)
roryhand 0:e89d7a0bfa3b 617 {
roryhand 1:aac37edee302 618 while(1) { //might have to change this to a while(1) loop?
roryhand 1:aac37edee302 619 //New format!! This should be (roughly) the way that this is done, with the new structures and classes
roryhand 1:aac37edee302 620 ////fread(Sound[Notch].FileData.slice_buf,Sound[Notch].FileFormat.block_align,1,Sound[notch].WavFile);
roryhand 1:aac37edee302 621 //data_sptr=(short *)Sound[Notch].FileInfo.slice_buf;
roryhand 1:aac37edee302 622
roryhand 1:aac37edee302 623 if(BellFlag) {
roryhand 1:aac37edee302 624 if(feof(BellWav)) {
roryhand 1:aac37edee302 625 if(feof(HornWav)) {
roryhand 0:e89d7a0bfa3b 626
roryhand 1:aac37edee302 627 } else {
roryhand 1:aac37edee302 628 fseek(BellWav,44,SEEK_SET);
roryhand 0:e89d7a0bfa3b 629 }
roryhand 0:e89d7a0bfa3b 630 }
roryhand 1:aac37edee302 631 fread(WavInfo_Horn.slice_buf,WavInfo_Horn.FileFormat.block_align,1,HornWav);
roryhand 1:aac37edee302 632 fread(WavInfo_Bell.slice_buf,WavInfo_Bell.FileFormat.block_align,1,BellWav);
roryhand 1:aac37edee302 633 fread(WavInfo_Flange.slice_buf,WavInfo_Flange.FileFormat.block_align,1,FlangeWav);
roryhand 1:aac37edee302 634 fread(WavInfo_N2.slice_buf,WavInfo_N2.FileFormat.block_align,1,N2Wav);
roryhand 1:aac37edee302 635 }
roryhand 1:aac37edee302 636 if( slice == (FileInfo.num_slices-1) ) {
roryhand 1:aac37edee302 637 slice = 0;
roryhand 1:aac37edee302 638 fseek(my_wav,44,SEEK_SET);
roryhand 1:aac37edee302 639 }
roryhand 1:aac37edee302 640
roryhand 1:aac37edee302 641 fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,my_wav);
roryhand 1:aac37edee302 642 data_sptr=(short *)FileInfo.slice_buf; // 16 bit samples
roryhand 1:aac37edee302 643 if(DualEngineFlag) {
roryhand 1:aac37edee302 644 fread(WavInfo_N2.slice_buf,WavInfo_N2.FileFormat.block_align,1,N2Wav);
roryhand 1:aac37edee302 645 data_sptr_N2 = (short *)WavInfo_N2.slice_buf;
roryhand 1:aac37edee302 646 *data_sptr = *data_sptr + *data_sptr_N2;
roryhand 1:aac37edee302 647 }
roryhand 1:aac37edee302 648
roryhand 1:aac37edee302 649
roryhand 1:aac37edee302 650 if(FadeFlag) {
roryhand 1:aac37edee302 651 if(feof(N2Wav)) {
roryhand 1:aac37edee302 652 fseek(N2Wav,44,SEEK_SET);
roryhand 0:e89d7a0bfa3b 653 }
roryhand 0:e89d7a0bfa3b 654
roryhand 1:aac37edee302 655 //NotchFadeOut.FadeCoeff = NotchFadeOut.FadeOut();//compute new FadeOut Coeff value
roryhand 1:aac37edee302 656 IdleFadeOut.FadeCoeff = IdleFadeOut.FadeOut();
roryhand 1:aac37edee302 657 data_sptr_IdleN2 = (short *)WavInfo_IdleN2.slice_buf;
roryhand 1:aac37edee302 658 fread(WavInfo_IdleN2.slice_buf,WavInfo_IdleN2.FileFormat.block_align,1,IdleN2Wav);
roryhand 1:aac37edee302 659 if( ((WavInfo_IdleN2.FileData.subchunk2_size) - N2FadeIn.Length - 2*11025) <= (ftell(IdleN2Wav) + 44))
roryhand 1:aac37edee302 660 //if( (WavInfo_IdleN2.FileData.subchunk2_size)/8 <=ftell(IdleN2Wav) )
roryhand 0:e89d7a0bfa3b 661 {
roryhand 0:e89d7a0bfa3b 662
roryhand 1:aac37edee302 663 N2FadeIn.FadeCoeff = N2FadeIn.FadeIn();
roryhand 1:aac37edee302 664 fread(WavInfo_N2.slice_buf,WavInfo_N2.FileFormat.block_align,1,N2Wav);
roryhand 0:e89d7a0bfa3b 665 data_sptr_N2 = (short *)WavInfo_N2.slice_buf;
roryhand 1:aac37edee302 666
roryhand 1:aac37edee302 667 if( (ftell(IdleN2Wav) + 44) >= WavInfo_IdleN2.FileData.subchunk2_size ) {
roryhand 1:aac37edee302 668 *data_sptr = *data_sptr_N2*N2FadeIn.FadeCoeff;
roryhand 1:aac37edee302 669 } else {
roryhand 1:aac37edee302 670 *data_sptr = *data_sptr*IdleFadeOut.FadeCoeff + *data_sptr_IdleN2 + *data_sptr_N2*N2FadeIn.FadeCoeff;// + *data_sptr_N2;
roryhand 1:aac37edee302 671 }
roryhand 1:aac37edee302 672
roryhand 1:aac37edee302 673 } else {
roryhand 1:aac37edee302 674 *data_sptr = *data_sptr*IdleFadeOut.FadeCoeff + *data_sptr_IdleN2;
roryhand 0:e89d7a0bfa3b 675 }
roryhand 1:aac37edee302 676
roryhand 1:aac37edee302 677 }
roryhand 1:aac37edee302 678 if(BellFlag) {
roryhand 1:aac37edee302 679 data_sptr_horn = (short *)WavInfo_Horn.slice_buf;
roryhand 1:aac37edee302 680 data_sptr_bell = (short *)WavInfo_Bell.slice_buf;
roryhand 1:aac37edee302 681 data_sptr_Flange = (short *)WavInfo_Flange.slice_buf;
roryhand 1:aac37edee302 682 data_sptr_N2 = (short *)WavInfo_N2.slice_buf;
roryhand 1:aac37edee302 683 *data_sptr = *data_sptr + *data_sptr_horn + *data_sptr_bell + *data_sptr_Flange + *data_sptr_N2;//use dereference operator
roryhand 1:aac37edee302 684 //*data_sptr = *data_sptr + *data_sptr_horn;
roryhand 1:aac37edee302 685 }
roryhand 1:aac37edee302 686 for (channel=0; channel<FileInfo.FileFormat.num_channels; channel++) {
roryhand 1:aac37edee302 687 switch (FileInfo.FileFormat.sig_bps) {
roryhand 0:e89d7a0bfa3b 688 case 16:
roryhand 1:aac37edee302 689 if(flag1 == 1) {
roryhand 1:aac37edee302 690 Buffer1[place_hold1] = data_sptr[channel];
roryhand 1:aac37edee302 691 place_hold1 = place_hold1 + 1;
roryhand 1:aac37edee302 692 if(place_hold1 >= BufferLen) {
roryhand 1:aac37edee302 693 while(1) {
roryhand 1:aac37edee302 694 if(flag1 == 0) {
roryhand 1:aac37edee302 695 break;
roryhand 1:aac37edee302 696 }//if(flag1 == 0)
roryhand 1:aac37edee302 697
roryhand 1:aac37edee302 698
roryhand 1:aac37edee302 699 }//while(1)
roryhand 1:aac37edee302 700 }//if(place_hold1 > = BufferLen)
roryhand 0:e89d7a0bfa3b 701
roryhand 1:aac37edee302 702 } else if(flag2 == 1) {
roryhand 1:aac37edee302 703 Buffer2[place_hold2] = data_sptr[channel];
roryhand 1:aac37edee302 704 place_hold2 = place_hold2 + 1;
roryhand 1:aac37edee302 705 if(place_hold2 >= BufferLen) {
roryhand 1:aac37edee302 706 while(1) {
roryhand 1:aac37edee302 707
roryhand 1:aac37edee302 708 if(flag2 == 0) {
roryhand 1:aac37edee302 709 break;
roryhand 1:aac37edee302 710 }
roryhand 1:aac37edee302 711 }
roryhand 0:e89d7a0bfa3b 712 }
roryhand 1:aac37edee302 713
roryhand 1:aac37edee302 714 }
roryhand 0:e89d7a0bfa3b 715 }
roryhand 0:e89d7a0bfa3b 716 }
roryhand 0:e89d7a0bfa3b 717 slice = slice + 1;
roryhand 0:e89d7a0bfa3b 718 }
roryhand 0:e89d7a0bfa3b 719 }
roryhand 0:e89d7a0bfa3b 720
roryhand 0:e89d7a0bfa3b 721
roryhand 0:e89d7a0bfa3b 722
roryhand 0:e89d7a0bfa3b 723
roryhand 0:e89d7a0bfa3b 724
roryhand 0:e89d7a0bfa3b 725
roryhand 0:e89d7a0bfa3b 726