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