old demo that i want to try in mbed studio
Dependencies: mbed SDFileSystem_Copy_of_mbed_version I2S
NotchingDemo.cpp@60:36df2997de3d, 2019-09-27 (annotated)
- Committer:
- roryhand
- Date:
- Fri Sep 27 20:12:29 2019 +0000
- Branch:
- LargeFile_Tests
- Revision:
- 60:36df2997de3d
- Parent:
- 59:8e7c25a915a0
- Child:
- 61:212d2db45c56
WIP - MILESTONE - Seem to be able to loop round a "file" within a file.
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 | 1:aac37edee302 | 46 | typedef struct uFMT_STRUCT { |
roryhand | 1:aac37edee302 | 47 | short comp_code; |
roryhand | 1:aac37edee302 | 48 | short num_channels; |
roryhand | 1:aac37edee302 | 49 | unsigned sample_rate; |
roryhand | 1:aac37edee302 | 50 | unsigned avg_Bps; |
roryhand | 1:aac37edee302 | 51 | short block_align; |
roryhand | 1:aac37edee302 | 52 | short sig_bps; |
roryhand | 0:e89d7a0bfa3b | 53 | } FMT_STRUCT; |
roryhand | 0:e89d7a0bfa3b | 54 | |
roryhand | 1:aac37edee302 | 55 | typedef struct uNotch_STRUCT { |
roryhand | 1:aac37edee302 | 56 | short Notch; |
roryhand | 1:aac37edee302 | 57 | short NotchTransUp; |
roryhand | 1:aac37edee302 | 58 | short NotchTransDown; |
roryhand | 1:aac37edee302 | 59 | short NotchDirection; |
roryhand | 1:aac37edee302 | 60 | } Notch_STRUCT; |
roryhand | 1:aac37edee302 | 61 | |
roryhand | 0:e89d7a0bfa3b | 62 | typedef struct uDATA_STRUCT { |
roryhand | 1:aac37edee302 | 63 | unsigned subchunk2_ID; |
roryhand | 1:aac37edee302 | 64 | unsigned subchunk2_size; |
roryhand | 1:aac37edee302 | 65 | char * data_buf; |
roryhand | 1:aac37edee302 | 66 | } DATA_STRUCT; |
roryhand | 0:e89d7a0bfa3b | 67 | |
roryhand | 1:aac37edee302 | 68 | typedef struct uWAV_FILE_STRUCT { |
roryhand | 1:aac37edee302 | 69 | FILE *WavFile; |
roryhand | 1:aac37edee302 | 70 | int id_number; |
roryhand | 1:aac37edee302 | 71 | char *slice_buf; |
roryhand | 1:aac37edee302 | 72 | int num_slices; |
roryhand | 1:aac37edee302 | 73 | FMT_STRUCT FileFormat; |
roryhand | 1:aac37edee302 | 74 | DATA_STRUCT FileData; |
roryhand | 0:e89d7a0bfa3b | 75 | } WAV_FILE_STRUCT; |
roryhand | 0:e89d7a0bfa3b | 76 | |
roryhand | 0:e89d7a0bfa3b | 77 | /*typedef struct uWAV_FILE_STRUCT{ |
roryhand | 1:aac37edee302 | 78 | FILE* WavFile; |
roryhand | 1:aac37edee302 | 79 | |
roryhand | 1:aac37edee302 | 80 | |
roryhand | 0:e89d7a0bfa3b | 81 | }WAV_FILE_STRUCT;*/ |
roryhand | 59:8e7c25a915a0 | 82 | |
roryhand | 59:8e7c25a915a0 | 83 | |
roryhand | 59:8e7c25a915a0 | 84 | |
roryhand | 59:8e7c25a915a0 | 85 | |
roryhand | 59:8e7c25a915a0 | 86 | |
roryhand | 59:8e7c25a915a0 | 87 | class classSoundFile |
roryhand | 59:8e7c25a915a0 | 88 | { |
roryhand | 59:8e7c25a915a0 | 89 | public: |
roryhand | 59:8e7c25a915a0 | 90 | |
roryhand | 59:8e7c25a915a0 | 91 | //add a class constructor at some point in the future (perform tests in visual studio) |
roryhand | 59:8e7c25a915a0 | 92 | WAV_FILE_STRUCT FileInfo; |
roryhand | 59:8e7c25a915a0 | 93 | short * data_sptr; |
roryhand | 59:8e7c25a915a0 | 94 | string file_location; |
roryhand | 59:8e7c25a915a0 | 95 | //classSoundFile(string filename);//this is the constructor |
roryhand | 59:8e7c25a915a0 | 96 | //string filename; |
roryhand | 59:8e7c25a915a0 | 97 | }; |
roryhand | 58:a174e7a8f5f2 | 98 | class classPositionIndicators |
roryhand | 57:0c76b15cabaf | 99 | { |
roryhand | 57:0c76b15cabaf | 100 | public: |
roryhand | 57:0c76b15cabaf | 101 | int notch1_indicator, notch2_indicator, notch3_indicator, notch4_indicator; |
roryhand | 57:0c76b15cabaf | 102 | int notch5_indicator, notch6_indicator, notch7_indicator, notch8_indicator; |
roryhand | 57:0c76b15cabaf | 103 | int notch1_start_pt, notch2_start_pt, notch3_start_pt, notch4_start_pt; |
roryhand | 57:0c76b15cabaf | 104 | int notch5_start_pt, notch6_start_pt, notch7_start_pt, notch8_start_pt; |
roryhand | 58:a174e7a8f5f2 | 105 | classPositionIndicators() |
roryhand | 57:0c76b15cabaf | 106 | { |
roryhand | 57:0c76b15cabaf | 107 | notch1_start_pt = 44; |
roryhand | 57:0c76b15cabaf | 108 | notch2_start_pt = 220884+44; |
roryhand | 57:0c76b15cabaf | 109 | notch3_start_pt = notch2_start_pt+217698; |
roryhand | 57:0c76b15cabaf | 110 | notch4_start_pt = notch3_start_pt + 193060; |
roryhand | 57:0c76b15cabaf | 111 | notch5_start_pt = notch4_start_pt + 92010; |
roryhand | 57:0c76b15cabaf | 112 | notch6_start_pt = notch5_start_pt + 216642; |
roryhand | 57:0c76b15cabaf | 113 | notch7_start_pt = notch6_start_pt + 250316; |
roryhand | 57:0c76b15cabaf | 114 | notch8_start_pt = notch7_start_pt + 165084; |
roryhand | 57:0c76b15cabaf | 115 | notch1_indicator = notch1_start_pt; |
roryhand | 57:0c76b15cabaf | 116 | notch2_indicator = notch2_start_pt; |
roryhand | 57:0c76b15cabaf | 117 | notch3_indicator = notch3_start_pt; |
roryhand | 57:0c76b15cabaf | 118 | notch4_indicator = notch4_start_pt; |
roryhand | 57:0c76b15cabaf | 119 | notch5_indicator = notch5_start_pt; |
roryhand | 57:0c76b15cabaf | 120 | notch6_indicator = notch6_start_pt; |
roryhand | 57:0c76b15cabaf | 121 | notch7_indicator = notch7_start_pt; |
roryhand | 57:0c76b15cabaf | 122 | notch8_indicator = notch8_start_pt; |
roryhand | 57:0c76b15cabaf | 123 | |
roryhand | 57:0c76b15cabaf | 124 | } |
roryhand | 57:0c76b15cabaf | 125 | }; |
roryhand | 57:0c76b15cabaf | 126 | |
roryhand | 54:606a83fff291 | 127 | int OneOff = 0; |
roryhand | 38:3b4c05af5f36 | 128 | int notch_flag = 0; |
roryhand | 0:e89d7a0bfa3b | 129 | int i = 0; |
roryhand | 0:e89d7a0bfa3b | 130 | int h = 0; |
roryhand | 0:e89d7a0bfa3b | 131 | short bufflen = 1; |
roryhand | 0:e89d7a0bfa3b | 132 | int buffer[1]; |
roryhand | 1:aac37edee302 | 133 | int AudioFormat, NumChannels, SampleRate, BitsPerSample ; |
roryhand | 0:e89d7a0bfa3b | 134 | char *slice_buf; |
roryhand | 0:e89d7a0bfa3b | 135 | short *data_sptr; |
roryhand | 0:e89d7a0bfa3b | 136 | short *data_sptr_horn; |
roryhand | 0:e89d7a0bfa3b | 137 | short *data_sptr_IdleN2; |
roryhand | 0:e89d7a0bfa3b | 138 | short * data_sptr_bell; |
roryhand | 0:e89d7a0bfa3b | 139 | short * data_sptr_N2; |
roryhand | 0:e89d7a0bfa3b | 140 | short * data_sptr_Flange; |
roryhand | 0:e89d7a0bfa3b | 141 | unsigned char *data_bptr; |
roryhand | 0:e89d7a0bfa3b | 142 | int *data_wptr; |
roryhand | 0:e89d7a0bfa3b | 143 | unsigned channel; |
roryhand | 45:0e8e1f2ec5d2 | 144 | long slice, slice1, slice2, slice3, num_slices; |
roryhand | 0:e89d7a0bfa3b | 145 | int verbosity = 0; |
roryhand | 0:e89d7a0bfa3b | 146 | int verbosity2 = 0; |
roryhand | 0:e89d7a0bfa3b | 147 | int verbosity3 = 0; |
roryhand | 0:e89d7a0bfa3b | 148 | int verbosity4 = 0; |
roryhand | 0:e89d7a0bfa3b | 149 | int verbosity5 = 0; |
roryhand | 0:e89d7a0bfa3b | 150 | int interrupt_condition = 1; |
roryhand | 0:e89d7a0bfa3b | 151 | int sampling_freq = 11025; |
roryhand | 0:e89d7a0bfa3b | 152 | const int BufferLen = 2000; |
roryhand | 0:e89d7a0bfa3b | 153 | short Buffer1[BufferLen]; |
roryhand | 0:e89d7a0bfa3b | 154 | short Buffer2[BufferLen]; |
roryhand | 0:e89d7a0bfa3b | 155 | short place_hold1 = 0; |
roryhand | 0:e89d7a0bfa3b | 156 | short place_hold2 = 0; |
roryhand | 0:e89d7a0bfa3b | 157 | |
roryhand | 3:6169aeeaeeb4 | 158 | |
roryhand | 3:6169aeeaeeb4 | 159 | string FOLDER; |
roryhand | 3:6169aeeaeeb4 | 160 | string RootFolder = "/sd/mydir/SoundDecoder/"; |
roryhand | 3:6169aeeaeeb4 | 161 | string filename[25]; |
roryhand | 3:6169aeeaeeb4 | 162 | classSoundFile Sound[22]; |
roryhand | 3:6169aeeaeeb4 | 163 | |
roryhand | 0:e89d7a0bfa3b | 164 | volatile int flag1 = 1; |
roryhand | 0:e89d7a0bfa3b | 165 | volatile int flag2 = 0; |
roryhand | 0:e89d7a0bfa3b | 166 | volatile int flag3 = 1; |
roryhand | 0:e89d7a0bfa3b | 167 | volatile int flag4 = 0; |
roryhand | 0:e89d7a0bfa3b | 168 | int FLAGBUFF1 = 0; |
roryhand | 0:e89d7a0bfa3b | 169 | int FLAGBUFF2 = 0; |
roryhand | 0:e89d7a0bfa3b | 170 | int BellFlag = 0; |
roryhand | 0:e89d7a0bfa3b | 171 | int BellFlag2 = 0; |
roryhand | 0:e89d7a0bfa3b | 172 | int FadeFlag = 0; |
roryhand | 54:606a83fff291 | 173 | int BlockFlag = 0; |
roryhand | 32:6ee488c97dcc | 174 | int FileSwitchFlag = 0; |
roryhand | 0:e89d7a0bfa3b | 175 | |
roryhand | 0:e89d7a0bfa3b | 176 | |
roryhand | 0:e89d7a0bfa3b | 177 | short value[1]; |
roryhand | 59:8e7c25a915a0 | 178 | |
roryhand | 0:e89d7a0bfa3b | 179 | //long long slice_value; |
roryhand | 0:e89d7a0bfa3b | 180 | int slice_value[1]; |
roryhand | 0:e89d7a0bfa3b | 181 | |
roryhand | 0:e89d7a0bfa3b | 182 | |
roryhand | 45:0e8e1f2ec5d2 | 183 | FILE *wavfile1; |
roryhand | 45:0e8e1f2ec5d2 | 184 | FILE *wavfile2; |
roryhand | 45:0e8e1f2ec5d2 | 185 | FILE *wavfile3; |
roryhand | 45:0e8e1f2ec5d2 | 186 | |
roryhand | 45:0e8e1f2ec5d2 | 187 | classSoundFile Sound1; |
roryhand | 45:0e8e1f2ec5d2 | 188 | classSoundFile Sound2; |
roryhand | 45:0e8e1f2ec5d2 | 189 | classSoundFile Sound3; |
roryhand | 45:0e8e1f2ec5d2 | 190 | |
roryhand | 0:e89d7a0bfa3b | 191 | |
roryhand | 0:e89d7a0bfa3b | 192 | void isr() |
roryhand | 0:e89d7a0bfa3b | 193 | { |
roryhand | 54:606a83fff291 | 194 | //timer_interrupt.start(); |
roryhand | 1:aac37edee302 | 195 | if(flag1 == 0) { |
roryhand | 0:e89d7a0bfa3b | 196 | value[0] = Buffer1[place_hold1]>>4; |
roryhand | 0:e89d7a0bfa3b | 197 | i2s.write(value,1);//Send next PWM value to amp |
roryhand | 0:e89d7a0bfa3b | 198 | place_hold1 = place_hold1 + 1; |
roryhand | 1:aac37edee302 | 199 | if( (place_hold1 >= BufferLen)) { |
roryhand | 0:e89d7a0bfa3b | 200 | led2 = !led2; |
roryhand | 0:e89d7a0bfa3b | 201 | place_hold1 = 0; |
roryhand | 0:e89d7a0bfa3b | 202 | place_hold2 = 0; |
roryhand | 0:e89d7a0bfa3b | 203 | flag1 = 1; |
roryhand | 0:e89d7a0bfa3b | 204 | flag2 = 0; |
roryhand | 1:aac37edee302 | 205 | } |
roryhand | 1:aac37edee302 | 206 | } else if(flag2 == 0) { |
roryhand | 0:e89d7a0bfa3b | 207 | value[0] = Buffer2[place_hold2]>>4; |
roryhand | 0:e89d7a0bfa3b | 208 | i2s.write(value,1);//Send next PWM value to amp |
roryhand | 0:e89d7a0bfa3b | 209 | place_hold2 = place_hold2 + 1; |
roryhand | 1:aac37edee302 | 210 | if( (place_hold2 >= BufferLen) ) { |
roryhand | 0:e89d7a0bfa3b | 211 | led2 = !led2; |
roryhand | 0:e89d7a0bfa3b | 212 | place_hold1 = 0; |
roryhand | 0:e89d7a0bfa3b | 213 | place_hold2 = 0; |
roryhand | 0:e89d7a0bfa3b | 214 | flag1 = 0; |
roryhand | 1:aac37edee302 | 215 | flag2 = 1; |
roryhand | 0:e89d7a0bfa3b | 216 | FLAGBUFF2 = 0; |
roryhand | 1:aac37edee302 | 217 | } |
roryhand | 0:e89d7a0bfa3b | 218 | } |
roryhand | 54:606a83fff291 | 219 | |
roryhand | 54:606a83fff291 | 220 | //timer_interrupt.stop(); |
roryhand | 54:606a83fff291 | 221 | |
roryhand | 0:e89d7a0bfa3b | 222 | } |
roryhand | 1:aac37edee302 | 223 | |
roryhand | 38:3b4c05af5f36 | 224 | |
roryhand | 38:3b4c05af5f36 | 225 | |
roryhand | 38:3b4c05af5f36 | 226 | |
roryhand | 38:3b4c05af5f36 | 227 | |
roryhand | 0:e89d7a0bfa3b | 228 | |
roryhand | 59:8e7c25a915a0 | 229 | |
roryhand | 59:8e7c25a915a0 | 230 | |
roryhand | 59:8e7c25a915a0 | 231 | |
roryhand | 59:8e7c25a915a0 | 232 | |
roryhand | 59:8e7c25a915a0 | 233 | |
roryhand | 3:6169aeeaeeb4 | 234 | |
roryhand | 3:6169aeeaeeb4 | 235 | |
roryhand | 3:6169aeeaeeb4 | 236 | |
roryhand | 3:6169aeeaeeb4 | 237 | |
roryhand | 3:6169aeeaeeb4 | 238 | |
roryhand | 3:6169aeeaeeb4 | 239 | //function prototypes |
roryhand | 45:0e8e1f2ec5d2 | 240 | classSoundFile ReadFileInfo(classSoundFile Sound, FILE * wav_file); |
roryhand | 3:6169aeeaeeb4 | 241 | classSoundFile LoadFileStream(classSoundFile FileInfo, string filename); |
roryhand | 3:6169aeeaeeb4 | 242 | void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo); |
roryhand | 32:6ee488c97dcc | 243 | void Play_WaveFileDual(FILE * my_wav, WAV_FILE_STRUCT FileInfo); |
roryhand | 59:8e7c25a915a0 | 244 | void Play_WaveFileLoop(classSoundFile Sound1, FILE* wavfile1,classPositionIndicators Positions); |
roryhand | 0:e89d7a0bfa3b | 245 | |
roryhand | 1:aac37edee302 | 246 | int main() |
roryhand | 1:aac37edee302 | 247 | { |
roryhand | 44:a9e84d333a6a | 248 | |
roryhand | 0:e89d7a0bfa3b | 249 | NotchUp.mode(PullUp); |
roryhand | 38:3b4c05af5f36 | 250 | NotchDown.mode(PullUp); |
roryhand | 0:e89d7a0bfa3b | 251 | |
roryhand | 0:e89d7a0bfa3b | 252 | pc.printf("Beginning of program\n"); |
roryhand | 32:6ee488c97dcc | 253 | |
roryhand | 13:8e93396a27c5 | 254 | |
roryhand | 13:8e93396a27c5 | 255 | |
roryhand | 4:55fbbb049bae | 256 | |
roryhand | 25:5336e1cf38d6 | 257 | printf("Do we even get to this stupid bloody point\n\r"); |
roryhand | 0:e89d7a0bfa3b | 258 | //Populate our class instances with some data (is there an implicit way to do this?) |
roryhand | 28:6b2353fad12d | 259 | |
roryhand | 1:aac37edee302 | 260 | |
roryhand | 3:6169aeeaeeb4 | 261 | printf("hello\n\r"); |
roryhand | 0:e89d7a0bfa3b | 262 | //Set up the wolfson Audio Codec board |
roryhand | 0:e89d7a0bfa3b | 263 | wm8731_Config_setup(); |
roryhand | 0:e89d7a0bfa3b | 264 | //i2s audio data transfer code?? |
roryhand | 0:e89d7a0bfa3b | 265 | i2s.stereomono(I2S_STEREO); |
roryhand | 0:e89d7a0bfa3b | 266 | i2s.masterslave(I2S_MASTER); |
roryhand | 0:e89d7a0bfa3b | 267 | led3 = 1; |
roryhand | 0:e89d7a0bfa3b | 268 | led2 = 1; |
roryhand | 45:0e8e1f2ec5d2 | 269 | printf("Hello i2s has started!"); |
roryhand | 30:4a8e80b243c4 | 270 | i2s.start(); |
roryhand | 0:e89d7a0bfa3b | 271 | sampletick.attach(&isr,1.0/sampling_freq); //1/16000 |
roryhand | 54:606a83fff291 | 272 | |
roryhand | 58:a174e7a8f5f2 | 273 | classPositionIndicators Positions; |
roryhand | 60:36df2997de3d | 274 | slice1 = Positions.notch2_start_pt; |
roryhand | 60:36df2997de3d | 275 | FILE* wavfile1 = fopen("/sd/mydir/SoundDecoder_second/All_eight_notches.wav","rb"); |
roryhand | 60:36df2997de3d | 276 | //FILE* wavfile1 = fopen("/sd/mydir/SoundDecoder_second/01.wav","rb"); |
roryhand | 58:a174e7a8f5f2 | 277 | classSoundFile Sound1; |
roryhand | 58:a174e7a8f5f2 | 278 | Sound1 = ReadFileInfo(Sound1, wavfile1); |
roryhand | 60:36df2997de3d | 279 | fseek(wavfile1,Positions.notch2_start_pt,SEEK_SET); |
roryhand | 20:9cc7d825c07b | 280 | printf("about to play wav file\n\r"); |
roryhand | 59:8e7c25a915a0 | 281 | Play_WaveFileLoop(Sound1,wavfile1,Positions); |
roryhand | 20:9cc7d825c07b | 282 | printf("finished playing Wav file\n\r"); |
roryhand | 54:606a83fff291 | 283 | |
roryhand | 54:606a83fff291 | 284 | |
roryhand | 31:0f8c3adf09c3 | 285 | timer_open.reset(); |
roryhand | 31:0f8c3adf09c3 | 286 | timer_open.start(); |
roryhand | 45:0e8e1f2ec5d2 | 287 | fclose(wavfile1); |
roryhand | 31:0f8c3adf09c3 | 288 | timer_open.stop(); |
roryhand | 31:0f8c3adf09c3 | 289 | printf("It took %d useconds to close file\n\r",timer_open.read_us()); |
roryhand | 54:606a83fff291 | 290 | |
roryhand | 54:606a83fff291 | 291 | |
roryhand | 54:606a83fff291 | 292 | |
roryhand | 54:606a83fff291 | 293 | |
roryhand | 9:dd9cae06b202 | 294 | /************************************PLAY WAV FILE LOOP*******************/ |
roryhand | 9:dd9cae06b202 | 295 | /************************************END OF PLAY WAV FILE LOOP*************/ |
roryhand | 13:8e93396a27c5 | 296 | |
roryhand | 13:8e93396a27c5 | 297 | |
roryhand | 1:aac37edee302 | 298 | i2s.stop(); |
roryhand | 0:e89d7a0bfa3b | 299 | |
roryhand | 0:e89d7a0bfa3b | 300 | } |
roryhand | 0:e89d7a0bfa3b | 301 | |
roryhand | 0:e89d7a0bfa3b | 302 | |
roryhand | 3:6169aeeaeeb4 | 303 | |
roryhand | 3:6169aeeaeeb4 | 304 | |
roryhand | 3:6169aeeaeeb4 | 305 | |
roryhand | 3:6169aeeaeeb4 | 306 | |
roryhand | 45:0e8e1f2ec5d2 | 307 | classSoundFile ReadFileInfo(classSoundFile Sound, FILE * wav_file) |
roryhand | 0:e89d7a0bfa3b | 308 | { |
roryhand | 0:e89d7a0bfa3b | 309 | fseek(wav_file,20,SEEK_SET); |
roryhand | 22:706e86dc0d45 | 310 | printf("We have just seeked through this file\n\r"); |
roryhand | 45:0e8e1f2ec5d2 | 311 | fread(&Sound.FileInfo.FileFormat,sizeof(Sound.FileInfo.FileFormat),1,wav_file); |
roryhand | 1:aac37edee302 | 312 | //printf("wav_format.sample_rate: %d\n\r",FileInfo.FileFormat.sample_rate); |
roryhand | 1:aac37edee302 | 313 | |
roryhand | 45:0e8e1f2ec5d2 | 314 | fread(&Sound.FileInfo.FileData,sizeof(Sound.FileInfo.FileData),1,wav_file); |
roryhand | 55:5a441d3b0d57 | 315 | printf("wav_data.subchunk2_size: %d\n\r",Sound.FileInfo.FileData.subchunk2_size); |
roryhand | 45:0e8e1f2ec5d2 | 316 | Sound.FileInfo.slice_buf = ( char *)malloc(Sound.FileInfo.FileFormat.block_align); |
roryhand | 59:8e7c25a915a0 | 317 | printf("Wav File Block Align (number of bytes per sample!!: %d\n\r", Sound.FileInfo.FileFormat.block_align); |
roryhand | 45:0e8e1f2ec5d2 | 318 | fread(Sound.FileInfo.slice_buf,Sound.FileInfo.FileFormat.block_align,1,wav_file); //This isnt actually required, its just a test |
roryhand | 45:0e8e1f2ec5d2 | 319 | Sound.FileInfo.num_slices = Sound.FileInfo.FileData.subchunk2_size/Sound.FileInfo.FileFormat.block_align; |
roryhand | 1:aac37edee302 | 320 | //printf("Number of Slices: %d\n\r",FileInfo.num_slices); |
roryhand | 45:0e8e1f2ec5d2 | 321 | return Sound; |
roryhand | 0:e89d7a0bfa3b | 322 | } |
roryhand | 1:aac37edee302 | 323 | |
roryhand | 1:aac37edee302 | 324 | |
roryhand | 1:aac37edee302 | 325 | |
roryhand | 1:aac37edee302 | 326 | |
roryhand | 1:aac37edee302 | 327 | |
roryhand | 0:e89d7a0bfa3b | 328 | |
roryhand | 0:e89d7a0bfa3b | 329 | void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo) |
roryhand | 0:e89d7a0bfa3b | 330 | { |
roryhand | 1:aac37edee302 | 331 | while(slice<FileInfo.num_slices) { |
roryhand | 1:aac37edee302 | 332 | fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,my_wav); |
roryhand | 1:aac37edee302 | 333 | data_sptr=(short *)FileInfo.slice_buf; // 16 bit samples |
roryhand | 1:aac37edee302 | 334 | for (channel=0; channel<FileInfo.FileFormat.num_channels; channel++) { |
roryhand | 1:aac37edee302 | 335 | if(flag1 == 1) { |
roryhand | 1:aac37edee302 | 336 | Buffer1[place_hold1] = data_sptr[channel]; |
roryhand | 1:aac37edee302 | 337 | place_hold1 = place_hold1 + 1; |
roryhand | 1:aac37edee302 | 338 | if(place_hold1 >= BufferLen) { |
roryhand | 1:aac37edee302 | 339 | while(1) { |
roryhand | 1:aac37edee302 | 340 | if(flag1 == 0) { |
roryhand | 0:e89d7a0bfa3b | 341 | |
roryhand | 1:aac37edee302 | 342 | break; |
roryhand | 0:e89d7a0bfa3b | 343 | } |
roryhand | 1:aac37edee302 | 344 | |
roryhand | 0:e89d7a0bfa3b | 345 | } |
roryhand | 1:aac37edee302 | 346 | } |
roryhand | 1:aac37edee302 | 347 | |
roryhand | 1:aac37edee302 | 348 | } else if(flag2 == 1) { |
roryhand | 1:aac37edee302 | 349 | Buffer2[place_hold2] = data_sptr[channel]; |
roryhand | 1:aac37edee302 | 350 | place_hold2 = place_hold2 + 1; |
roryhand | 1:aac37edee302 | 351 | if(place_hold2 >= BufferLen) { |
roryhand | 1:aac37edee302 | 352 | |
roryhand | 1:aac37edee302 | 353 | while(1) { |
roryhand | 1:aac37edee302 | 354 | if(flag2 == 0) { |
roryhand | 1:aac37edee302 | 355 | |
roryhand | 1:aac37edee302 | 356 | break; |
roryhand | 1:aac37edee302 | 357 | } |
roryhand | 0:e89d7a0bfa3b | 358 | } |
roryhand | 1:aac37edee302 | 359 | } |
roryhand | 0:e89d7a0bfa3b | 360 | } |
roryhand | 1:aac37edee302 | 361 | |
roryhand | 1:aac37edee302 | 362 | } |
roryhand | 1:aac37edee302 | 363 | slice = slice + 1; |
roryhand | 0:e89d7a0bfa3b | 364 | } |
roryhand | 0:e89d7a0bfa3b | 365 | } |
roryhand | 0:e89d7a0bfa3b | 366 | |
roryhand | 0:e89d7a0bfa3b | 367 | |
roryhand | 0:e89d7a0bfa3b | 368 | |
roryhand | 0:e89d7a0bfa3b | 369 | |
roryhand | 38:3b4c05af5f36 | 370 | //***************************************************************************// |
roryhand | 38:3b4c05af5f36 | 371 | |
roryhand | 38:3b4c05af5f36 | 372 | //**************************************************************************// |
roryhand | 38:3b4c05af5f36 | 373 | |
roryhand | 38:3b4c05af5f36 | 374 | |
roryhand | 38:3b4c05af5f36 | 375 | |
roryhand | 38:3b4c05af5f36 | 376 | |
roryhand | 38:3b4c05af5f36 | 377 | |
roryhand | 59:8e7c25a915a0 | 378 | |
roryhand | 44:a9e84d333a6a | 379 | |
roryhand | 57:0c76b15cabaf | 380 | void Play_WaveFileLoop(classSoundFile Sound1, FILE *wavfile1, classPositionIndicators Positions) |
roryhand | 45:0e8e1f2ec5d2 | 381 | { |
roryhand | 45:0e8e1f2ec5d2 | 382 | while(1) { //might have to change this to a while(1) loop? |
roryhand | 44:a9e84d333a6a | 383 | |
roryhand | 2:957d3b2afff4 | 384 | |
roryhand | 44:a9e84d333a6a | 385 | |
roryhand | 44:a9e84d333a6a | 386 | |
roryhand | 54:606a83fff291 | 387 | |
roryhand | 44:a9e84d333a6a | 388 | //Sound1======================================================================================= |
roryhand | 60:36df2997de3d | 389 | if( slice1 == (Positions.notch3_start_pt) ) { |
roryhand | 60:36df2997de3d | 390 | slice1 = Positions.notch2_start_pt; |
roryhand | 60:36df2997de3d | 391 | fseek(wavfile1,Positions.notch2_start_pt,SEEK_SET); |
roryhand | 2:957d3b2afff4 | 392 | } |
roryhand | 57:0c76b15cabaf | 393 | |
roryhand | 44:a9e84d333a6a | 394 | fread(Sound1.FileInfo.slice_buf,Sound1.FileInfo.FileFormat.block_align,1,wavfile1); |
roryhand | 44:a9e84d333a6a | 395 | Sound1.data_sptr=(short *)Sound1.FileInfo.slice_buf; // 16 bit samples |
roryhand | 44:a9e84d333a6a | 396 | //============================================================================================= |
roryhand | 44:a9e84d333a6a | 397 | |
roryhand | 58:a174e7a8f5f2 | 398 | |
roryhand | 1:aac37edee302 | 399 | |
roryhand | 1:aac37edee302 | 400 | |
roryhand | 44:a9e84d333a6a | 401 | |
roryhand | 45:0e8e1f2ec5d2 | 402 | for (channel=0; channel<Sound1.FileInfo.FileFormat.num_channels; channel++) { |
roryhand | 45:0e8e1f2ec5d2 | 403 | switch (Sound1.FileInfo.FileFormat.sig_bps) { |
roryhand | 0:e89d7a0bfa3b | 404 | case 16: |
roryhand | 1:aac37edee302 | 405 | if(flag1 == 1) { |
roryhand | 45:0e8e1f2ec5d2 | 406 | Buffer1[place_hold1] = Sound1.data_sptr[channel]; |
roryhand | 1:aac37edee302 | 407 | place_hold1 = place_hold1 + 1; |
roryhand | 1:aac37edee302 | 408 | if(place_hold1 >= BufferLen) { |
roryhand | 1:aac37edee302 | 409 | while(1) { |
roryhand | 1:aac37edee302 | 410 | if(flag1 == 0) { |
roryhand | 1:aac37edee302 | 411 | break; |
roryhand | 1:aac37edee302 | 412 | }//if(flag1 == 0) |
roryhand | 1:aac37edee302 | 413 | |
roryhand | 1:aac37edee302 | 414 | |
roryhand | 1:aac37edee302 | 415 | }//while(1) |
roryhand | 1:aac37edee302 | 416 | }//if(place_hold1 > = BufferLen) |
roryhand | 0:e89d7a0bfa3b | 417 | |
roryhand | 1:aac37edee302 | 418 | } else if(flag2 == 1) { |
roryhand | 45:0e8e1f2ec5d2 | 419 | Buffer2[place_hold2] = Sound1.data_sptr[channel]; |
roryhand | 1:aac37edee302 | 420 | place_hold2 = place_hold2 + 1; |
roryhand | 1:aac37edee302 | 421 | if(place_hold2 >= BufferLen) { |
roryhand | 1:aac37edee302 | 422 | while(1) { |
roryhand | 1:aac37edee302 | 423 | |
roryhand | 1:aac37edee302 | 424 | if(flag2 == 0) { |
roryhand | 1:aac37edee302 | 425 | break; |
roryhand | 1:aac37edee302 | 426 | } |
roryhand | 1:aac37edee302 | 427 | } |
roryhand | 0:e89d7a0bfa3b | 428 | } |
roryhand | 1:aac37edee302 | 429 | |
roryhand | 1:aac37edee302 | 430 | } |
roryhand | 0:e89d7a0bfa3b | 431 | } |
roryhand | 0:e89d7a0bfa3b | 432 | } |
roryhand | 59:8e7c25a915a0 | 433 | slice1 = slice1 + 2;//increment up by the number of bytes per Audio data sample! Makes sense it is 2 bytes, as this is 16-bit data. |
roryhand | 45:0e8e1f2ec5d2 | 434 | slice2 = slice2 + 1; |
roryhand | 45:0e8e1f2ec5d2 | 435 | slice3 = slice3 + 1; |
roryhand | 0:e89d7a0bfa3b | 436 | } |
roryhand | 0:e89d7a0bfa3b | 437 | } |
roryhand | 0:e89d7a0bfa3b | 438 | |
roryhand | 0:e89d7a0bfa3b | 439 | |
roryhand | 0:e89d7a0bfa3b | 440 | |
roryhand | 0:e89d7a0bfa3b | 441 | |
roryhand | 0:e89d7a0bfa3b | 442 | |
roryhand | 0:e89d7a0bfa3b | 443 | |
roryhand | 59:8e7c25a915a0 | 444 | |
roryhand | 59:8e7c25a915a0 | 445 |