old demo that i want to try in mbed studio
Dependencies: mbed SDFileSystem_Copy_of_mbed_version I2S
NotchingDemo.cpp@20:9cc7d825c07b, 2019-04-01 (annotated)
- Committer:
- roryhand
- Date:
- Mon Apr 01 20:30:35 2019 +0000
- Revision:
- 20:9cc7d825c07b
- Parent:
- 17:832eb9a75c05
- Child:
- 21:1aacd67d19c1
- Child:
- 29:d2139f3f7ba1
Can even play the HeyWav File that gave so much trouble before.
Who changed what in which revision?
User | Revision | Line number | New 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 | 3:6169aeeaeeb4 | 28 | Ticker TestTick; |
roryhand | 0:e89d7a0bfa3b | 29 | Timer t; |
roryhand | 0:e89d7a0bfa3b | 30 | Timer t2; |
roryhand | 3:6169aeeaeeb4 | 31 | Timer NotchTimer; |
roryhand | 0:e89d7a0bfa3b | 32 | |
roryhand | 0:e89d7a0bfa3b | 33 | Serial pc(USBTX, USBRX); // tx, rx //FOR DEBUGGING PROGRAM USING GNU SCREEN |
roryhand | 0:e89d7a0bfa3b | 34 | DigitalOut cs(p8); |
roryhand | 0:e89d7a0bfa3b | 35 | I2S i2s(I2S_TRANSMIT, p5, p6, p7); |
roryhand | 0:e89d7a0bfa3b | 36 | SDFileSystem sd(p11, p12, p13, p8, "sd"); // the new pinout that i am using |
roryhand | 0:e89d7a0bfa3b | 37 | |
roryhand | 0:e89d7a0bfa3b | 38 | |
roryhand | 0:e89d7a0bfa3b | 39 | /*struct A { |
roryhand | 0:e89d7a0bfa3b | 40 | int data; |
roryhand | 0:e89d7a0bfa3b | 41 | B b; |
roryhand | 0:e89d7a0bfa3b | 42 | };*/ |
roryhand | 0:e89d7a0bfa3b | 43 | |
roryhand | 0:e89d7a0bfa3b | 44 | |
roryhand | 0:e89d7a0bfa3b | 45 | |
roryhand | 0:e89d7a0bfa3b | 46 | |
roryhand | 0:e89d7a0bfa3b | 47 | class classFade |
roryhand | 0:e89d7a0bfa3b | 48 | { |
roryhand | 1:aac37edee302 | 49 | public: |
roryhand | 1:aac37edee302 | 50 | |
roryhand | 0:e89d7a0bfa3b | 51 | float powerval; |
roryhand | 0:e89d7a0bfa3b | 52 | float FadeIteration; |
roryhand | 0:e89d7a0bfa3b | 53 | float DecayFactor; |
roryhand | 0:e89d7a0bfa3b | 54 | float Denom; |
roryhand | 0:e89d7a0bfa3b | 55 | float FadeCoeff; |
roryhand | 0:e89d7a0bfa3b | 56 | float Natural_Exp; |
roryhand | 0:e89d7a0bfa3b | 57 | int LengthSecs; |
roryhand | 0:e89d7a0bfa3b | 58 | int Length; |
roryhand | 1:aac37edee302 | 59 | |
roryhand | 0:e89d7a0bfa3b | 60 | //member Functions |
roryhand | 0:e89d7a0bfa3b | 61 | float FadeOut(void) |
roryhand | 0:e89d7a0bfa3b | 62 | { |
roryhand | 0:e89d7a0bfa3b | 63 | powerval = -FadeIteration/Denom; |
roryhand | 1:aac37edee302 | 64 | if (FadeIteration >=Length) { |
roryhand | 1:aac37edee302 | 65 | FadeCoeff = 0; |
roryhand | 1:aac37edee302 | 66 | |
roryhand | 1:aac37edee302 | 67 | } else { |
roryhand | 0:e89d7a0bfa3b | 68 | FadeCoeff = (Length - FadeIteration)/Length; |
roryhand | 0:e89d7a0bfa3b | 69 | } |
roryhand | 1:aac37edee302 | 70 | FadeIteration = FadeIteration + 1; |
roryhand | 1:aac37edee302 | 71 | return FadeCoeff; |
roryhand | 1:aac37edee302 | 72 | |
roryhand | 1:aac37edee302 | 73 | } |
roryhand | 1:aac37edee302 | 74 | float FadeIn(void) |
roryhand | 0:e89d7a0bfa3b | 75 | { |
roryhand | 0:e89d7a0bfa3b | 76 | powerval = FadeIteration/Denom; |
roryhand | 1:aac37edee302 | 77 | if (FadeIteration >=Length) { |
roryhand | 1:aac37edee302 | 78 | FadeCoeff = 1; |
roryhand | 1:aac37edee302 | 79 | |
roryhand | 1:aac37edee302 | 80 | } else { |
roryhand | 0:e89d7a0bfa3b | 81 | FadeCoeff = FadeIteration/Length; |
roryhand | 0:e89d7a0bfa3b | 82 | } |
roryhand | 0:e89d7a0bfa3b | 83 | |
roryhand | 1:aac37edee302 | 84 | FadeIteration = FadeIteration + 1; |
roryhand | 1:aac37edee302 | 85 | return FadeCoeff; |
roryhand | 1:aac37edee302 | 86 | |
roryhand | 1:aac37edee302 | 87 | } |
roryhand | 0:e89d7a0bfa3b | 88 | }; |
roryhand | 0:e89d7a0bfa3b | 89 | |
roryhand | 0:e89d7a0bfa3b | 90 | classFade IdleFadeOut; |
roryhand | 0:e89d7a0bfa3b | 91 | classFade N2FadeIn; |
roryhand | 0:e89d7a0bfa3b | 92 | |
roryhand | 2:957d3b2afff4 | 93 | classFade NotchFadeOut; |
roryhand | 2:957d3b2afff4 | 94 | classFade NotchFadeIn; |
roryhand | 2:957d3b2afff4 | 95 | |
roryhand | 0:e89d7a0bfa3b | 96 | |
roryhand | 0:e89d7a0bfa3b | 97 | |
roryhand | 0:e89d7a0bfa3b | 98 | |
roryhand | 0:e89d7a0bfa3b | 99 | |
roryhand | 1:aac37edee302 | 100 | typedef struct uFMT_STRUCT { |
roryhand | 1:aac37edee302 | 101 | short comp_code; |
roryhand | 1:aac37edee302 | 102 | short num_channels; |
roryhand | 1:aac37edee302 | 103 | unsigned sample_rate; |
roryhand | 1:aac37edee302 | 104 | unsigned avg_Bps; |
roryhand | 1:aac37edee302 | 105 | short block_align; |
roryhand | 1:aac37edee302 | 106 | short sig_bps; |
roryhand | 0:e89d7a0bfa3b | 107 | } FMT_STRUCT; |
roryhand | 0:e89d7a0bfa3b | 108 | |
roryhand | 1:aac37edee302 | 109 | typedef struct uNotch_STRUCT { |
roryhand | 1:aac37edee302 | 110 | short Notch; |
roryhand | 1:aac37edee302 | 111 | short NotchTransUp; |
roryhand | 1:aac37edee302 | 112 | short NotchTransDown; |
roryhand | 1:aac37edee302 | 113 | short NotchDirection; |
roryhand | 1:aac37edee302 | 114 | } Notch_STRUCT; |
roryhand | 1:aac37edee302 | 115 | |
roryhand | 0:e89d7a0bfa3b | 116 | typedef struct uDATA_STRUCT { |
roryhand | 1:aac37edee302 | 117 | unsigned subchunk2_ID; |
roryhand | 1:aac37edee302 | 118 | unsigned subchunk2_size; |
roryhand | 1:aac37edee302 | 119 | char * data_buf; |
roryhand | 1:aac37edee302 | 120 | } DATA_STRUCT; |
roryhand | 0:e89d7a0bfa3b | 121 | |
roryhand | 1:aac37edee302 | 122 | typedef struct uWAV_FILE_STRUCT { |
roryhand | 1:aac37edee302 | 123 | FILE *WavFile; |
roryhand | 1:aac37edee302 | 124 | int id_number; |
roryhand | 1:aac37edee302 | 125 | char *slice_buf; |
roryhand | 1:aac37edee302 | 126 | int num_slices; |
roryhand | 1:aac37edee302 | 127 | FMT_STRUCT FileFormat; |
roryhand | 1:aac37edee302 | 128 | DATA_STRUCT FileData; |
roryhand | 0:e89d7a0bfa3b | 129 | } WAV_FILE_STRUCT; |
roryhand | 0:e89d7a0bfa3b | 130 | |
roryhand | 0:e89d7a0bfa3b | 131 | /*typedef struct uWAV_FILE_STRUCT{ |
roryhand | 1:aac37edee302 | 132 | FILE* WavFile; |
roryhand | 1:aac37edee302 | 133 | |
roryhand | 1:aac37edee302 | 134 | |
roryhand | 0:e89d7a0bfa3b | 135 | }WAV_FILE_STRUCT;*/ |
roryhand | 0:e89d7a0bfa3b | 136 | class classSoundFile |
roryhand | 0:e89d7a0bfa3b | 137 | { |
roryhand | 1:aac37edee302 | 138 | public: |
roryhand | 1:aac37edee302 | 139 | |
roryhand | 1:aac37edee302 | 140 | //add a class constructor |
roryhand | 1:aac37edee302 | 141 | WAV_FILE_STRUCT FileInfo; |
roryhand | 2:957d3b2afff4 | 142 | short * data_sptr; |
roryhand | 1:aac37edee302 | 143 | //classSoundFile(string filename);//this is the constructor |
roryhand | 1:aac37edee302 | 144 | //string filename; |
roryhand | 0:e89d7a0bfa3b | 145 | }; |
roryhand | 0:e89d7a0bfa3b | 146 | |
roryhand | 1:aac37edee302 | 147 | //class constructor; |
roryhand | 1:aac37edee302 | 148 | /*classSoundFile::classSoundFile(string filename) |
roryhand | 1:aac37edee302 | 149 | { |
roryhand | 1:aac37edee302 | 150 | //Declare RootFolder and the directory for the appropriate file. |
roryhand | 1:aac37edee302 | 151 | //How we index into filename[] from the outside of this class is another |
roryhand | 1:aac37edee302 | 152 | //issue... |
roryhand | 1:aac37edee302 | 153 | FileInfo.WavFile = fopen("/sd/mydir/645Engine/Startup.wav","rb"); |
roryhand | 1:aac37edee302 | 154 | fseek(FileInfo.WavFile,20,SEEK_SET); |
roryhand | 1:aac37edee302 | 155 | fread(&FileInfo.FileFormat,sizeof(FileInfo.FileFormat),1,FileInfo.WavFile); |
roryhand | 1:aac37edee302 | 156 | printf("wav_format.sample_rate: %d\n\r",FileInfo.FileFormat.sample_rate); |
roryhand | 1:aac37edee302 | 157 | fread(&FileInfo.FileData,sizeof(FileInfo.FileData),1,FileInfo.WavFile); |
roryhand | 1:aac37edee302 | 158 | printf("wav_data.subchunk2_size: %d\n\r",FileInfo.FileData.subchunk2_size); |
roryhand | 1:aac37edee302 | 159 | FileInfo.slice_buf = ( char *)malloc(FileInfo.FileFormat.block_align); |
roryhand | 1:aac37edee302 | 160 | fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,FileInfo.WavFile); //This isnt actually required, its just a test |
roryhand | 1:aac37edee302 | 161 | FileInfo.num_slices = FileInfo.FileData.subchunk2_size/FileInfo.FileFormat.block_align; |
roryhand | 1:aac37edee302 | 162 | }*/ |
roryhand | 1:aac37edee302 | 163 | |
roryhand | 0:e89d7a0bfa3b | 164 | |
roryhand | 0:e89d7a0bfa3b | 165 | int i = 0; |
roryhand | 0:e89d7a0bfa3b | 166 | int h = 0; |
roryhand | 0:e89d7a0bfa3b | 167 | short bufflen = 1; |
roryhand | 0:e89d7a0bfa3b | 168 | int buffer[1]; |
roryhand | 1:aac37edee302 | 169 | int AudioFormat, NumChannels, SampleRate, BitsPerSample ; |
roryhand | 0:e89d7a0bfa3b | 170 | char *slice_buf; |
roryhand | 0:e89d7a0bfa3b | 171 | short *data_sptr; |
roryhand | 0:e89d7a0bfa3b | 172 | short *data_sptr_horn; |
roryhand | 0:e89d7a0bfa3b | 173 | short *data_sptr_IdleN2; |
roryhand | 0:e89d7a0bfa3b | 174 | short * data_sptr_bell; |
roryhand | 0:e89d7a0bfa3b | 175 | short * data_sptr_N2; |
roryhand | 0:e89d7a0bfa3b | 176 | short * data_sptr_Flange; |
roryhand | 0:e89d7a0bfa3b | 177 | unsigned char *data_bptr; |
roryhand | 0:e89d7a0bfa3b | 178 | int *data_wptr; |
roryhand | 0:e89d7a0bfa3b | 179 | unsigned channel; |
roryhand | 0:e89d7a0bfa3b | 180 | long slice, num_slices; |
roryhand | 0:e89d7a0bfa3b | 181 | int verbosity = 0; |
roryhand | 0:e89d7a0bfa3b | 182 | int verbosity2 = 0; |
roryhand | 0:e89d7a0bfa3b | 183 | int verbosity3 = 0; |
roryhand | 0:e89d7a0bfa3b | 184 | int verbosity4 = 0; |
roryhand | 0:e89d7a0bfa3b | 185 | int verbosity5 = 0; |
roryhand | 0:e89d7a0bfa3b | 186 | int interrupt_condition = 1; |
roryhand | 0:e89d7a0bfa3b | 187 | int sampling_freq = 11025; |
roryhand | 0:e89d7a0bfa3b | 188 | const int BufferLen = 2000; |
roryhand | 0:e89d7a0bfa3b | 189 | short Buffer1[BufferLen]; |
roryhand | 0:e89d7a0bfa3b | 190 | short Buffer2[BufferLen]; |
roryhand | 0:e89d7a0bfa3b | 191 | short place_hold1 = 0; |
roryhand | 0:e89d7a0bfa3b | 192 | short place_hold2 = 0; |
roryhand | 0:e89d7a0bfa3b | 193 | |
roryhand | 3:6169aeeaeeb4 | 194 | |
roryhand | 3:6169aeeaeeb4 | 195 | string FOLDER; |
roryhand | 3:6169aeeaeeb4 | 196 | string RootFolder = "/sd/mydir/SoundDecoder/"; |
roryhand | 3:6169aeeaeeb4 | 197 | string filename[25]; |
roryhand | 3:6169aeeaeeb4 | 198 | classSoundFile Sound[22]; |
roryhand | 3:6169aeeaeeb4 | 199 | |
roryhand | 0:e89d7a0bfa3b | 200 | volatile int flag1 = 1; |
roryhand | 0:e89d7a0bfa3b | 201 | volatile int flag2 = 0; |
roryhand | 0:e89d7a0bfa3b | 202 | volatile int flag3 = 1; |
roryhand | 0:e89d7a0bfa3b | 203 | volatile int flag4 = 0; |
roryhand | 0:e89d7a0bfa3b | 204 | int FLAGBUFF1 = 0; |
roryhand | 0:e89d7a0bfa3b | 205 | int FLAGBUFF2 = 0; |
roryhand | 0:e89d7a0bfa3b | 206 | int BellFlag = 0; |
roryhand | 0:e89d7a0bfa3b | 207 | int BellFlag2 = 0; |
roryhand | 0:e89d7a0bfa3b | 208 | int FadeFlag = 0; |
roryhand | 0:e89d7a0bfa3b | 209 | int DualEngineFlag = 0; |
roryhand | 0:e89d7a0bfa3b | 210 | |
roryhand | 0:e89d7a0bfa3b | 211 | |
roryhand | 0:e89d7a0bfa3b | 212 | short value[1]; |
roryhand | 0:e89d7a0bfa3b | 213 | FILE *HornWav; |
roryhand | 0:e89d7a0bfa3b | 214 | FILE *edsheeran_wav; |
roryhand | 0:e89d7a0bfa3b | 215 | FILE *Startup_wav; |
roryhand | 0:e89d7a0bfa3b | 216 | FILE *IdleN2Wav; |
roryhand | 0:e89d7a0bfa3b | 217 | FILE *N2Wav; |
roryhand | 0:e89d7a0bfa3b | 218 | FILE *BellWav; |
roryhand | 0:e89d7a0bfa3b | 219 | FILE *FlangeWav; |
roryhand | 16:5e3420d0509b | 220 | FILE *HeyWav; |
roryhand | 0:e89d7a0bfa3b | 221 | //long long slice_value; |
roryhand | 0:e89d7a0bfa3b | 222 | int slice_value[1]; |
roryhand | 0:e89d7a0bfa3b | 223 | |
roryhand | 0:e89d7a0bfa3b | 224 | |
roryhand | 0:e89d7a0bfa3b | 225 | WAV_FILE_STRUCT WavInfo_Horn; |
roryhand | 0:e89d7a0bfa3b | 226 | WAV_FILE_STRUCT WavInfo_IdleN2; |
roryhand | 0:e89d7a0bfa3b | 227 | WAV_FILE_STRUCT WavInfo_N2; |
roryhand | 0:e89d7a0bfa3b | 228 | WAV_FILE_STRUCT WavInfo_Bell; |
roryhand | 0:e89d7a0bfa3b | 229 | WAV_FILE_STRUCT WavInfo_Flange; |
roryhand | 20:9cc7d825c07b | 230 | WAV_FILE_STRUCT WavInfo_Hey; |
roryhand | 16:5e3420d0509b | 231 | WAV_FILE_STRUCT WavInfo_Frustration; |
roryhand | 0:e89d7a0bfa3b | 232 | Ticker flipper; |
roryhand | 0:e89d7a0bfa3b | 233 | char * slice_buf_bell; |
roryhand | 0:e89d7a0bfa3b | 234 | char * slice_buf_ed; |
roryhand | 0:e89d7a0bfa3b | 235 | char * slice_buf_startup; |
roryhand | 0:e89d7a0bfa3b | 236 | char * slice_buf_N2; |
roryhand | 1:aac37edee302 | 237 | Notch_STRUCT NotchingSet; |
roryhand | 0:e89d7a0bfa3b | 238 | //test |
roryhand | 0:e89d7a0bfa3b | 239 | //short *data_sptr_bell = 0; |
roryhand | 0:e89d7a0bfa3b | 240 | short *data_sptr_ed = 0; |
roryhand | 0:e89d7a0bfa3b | 241 | short *data_sptr_startup = 0; |
roryhand | 1:aac37edee302 | 242 | void flip() |
roryhand | 1:aac37edee302 | 243 | { |
roryhand | 0:e89d7a0bfa3b | 244 | led2 = !led2; |
roryhand | 0:e89d7a0bfa3b | 245 | } |
roryhand | 0:e89d7a0bfa3b | 246 | |
roryhand | 0:e89d7a0bfa3b | 247 | |
roryhand | 0:e89d7a0bfa3b | 248 | void isr() |
roryhand | 0:e89d7a0bfa3b | 249 | { |
roryhand | 1:aac37edee302 | 250 | if(flag1 == 0) { |
roryhand | 0:e89d7a0bfa3b | 251 | value[0] = Buffer1[place_hold1]>>4; |
roryhand | 0:e89d7a0bfa3b | 252 | i2s.write(value,1);//Send next PWM value to amp |
roryhand | 0:e89d7a0bfa3b | 253 | place_hold1 = place_hold1 + 1; |
roryhand | 1:aac37edee302 | 254 | if( (place_hold1 >= BufferLen)) { |
roryhand | 0:e89d7a0bfa3b | 255 | led2 = !led2; |
roryhand | 0:e89d7a0bfa3b | 256 | place_hold1 = 0; |
roryhand | 0:e89d7a0bfa3b | 257 | place_hold2 = 0; |
roryhand | 0:e89d7a0bfa3b | 258 | flag1 = 1; |
roryhand | 0:e89d7a0bfa3b | 259 | flag2 = 0; |
roryhand | 1:aac37edee302 | 260 | } |
roryhand | 1:aac37edee302 | 261 | } else if(flag2 == 0) { |
roryhand | 0:e89d7a0bfa3b | 262 | value[0] = Buffer2[place_hold2]>>4; |
roryhand | 0:e89d7a0bfa3b | 263 | i2s.write(value,1);//Send next PWM value to amp |
roryhand | 0:e89d7a0bfa3b | 264 | place_hold2 = place_hold2 + 1; |
roryhand | 1:aac37edee302 | 265 | if( (place_hold2 >= 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 = 0; |
roryhand | 1:aac37edee302 | 270 | flag2 = 1; |
roryhand | 0:e89d7a0bfa3b | 271 | FLAGBUFF2 = 0; |
roryhand | 1:aac37edee302 | 272 | } |
roryhand | 0:e89d7a0bfa3b | 273 | } |
roryhand | 0:e89d7a0bfa3b | 274 | } |
roryhand | 1:aac37edee302 | 275 | |
roryhand | 0:e89d7a0bfa3b | 276 | void horn_sound() |
roryhand | 0:e89d7a0bfa3b | 277 | { |
roryhand | 0:e89d7a0bfa3b | 278 | BellFlag = 1; |
roryhand | 0:e89d7a0bfa3b | 279 | fseek(HornWav,44,SEEK_SET); |
roryhand | 0:e89d7a0bfa3b | 280 | fseek(BellWav,44,SEEK_SET); |
roryhand | 0:e89d7a0bfa3b | 281 | fseek(FlangeWav,44,SEEK_SET); |
roryhand | 0:e89d7a0bfa3b | 282 | fseek(N2Wav,44,SEEK_SET); |
roryhand | 0:e89d7a0bfa3b | 283 | } |
roryhand | 0:e89d7a0bfa3b | 284 | |
roryhand | 0:e89d7a0bfa3b | 285 | |
roryhand | 0:e89d7a0bfa3b | 286 | void N2SoundIsr() |
roryhand | 0:e89d7a0bfa3b | 287 | { |
roryhand | 0:e89d7a0bfa3b | 288 | DualEngineFlag = 1; |
roryhand | 0:e89d7a0bfa3b | 289 | fseek(N2Wav,44,SEEK_SET); |
roryhand | 0:e89d7a0bfa3b | 290 | fseek(HornWav,44,SEEK_SET); |
roryhand | 0:e89d7a0bfa3b | 291 | //TickFadeOut.detach(&N2SoundIsr);//,5.0); |
roryhand | 0:e89d7a0bfa3b | 292 | } |
roryhand | 0:e89d7a0bfa3b | 293 | |
roryhand | 0:e89d7a0bfa3b | 294 | |
roryhand | 0:e89d7a0bfa3b | 295 | void FadeOutIsr() |
roryhand | 0:e89d7a0bfa3b | 296 | { |
roryhand | 1:aac37edee302 | 297 | FadeFlag = 1; |
roryhand | 1:aac37edee302 | 298 | fseek(IdleN2Wav,44,SEEK_SET); |
roryhand | 1:aac37edee302 | 299 | fseek(N2Wav,44,SEEK_SET); |
roryhand | 1:aac37edee302 | 300 | fseek(HornWav,44,SEEK_SET); |
roryhand | 0:e89d7a0bfa3b | 301 | fseek(FlangeWav,44,SEEK_SET); |
roryhand | 1:aac37edee302 | 302 | |
roryhand | 0:e89d7a0bfa3b | 303 | } |
roryhand | 0:e89d7a0bfa3b | 304 | |
roryhand | 3:6169aeeaeeb4 | 305 | classFade FadeDataInitialise(classFade FadeData); |
roryhand | 3:6169aeeaeeb4 | 306 | |
roryhand | 3:6169aeeaeeb4 | 307 | |
roryhand | 3:6169aeeaeeb4 | 308 | |
roryhand | 3:6169aeeaeeb4 | 309 | |
roryhand | 3:6169aeeaeeb4 | 310 | |
roryhand | 3:6169aeeaeeb4 | 311 | //function prototypes |
roryhand | 3:6169aeeaeeb4 | 312 | WAV_FILE_STRUCT ReadFileInfo(WAV_FILE_STRUCT FileInfo, FILE * wav_file); |
roryhand | 3:6169aeeaeeb4 | 313 | classSoundFile LoadFileStream(classSoundFile FileInfo, string filename); |
roryhand | 3:6169aeeaeeb4 | 314 | |
roryhand | 3:6169aeeaeeb4 | 315 | float FadeOut(void); |
roryhand | 3:6169aeeaeeb4 | 316 | void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo); |
roryhand | 3:6169aeeaeeb4 | 317 | //void Play_WaveFileLoop(FILE * my_wav, WAV_FILE_STRUCT FileInfo); |
roryhand | 3:6169aeeaeeb4 | 318 | //*********************INTERRUPT ROUTINE FOR NOTCHING*************************** |
roryhand | 0:e89d7a0bfa3b | 319 | |
roryhand | 1:aac37edee302 | 320 | void NotchUpIsr() |
roryhand | 0:e89d7a0bfa3b | 321 | { |
roryhand | 1:aac37edee302 | 322 | if(1 <= NotchingSet.Notch < 8) { |
roryhand | 1:aac37edee302 | 323 | |
roryhand | 1:aac37edee302 | 324 | NotchingSet.Notch = NotchingSet.Notch + 1; |
roryhand | 1:aac37edee302 | 325 | NotchingSet.NotchTransUp = NotchingSet.Notch + 7; |
roryhand | 1:aac37edee302 | 326 | NotchingSet.NotchDirection = 1; |
roryhand | 3:6169aeeaeeb4 | 327 | FadeDataInitialise(NotchFadeIn); |
roryhand | 3:6169aeeaeeb4 | 328 | FadeDataInitialise(NotchFadeOut); |
roryhand | 1:aac37edee302 | 329 | } |
roryhand | 0:e89d7a0bfa3b | 330 | } |
roryhand | 0:e89d7a0bfa3b | 331 | |
roryhand | 0:e89d7a0bfa3b | 332 | void NotchDownIsr() |
roryhand | 0:e89d7a0bfa3b | 333 | { |
roryhand | 1:aac37edee302 | 334 | if(1 < NotchingSet.Notch <= 8) { |
roryhand | 1:aac37edee302 | 335 | NotchingSet.Notch = NotchingSet.Notch - 1; |
roryhand | 1:aac37edee302 | 336 | NotchingSet.NotchTransDown = NotchingSet.Notch + 15;; |
roryhand | 1:aac37edee302 | 337 | NotchingSet.NotchDirection = 0; |
roryhand | 3:6169aeeaeeb4 | 338 | FadeDataInitialise(NotchFadeIn); |
roryhand | 3:6169aeeaeeb4 | 339 | FadeDataInitialise(NotchFadeOut); |
roryhand | 1:aac37edee302 | 340 | } |
roryhand | 1:aac37edee302 | 341 | } |
roryhand | 0:e89d7a0bfa3b | 342 | |
roryhand | 0:e89d7a0bfa3b | 343 | |
roryhand | 3:6169aeeaeeb4 | 344 | /**********************END OF INTERRUPT ROUTINE FOR NOTCHING*******************/ |
roryhand | 3:6169aeeaeeb4 | 345 | |
roryhand | 3:6169aeeaeeb4 | 346 | |
roryhand | 1:aac37edee302 | 347 | |
roryhand | 0:e89d7a0bfa3b | 348 | |
roryhand | 3:6169aeeaeeb4 | 349 | |
roryhand | 3:6169aeeaeeb4 | 350 | |
roryhand | 9:dd9cae06b202 | 351 | void Play_WaveFileLoop(classSoundFile Sounds[], Notch_STRUCT NotchingSet); |
roryhand | 1:aac37edee302 | 352 | int main() |
roryhand | 1:aac37edee302 | 353 | { |
roryhand | 0:e89d7a0bfa3b | 354 | //LocalFileSystem local("local"); |
roryhand | 0:e89d7a0bfa3b | 355 | NotchUp.mode(PullUp); |
roryhand | 0:e89d7a0bfa3b | 356 | |
roryhand | 0:e89d7a0bfa3b | 357 | |
roryhand | 0:e89d7a0bfa3b | 358 | //classSoundFile Sounds[4]; |
roryhand | 1:aac37edee302 | 359 | /* for(int iii = 0; iii < 3; iii ++) |
roryhand | 1:aac37edee302 | 360 | { |
roryhand | 1:aac37edee302 | 361 | Sounds[iii].setX(iii); |
roryhand | 1:aac37edee302 | 362 | }*/ |
roryhand | 0:e89d7a0bfa3b | 363 | WAV_FILE_STRUCT WavInfo_Startup; |
roryhand | 0:e89d7a0bfa3b | 364 | WAV_FILE_STRUCT WavInfo_Idle; |
roryhand | 0:e89d7a0bfa3b | 365 | |
roryhand | 0:e89d7a0bfa3b | 366 | pc.printf("Beginning of program\n"); |
roryhand | 0:e89d7a0bfa3b | 367 | FILE *StartupWav; |
roryhand | 0:e89d7a0bfa3b | 368 | FILE *IdleWav; |
roryhand | 1:aac37edee302 | 369 | |
roryhand | 3:6169aeeaeeb4 | 370 | |
roryhand | 0:e89d7a0bfa3b | 371 | DIR *dir; |
roryhand | 0:e89d7a0bfa3b | 372 | dirent *ent; |
roryhand | 0:e89d7a0bfa3b | 373 | int iterator = 0; |
roryhand | 13:8e93396a27c5 | 374 | |
roryhand | 13:8e93396a27c5 | 375 | |
roryhand | 13:8e93396a27c5 | 376 | |
roryhand | 13:8e93396a27c5 | 377 | |
roryhand | 3:6169aeeaeeb4 | 378 | printf("Directory is about to be opened? Still dont really Get this concept\n\r"); |
roryhand | 3:6169aeeaeeb4 | 379 | //if i try to open folder SoundDecoder2, it gets stuck after file 13... WHY |
roryhand | 3:6169aeeaeeb4 | 380 | if ((dir = opendir ("/sd/mydir/SoundDecoder_second")) != NULL) { |
roryhand | 1:aac37edee302 | 381 | |
roryhand | 0:e89d7a0bfa3b | 382 | // print all the files and directories within directory |
roryhand | 1:aac37edee302 | 383 | while ((ent = readdir (dir)) != NULL) { |
roryhand | 3:6169aeeaeeb4 | 384 | //printf("%s\r\n",string(ent->d_name)); |
roryhand | 3:6169aeeaeeb4 | 385 | filename[iterator] = (ent->d_name); |
roryhand | 3:6169aeeaeeb4 | 386 | printf("Filename: %s\n\r",filename[iterator]); |
roryhand | 0:e89d7a0bfa3b | 387 | //printf("%s\r\n",filename[iterator]); |
roryhand | 0:e89d7a0bfa3b | 388 | iterator = iterator + 1; |
roryhand | 0:e89d7a0bfa3b | 389 | //printf("%s\r\n", ent->d_name); |
roryhand | 1:aac37edee302 | 390 | //filenames.push_back(string(dirp->d_name)); |
roryhand | 0:e89d7a0bfa3b | 391 | } |
roryhand | 0:e89d7a0bfa3b | 392 | closedir (dir); |
roryhand | 1:aac37edee302 | 393 | } |
roryhand | 4:55fbbb049bae | 394 | /* |
roryhand | 3:6169aeeaeeb4 | 395 | printf("Now printing all the files"); |
roryhand | 3:6169aeeaeeb4 | 396 | for(iterator = 0; iterator < 21; iterator ++) { |
roryhand | 1:aac37edee302 | 397 | printf("All the Files: %s\r\n",filename[iterator]); |
roryhand | 1:aac37edee302 | 398 | //printf("All the Files: %s\r\n",ent[iterator]); |
roryhand | 1:aac37edee302 | 399 | } |
roryhand | 4:55fbbb049bae | 400 | */ |
roryhand | 13:8e93396a27c5 | 401 | |
roryhand | 1:aac37edee302 | 402 | //strcat(RootFolder,qdfilename[0]); |
roryhand | 3:6169aeeaeeb4 | 403 | //string folder = RootFolder + filename[9]; |
roryhand | 3:6169aeeaeeb4 | 404 | //printf("Folder: %s\n\r",folder); |
roryhand | 1:aac37edee302 | 405 | |
roryhand | 1:aac37edee302 | 406 | |
roryhand | 0:e89d7a0bfa3b | 407 | //printf("Files and Folders contained here: %d\n\r",readdir(dp)); |
roryhand | 1:aac37edee302 | 408 | |
roryhand | 1:aac37edee302 | 409 | |
roryhand | 9:dd9cae06b202 | 410 | StartupWav = fopen("/sd/mydir/Startup.wav","rb"); |
roryhand | 3:6169aeeaeeb4 | 411 | //const char* folder2 = folder.c_str(); |
roryhand | 1:aac37edee302 | 412 | |
roryhand | 1:aac37edee302 | 413 | |
roryhand | 1:aac37edee302 | 414 | string FileName; |
roryhand | 1:aac37edee302 | 415 | //vector <classSoundFile> Sound (27); |
roryhand | 3:6169aeeaeeb4 | 416 | const char* FOLDER; |
roryhand | 13:8e93396a27c5 | 417 | |
roryhand | 13:8e93396a27c5 | 418 | /* |
roryhand | 13:8e93396a27c5 | 419 | WAV_FILE_STRUCT MyNewWav; |
roryhand | 13:8e93396a27c5 | 420 | |
roryhand | 13:8e93396a27c5 | 421 | string folder; |
roryhand | 9:dd9cae06b202 | 422 | |
roryhand | 13:8e93396a27c5 | 423 | for(int aaa = 0;aaa < 21; aaa ++ ) |
roryhand | 13:8e93396a27c5 | 424 | { |
roryhand | 13:8e93396a27c5 | 425 | folder = RootFolder + filename[aaa]; |
roryhand | 13:8e93396a27c5 | 426 | FOLDER = folder.c_str(); |
roryhand | 13:8e93396a27c5 | 427 | Sound[aaa].FileInfo.WavFile = fopen(FOLDER,"rb"); |
roryhand | 13:8e93396a27c5 | 428 | //MyNewWav.WavFile = fopen("/sd/mydir/Startup.wav","rb"); |
roryhand | 13:8e93396a27c5 | 429 | printf("we opened This file %d\n\r",aaa); |
roryhand | 9:dd9cae06b202 | 430 | |
roryhand | 13:8e93396a27c5 | 431 | /* |
roryhand | 13:8e93396a27c5 | 432 | printf("Size of FILE* %d\n\r ",sizeof(Sound[aaa].FileInfo.WavFile)); |
roryhand | 13:8e93396a27c5 | 433 | fseek(Sound[aaa].FileInfo.WavFile,20,SEEK_SET); |
roryhand | 13:8e93396a27c5 | 434 | fread(&Sound[aaa].FileInfo.FileFormat,sizeof(Sound[aaa].FileInfo.FileFormat),1,Sound[aaa].FileInfo.WavFile); |
roryhand | 13:8e93396a27c5 | 435 | fread(&Sound[aaa].FileInfo.FileData,sizeof(Sound[aaa].FileInfo.FileData),1,Sound[aaa].FileInfo.WavFile); |
roryhand | 13:8e93396a27c5 | 436 | */ |
roryhand | 13:8e93396a27c5 | 437 | |
roryhand | 13:8e93396a27c5 | 438 | |
roryhand | 9:dd9cae06b202 | 439 | //fseek(Sound[aaa].FileInfo.WavFile,20,SEEK_SET); |
roryhand | 9:dd9cae06b202 | 440 | |
roryhand | 9:dd9cae06b202 | 441 | //fseek(MyNewWav.WavFile,20,SEEK_SET); |
roryhand | 9:dd9cae06b202 | 442 | //fread(&WavInfo_Horn.FileFormat,sizeof(WavInfo_Horn.FileFormat),1,MyNewWav.WavFile); |
roryhand | 13:8e93396a27c5 | 443 | /* |
roryhand | 13:8e93396a27c5 | 444 | fread(&Sound[aaa].FileInfo.FileData,sizeof(Sound[aaa].FileInfo.FileData),1,Sound[aaa].FileInfo.WavFile); |
roryhand | 9:dd9cae06b202 | 445 | |
roryhand | 7:131ac4231c46 | 446 | Sound[aaa].FileInfo.slice_buf = ( char *)malloc(Sound[aaa].FileInfo.FileFormat.block_align); |
roryhand | 7:131ac4231c46 | 447 | fread(Sound[aaa].FileInfo.slice_buf,Sound[aaa].FileInfo.FileFormat.block_align,1,Sound[aaa].FileInfo.WavFile); //This isnt actually required, its just a test |
roryhand | 7:131ac4231c46 | 448 | Sound[aaa].FileInfo.num_slices = Sound[aaa].FileInfo.FileData.subchunk2_size/Sound[aaa].FileInfo.FileFormat.block_align; |
roryhand | 13:8e93396a27c5 | 449 | */ |
roryhand | 8:c2faf06e7240 | 450 | |
roryhand | 13:8e93396a27c5 | 451 | /* |
roryhand | 13:8e93396a27c5 | 452 | Sound[aaa].FileInfo.slice_buf = ( char *)malloc(Sound[aaa].FileInfo.FileFormat.block_align); |
roryhand | 13:8e93396a27c5 | 453 | fread(Sound[aaa].FileInfo.slice_buf,Sound[aaa].FileInfo.FileFormat.block_align,1,Sound[aaa].FileInfo.WavFile); //This isnt actually required, its just a test |
roryhand | 13:8e93396a27c5 | 454 | Sound[aaa].FileInfo.num_slices = Sound[aaa].FileInfo.FileData.subchunk2_size/Sound[aaa].FileInfo.FileFormat.block_align; |
roryhand | 13:8e93396a27c5 | 455 | |
roryhand | 13:8e93396a27c5 | 456 | |
roryhand | 13:8e93396a27c5 | 457 | } |
roryhand | 13:8e93396a27c5 | 458 | */ |
roryhand | 13:8e93396a27c5 | 459 | |
roryhand | 10:ce38f2e9e80e | 460 | int aaa = 0; |
roryhand | 10:ce38f2e9e80e | 461 | string folder = RootFolder + filename[0]; |
roryhand | 10:ce38f2e9e80e | 462 | FOLDER = folder.c_str(); |
roryhand | 12:e386150cefd3 | 463 | WAV_FILE_STRUCT WavStruct0; |
roryhand | 12:e386150cefd3 | 464 | WAV_FILE_STRUCT WavStruct1; |
roryhand | 12:e386150cefd3 | 465 | WAV_FILE_STRUCT WavStruct2; |
roryhand | 12:e386150cefd3 | 466 | WAV_FILE_STRUCT WavStruct3; |
roryhand | 12:e386150cefd3 | 467 | WAV_FILE_STRUCT WavStruct4; |
roryhand | 12:e386150cefd3 | 468 | WAV_FILE_STRUCT WavStruct5; |
roryhand | 12:e386150cefd3 | 469 | WAV_FILE_STRUCT WavStruct6; |
roryhand | 12:e386150cefd3 | 470 | WAV_FILE_STRUCT WavStruct7; |
roryhand | 12:e386150cefd3 | 471 | WAV_FILE_STRUCT WavStruct8; |
roryhand | 12:e386150cefd3 | 472 | WAV_FILE_STRUCT WavStruct9; |
roryhand | 12:e386150cefd3 | 473 | WAV_FILE_STRUCT WavStruct10; |
roryhand | 12:e386150cefd3 | 474 | WAV_FILE_STRUCT WavStruct11; |
roryhand | 12:e386150cefd3 | 475 | WAV_FILE_STRUCT WavStruct12; |
roryhand | 12:e386150cefd3 | 476 | WAV_FILE_STRUCT WavStruct13; |
roryhand | 12:e386150cefd3 | 477 | WAV_FILE_STRUCT WavStruct14; |
roryhand | 12:e386150cefd3 | 478 | WAV_FILE_STRUCT WavStruct15; |
roryhand | 12:e386150cefd3 | 479 | WAV_FILE_STRUCT WavStruct16; |
roryhand | 12:e386150cefd3 | 480 | WAV_FILE_STRUCT WavStruct17; |
roryhand | 12:e386150cefd3 | 481 | WAV_FILE_STRUCT WavStruct18; |
roryhand | 12:e386150cefd3 | 482 | WAV_FILE_STRUCT WavStruct19; |
roryhand | 12:e386150cefd3 | 483 | WAV_FILE_STRUCT WavStruct20; |
roryhand | 12:e386150cefd3 | 484 | WAV_FILE_STRUCT WavStruct21; |
roryhand | 12:e386150cefd3 | 485 | WAV_FILE_STRUCT WavStruct22; |
roryhand | 12:e386150cefd3 | 486 | //WavStruct0.WavFile = fopen(FOLDER,"rb"); |
roryhand | 12:e386150cefd3 | 487 | FILE* mywav0 = fopen(FOLDER,"rb"); |
roryhand | 10:ce38f2e9e80e | 488 | printf("we opened This file %d\n\r",aaa); |
roryhand | 13:8e93396a27c5 | 489 | |
roryhand | 10:ce38f2e9e80e | 490 | aaa = aaa+1; |
roryhand | 13:8e93396a27c5 | 491 | |
roryhand | 13:8e93396a27c5 | 492 | |
roryhand | 10:ce38f2e9e80e | 493 | folder = RootFolder + filename[1]; |
roryhand | 10:ce38f2e9e80e | 494 | FOLDER = folder.c_str(); |
roryhand | 12:e386150cefd3 | 495 | FILE* mywav1 = fopen(FOLDER,"rb"); |
roryhand | 13:8e93396a27c5 | 496 | |
roryhand | 10:ce38f2e9e80e | 497 | printf("we opened This file %d\n\r",aaa); |
roryhand | 13:8e93396a27c5 | 498 | |
roryhand | 13:8e93396a27c5 | 499 | printf("Size of WavStruct1: %d\n\r",sizeof(WavStruct1)); |
roryhand | 13:8e93396a27c5 | 500 | aaa = aaa+1; |
roryhand | 13:8e93396a27c5 | 501 | |
roryhand | 10:ce38f2e9e80e | 502 | folder = RootFolder + filename[2]; |
roryhand | 13:8e93396a27c5 | 503 | FOLDER = folder.c_str(); |
roryhand | 12:e386150cefd3 | 504 | FILE* mywav2 = fopen(FOLDER,"rb"); |
roryhand | 13:8e93396a27c5 | 505 | |
roryhand | 13:8e93396a27c5 | 506 | |
roryhand | 10:ce38f2e9e80e | 507 | printf("we opened This file %d\n\r",aaa); |
roryhand | 13:8e93396a27c5 | 508 | |
roryhand | 13:8e93396a27c5 | 509 | |
roryhand | 13:8e93396a27c5 | 510 | |
roryhand | 13:8e93396a27c5 | 511 | |
roryhand | 13:8e93396a27c5 | 512 | |
roryhand | 13:8e93396a27c5 | 513 | aaa = aaa+1; |
roryhand | 13:8e93396a27c5 | 514 | |
roryhand | 13:8e93396a27c5 | 515 | folder = RootFolder + filename[3]; |
roryhand | 13:8e93396a27c5 | 516 | FOLDER = folder.c_str(); |
roryhand | 13:8e93396a27c5 | 517 | FILE* mywav3 = fopen(FOLDER,"rb"); |
roryhand | 13:8e93396a27c5 | 518 | |
roryhand | 13:8e93396a27c5 | 519 | |
roryhand | 13:8e93396a27c5 | 520 | printf("we opened This file %d\n\r",aaa); |
roryhand | 13:8e93396a27c5 | 521 | |
roryhand | 13:8e93396a27c5 | 522 | |
roryhand | 12:e386150cefd3 | 523 | |
roryhand | 12:e386150cefd3 | 524 | |
roryhand | 12:e386150cefd3 | 525 | |
roryhand | 10:ce38f2e9e80e | 526 | aaa = aaa+1; |
roryhand | 13:8e93396a27c5 | 527 | |
roryhand | 13:8e93396a27c5 | 528 | folder = RootFolder + filename[4]; |
roryhand | 13:8e93396a27c5 | 529 | FOLDER = folder.c_str(); |
roryhand | 13:8e93396a27c5 | 530 | FILE* mywav4 = fopen(FOLDER,"rb"); |
roryhand | 13:8e93396a27c5 | 531 | |
roryhand | 13:8e93396a27c5 | 532 | |
roryhand | 10:ce38f2e9e80e | 533 | printf("we opened This file %d\n\r",aaa); |
roryhand | 11:34136ff82179 | 534 | |
roryhand | 13:8e93396a27c5 | 535 | |
roryhand | 13:8e93396a27c5 | 536 | |
roryhand | 13:8e93396a27c5 | 537 | |
roryhand | 13:8e93396a27c5 | 538 | |
roryhand | 13:8e93396a27c5 | 539 | aaa = aaa+1; |
roryhand | 12:e386150cefd3 | 540 | |
roryhand | 13:8e93396a27c5 | 541 | folder = RootFolder + filename[5]; |
roryhand | 13:8e93396a27c5 | 542 | FOLDER = folder.c_str(); |
roryhand | 13:8e93396a27c5 | 543 | |
roryhand | 13:8e93396a27c5 | 544 | FILE* mywav5 = fopen(FOLDER,"rb"); |
roryhand | 13:8e93396a27c5 | 545 | |
roryhand | 10:ce38f2e9e80e | 546 | printf("we opened This file %d\n\r",aaa); |
roryhand | 12:e386150cefd3 | 547 | |
roryhand | 12:e386150cefd3 | 548 | |
roryhand | 11:34136ff82179 | 549 | |
roryhand | 10:ce38f2e9e80e | 550 | aaa = aaa+1; |
roryhand | 13:8e93396a27c5 | 551 | |
roryhand | 10:ce38f2e9e80e | 552 | folder = RootFolder + filename[6]; |
roryhand | 13:8e93396a27c5 | 553 | FOLDER = folder.c_str(); |
roryhand | 12:e386150cefd3 | 554 | FILE* mywav6 = fopen(FOLDER,"rb"); |
roryhand | 13:8e93396a27c5 | 555 | |
roryhand | 10:ce38f2e9e80e | 556 | printf("we opened This file %d\n\r",aaa); |
roryhand | 12:e386150cefd3 | 557 | |
roryhand | 13:8e93396a27c5 | 558 | aaa = aaa+1; |
roryhand | 13:8e93396a27c5 | 559 | |
roryhand | 13:8e93396a27c5 | 560 | folder = RootFolder + filename[7]; |
roryhand | 13:8e93396a27c5 | 561 | FOLDER = folder.c_str(); |
roryhand | 13:8e93396a27c5 | 562 | FILE* mywav7 = fopen(FOLDER,"rb"); |
roryhand | 12:e386150cefd3 | 563 | |
roryhand | 13:8e93396a27c5 | 564 | printf("we opened This file %d\n\r",aaa); |
roryhand | 13:8e93396a27c5 | 565 | |
roryhand | 13:8e93396a27c5 | 566 | |
roryhand | 13:8e93396a27c5 | 567 | |
roryhand | 13:8e93396a27c5 | 568 | |
roryhand | 10:ce38f2e9e80e | 569 | aaa = aaa+1; |
roryhand | 13:8e93396a27c5 | 570 | |
roryhand | 10:ce38f2e9e80e | 571 | folder = RootFolder + filename[8]; |
roryhand | 13:8e93396a27c5 | 572 | FOLDER = folder.c_str(); |
roryhand | 13:8e93396a27c5 | 573 | FILE* mywav8 = fopen(FOLDER,"rb"); |
roryhand | 13:8e93396a27c5 | 574 | |
roryhand | 10:ce38f2e9e80e | 575 | printf("we opened This file %d\n\r",aaa); |
roryhand | 13:8e93396a27c5 | 576 | |
roryhand | 12:e386150cefd3 | 577 | |
roryhand | 11:34136ff82179 | 578 | |
roryhand | 10:ce38f2e9e80e | 579 | aaa = aaa+1; |
roryhand | 13:8e93396a27c5 | 580 | |
roryhand | 10:ce38f2e9e80e | 581 | folder = RootFolder + filename[9]; |
roryhand | 13:8e93396a27c5 | 582 | FOLDER = folder.c_str(); |
roryhand | 13:8e93396a27c5 | 583 | FILE* mywav9 = fopen(FOLDER,"rb"); |
roryhand | 13:8e93396a27c5 | 584 | |
roryhand | 10:ce38f2e9e80e | 585 | printf("we opened This file %d\n\r",aaa); |
roryhand | 13:8e93396a27c5 | 586 | |
roryhand | 13:8e93396a27c5 | 587 | |
roryhand | 10:ce38f2e9e80e | 588 | aaa = aaa+1; |
roryhand | 13:8e93396a27c5 | 589 | |
roryhand | 10:ce38f2e9e80e | 590 | folder = RootFolder + filename[10]; |
roryhand | 13:8e93396a27c5 | 591 | FOLDER = folder.c_str(); |
roryhand | 13:8e93396a27c5 | 592 | FILE* mywav10 = fopen(FOLDER,"rb"); |
roryhand | 13:8e93396a27c5 | 593 | |
roryhand | 10:ce38f2e9e80e | 594 | printf("we opened This file %d\n\r",aaa); |
roryhand | 11:34136ff82179 | 595 | |
roryhand | 13:8e93396a27c5 | 596 | |
roryhand | 11:34136ff82179 | 597 | |
roryhand | 10:ce38f2e9e80e | 598 | aaa = aaa+1; |
roryhand | 13:8e93396a27c5 | 599 | |
roryhand | 10:ce38f2e9e80e | 600 | folder = RootFolder + filename[11]; |
roryhand | 10:ce38f2e9e80e | 601 | FOLDER = folder.c_str(); |
roryhand | 13:8e93396a27c5 | 602 | FILE* mywav11 = fopen(FOLDER,"rb"); |
roryhand | 13:8e93396a27c5 | 603 | |
roryhand | 10:ce38f2e9e80e | 604 | printf("we opened This file %d\n\r",aaa); |
roryhand | 13:8e93396a27c5 | 605 | |
roryhand | 13:8e93396a27c5 | 606 | |
roryhand | 10:ce38f2e9e80e | 607 | aaa = aaa+1; |
roryhand | 13:8e93396a27c5 | 608 | |
roryhand | 10:ce38f2e9e80e | 609 | folder = RootFolder + filename[12]; |
roryhand | 10:ce38f2e9e80e | 610 | FOLDER = folder.c_str(); |
roryhand | 13:8e93396a27c5 | 611 | FILE* mywav12 = fopen(FOLDER,"rb"); |
roryhand | 13:8e93396a27c5 | 612 | |
roryhand | 10:ce38f2e9e80e | 613 | printf("we opened This file %d\n\r",aaa); |
roryhand | 11:34136ff82179 | 614 | |
roryhand | 13:8e93396a27c5 | 615 | |
roryhand | 13:8e93396a27c5 | 616 | |
roryhand | 13:8e93396a27c5 | 617 | aaa = aaa+1; |
roryhand | 13:8e93396a27c5 | 618 | |
roryhand | 13:8e93396a27c5 | 619 | folder = RootFolder + filename[13]; |
roryhand | 13:8e93396a27c5 | 620 | FOLDER = folder.c_str(); |
roryhand | 13:8e93396a27c5 | 621 | FILE* mywav13 = fopen(FOLDER,"rb"); |
roryhand | 13:8e93396a27c5 | 622 | |
roryhand | 13:8e93396a27c5 | 623 | printf("we opened This file %d\n\r",aaa); |
roryhand | 13:8e93396a27c5 | 624 | |
roryhand | 13:8e93396a27c5 | 625 | |
roryhand | 11:34136ff82179 | 626 | |
roryhand | 10:ce38f2e9e80e | 627 | aaa = aaa+1; |
roryhand | 13:8e93396a27c5 | 628 | |
roryhand | 10:ce38f2e9e80e | 629 | folder = RootFolder + filename[14]; |
roryhand | 13:8e93396a27c5 | 630 | FOLDER = folder.c_str(); |
roryhand | 13:8e93396a27c5 | 631 | FILE* mywav14 = fopen(FOLDER,"rb"); |
roryhand | 13:8e93396a27c5 | 632 | |
roryhand | 10:ce38f2e9e80e | 633 | printf("we opened This file %d\n\r",aaa); |
roryhand | 13:8e93396a27c5 | 634 | |
roryhand | 13:8e93396a27c5 | 635 | |
roryhand | 13:8e93396a27c5 | 636 | |
roryhand | 10:ce38f2e9e80e | 637 | aaa = aaa+1; |
roryhand | 13:8e93396a27c5 | 638 | |
roryhand | 10:ce38f2e9e80e | 639 | folder = RootFolder + filename[15]; |
roryhand | 13:8e93396a27c5 | 640 | FOLDER = folder.c_str(); |
roryhand | 13:8e93396a27c5 | 641 | FILE* mywav15 = fopen(FOLDER,"rb"); |
roryhand | 13:8e93396a27c5 | 642 | |
roryhand | 10:ce38f2e9e80e | 643 | printf("we opened This file %d\n\r",aaa); |
roryhand | 13:8e93396a27c5 | 644 | |
roryhand | 13:8e93396a27c5 | 645 | |
roryhand | 13:8e93396a27c5 | 646 | |
roryhand | 10:ce38f2e9e80e | 647 | aaa = aaa+1; |
roryhand | 13:8e93396a27c5 | 648 | |
roryhand | 10:ce38f2e9e80e | 649 | folder = RootFolder + filename[16]; |
roryhand | 13:8e93396a27c5 | 650 | FOLDER = folder.c_str(); |
roryhand | 13:8e93396a27c5 | 651 | FILE* mywav16 = fopen(FOLDER,"rb"); |
roryhand | 13:8e93396a27c5 | 652 | |
roryhand | 10:ce38f2e9e80e | 653 | printf("we opened This file %d\n\r",aaa); |
roryhand | 13:8e93396a27c5 | 654 | |
roryhand | 13:8e93396a27c5 | 655 | |
roryhand | 13:8e93396a27c5 | 656 | |
roryhand | 10:ce38f2e9e80e | 657 | aaa = aaa+1; |
roryhand | 13:8e93396a27c5 | 658 | |
roryhand | 10:ce38f2e9e80e | 659 | folder = RootFolder + filename[17]; |
roryhand | 13:8e93396a27c5 | 660 | FOLDER = folder.c_str(); |
roryhand | 13:8e93396a27c5 | 661 | FILE* mywav17 = fopen(FOLDER,"rb"); |
roryhand | 13:8e93396a27c5 | 662 | |
roryhand | 10:ce38f2e9e80e | 663 | printf("we opened This file %d\n\r",aaa); |
roryhand | 13:8e93396a27c5 | 664 | |
roryhand | 13:8e93396a27c5 | 665 | |
roryhand | 13:8e93396a27c5 | 666 | |
roryhand | 10:ce38f2e9e80e | 667 | aaa = aaa+1; |
roryhand | 13:8e93396a27c5 | 668 | |
roryhand | 10:ce38f2e9e80e | 669 | folder = RootFolder + filename[18]; |
roryhand | 13:8e93396a27c5 | 670 | FOLDER = folder.c_str(); |
roryhand | 13:8e93396a27c5 | 671 | FILE* mywav18 = fopen(FOLDER,"rb"); |
roryhand | 13:8e93396a27c5 | 672 | |
roryhand | 10:ce38f2e9e80e | 673 | printf("we opened This file %d\n\r",aaa); |
roryhand | 13:8e93396a27c5 | 674 | |
roryhand | 13:8e93396a27c5 | 675 | |
roryhand | 13:8e93396a27c5 | 676 | |
roryhand | 13:8e93396a27c5 | 677 | printf("We performed all ReadFileInfo Operations!\n\r"); |
roryhand | 10:ce38f2e9e80e | 678 | aaa = aaa+1; |
roryhand | 13:8e93396a27c5 | 679 | |
roryhand | 1:aac37edee302 | 680 | |
roryhand | 1:aac37edee302 | 681 | printf("DO WE GET PAST THE ALLOCATION POINT\n\r"); |
roryhand | 1:aac37edee302 | 682 | |
roryhand | 1:aac37edee302 | 683 | |
roryhand | 1:aac37edee302 | 684 | |
roryhand | 1:aac37edee302 | 685 | |
roryhand | 1:aac37edee302 | 686 | |
roryhand | 13:8e93396a27c5 | 687 | /* |
roryhand | 1:aac37edee302 | 688 | StartupWav = fopen("/sd/mydir/645Engine/Startup.wav","rb"); |
roryhand | 0:e89d7a0bfa3b | 689 | IdleWav = fopen("/sd/mydir/645Engine/N2_11k_minus10dB.wav","rb"); |
roryhand | 0:e89d7a0bfa3b | 690 | IdleN2Wav = fopen("/sd/mydir/645Engine/N2N3_11k_minus10dB.wav","rb"); |
roryhand | 0:e89d7a0bfa3b | 691 | HornWav = fopen("/sd/mydir/645Engine/K3H_1_A_short_quiet.wav","rb"); |
roryhand | 0:e89d7a0bfa3b | 692 | N2Wav = fopen("/sd/mydir/645Engine/N3_11k_minus11dB.wav","rb"); |
roryhand | 0:e89d7a0bfa3b | 693 | BellWav = fopen("/sd/mydir/645Engine/EMD_BRONZE_BELL_1_11k_minus10dB.wav","rb"); |
roryhand | 0:e89d7a0bfa3b | 694 | FlangeWav = fopen("/sd/mydir/645Engine/EX_FlangeJoint1_11k_minus12dB.wav","rb"); |
roryhand | 13:8e93396a27c5 | 695 | |
roryhand | 13:8e93396a27c5 | 696 | |
roryhand | 13:8e93396a27c5 | 697 | |
roryhand | 1:aac37edee302 | 698 | |
roryhand | 0:e89d7a0bfa3b | 699 | WavInfo_Startup = ReadFileInfo(WavInfo_Startup, StartupWav); |
roryhand | 1:aac37edee302 | 700 | printf("WavInfo_Startup Size: %d\n\r",sizeof(WavInfo_Startup)); |
roryhand | 0:e89d7a0bfa3b | 701 | WavInfo_Idle = ReadFileInfo(WavInfo_Idle, IdleWav); |
roryhand | 0:e89d7a0bfa3b | 702 | WavInfo_Horn = ReadFileInfo(WavInfo_Horn, HornWav); |
roryhand | 0:e89d7a0bfa3b | 703 | WavInfo_IdleN2 = ReadFileInfo(WavInfo_IdleN2, IdleN2Wav); |
roryhand | 0:e89d7a0bfa3b | 704 | WavInfo_N2 = ReadFileInfo(WavInfo_N2, N2Wav); |
roryhand | 0:e89d7a0bfa3b | 705 | WavInfo_Bell = ReadFileInfo(WavInfo_Bell, BellWav); |
roryhand | 0:e89d7a0bfa3b | 706 | WavInfo_Flange = ReadFileInfo(WavInfo_Flange, FlangeWav); |
roryhand | 13:8e93396a27c5 | 707 | */ |
roryhand | 13:8e93396a27c5 | 708 | |
roryhand | 13:8e93396a27c5 | 709 | printf("About to Start ReadFileInfo Operations\n\r"); |
roryhand | 13:8e93396a27c5 | 710 | |
roryhand | 14:cc555d14e3f8 | 711 | |
roryhand | 13:8e93396a27c5 | 712 | StartupWav = fopen("/sd/mydir/645Engine/Startup.wav","rb"); |
roryhand | 13:8e93396a27c5 | 713 | IdleWav = fopen("/sd/mydir/645Engine/N2_11k_minus10dB.wav","rb"); |
roryhand | 13:8e93396a27c5 | 714 | IdleN2Wav = fopen("/sd/mydir/645Engine/N2N3_11k_minus10dB.wav","rb"); |
roryhand | 13:8e93396a27c5 | 715 | HornWav = fopen("/sd/mydir/645Engine/K3H_1_A_short_quiet.wav","rb"); |
roryhand | 13:8e93396a27c5 | 716 | N2Wav = fopen("/sd/mydir/645Engine/N3_11k_minus11dB.wav","rb"); |
roryhand | 13:8e93396a27c5 | 717 | BellWav = fopen("/sd/mydir/645Engine/EMD_BRONZE_BELL_1_11k_minus10dB.wav","rb"); |
roryhand | 20:9cc7d825c07b | 718 | //FlangeWav = fopen("/sd/mydir/645Engine/EX_FlangeJoint1_11k_minus12dB.wav","rb"); |
roryhand | 16:5e3420d0509b | 719 | |
roryhand | 20:9cc7d825c07b | 720 | HeyWav = fopen("/sd/mydir/645Engine/EX_FlangeJoint1_11k_minus12dB.wav","rb"); |
roryhand | 16:5e3420d0509b | 721 | //HeyWav = fopen("/sd/mydir/edsheeran.wav","rb"); |
roryhand | 13:8e93396a27c5 | 722 | |
roryhand | 13:8e93396a27c5 | 723 | |
roryhand | 13:8e93396a27c5 | 724 | |
roryhand | 13:8e93396a27c5 | 725 | WavInfo_Startup = ReadFileInfo(WavInfo_Startup, StartupWav); |
roryhand | 17:832eb9a75c05 | 726 | //printf("WavInfo_Startup Size: %d\n\r",sizeof(WavInfo_Startup)); |
roryhand | 13:8e93396a27c5 | 727 | WavInfo_Idle = ReadFileInfo(WavInfo_Idle, IdleWav); |
roryhand | 13:8e93396a27c5 | 728 | WavInfo_Horn = ReadFileInfo(WavInfo_Horn, HornWav); |
roryhand | 13:8e93396a27c5 | 729 | WavInfo_IdleN2 = ReadFileInfo(WavInfo_IdleN2, IdleN2Wav); |
roryhand | 13:8e93396a27c5 | 730 | WavInfo_N2 = ReadFileInfo(WavInfo_N2, N2Wav); |
roryhand | 13:8e93396a27c5 | 731 | WavInfo_Bell = ReadFileInfo(WavInfo_Bell, BellWav); |
roryhand | 20:9cc7d825c07b | 732 | //WavInfo_Flange = ReadFileInfo(WavInfo_Flange, HeyWav); |
roryhand | 20:9cc7d825c07b | 733 | //WavInfo_Hey = ReadFileInfo(WavInfo_Hey,HeyWav); |
roryhand | 16:5e3420d0509b | 734 | //WAV_FILE_STRUCT WavInfo_Frustration; |
roryhand | 16:5e3420d0509b | 735 | //FILE* FrustrationWav = fopen("/sd/mydir/645Engine/EX_FlangeJoint1_11k_minus12dB.wav","rb"); |
roryhand | 17:832eb9a75c05 | 736 | //WAV_FILE_STRUCT WavInfo_Hey; |
roryhand | 20:9cc7d825c07b | 737 | WavInfo_Hey = ReadFileInfo(WavInfo_Hey,HeyWav); |
roryhand | 16:5e3420d0509b | 738 | //FlangeWav - this one works. |
roryhand | 16:5e3420d0509b | 739 | //HeyWav - this one doesn't. Despite the fact they reference teh exact same file. |
roryhand | 16:5e3420d0509b | 740 | //WavInfo_Bell = ReadFileInfo(WavInfo_Bell,HeyWav); |
roryhand | 16:5e3420d0509b | 741 | //WavInfo_Frustration = ReadFileInfo(WavInfo_Frustration,FlangeWav); |
roryhand | 17:832eb9a75c05 | 742 | //printf("Frustration\n\r"); |
roryhand | 13:8e93396a27c5 | 743 | |
roryhand | 13:8e93396a27c5 | 744 | |
roryhand | 4:55fbbb049bae | 745 | |
roryhand | 14:cc555d14e3f8 | 746 | printf("Do we even get to this stupid bloody point\n\r"); |
roryhand | 0:e89d7a0bfa3b | 747 | //Populate our class instances with some data (is there an implicit way to do this?) |
roryhand | 0:e89d7a0bfa3b | 748 | N2FadeIn.LengthSecs = 4; |
roryhand | 0:e89d7a0bfa3b | 749 | IdleFadeOut.LengthSecs = 2; |
roryhand | 0:e89d7a0bfa3b | 750 | N2FadeIn = FadeDataInitialise(N2FadeIn); |
roryhand | 0:e89d7a0bfa3b | 751 | IdleFadeOut = FadeDataInitialise(IdleFadeOut); |
roryhand | 1:aac37edee302 | 752 | |
roryhand | 3:6169aeeaeeb4 | 753 | printf("hello\n\r"); |
roryhand | 0:e89d7a0bfa3b | 754 | //Set up the wolfson Audio Codec board |
roryhand | 0:e89d7a0bfa3b | 755 | wm8731_Config_setup(); |
roryhand | 0:e89d7a0bfa3b | 756 | //i2s audio data transfer code?? |
roryhand | 0:e89d7a0bfa3b | 757 | i2s.stereomono(I2S_STEREO); |
roryhand | 0:e89d7a0bfa3b | 758 | i2s.masterslave(I2S_MASTER); |
roryhand | 0:e89d7a0bfa3b | 759 | led3 = 1; |
roryhand | 0:e89d7a0bfa3b | 760 | led2 = 1; |
roryhand | 13:8e93396a27c5 | 761 | |
roryhand | 0:e89d7a0bfa3b | 762 | sampletick.attach(&isr,1.0/sampling_freq); //1/16000 |
roryhand | 0:e89d7a0bfa3b | 763 | //TickFadeOut.attach(&FadeOutIsr,10.0); |
roryhand | 3:6169aeeaeeb4 | 764 | printf("SamplingFreq: %d\n\r",sampling_freq); |
roryhand | 0:e89d7a0bfa3b | 765 | i2s.start(); |
roryhand | 3:6169aeeaeeb4 | 766 | printf("Hello i2s has starrted!!"); |
roryhand | 0:e89d7a0bfa3b | 767 | Horn.rise(&FadeOutIsr); |
roryhand | 0:e89d7a0bfa3b | 768 | slice = 0; |
roryhand | 0:e89d7a0bfa3b | 769 | fseek(IdleN2Wav,44,SEEK_SET); |
roryhand | 0:e89d7a0bfa3b | 770 | //Play_WaveFile(IdleN2Wav,WavInfo_IdleN2); |
roryhand | 0:e89d7a0bfa3b | 771 | //Play_WaveFile(N2Wav,WavInfo_N2); |
roryhand | 0:e89d7a0bfa3b | 772 | t.reset(); |
roryhand | 0:e89d7a0bfa3b | 773 | t.start(); |
roryhand | 0:e89d7a0bfa3b | 774 | N2FadeIn.FadeCoeff = N2FadeIn.FadeOut(); |
roryhand | 0:e89d7a0bfa3b | 775 | t.stop(); |
roryhand | 0:e89d7a0bfa3b | 776 | printf("Time to Calcualte Fade Coeff: %d\n\r",t.read_us()); |
roryhand | 0:e89d7a0bfa3b | 777 | t.reset(); |
roryhand | 1:aac37edee302 | 778 | |
roryhand | 0:e89d7a0bfa3b | 779 | fseek(IdleN2Wav,44,SEEK_SET); |
roryhand | 0:e89d7a0bfa3b | 780 | t.start(); |
roryhand | 1:aac37edee302 | 781 | fread(WavInfo_IdleN2.slice_buf,WavInfo_IdleN2.FileFormat.block_align,1,IdleN2Wav); |
roryhand | 0:e89d7a0bfa3b | 782 | data_sptr_IdleN2 = (short *)WavInfo_IdleN2.slice_buf; |
roryhand | 0:e89d7a0bfa3b | 783 | t.stop(); |
roryhand | 0:e89d7a0bfa3b | 784 | printf("Time to Read in a slice: %dus\n\r",t.read_us()); |
roryhand | 0:e89d7a0bfa3b | 785 | t.reset(); |
roryhand | 1:aac37edee302 | 786 | |
roryhand | 0:e89d7a0bfa3b | 787 | printf("point to start sound: %d\n\r",((WavInfo_IdleN2.FileData.subchunk2_size) - N2FadeIn.Length)); |
roryhand | 0:e89d7a0bfa3b | 788 | printf("Size of Data: %d\n\r",WavInfo_IdleN2.FileData.subchunk2_size); |
roryhand | 1:aac37edee302 | 789 | |
roryhand | 20:9cc7d825c07b | 790 | fseek(HeyWav,44,SEEK_SET); |
roryhand | 13:8e93396a27c5 | 791 | |
roryhand | 20:9cc7d825c07b | 792 | printf("about to play wav file\n\r"); |
roryhand | 20:9cc7d825c07b | 793 | Play_WaveFile(HeyWav,WavInfo_Hey); |
roryhand | 20:9cc7d825c07b | 794 | printf("finished playing Wav file\n\r"); |
roryhand | 9:dd9cae06b202 | 795 | /************************************PLAY WAV FILE LOOP*******************/ |
roryhand | 20:9cc7d825c07b | 796 | //Play_WaveFileLoop(Sound, NotchingSet); |
roryhand | 9:dd9cae06b202 | 797 | /************************************END OF PLAY WAV FILE LOOP*************/ |
roryhand | 13:8e93396a27c5 | 798 | |
roryhand | 13:8e93396a27c5 | 799 | |
roryhand | 13:8e93396a27c5 | 800 | |
roryhand | 9:dd9cae06b202 | 801 | |
roryhand | 3:6169aeeaeeb4 | 802 | |
roryhand | 0:e89d7a0bfa3b | 803 | fseek(IdleN2Wav,44,SEEK_SET);//reset for use in the Loop code |
roryhand | 0:e89d7a0bfa3b | 804 | slice = 0; |
roryhand | 0:e89d7a0bfa3b | 805 | fseek(IdleWav,44,SEEK_SET); |
roryhand | 3:6169aeeaeeb4 | 806 | NotchingSet.Notch = 1; |
roryhand | 1:aac37edee302 | 807 | //Play_WaveFileLoop(IdleWav, WavInfo_Idle); |
roryhand | 1:aac37edee302 | 808 | |
roryhand | 1:aac37edee302 | 809 | i2s.stop(); |
roryhand | 0:e89d7a0bfa3b | 810 | |
roryhand | 0:e89d7a0bfa3b | 811 | } |
roryhand | 0:e89d7a0bfa3b | 812 | |
roryhand | 0:e89d7a0bfa3b | 813 | |
roryhand | 3:6169aeeaeeb4 | 814 | |
roryhand | 3:6169aeeaeeb4 | 815 | |
roryhand | 3:6169aeeaeeb4 | 816 | |
roryhand | 3:6169aeeaeeb4 | 817 | |
roryhand | 0:e89d7a0bfa3b | 818 | WAV_FILE_STRUCT ReadFileInfo(WAV_FILE_STRUCT FileInfo, FILE * wav_file) |
roryhand | 0:e89d7a0bfa3b | 819 | { |
roryhand | 0:e89d7a0bfa3b | 820 | fseek(wav_file,20,SEEK_SET); |
roryhand | 0:e89d7a0bfa3b | 821 | fread(&FileInfo.FileFormat,sizeof(FileInfo.FileFormat),1,wav_file); |
roryhand | 1:aac37edee302 | 822 | //printf("wav_format.sample_rate: %d\n\r",FileInfo.FileFormat.sample_rate); |
roryhand | 1:aac37edee302 | 823 | |
roryhand | 0:e89d7a0bfa3b | 824 | fread(&FileInfo.FileData,sizeof(FileInfo.FileData),1,wav_file); |
roryhand | 1:aac37edee302 | 825 | //printf("wav_data.subchunk2_size: %d\n\r",FileInfo.FileData.subchunk2_size); |
roryhand | 0:e89d7a0bfa3b | 826 | FileInfo.slice_buf = ( char *)malloc(FileInfo.FileFormat.block_align); |
roryhand | 0:e89d7a0bfa3b | 827 | fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,wav_file); //This isnt actually required, its just a test |
roryhand | 1:aac37edee302 | 828 | FileInfo.num_slices = FileInfo.FileData.subchunk2_size/FileInfo.FileFormat.block_align; |
roryhand | 1:aac37edee302 | 829 | //printf("Number of Slices: %d\n\r",FileInfo.num_slices); |
roryhand | 1:aac37edee302 | 830 | return FileInfo; |
roryhand | 0:e89d7a0bfa3b | 831 | } |
roryhand | 1:aac37edee302 | 832 | |
roryhand | 1:aac37edee302 | 833 | classSoundFile LoadFileStream(classSoundFile Sound, string filename) |
roryhand | 1:aac37edee302 | 834 | { |
roryhand | 1:aac37edee302 | 835 | //Declare RootFolder and the directory for the appropriate file. |
roryhand | 1:aac37edee302 | 836 | //How we index into filename[] from the outside of this class is another |
roryhand | 1:aac37edee302 | 837 | //issue... |
roryhand | 1:aac37edee302 | 838 | //printf("FileName: %s\n\r",filename); |
roryhand | 1:aac37edee302 | 839 | //string RootFolder = "/sd/mydir/SoundDecoder/"; |
roryhand | 1:aac37edee302 | 840 | //string Directory = RootFolder + "01.wav";// + filename[0]; |
roryhand | 1:aac37edee302 | 841 | //printf("%s\n\r",Directory); |
roryhand | 1:aac37edee302 | 842 | //const char* DirectoryChar = Directory.c_str(); |
roryhand | 1:aac37edee302 | 843 | //Sound.FileInfo.WavFile = fopen(DirectoryChar,"rb"); |
roryhand | 1:aac37edee302 | 844 | Sound.FileInfo.WavFile = fopen("/sd/mydir/645Engine/Startup.wav","rb"); |
roryhand | 1:aac37edee302 | 845 | fseek(Sound.FileInfo.WavFile,20,SEEK_SET); |
roryhand | 1:aac37edee302 | 846 | fread(&Sound.FileInfo.FileFormat,sizeof(Sound.FileInfo.FileFormat),1,Sound.FileInfo.WavFile); |
roryhand | 1:aac37edee302 | 847 | printf("wav_format.sample_rate: %d\n\r",Sound.FileInfo.FileFormat.sample_rate); |
roryhand | 1:aac37edee302 | 848 | fread(&Sound.FileInfo.FileData,sizeof(Sound.FileInfo.FileData),1,Sound.FileInfo.WavFile); |
roryhand | 1:aac37edee302 | 849 | printf("wav_data.subchunk2_size: %d\n\r",Sound.FileInfo.FileData.subchunk2_size); |
roryhand | 1:aac37edee302 | 850 | Sound.FileInfo.slice_buf = ( char *)malloc(Sound.FileInfo.FileFormat.block_align); |
roryhand | 1:aac37edee302 | 851 | 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 | 852 | Sound.FileInfo.num_slices = Sound.FileInfo.FileData.subchunk2_size/Sound.FileInfo.FileFormat.block_align; |
roryhand | 1:aac37edee302 | 853 | printf("Number of Slices: %d\n\r",Sound.FileInfo.num_slices); |
roryhand | 1:aac37edee302 | 854 | return Sound; |
roryhand | 1:aac37edee302 | 855 | } |
roryhand | 1:aac37edee302 | 856 | |
roryhand | 1:aac37edee302 | 857 | |
roryhand | 0:e89d7a0bfa3b | 858 | classFade FadeDataInitialise(classFade FadeData) |
roryhand | 0:e89d7a0bfa3b | 859 | { |
roryhand | 1:aac37edee302 | 860 | FadeData.DecayFactor = 1.3; |
roryhand | 0:e89d7a0bfa3b | 861 | FadeData.FadeIteration = 1; |
roryhand | 0:e89d7a0bfa3b | 862 | //FadeData.Denom = 11025*FadeData.DecayFactor; |
roryhand | 0:e89d7a0bfa3b | 863 | FadeData.Denom = 11025*FadeData.DecayFactor; |
roryhand | 0:e89d7a0bfa3b | 864 | FadeData.Natural_Exp = 2.7183; |
roryhand | 0:e89d7a0bfa3b | 865 | FadeData.Length = 11025*FadeData.LengthSecs; |
roryhand | 0:e89d7a0bfa3b | 866 | //FadeData.Natural_Exp = 2.7; |
roryhand | 0:e89d7a0bfa3b | 867 | return FadeData; |
roryhand | 0:e89d7a0bfa3b | 868 | } |
roryhand | 0:e89d7a0bfa3b | 869 | |
roryhand | 0:e89d7a0bfa3b | 870 | //Playing Files Code |
roryhand | 0:e89d7a0bfa3b | 871 | /*float FadeIn(void) |
roryhand | 0:e89d7a0bfa3b | 872 | { |
roryhand | 0:e89d7a0bfa3b | 873 | powervalFadeIn = FadeIterationIn/denom; |
roryhand | 0:e89d7a0bfa3b | 874 | FadeCoeffFadeIn |
roryhand | 1:aac37edee302 | 875 | |
roryhand | 1:aac37edee302 | 876 | |
roryhand | 0:e89d7a0bfa3b | 877 | }*/ |
roryhand | 0:e89d7a0bfa3b | 878 | /*float FadeOut(void) |
roryhand | 0:e89d7a0bfa3b | 879 | { |
roryhand | 0:e89d7a0bfa3b | 880 | powerval = -FadeIteration/denom; |
roryhand | 0:e89d7a0bfa3b | 881 | FadeCoeff = pow(natural_exp,powerval); |
roryhand | 1:aac37edee302 | 882 | FadeIteration = FadeIteration + 1; |
roryhand | 1:aac37edee302 | 883 | return FadeCoeff; |
roryhand | 1:aac37edee302 | 884 | |
roryhand | 0:e89d7a0bfa3b | 885 | }*/ |
roryhand | 0:e89d7a0bfa3b | 886 | |
roryhand | 0:e89d7a0bfa3b | 887 | |
roryhand | 0:e89d7a0bfa3b | 888 | void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo) |
roryhand | 0:e89d7a0bfa3b | 889 | { |
roryhand | 1:aac37edee302 | 890 | while(slice<FileInfo.num_slices) { |
roryhand | 1:aac37edee302 | 891 | fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,my_wav); |
roryhand | 1:aac37edee302 | 892 | data_sptr=(short *)FileInfo.slice_buf; // 16 bit samples |
roryhand | 1:aac37edee302 | 893 | for (channel=0; channel<FileInfo.FileFormat.num_channels; channel++) { |
roryhand | 1:aac37edee302 | 894 | if(flag1 == 1) { |
roryhand | 1:aac37edee302 | 895 | Buffer1[place_hold1] = data_sptr[channel]; |
roryhand | 1:aac37edee302 | 896 | place_hold1 = place_hold1 + 1; |
roryhand | 1:aac37edee302 | 897 | if(place_hold1 >= BufferLen) { |
roryhand | 1:aac37edee302 | 898 | while(1) { |
roryhand | 1:aac37edee302 | 899 | if(flag1 == 0) { |
roryhand | 0:e89d7a0bfa3b | 900 | |
roryhand | 1:aac37edee302 | 901 | break; |
roryhand | 0:e89d7a0bfa3b | 902 | } |
roryhand | 1:aac37edee302 | 903 | |
roryhand | 0:e89d7a0bfa3b | 904 | } |
roryhand | 1:aac37edee302 | 905 | } |
roryhand | 1:aac37edee302 | 906 | |
roryhand | 1:aac37edee302 | 907 | } else if(flag2 == 1) { |
roryhand | 1:aac37edee302 | 908 | Buffer2[place_hold2] = data_sptr[channel]; |
roryhand | 1:aac37edee302 | 909 | place_hold2 = place_hold2 + 1; |
roryhand | 1:aac37edee302 | 910 | if(place_hold2 >= BufferLen) { |
roryhand | 1:aac37edee302 | 911 | |
roryhand | 1:aac37edee302 | 912 | while(1) { |
roryhand | 1:aac37edee302 | 913 | if(flag2 == 0) { |
roryhand | 1:aac37edee302 | 914 | |
roryhand | 1:aac37edee302 | 915 | break; |
roryhand | 1:aac37edee302 | 916 | } |
roryhand | 0:e89d7a0bfa3b | 917 | } |
roryhand | 1:aac37edee302 | 918 | } |
roryhand | 0:e89d7a0bfa3b | 919 | } |
roryhand | 1:aac37edee302 | 920 | |
roryhand | 1:aac37edee302 | 921 | } |
roryhand | 1:aac37edee302 | 922 | slice = slice + 1; |
roryhand | 0:e89d7a0bfa3b | 923 | } |
roryhand | 0:e89d7a0bfa3b | 924 | } |
roryhand | 0:e89d7a0bfa3b | 925 | |
roryhand | 0:e89d7a0bfa3b | 926 | |
roryhand | 0:e89d7a0bfa3b | 927 | |
roryhand | 0:e89d7a0bfa3b | 928 | |
roryhand | 0:e89d7a0bfa3b | 929 | |
roryhand | 0:e89d7a0bfa3b | 930 | |
roryhand | 2:957d3b2afff4 | 931 | //void Play_WaveFileLoop(FILE * my_wav, WAV_FILE_STRUCT FileInfo)//(classSoundFile Sounds) |
roryhand | 9:dd9cae06b202 | 932 | |
roryhand | 9:dd9cae06b202 | 933 | void Play_WaveFileLoop(classSoundFile Sounds[], Notch_STRUCT NotchingSet) |
roryhand | 0:e89d7a0bfa3b | 934 | { |
roryhand | 1:aac37edee302 | 935 | while(1) { //might have to change this to a while(1) loop? |
roryhand | 1:aac37edee302 | 936 | //New format!! This should be (roughly) the way that this is done, with the new structures and classes |
roryhand | 1:aac37edee302 | 937 | ////fread(Sound[Notch].FileData.slice_buf,Sound[Notch].FileFormat.block_align,1,Sound[notch].WavFile); |
roryhand | 1:aac37edee302 | 938 | //data_sptr=(short *)Sound[Notch].FileInfo.slice_buf; |
roryhand | 1:aac37edee302 | 939 | |
roryhand | 0:e89d7a0bfa3b | 940 | |
roryhand | 2:957d3b2afff4 | 941 | if( slice == (Sounds[NotchingSet.Notch].FileInfo.num_slices-1) ) { |
roryhand | 1:aac37edee302 | 942 | slice = 0; |
roryhand | 2:957d3b2afff4 | 943 | fseek(Sounds[NotchingSet.Notch].FileInfo.WavFile,44,SEEK_SET); |
roryhand | 1:aac37edee302 | 944 | } |
roryhand | 1:aac37edee302 | 945 | |
roryhand | 2:957d3b2afff4 | 946 | //fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,my_wav); |
roryhand | 2:957d3b2afff4 | 947 | data_sptr=(short *)Sounds[NotchingSet.Notch].FileInfo.slice_buf; // 16 bit samples |
roryhand | 2:957d3b2afff4 | 948 | //make sure we are reading in the correct "notch" here |
roryhand | 2:957d3b2afff4 | 949 | |
roryhand | 2:957d3b2afff4 | 950 | if(FadeFlag) { |
roryhand | 2:957d3b2afff4 | 951 | if(feof(Sounds[NotchingSet.Notch].FileInfo.WavFile)) { |
roryhand | 2:957d3b2afff4 | 952 | fseek(Sounds[NotchingSet.Notch].FileInfo.WavFile,44,SEEK_SET); |
roryhand | 2:957d3b2afff4 | 953 | } |
roryhand | 3:6169aeeaeeb4 | 954 | |
roryhand | 2:957d3b2afff4 | 955 | //Read in data for current (i.e. now the previous notch, according to the index!!) |
roryhand | 2:957d3b2afff4 | 956 | //We might not need this code here...as its probably done somewhere else?? |
roryhand | 2:957d3b2afff4 | 957 | fread(Sounds[NotchingSet.Notch-1].FileInfo.slice_buf,Sounds[NotchingSet.Notch-1].FileInfo.FileFormat.block_align,1,Sounds[NotchingSet.Notch-1].FileInfo.WavFile); |
roryhand | 2:957d3b2afff4 | 958 | Sounds[NotchingSet.Notch-1].data_sptr = (short *)Sounds[NotchingSet.Notch-1].FileInfo.slice_buf; |
roryhand | 3:6169aeeaeeb4 | 959 | |
roryhand | 2:957d3b2afff4 | 960 | NotchFadeOut.FadeCoeff = NotchFadeOut.FadeOut();//compute new FadeOut Coeff value |
roryhand | 2:957d3b2afff4 | 961 | |
roryhand | 2:957d3b2afff4 | 962 | //Read in the notch transition file for transitioning up |
roryhand | 2:957d3b2afff4 | 963 | fread(Sounds[NotchingSet.NotchTransUp].FileInfo.slice_buf,Sounds[NotchingSet.NotchTransUp].FileInfo.FileFormat.block_align,1,Sounds[NotchingSet.NotchTransUp].FileInfo.WavFile); |
roryhand | 2:957d3b2afff4 | 964 | Sounds[NotchingSet.NotchTransUp].data_sptr = (short*)Sounds[NotchingSet.NotchTransUp].FileInfo.slice_buf; |
roryhand | 3:6169aeeaeeb4 | 965 | |
roryhand | 2:957d3b2afff4 | 966 | if( ((Sounds[NotchingSet.NotchTransUp].FileInfo.FileData.subchunk2_size) - NotchFadeIn.Length - 2*11025) <= (ftell(Sounds[NotchingSet.NotchTransUp].FileInfo.WavFile) + 44)) |
roryhand | 2:957d3b2afff4 | 967 | //if( (WavInfo_IdleN2.FileData.subchunk2_size)/8 <=ftell(IdleN2Wav) ) |
roryhand | 2:957d3b2afff4 | 968 | { |
roryhand | 2:957d3b2afff4 | 969 | |
roryhand | 2:957d3b2afff4 | 970 | NotchFadeIn.FadeCoeff = NotchFadeIn.FadeIn(); |
roryhand | 3:6169aeeaeeb4 | 971 | |
roryhand | 2:957d3b2afff4 | 972 | //Read In the next Notch |
roryhand | 2:957d3b2afff4 | 973 | fread(Sounds[NotchingSet.Notch].FileInfo.slice_buf,Sounds[NotchingSet.Notch].FileInfo.FileFormat.block_align,1,Sounds[NotchingSet.Notch].FileInfo.WavFile); |
roryhand | 2:957d3b2afff4 | 974 | Sounds[NotchingSet.Notch].data_sptr = (short *)Sounds[NotchingSet.Notch].FileInfo.slice_buf; |
roryhand | 2:957d3b2afff4 | 975 | |
roryhand | 2:957d3b2afff4 | 976 | if( (ftell(Sounds[NotchingSet.NotchTransUp].FileInfo.WavFile) + 44) >= Sounds[NotchingSet.NotchTransUp].FileInfo.FileData.subchunk2_size ) { |
roryhand | 3:6169aeeaeeb4 | 977 | |
roryhand | 2:957d3b2afff4 | 978 | //need to explicitly test if this notation/syntax works for pointers.... |
roryhand | 2:957d3b2afff4 | 979 | *Sounds[NotchingSet.Notch].data_sptr = *Sounds[NotchingSet.Notch].data_sptr*NotchFadeIn.FadeCoeff; |
roryhand | 2:957d3b2afff4 | 980 | } else { |
roryhand | 2:957d3b2afff4 | 981 | *Sounds[NotchingSet.Notch-1].data_sptr = *Sounds[NotchingSet.Notch - 1].data_sptr*NotchFadeOut.FadeCoeff + *Sounds[NotchingSet.NotchTransUp].data_sptr + *Sounds[NotchingSet.Notch].data_sptr*NotchFadeIn.FadeCoeff;// + *data_sptr_N2; |
roryhand | 2:957d3b2afff4 | 982 | } |
roryhand | 2:957d3b2afff4 | 983 | |
roryhand | 2:957d3b2afff4 | 984 | } else { |
roryhand | 2:957d3b2afff4 | 985 | *Sounds[NotchingSet.Notch-1].data_sptr = *Sounds[NotchingSet.Notch-1].data_sptr*NotchFadeOut.FadeCoeff + *Sounds[NotchingSet.NotchTransUp].data_sptr; |
roryhand | 2:957d3b2afff4 | 986 | } |
roryhand | 2:957d3b2afff4 | 987 | |
roryhand | 1:aac37edee302 | 988 | } |
roryhand | 1:aac37edee302 | 989 | |
roryhand | 1:aac37edee302 | 990 | |
roryhand | 3:6169aeeaeeb4 | 991 | /********************END OF DATA ASSIGNMENT SECTION*************************************************/ |
roryhand | 9:dd9cae06b202 | 992 | |
roryhand | 2:957d3b2afff4 | 993 | for (channel=0; channel<Sounds[NotchingSet.Notch].FileInfo.FileFormat.num_channels; channel++) { |
roryhand | 2:957d3b2afff4 | 994 | switch (Sounds[NotchingSet.Notch].FileInfo.FileFormat.sig_bps) { |
roryhand | 0:e89d7a0bfa3b | 995 | case 16: |
roryhand | 1:aac37edee302 | 996 | if(flag1 == 1) { |
roryhand | 2:957d3b2afff4 | 997 | Buffer1[place_hold1] = Sounds[NotchingSet.Notch].data_sptr[channel]; |
roryhand | 1:aac37edee302 | 998 | place_hold1 = place_hold1 + 1; |
roryhand | 1:aac37edee302 | 999 | if(place_hold1 >= BufferLen) { |
roryhand | 1:aac37edee302 | 1000 | while(1) { |
roryhand | 1:aac37edee302 | 1001 | if(flag1 == 0) { |
roryhand | 1:aac37edee302 | 1002 | break; |
roryhand | 1:aac37edee302 | 1003 | }//if(flag1 == 0) |
roryhand | 1:aac37edee302 | 1004 | |
roryhand | 1:aac37edee302 | 1005 | |
roryhand | 1:aac37edee302 | 1006 | }//while(1) |
roryhand | 1:aac37edee302 | 1007 | }//if(place_hold1 > = BufferLen) |
roryhand | 0:e89d7a0bfa3b | 1008 | |
roryhand | 1:aac37edee302 | 1009 | } else if(flag2 == 1) { |
roryhand | 2:957d3b2afff4 | 1010 | Buffer2[place_hold2] = Sounds[NotchingSet.Notch].data_sptr[channel]; |
roryhand | 1:aac37edee302 | 1011 | place_hold2 = place_hold2 + 1; |
roryhand | 1:aac37edee302 | 1012 | if(place_hold2 >= BufferLen) { |
roryhand | 1:aac37edee302 | 1013 | while(1) { |
roryhand | 1:aac37edee302 | 1014 | |
roryhand | 1:aac37edee302 | 1015 | if(flag2 == 0) { |
roryhand | 1:aac37edee302 | 1016 | break; |
roryhand | 1:aac37edee302 | 1017 | } |
roryhand | 1:aac37edee302 | 1018 | } |
roryhand | 0:e89d7a0bfa3b | 1019 | } |
roryhand | 1:aac37edee302 | 1020 | |
roryhand | 1:aac37edee302 | 1021 | } |
roryhand | 0:e89d7a0bfa3b | 1022 | } |
roryhand | 0:e89d7a0bfa3b | 1023 | } |
roryhand | 0:e89d7a0bfa3b | 1024 | slice = slice + 1; |
roryhand | 0:e89d7a0bfa3b | 1025 | } |
roryhand | 0:e89d7a0bfa3b | 1026 | } |
roryhand | 0:e89d7a0bfa3b | 1027 | |
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 | 9:dd9cae06b202 | 1034 |