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