old demo that i want to try in mbed studio

Dependencies:   mbed SDFileSystem_Copy_of_mbed_version I2S

Committer:
roryhand
Date:
Sun Sep 08 19:23:09 2019 +0000
Revision:
44:a9e84d333a6a
Parent:
43:890d76ffe627
Child:
45:0e8e1f2ec5d2
WIP - Adding in appropriate info to use new method of sharing objects, Tristan and Rory idea

Who changed what in which revision?

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