old demo that i want to try in mbed studio
Dependencies: mbed SDFileSystem_Copy_of_mbed_version I2S
NotchingDemo.cpp@61:212d2db45c56, 2019-09-27 (annotated)
- Committer:
- roryhand
- Date:
- Fri Sep 27 22:06:43 2019 +0000
- Branch:
- LargeFile_Tests
- Revision:
- 61:212d2db45c56
- Parent:
- 60:36df2997de3d
- Child:
- 63:a8c1971d3d42
WIP - adding in the stuff to do switching between files
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
roryhand | 1:aac37edee302 | 1 | |
roryhand | 0:e89d7a0bfa3b | 2 | // 24/03/2018 update - I appear to be able to address the device and write something, as I am getting an ACK returned from the i2c write() function. |
roryhand | 0:e89d7a0bfa3b | 3 | //however if i use the write function with 4 arguments (as opposed to just 1 argument) then it doesnt work |
roryhand | 0:e89d7a0bfa3b | 4 | //only works with the 1 argument version!!! |
roryhand | 0:e89d7a0bfa3b | 5 | |
roryhand | 0:e89d7a0bfa3b | 6 | |
roryhand | 0:e89d7a0bfa3b | 7 | //THIS VERSION WORKED, CHANGED SOME THINGS, THEN CHANGED THEM BACK. NOW IT NO LONGER WORKS!!!! |
roryhand | 0:e89d7a0bfa3b | 8 | #include "mbed.h" |
roryhand | 0:e89d7a0bfa3b | 9 | #include "math.h" |
roryhand | 1:aac37edee302 | 10 | #include "I2S.h" |
roryhand | 1:aac37edee302 | 11 | #include "SDFileSystem.h" |
roryhand | 0:e89d7a0bfa3b | 12 | #include "wm8731_Config_setup.h" |
roryhand | 0:e89d7a0bfa3b | 13 | #include "WOLFSON_config_consts.h" |
roryhand | 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 | 61:212d2db45c56 | 105 | |
roryhand | 61:212d2db45c56 | 106 | int notch_start_pts [9]; |
roryhand | 61:212d2db45c56 | 107 | int notch_position_indicators[9]; |
roryhand | 61:212d2db45c56 | 108 | int notch_transitions_start_pts[15]; |
roryhand | 61:212d2db45c56 | 109 | int notch_transitions_position_indicators[15]; |
roryhand | 61:212d2db45c56 | 110 | int auxiliary_start_pts[5]; |
roryhand | 61:212d2db45c56 | 111 | int auxiliary_position_indicators[5]; |
roryhand | 58:a174e7a8f5f2 | 112 | classPositionIndicators() |
roryhand | 57:0c76b15cabaf | 113 | { |
roryhand | 57:0c76b15cabaf | 114 | notch1_start_pt = 44; |
roryhand | 57:0c76b15cabaf | 115 | notch2_start_pt = 220884+44; |
roryhand | 57:0c76b15cabaf | 116 | notch3_start_pt = notch2_start_pt+217698; |
roryhand | 57:0c76b15cabaf | 117 | notch4_start_pt = notch3_start_pt + 193060; |
roryhand | 57:0c76b15cabaf | 118 | notch5_start_pt = notch4_start_pt + 92010; |
roryhand | 57:0c76b15cabaf | 119 | notch6_start_pt = notch5_start_pt + 216642; |
roryhand | 57:0c76b15cabaf | 120 | notch7_start_pt = notch6_start_pt + 250316; |
roryhand | 61:212d2db45c56 | 121 | notch8_start_pt = notch7_start_pt + 150152; |
roryhand | 57:0c76b15cabaf | 122 | notch1_indicator = notch1_start_pt; |
roryhand | 57:0c76b15cabaf | 123 | notch2_indicator = notch2_start_pt; |
roryhand | 57:0c76b15cabaf | 124 | notch3_indicator = notch3_start_pt; |
roryhand | 57:0c76b15cabaf | 125 | notch4_indicator = notch4_start_pt; |
roryhand | 57:0c76b15cabaf | 126 | notch5_indicator = notch5_start_pt; |
roryhand | 57:0c76b15cabaf | 127 | notch6_indicator = notch6_start_pt; |
roryhand | 57:0c76b15cabaf | 128 | notch7_indicator = notch7_start_pt; |
roryhand | 57:0c76b15cabaf | 129 | notch8_indicator = notch8_start_pt; |
roryhand | 61:212d2db45c56 | 130 | notch_start_pts[1] = notch1_start_pt; |
roryhand | 61:212d2db45c56 | 131 | notch_start_pts[2] = notch2_start_pt; |
roryhand | 61:212d2db45c56 | 132 | notch_start_pts[3] = notch3_start_pt; |
roryhand | 61:212d2db45c56 | 133 | notch_start_pts[4] = notch4_start_pt; |
roryhand | 61:212d2db45c56 | 134 | notch_start_pts[5] = notch5_start_pt; |
roryhand | 61:212d2db45c56 | 135 | notch_start_pts[6] = notch6_start_pt; |
roryhand | 61:212d2db45c56 | 136 | notch_start_pts[7] = notch7_start_pt; |
roryhand | 61:212d2db45c56 | 137 | notch_start_pts[8] = notch8_start_pt; |
roryhand | 61:212d2db45c56 | 138 | notch_position_indicators[1] = notch1_indicator; |
roryhand | 61:212d2db45c56 | 139 | notch_position_indicators[2] = notch2_indicator; |
roryhand | 61:212d2db45c56 | 140 | notch_position_indicators[3] = notch3_indicator; |
roryhand | 61:212d2db45c56 | 141 | notch_position_indicators[4] = notch4_indicator; |
roryhand | 61:212d2db45c56 | 142 | notch_position_indicators[5] = notch5_indicator; |
roryhand | 61:212d2db45c56 | 143 | notch_position_indicators[6] = notch6_indicator; |
roryhand | 61:212d2db45c56 | 144 | notch_position_indicators[7] = notch7_indicator; |
roryhand | 61:212d2db45c56 | 145 | notch_position_indicators[8] = notch8_indicator; |
roryhand | 57:0c76b15cabaf | 146 | |
roryhand | 57:0c76b15cabaf | 147 | } |
roryhand | 57:0c76b15cabaf | 148 | }; |
roryhand | 57:0c76b15cabaf | 149 | |
roryhand | 54:606a83fff291 | 150 | int OneOff = 0; |
roryhand | 38:3b4c05af5f36 | 151 | int notch_flag = 0; |
roryhand | 0:e89d7a0bfa3b | 152 | int i = 0; |
roryhand | 0:e89d7a0bfa3b | 153 | int h = 0; |
roryhand | 0:e89d7a0bfa3b | 154 | short bufflen = 1; |
roryhand | 0:e89d7a0bfa3b | 155 | int buffer[1]; |
roryhand | 1:aac37edee302 | 156 | int AudioFormat, NumChannels, SampleRate, BitsPerSample ; |
roryhand | 0:e89d7a0bfa3b | 157 | char *slice_buf; |
roryhand | 0:e89d7a0bfa3b | 158 | short *data_sptr; |
roryhand | 0:e89d7a0bfa3b | 159 | short *data_sptr_horn; |
roryhand | 0:e89d7a0bfa3b | 160 | short *data_sptr_IdleN2; |
roryhand | 0:e89d7a0bfa3b | 161 | short * data_sptr_bell; |
roryhand | 0:e89d7a0bfa3b | 162 | short * data_sptr_N2; |
roryhand | 0:e89d7a0bfa3b | 163 | short * data_sptr_Flange; |
roryhand | 0:e89d7a0bfa3b | 164 | unsigned char *data_bptr; |
roryhand | 0:e89d7a0bfa3b | 165 | int *data_wptr; |
roryhand | 0:e89d7a0bfa3b | 166 | unsigned channel; |
roryhand | 45:0e8e1f2ec5d2 | 167 | long slice, slice1, slice2, slice3, num_slices; |
roryhand | 0:e89d7a0bfa3b | 168 | int verbosity = 0; |
roryhand | 0:e89d7a0bfa3b | 169 | int verbosity2 = 0; |
roryhand | 0:e89d7a0bfa3b | 170 | int verbosity3 = 0; |
roryhand | 0:e89d7a0bfa3b | 171 | int verbosity4 = 0; |
roryhand | 0:e89d7a0bfa3b | 172 | int verbosity5 = 0; |
roryhand | 0:e89d7a0bfa3b | 173 | int interrupt_condition = 1; |
roryhand | 0:e89d7a0bfa3b | 174 | int sampling_freq = 11025; |
roryhand | 0:e89d7a0bfa3b | 175 | const int BufferLen = 2000; |
roryhand | 0:e89d7a0bfa3b | 176 | short Buffer1[BufferLen]; |
roryhand | 0:e89d7a0bfa3b | 177 | short Buffer2[BufferLen]; |
roryhand | 0:e89d7a0bfa3b | 178 | short place_hold1 = 0; |
roryhand | 0:e89d7a0bfa3b | 179 | short place_hold2 = 0; |
roryhand | 0:e89d7a0bfa3b | 180 | |
roryhand | 3:6169aeeaeeb4 | 181 | |
roryhand | 3:6169aeeaeeb4 | 182 | string FOLDER; |
roryhand | 3:6169aeeaeeb4 | 183 | string RootFolder = "/sd/mydir/SoundDecoder/"; |
roryhand | 3:6169aeeaeeb4 | 184 | string filename[25]; |
roryhand | 3:6169aeeaeeb4 | 185 | classSoundFile Sound[22]; |
roryhand | 3:6169aeeaeeb4 | 186 | |
roryhand | 0:e89d7a0bfa3b | 187 | volatile int flag1 = 1; |
roryhand | 0:e89d7a0bfa3b | 188 | volatile int flag2 = 0; |
roryhand | 0:e89d7a0bfa3b | 189 | volatile int flag3 = 1; |
roryhand | 0:e89d7a0bfa3b | 190 | volatile int flag4 = 0; |
roryhand | 0:e89d7a0bfa3b | 191 | int FLAGBUFF1 = 0; |
roryhand | 0:e89d7a0bfa3b | 192 | int FLAGBUFF2 = 0; |
roryhand | 0:e89d7a0bfa3b | 193 | int BellFlag = 0; |
roryhand | 0:e89d7a0bfa3b | 194 | int BellFlag2 = 0; |
roryhand | 0:e89d7a0bfa3b | 195 | int FadeFlag = 0; |
roryhand | 54:606a83fff291 | 196 | int BlockFlag = 0; |
roryhand | 32:6ee488c97dcc | 197 | int FileSwitchFlag = 0; |
roryhand | 0:e89d7a0bfa3b | 198 | |
roryhand | 0:e89d7a0bfa3b | 199 | |
roryhand | 0:e89d7a0bfa3b | 200 | short value[1]; |
roryhand | 59:8e7c25a915a0 | 201 | |
roryhand | 0:e89d7a0bfa3b | 202 | //long long slice_value; |
roryhand | 0:e89d7a0bfa3b | 203 | int slice_value[1]; |
roryhand | 0:e89d7a0bfa3b | 204 | |
roryhand | 0:e89d7a0bfa3b | 205 | |
roryhand | 45:0e8e1f2ec5d2 | 206 | FILE *wavfile1; |
roryhand | 45:0e8e1f2ec5d2 | 207 | FILE *wavfile2; |
roryhand | 45:0e8e1f2ec5d2 | 208 | FILE *wavfile3; |
roryhand | 45:0e8e1f2ec5d2 | 209 | |
roryhand | 45:0e8e1f2ec5d2 | 210 | classSoundFile Sound1; |
roryhand | 45:0e8e1f2ec5d2 | 211 | classSoundFile Sound2; |
roryhand | 45:0e8e1f2ec5d2 | 212 | classSoundFile Sound3; |
roryhand | 45:0e8e1f2ec5d2 | 213 | |
roryhand | 0:e89d7a0bfa3b | 214 | |
roryhand | 0:e89d7a0bfa3b | 215 | void isr() |
roryhand | 0:e89d7a0bfa3b | 216 | { |
roryhand | 54:606a83fff291 | 217 | //timer_interrupt.start(); |
roryhand | 1:aac37edee302 | 218 | if(flag1 == 0) { |
roryhand | 0:e89d7a0bfa3b | 219 | value[0] = Buffer1[place_hold1]>>4; |
roryhand | 0:e89d7a0bfa3b | 220 | i2s.write(value,1);//Send next PWM value to amp |
roryhand | 0:e89d7a0bfa3b | 221 | place_hold1 = place_hold1 + 1; |
roryhand | 1:aac37edee302 | 222 | if( (place_hold1 >= BufferLen)) { |
roryhand | 0:e89d7a0bfa3b | 223 | led2 = !led2; |
roryhand | 0:e89d7a0bfa3b | 224 | place_hold1 = 0; |
roryhand | 0:e89d7a0bfa3b | 225 | place_hold2 = 0; |
roryhand | 0:e89d7a0bfa3b | 226 | flag1 = 1; |
roryhand | 0:e89d7a0bfa3b | 227 | flag2 = 0; |
roryhand | 1:aac37edee302 | 228 | } |
roryhand | 1:aac37edee302 | 229 | } else if(flag2 == 0) { |
roryhand | 0:e89d7a0bfa3b | 230 | value[0] = Buffer2[place_hold2]>>4; |
roryhand | 0:e89d7a0bfa3b | 231 | i2s.write(value,1);//Send next PWM value to amp |
roryhand | 0:e89d7a0bfa3b | 232 | place_hold2 = place_hold2 + 1; |
roryhand | 1:aac37edee302 | 233 | if( (place_hold2 >= BufferLen) ) { |
roryhand | 0:e89d7a0bfa3b | 234 | led2 = !led2; |
roryhand | 0:e89d7a0bfa3b | 235 | place_hold1 = 0; |
roryhand | 0:e89d7a0bfa3b | 236 | place_hold2 = 0; |
roryhand | 0:e89d7a0bfa3b | 237 | flag1 = 0; |
roryhand | 1:aac37edee302 | 238 | flag2 = 1; |
roryhand | 0:e89d7a0bfa3b | 239 | FLAGBUFF2 = 0; |
roryhand | 1:aac37edee302 | 240 | } |
roryhand | 0:e89d7a0bfa3b | 241 | } |
roryhand | 54:606a83fff291 | 242 | |
roryhand | 54:606a83fff291 | 243 | //timer_interrupt.stop(); |
roryhand | 54:606a83fff291 | 244 | |
roryhand | 0:e89d7a0bfa3b | 245 | } |
roryhand | 1:aac37edee302 | 246 | |
roryhand | 38:3b4c05af5f36 | 247 | |
roryhand | 38:3b4c05af5f36 | 248 | |
roryhand | 38:3b4c05af5f36 | 249 | |
roryhand | 38:3b4c05af5f36 | 250 | |
roryhand | 0:e89d7a0bfa3b | 251 | |
roryhand | 59:8e7c25a915a0 | 252 | |
roryhand | 59:8e7c25a915a0 | 253 | |
roryhand | 59:8e7c25a915a0 | 254 | |
roryhand | 59:8e7c25a915a0 | 255 | |
roryhand | 59:8e7c25a915a0 | 256 | |
roryhand | 3:6169aeeaeeb4 | 257 | |
roryhand | 3:6169aeeaeeb4 | 258 | |
roryhand | 3:6169aeeaeeb4 | 259 | |
roryhand | 3:6169aeeaeeb4 | 260 | |
roryhand | 3:6169aeeaeeb4 | 261 | |
roryhand | 3:6169aeeaeeb4 | 262 | //function prototypes |
roryhand | 45:0e8e1f2ec5d2 | 263 | classSoundFile ReadFileInfo(classSoundFile Sound, FILE * wav_file); |
roryhand | 3:6169aeeaeeb4 | 264 | classSoundFile LoadFileStream(classSoundFile FileInfo, string filename); |
roryhand | 3:6169aeeaeeb4 | 265 | void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo); |
roryhand | 32:6ee488c97dcc | 266 | void Play_WaveFileDual(FILE * my_wav, WAV_FILE_STRUCT FileInfo); |
roryhand | 59:8e7c25a915a0 | 267 | void Play_WaveFileLoop(classSoundFile Sound1, FILE* wavfile1,classPositionIndicators Positions); |
roryhand | 0:e89d7a0bfa3b | 268 | |
roryhand | 1:aac37edee302 | 269 | int main() |
roryhand | 1:aac37edee302 | 270 | { |
roryhand | 44:a9e84d333a6a | 271 | |
roryhand | 0:e89d7a0bfa3b | 272 | NotchUp.mode(PullUp); |
roryhand | 38:3b4c05af5f36 | 273 | NotchDown.mode(PullUp); |
roryhand | 0:e89d7a0bfa3b | 274 | |
roryhand | 0:e89d7a0bfa3b | 275 | pc.printf("Beginning of program\n"); |
roryhand | 32:6ee488c97dcc | 276 | |
roryhand | 13:8e93396a27c5 | 277 | |
roryhand | 13:8e93396a27c5 | 278 | |
roryhand | 4:55fbbb049bae | 279 | |
roryhand | 25:5336e1cf38d6 | 280 | printf("Do we even get to this stupid bloody point\n\r"); |
roryhand | 0:e89d7a0bfa3b | 281 | //Populate our class instances with some data (is there an implicit way to do this?) |
roryhand | 28:6b2353fad12d | 282 | |
roryhand | 1:aac37edee302 | 283 | |
roryhand | 3:6169aeeaeeb4 | 284 | printf("hello\n\r"); |
roryhand | 0:e89d7a0bfa3b | 285 | //Set up the wolfson Audio Codec board |
roryhand | 0:e89d7a0bfa3b | 286 | wm8731_Config_setup(); |
roryhand | 0:e89d7a0bfa3b | 287 | //i2s audio data transfer code?? |
roryhand | 0:e89d7a0bfa3b | 288 | i2s.stereomono(I2S_STEREO); |
roryhand | 0:e89d7a0bfa3b | 289 | i2s.masterslave(I2S_MASTER); |
roryhand | 0:e89d7a0bfa3b | 290 | led3 = 1; |
roryhand | 0:e89d7a0bfa3b | 291 | led2 = 1; |
roryhand | 45:0e8e1f2ec5d2 | 292 | printf("Hello i2s has started!"); |
roryhand | 30:4a8e80b243c4 | 293 | i2s.start(); |
roryhand | 0:e89d7a0bfa3b | 294 | sampletick.attach(&isr,1.0/sampling_freq); //1/16000 |
roryhand | 54:606a83fff291 | 295 | |
roryhand | 58:a174e7a8f5f2 | 296 | classPositionIndicators Positions; |
roryhand | 61:212d2db45c56 | 297 | slice1 = Positions.notch7_start_pt; |
roryhand | 60:36df2997de3d | 298 | FILE* wavfile1 = fopen("/sd/mydir/SoundDecoder_second/All_eight_notches.wav","rb"); |
roryhand | 60:36df2997de3d | 299 | //FILE* wavfile1 = fopen("/sd/mydir/SoundDecoder_second/01.wav","rb"); |
roryhand | 58:a174e7a8f5f2 | 300 | classSoundFile Sound1; |
roryhand | 58:a174e7a8f5f2 | 301 | Sound1 = ReadFileInfo(Sound1, wavfile1); |
roryhand | 61:212d2db45c56 | 302 | fseek(wavfile1,Positions.notch7_start_pt,SEEK_SET); |
roryhand | 20:9cc7d825c07b | 303 | printf("about to play wav file\n\r"); |
roryhand | 59:8e7c25a915a0 | 304 | Play_WaveFileLoop(Sound1,wavfile1,Positions); |
roryhand | 20:9cc7d825c07b | 305 | printf("finished playing Wav file\n\r"); |
roryhand | 54:606a83fff291 | 306 | |
roryhand | 54:606a83fff291 | 307 | |
roryhand | 31:0f8c3adf09c3 | 308 | timer_open.reset(); |
roryhand | 31:0f8c3adf09c3 | 309 | timer_open.start(); |
roryhand | 45:0e8e1f2ec5d2 | 310 | fclose(wavfile1); |
roryhand | 31:0f8c3adf09c3 | 311 | timer_open.stop(); |
roryhand | 31:0f8c3adf09c3 | 312 | printf("It took %d useconds to close file\n\r",timer_open.read_us()); |
roryhand | 54:606a83fff291 | 313 | |
roryhand | 54:606a83fff291 | 314 | |
roryhand | 54:606a83fff291 | 315 | |
roryhand | 54:606a83fff291 | 316 | |
roryhand | 9:dd9cae06b202 | 317 | /************************************PLAY WAV FILE LOOP*******************/ |
roryhand | 9:dd9cae06b202 | 318 | /************************************END OF PLAY WAV FILE LOOP*************/ |
roryhand | 13:8e93396a27c5 | 319 | |
roryhand | 13:8e93396a27c5 | 320 | |
roryhand | 1:aac37edee302 | 321 | i2s.stop(); |
roryhand | 0:e89d7a0bfa3b | 322 | |
roryhand | 0:e89d7a0bfa3b | 323 | } |
roryhand | 0:e89d7a0bfa3b | 324 | |
roryhand | 0:e89d7a0bfa3b | 325 | |
roryhand | 3:6169aeeaeeb4 | 326 | |
roryhand | 3:6169aeeaeeb4 | 327 | |
roryhand | 3:6169aeeaeeb4 | 328 | |
roryhand | 3:6169aeeaeeb4 | 329 | |
roryhand | 45:0e8e1f2ec5d2 | 330 | classSoundFile ReadFileInfo(classSoundFile Sound, FILE * wav_file) |
roryhand | 0:e89d7a0bfa3b | 331 | { |
roryhand | 0:e89d7a0bfa3b | 332 | fseek(wav_file,20,SEEK_SET); |
roryhand | 22:706e86dc0d45 | 333 | printf("We have just seeked through this file\n\r"); |
roryhand | 45:0e8e1f2ec5d2 | 334 | fread(&Sound.FileInfo.FileFormat,sizeof(Sound.FileInfo.FileFormat),1,wav_file); |
roryhand | 1:aac37edee302 | 335 | //printf("wav_format.sample_rate: %d\n\r",FileInfo.FileFormat.sample_rate); |
roryhand | 1:aac37edee302 | 336 | |
roryhand | 45:0e8e1f2ec5d2 | 337 | fread(&Sound.FileInfo.FileData,sizeof(Sound.FileInfo.FileData),1,wav_file); |
roryhand | 55:5a441d3b0d57 | 338 | printf("wav_data.subchunk2_size: %d\n\r",Sound.FileInfo.FileData.subchunk2_size); |
roryhand | 45:0e8e1f2ec5d2 | 339 | Sound.FileInfo.slice_buf = ( char *)malloc(Sound.FileInfo.FileFormat.block_align); |
roryhand | 59:8e7c25a915a0 | 340 | printf("Wav File Block Align (number of bytes per sample!!: %d\n\r", Sound.FileInfo.FileFormat.block_align); |
roryhand | 45:0e8e1f2ec5d2 | 341 | fread(Sound.FileInfo.slice_buf,Sound.FileInfo.FileFormat.block_align,1,wav_file); //This isnt actually required, its just a test |
roryhand | 45:0e8e1f2ec5d2 | 342 | Sound.FileInfo.num_slices = Sound.FileInfo.FileData.subchunk2_size/Sound.FileInfo.FileFormat.block_align; |
roryhand | 1:aac37edee302 | 343 | //printf("Number of Slices: %d\n\r",FileInfo.num_slices); |
roryhand | 45:0e8e1f2ec5d2 | 344 | return Sound; |
roryhand | 0:e89d7a0bfa3b | 345 | } |
roryhand | 1:aac37edee302 | 346 | |
roryhand | 1:aac37edee302 | 347 | |
roryhand | 1:aac37edee302 | 348 | |
roryhand | 1:aac37edee302 | 349 | |
roryhand | 1:aac37edee302 | 350 | |
roryhand | 0:e89d7a0bfa3b | 351 | |
roryhand | 0:e89d7a0bfa3b | 352 | void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo) |
roryhand | 0:e89d7a0bfa3b | 353 | { |
roryhand | 1:aac37edee302 | 354 | while(slice<FileInfo.num_slices) { |
roryhand | 1:aac37edee302 | 355 | fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,my_wav); |
roryhand | 1:aac37edee302 | 356 | data_sptr=(short *)FileInfo.slice_buf; // 16 bit samples |
roryhand | 1:aac37edee302 | 357 | for (channel=0; channel<FileInfo.FileFormat.num_channels; channel++) { |
roryhand | 1:aac37edee302 | 358 | if(flag1 == 1) { |
roryhand | 1:aac37edee302 | 359 | Buffer1[place_hold1] = data_sptr[channel]; |
roryhand | 1:aac37edee302 | 360 | place_hold1 = place_hold1 + 1; |
roryhand | 1:aac37edee302 | 361 | if(place_hold1 >= BufferLen) { |
roryhand | 1:aac37edee302 | 362 | while(1) { |
roryhand | 1:aac37edee302 | 363 | if(flag1 == 0) { |
roryhand | 0:e89d7a0bfa3b | 364 | |
roryhand | 1:aac37edee302 | 365 | break; |
roryhand | 0:e89d7a0bfa3b | 366 | } |
roryhand | 1:aac37edee302 | 367 | |
roryhand | 0:e89d7a0bfa3b | 368 | } |
roryhand | 1:aac37edee302 | 369 | } |
roryhand | 1:aac37edee302 | 370 | |
roryhand | 1:aac37edee302 | 371 | } else if(flag2 == 1) { |
roryhand | 1:aac37edee302 | 372 | Buffer2[place_hold2] = data_sptr[channel]; |
roryhand | 1:aac37edee302 | 373 | place_hold2 = place_hold2 + 1; |
roryhand | 1:aac37edee302 | 374 | if(place_hold2 >= BufferLen) { |
roryhand | 1:aac37edee302 | 375 | |
roryhand | 1:aac37edee302 | 376 | while(1) { |
roryhand | 1:aac37edee302 | 377 | if(flag2 == 0) { |
roryhand | 1:aac37edee302 | 378 | |
roryhand | 1:aac37edee302 | 379 | break; |
roryhand | 1:aac37edee302 | 380 | } |
roryhand | 0:e89d7a0bfa3b | 381 | } |
roryhand | 1:aac37edee302 | 382 | } |
roryhand | 0:e89d7a0bfa3b | 383 | } |
roryhand | 1:aac37edee302 | 384 | |
roryhand | 1:aac37edee302 | 385 | } |
roryhand | 1:aac37edee302 | 386 | slice = slice + 1; |
roryhand | 0:e89d7a0bfa3b | 387 | } |
roryhand | 0:e89d7a0bfa3b | 388 | } |
roryhand | 0:e89d7a0bfa3b | 389 | |
roryhand | 0:e89d7a0bfa3b | 390 | |
roryhand | 0:e89d7a0bfa3b | 391 | |
roryhand | 0:e89d7a0bfa3b | 392 | |
roryhand | 38:3b4c05af5f36 | 393 | //***************************************************************************// |
roryhand | 38:3b4c05af5f36 | 394 | |
roryhand | 38:3b4c05af5f36 | 395 | //**************************************************************************// |
roryhand | 38:3b4c05af5f36 | 396 | |
roryhand | 38:3b4c05af5f36 | 397 | |
roryhand | 38:3b4c05af5f36 | 398 | |
roryhand | 38:3b4c05af5f36 | 399 | |
roryhand | 38:3b4c05af5f36 | 400 | |
roryhand | 59:8e7c25a915a0 | 401 | |
roryhand | 44:a9e84d333a6a | 402 | |
roryhand | 57:0c76b15cabaf | 403 | void Play_WaveFileLoop(classSoundFile Sound1, FILE *wavfile1, classPositionIndicators Positions) |
roryhand | 45:0e8e1f2ec5d2 | 404 | { |
roryhand | 45:0e8e1f2ec5d2 | 405 | while(1) { //might have to change this to a while(1) loop? |
roryhand | 44:a9e84d333a6a | 406 | |
roryhand | 2:957d3b2afff4 | 407 | |
roryhand | 44:a9e84d333a6a | 408 | |
roryhand | 44:a9e84d333a6a | 409 | |
roryhand | 54:606a83fff291 | 410 | |
roryhand | 44:a9e84d333a6a | 411 | //Sound1======================================================================================= |
roryhand | 61:212d2db45c56 | 412 | if( slice1 == (Positions.notch8_start_pt) ) { |
roryhand | 61:212d2db45c56 | 413 | slice1 = Positions.notch7_start_pt; |
roryhand | 61:212d2db45c56 | 414 | fseek(wavfile1,Positions.notch7_start_pt,SEEK_SET); |
roryhand | 2:957d3b2afff4 | 415 | } |
roryhand | 57:0c76b15cabaf | 416 | |
roryhand | 44:a9e84d333a6a | 417 | fread(Sound1.FileInfo.slice_buf,Sound1.FileInfo.FileFormat.block_align,1,wavfile1); |
roryhand | 44:a9e84d333a6a | 418 | Sound1.data_sptr=(short *)Sound1.FileInfo.slice_buf; // 16 bit samples |
roryhand | 44:a9e84d333a6a | 419 | //============================================================================================= |
roryhand | 44:a9e84d333a6a | 420 | |
roryhand | 58:a174e7a8f5f2 | 421 | |
roryhand | 1:aac37edee302 | 422 | |
roryhand | 1:aac37edee302 | 423 | |
roryhand | 44:a9e84d333a6a | 424 | |
roryhand | 45:0e8e1f2ec5d2 | 425 | for (channel=0; channel<Sound1.FileInfo.FileFormat.num_channels; channel++) { |
roryhand | 45:0e8e1f2ec5d2 | 426 | switch (Sound1.FileInfo.FileFormat.sig_bps) { |
roryhand | 0:e89d7a0bfa3b | 427 | case 16: |
roryhand | 1:aac37edee302 | 428 | if(flag1 == 1) { |
roryhand | 45:0e8e1f2ec5d2 | 429 | Buffer1[place_hold1] = Sound1.data_sptr[channel]; |
roryhand | 1:aac37edee302 | 430 | place_hold1 = place_hold1 + 1; |
roryhand | 1:aac37edee302 | 431 | if(place_hold1 >= BufferLen) { |
roryhand | 1:aac37edee302 | 432 | while(1) { |
roryhand | 1:aac37edee302 | 433 | if(flag1 == 0) { |
roryhand | 1:aac37edee302 | 434 | break; |
roryhand | 1:aac37edee302 | 435 | }//if(flag1 == 0) |
roryhand | 1:aac37edee302 | 436 | |
roryhand | 1:aac37edee302 | 437 | |
roryhand | 1:aac37edee302 | 438 | }//while(1) |
roryhand | 1:aac37edee302 | 439 | }//if(place_hold1 > = BufferLen) |
roryhand | 0:e89d7a0bfa3b | 440 | |
roryhand | 1:aac37edee302 | 441 | } else if(flag2 == 1) { |
roryhand | 45:0e8e1f2ec5d2 | 442 | Buffer2[place_hold2] = Sound1.data_sptr[channel]; |
roryhand | 1:aac37edee302 | 443 | place_hold2 = place_hold2 + 1; |
roryhand | 1:aac37edee302 | 444 | if(place_hold2 >= BufferLen) { |
roryhand | 1:aac37edee302 | 445 | while(1) { |
roryhand | 1:aac37edee302 | 446 | |
roryhand | 1:aac37edee302 | 447 | if(flag2 == 0) { |
roryhand | 1:aac37edee302 | 448 | break; |
roryhand | 1:aac37edee302 | 449 | } |
roryhand | 1:aac37edee302 | 450 | } |
roryhand | 0:e89d7a0bfa3b | 451 | } |
roryhand | 1:aac37edee302 | 452 | |
roryhand | 1:aac37edee302 | 453 | } |
roryhand | 0:e89d7a0bfa3b | 454 | } |
roryhand | 0:e89d7a0bfa3b | 455 | } |
roryhand | 59:8e7c25a915a0 | 456 | 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 | 457 | slice2 = slice2 + 1; |
roryhand | 45:0e8e1f2ec5d2 | 458 | slice3 = slice3 + 1; |
roryhand | 0:e89d7a0bfa3b | 459 | } |
roryhand | 0:e89d7a0bfa3b | 460 | } |
roryhand | 0:e89d7a0bfa3b | 461 | |
roryhand | 0:e89d7a0bfa3b | 462 | |
roryhand | 0:e89d7a0bfa3b | 463 | |
roryhand | 0:e89d7a0bfa3b | 464 | |
roryhand | 0:e89d7a0bfa3b | 465 | |
roryhand | 0:e89d7a0bfa3b | 466 | |
roryhand | 59:8e7c25a915a0 | 467 | |
roryhand | 59:8e7c25a915a0 | 468 |