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