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