old demo that i want to try in mbed studio

Dependencies:   mbed SDFileSystem_Copy_of_mbed_version I2S

Committer:
roryhand
Date:
Sat Feb 16 17:19:43 2019 +0000
Revision:
0:e89d7a0bfa3b
Child:
1:aac37edee302
Doesn't work at present, however it does contain some rudimentary code for passing in the file names into a string array (too difficult compared to matlab)

Who changed what in which revision?

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