old demo that i want to try in mbed studio

Dependencies:   mbed SDFileSystem_Copy_of_mbed_version I2S

Committer:
roryhand
Date:
Sun Sep 29 19:51:14 2019 +0000
Branch:
LargeFile_Tests
Revision:
63:a8c1971d3d42
Parent:
61:212d2db45c56
Child:
64:6061ffe25985
WIP - Have now added various new elements to classPositionIndicators

Who changed what in which revision?

UserRevisionLine numberNew 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 63:a8c1971d3d42 105 int N1N2_start_pt, N2N3_start_pt, N3N4_start_pt, N4N5_start_pt, N5N6_start_pt;
roryhand 63:a8c1971d3d42 106 int N6N7_start_pt, N7N8_start_pt, N8N7_start_pt, N7N6_start_pt, N6N5_start_pt;
roryhand 63:a8c1971d3d42 107 int N5N4_start_pt, N4N3_start_pt, N3N2_start_pt, N2N1_start_pt;
roryhand 63:a8c1971d3d42 108
roryhand 61:212d2db45c56 109 int notch_start_pts [9];
roryhand 61:212d2db45c56 110 int notch_position_indicators[9];
roryhand 61:212d2db45c56 111 int notch_transitions_start_pts[15];
roryhand 61:212d2db45c56 112 int notch_transitions_position_indicators[15];
roryhand 61:212d2db45c56 113 int auxiliary_start_pts[5];
roryhand 61:212d2db45c56 114 int auxiliary_position_indicators[5];
roryhand 58:a174e7a8f5f2 115 classPositionIndicators()
roryhand 57:0c76b15cabaf 116 {
roryhand 57:0c76b15cabaf 117 notch1_start_pt = 44;
roryhand 57:0c76b15cabaf 118 notch2_start_pt = 220884+44;
roryhand 57:0c76b15cabaf 119 notch3_start_pt = notch2_start_pt+217698;
roryhand 57:0c76b15cabaf 120 notch4_start_pt = notch3_start_pt + 193060;
roryhand 57:0c76b15cabaf 121 notch5_start_pt = notch4_start_pt + 92010;
roryhand 57:0c76b15cabaf 122 notch6_start_pt = notch5_start_pt + 216642;
roryhand 57:0c76b15cabaf 123 notch7_start_pt = notch6_start_pt + 250316;
roryhand 61:212d2db45c56 124 notch8_start_pt = notch7_start_pt + 150152;
roryhand 57:0c76b15cabaf 125 notch1_indicator = notch1_start_pt;
roryhand 57:0c76b15cabaf 126 notch2_indicator = notch2_start_pt;
roryhand 57:0c76b15cabaf 127 notch3_indicator = notch3_start_pt;
roryhand 57:0c76b15cabaf 128 notch4_indicator = notch4_start_pt;
roryhand 57:0c76b15cabaf 129 notch5_indicator = notch5_start_pt;
roryhand 57:0c76b15cabaf 130 notch6_indicator = notch6_start_pt;
roryhand 57:0c76b15cabaf 131 notch7_indicator = notch7_start_pt;
roryhand 57:0c76b15cabaf 132 notch8_indicator = notch8_start_pt;
roryhand 61:212d2db45c56 133 notch_start_pts[1] = notch1_start_pt;
roryhand 61:212d2db45c56 134 notch_start_pts[2] = notch2_start_pt;
roryhand 61:212d2db45c56 135 notch_start_pts[3] = notch3_start_pt;
roryhand 61:212d2db45c56 136 notch_start_pts[4] = notch4_start_pt;
roryhand 61:212d2db45c56 137 notch_start_pts[5] = notch5_start_pt;
roryhand 61:212d2db45c56 138 notch_start_pts[6] = notch6_start_pt;
roryhand 61:212d2db45c56 139 notch_start_pts[7] = notch7_start_pt;
roryhand 61:212d2db45c56 140 notch_start_pts[8] = notch8_start_pt;
roryhand 61:212d2db45c56 141 notch_position_indicators[1] = notch1_indicator;
roryhand 61:212d2db45c56 142 notch_position_indicators[2] = notch2_indicator;
roryhand 61:212d2db45c56 143 notch_position_indicators[3] = notch3_indicator;
roryhand 61:212d2db45c56 144 notch_position_indicators[4] = notch4_indicator;
roryhand 61:212d2db45c56 145 notch_position_indicators[5] = notch5_indicator;
roryhand 61:212d2db45c56 146 notch_position_indicators[6] = notch6_indicator;
roryhand 61:212d2db45c56 147 notch_position_indicators[7] = notch7_indicator;
roryhand 61:212d2db45c56 148 notch_position_indicators[8] = notch8_indicator;
roryhand 63:a8c1971d3d42 149
roryhand 63:a8c1971d3d42 150 N1N2_start_pt = 44;
roryhand 63:a8c1971d3d42 151 N2N3_start_pt = N1N2_start_pt + 73220;
roryhand 63:a8c1971d3d42 152 N3N4_start_pt = N2N3_start_pt + 78164;
roryhand 63:a8c1971d3d42 153 N4N5_start_pt = N3N4_start_pt + 59432;
roryhand 63:a8c1971d3d42 154 N5N6_start_pt = N4N5_start_pt + 64984;
roryhand 63:a8c1971d3d42 155 N6N7_start_pt = N5N6_start_pt + 59924;
roryhand 63:a8c1971d3d42 156 N7N8_start_pt = N6N7_start_pt + 97874;
roryhand 63:a8c1971d3d42 157 N8N7_start_pt = N7N8_start_pt + 63992;
roryhand 63:a8c1971d3d42 158 N7N6_start_pt = N8N7_start_pt + 44506;
roryhand 63:a8c1971d3d42 159 N6N5_start_pt = N7N6_start_pt + 55052;
roryhand 63:a8c1971d3d42 160 N5N4_start_pt = N6N5_start_pt + 37038;
roryhand 63:a8c1971d3d42 161 N4N3_start_pt = N5N4_start_pt + 49692;
roryhand 63:a8c1971d3d42 162 N3N2_start_pt = N4N3_start_pt + 44100;
roryhand 63:a8c1971d3d42 163 N2N1_start_pt = N3N2_start_pt + 58346;
roryhand 63:a8c1971d3d42 164
roryhand 63:a8c1971d3d42 165
roryhand 63:a8c1971d3d42 166 notch_transitions_start_pts[1] = N1N2_start_pt;
roryhand 63:a8c1971d3d42 167 notch_transitions_start_pts[2] = N2N3_start_pt;
roryhand 63:a8c1971d3d42 168 notch_transitions_start_pts[3] = N3N4_start_pt;
roryhand 63:a8c1971d3d42 169 notch_transitions_start_pts[4] = N4N5_start_pt;
roryhand 63:a8c1971d3d42 170 notch_transitions_start_pts[5] = N5N6_start_pt;
roryhand 63:a8c1971d3d42 171 notch_transitions_start_pts[6] = N6N7_start_pt;
roryhand 63:a8c1971d3d42 172 notch_transitions_start_pts[7] = N7N8_start_pt;
roryhand 63:a8c1971d3d42 173 notch_transitions_start_pts[8] = N8N7_start_pt;
roryhand 63:a8c1971d3d42 174 notch_transitions_start_pts[9] = N7N6_start_pt;
roryhand 63:a8c1971d3d42 175 notch_transitions_start_pts[10] = N6N5_start_pt;
roryhand 63:a8c1971d3d42 176 notch_transitions_start_pts[11] = N5N4_start_pt;
roryhand 63:a8c1971d3d42 177 notch_transitions_start_pts[12] = N4N3_start_pt;
roryhand 63:a8c1971d3d42 178 notch_transitions_start_pts[13] = N3N2_start_pt;
roryhand 63:a8c1971d3d42 179 notch_transitions_start_pts[14] = N2N1_start_pt;
roryhand 63:a8c1971d3d42 180
roryhand 63:a8c1971d3d42 181
roryhand 63:a8c1971d3d42 182 notch_transitions_position_indicators[1] = N1N2_start_pt;
roryhand 63:a8c1971d3d42 183 notch_transitions_position_indicators[2] = N2N3_start_pt;
roryhand 63:a8c1971d3d42 184 notch_transitions_position_indicators[3] = N3N4_start_pt;
roryhand 63:a8c1971d3d42 185 notch_transitions_position_indicators[4] = N4N5_start_pt;
roryhand 63:a8c1971d3d42 186 notch_transitions_position_indicators[5] = N5N6_start_pt;
roryhand 63:a8c1971d3d42 187 notch_transitions_position_indicators[6] = N6N7_start_pt;
roryhand 63:a8c1971d3d42 188 notch_transitions_position_indicators[7] = N7N8_start_pt;
roryhand 63:a8c1971d3d42 189 notch_transitions_position_indicators[8] = N8N7_start_pt;
roryhand 63:a8c1971d3d42 190 notch_transitions_position_indicators[9] = N7N6_start_pt;
roryhand 63:a8c1971d3d42 191 notch_transitions_position_indicators[10] = N6N5_start_pt;
roryhand 63:a8c1971d3d42 192 notch_transitions_position_indicators[11] = N5N4_start_pt;
roryhand 63:a8c1971d3d42 193 notch_transitions_position_indicators[12] = N4N3_start_pt;
roryhand 63:a8c1971d3d42 194 notch_transitions_position_indicators[13] = N3N2_start_pt;
roryhand 63:a8c1971d3d42 195 notch_transitions_position_indicators[14] = N2N1_start_pt;
roryhand 57:0c76b15cabaf 196 }
roryhand 57:0c76b15cabaf 197 };
roryhand 57:0c76b15cabaf 198
roryhand 54:606a83fff291 199 int OneOff = 0;
roryhand 38:3b4c05af5f36 200 int notch_flag = 0;
roryhand 0:e89d7a0bfa3b 201 int i = 0;
roryhand 0:e89d7a0bfa3b 202 int h = 0;
roryhand 0:e89d7a0bfa3b 203 short bufflen = 1;
roryhand 0:e89d7a0bfa3b 204 int buffer[1];
roryhand 1:aac37edee302 205 int AudioFormat, NumChannels, SampleRate, BitsPerSample ;
roryhand 0:e89d7a0bfa3b 206 char *slice_buf;
roryhand 0:e89d7a0bfa3b 207 short *data_sptr;
roryhand 0:e89d7a0bfa3b 208 short *data_sptr_horn;
roryhand 0:e89d7a0bfa3b 209 short *data_sptr_IdleN2;
roryhand 0:e89d7a0bfa3b 210 short * data_sptr_bell;
roryhand 0:e89d7a0bfa3b 211 short * data_sptr_N2;
roryhand 0:e89d7a0bfa3b 212 short * data_sptr_Flange;
roryhand 0:e89d7a0bfa3b 213 unsigned char *data_bptr;
roryhand 0:e89d7a0bfa3b 214 int *data_wptr;
roryhand 0:e89d7a0bfa3b 215 unsigned channel;
roryhand 45:0e8e1f2ec5d2 216 long slice, slice1, slice2, slice3, num_slices;
roryhand 0:e89d7a0bfa3b 217 int verbosity = 0;
roryhand 0:e89d7a0bfa3b 218 int verbosity2 = 0;
roryhand 0:e89d7a0bfa3b 219 int verbosity3 = 0;
roryhand 0:e89d7a0bfa3b 220 int verbosity4 = 0;
roryhand 0:e89d7a0bfa3b 221 int verbosity5 = 0;
roryhand 0:e89d7a0bfa3b 222 int interrupt_condition = 1;
roryhand 0:e89d7a0bfa3b 223 int sampling_freq = 11025;
roryhand 0:e89d7a0bfa3b 224 const int BufferLen = 2000;
roryhand 0:e89d7a0bfa3b 225 short Buffer1[BufferLen];
roryhand 0:e89d7a0bfa3b 226 short Buffer2[BufferLen];
roryhand 0:e89d7a0bfa3b 227 short place_hold1 = 0;
roryhand 0:e89d7a0bfa3b 228 short place_hold2 = 0;
roryhand 0:e89d7a0bfa3b 229
roryhand 3:6169aeeaeeb4 230
roryhand 3:6169aeeaeeb4 231 string FOLDER;
roryhand 3:6169aeeaeeb4 232 string RootFolder = "/sd/mydir/SoundDecoder/";
roryhand 3:6169aeeaeeb4 233 string filename[25];
roryhand 3:6169aeeaeeb4 234 classSoundFile Sound[22];
roryhand 3:6169aeeaeeb4 235
roryhand 0:e89d7a0bfa3b 236 volatile int flag1 = 1;
roryhand 0:e89d7a0bfa3b 237 volatile int flag2 = 0;
roryhand 0:e89d7a0bfa3b 238 volatile int flag3 = 1;
roryhand 0:e89d7a0bfa3b 239 volatile int flag4 = 0;
roryhand 0:e89d7a0bfa3b 240 int FLAGBUFF1 = 0;
roryhand 0:e89d7a0bfa3b 241 int FLAGBUFF2 = 0;
roryhand 0:e89d7a0bfa3b 242 int BellFlag = 0;
roryhand 0:e89d7a0bfa3b 243 int BellFlag2 = 0;
roryhand 0:e89d7a0bfa3b 244 int FadeFlag = 0;
roryhand 54:606a83fff291 245 int BlockFlag = 0;
roryhand 32:6ee488c97dcc 246 int FileSwitchFlag = 0;
roryhand 0:e89d7a0bfa3b 247
roryhand 0:e89d7a0bfa3b 248
roryhand 0:e89d7a0bfa3b 249 short value[1];
roryhand 59:8e7c25a915a0 250
roryhand 0:e89d7a0bfa3b 251 //long long slice_value;
roryhand 0:e89d7a0bfa3b 252 int slice_value[1];
roryhand 0:e89d7a0bfa3b 253
roryhand 0:e89d7a0bfa3b 254
roryhand 45:0e8e1f2ec5d2 255 FILE *wavfile1;
roryhand 45:0e8e1f2ec5d2 256 FILE *wavfile2;
roryhand 45:0e8e1f2ec5d2 257 FILE *wavfile3;
roryhand 45:0e8e1f2ec5d2 258
roryhand 45:0e8e1f2ec5d2 259 classSoundFile Sound1;
roryhand 45:0e8e1f2ec5d2 260 classSoundFile Sound2;
roryhand 45:0e8e1f2ec5d2 261 classSoundFile Sound3;
roryhand 45:0e8e1f2ec5d2 262
roryhand 0:e89d7a0bfa3b 263
roryhand 0:e89d7a0bfa3b 264 void isr()
roryhand 0:e89d7a0bfa3b 265 {
roryhand 54:606a83fff291 266 //timer_interrupt.start();
roryhand 1:aac37edee302 267 if(flag1 == 0) {
roryhand 0:e89d7a0bfa3b 268 value[0] = Buffer1[place_hold1]>>4;
roryhand 0:e89d7a0bfa3b 269 i2s.write(value,1);//Send next PWM value to amp
roryhand 0:e89d7a0bfa3b 270 place_hold1 = place_hold1 + 1;
roryhand 1:aac37edee302 271 if( (place_hold1 >= BufferLen)) {
roryhand 0:e89d7a0bfa3b 272 led2 = !led2;
roryhand 0:e89d7a0bfa3b 273 place_hold1 = 0;
roryhand 0:e89d7a0bfa3b 274 place_hold2 = 0;
roryhand 0:e89d7a0bfa3b 275 flag1 = 1;
roryhand 0:e89d7a0bfa3b 276 flag2 = 0;
roryhand 1:aac37edee302 277 }
roryhand 1:aac37edee302 278 } else if(flag2 == 0) {
roryhand 0:e89d7a0bfa3b 279 value[0] = Buffer2[place_hold2]>>4;
roryhand 0:e89d7a0bfa3b 280 i2s.write(value,1);//Send next PWM value to amp
roryhand 0:e89d7a0bfa3b 281 place_hold2 = place_hold2 + 1;
roryhand 1:aac37edee302 282 if( (place_hold2 >= BufferLen) ) {
roryhand 0:e89d7a0bfa3b 283 led2 = !led2;
roryhand 0:e89d7a0bfa3b 284 place_hold1 = 0;
roryhand 0:e89d7a0bfa3b 285 place_hold2 = 0;
roryhand 0:e89d7a0bfa3b 286 flag1 = 0;
roryhand 1:aac37edee302 287 flag2 = 1;
roryhand 0:e89d7a0bfa3b 288 FLAGBUFF2 = 0;
roryhand 1:aac37edee302 289 }
roryhand 0:e89d7a0bfa3b 290 }
roryhand 54:606a83fff291 291
roryhand 54:606a83fff291 292 //timer_interrupt.stop();
roryhand 54:606a83fff291 293
roryhand 0:e89d7a0bfa3b 294 }
roryhand 1:aac37edee302 295
roryhand 38:3b4c05af5f36 296
roryhand 38:3b4c05af5f36 297
roryhand 38:3b4c05af5f36 298
roryhand 38:3b4c05af5f36 299
roryhand 0:e89d7a0bfa3b 300
roryhand 59:8e7c25a915a0 301
roryhand 59:8e7c25a915a0 302
roryhand 59:8e7c25a915a0 303
roryhand 59:8e7c25a915a0 304
roryhand 59:8e7c25a915a0 305
roryhand 3:6169aeeaeeb4 306
roryhand 3:6169aeeaeeb4 307
roryhand 3:6169aeeaeeb4 308
roryhand 3:6169aeeaeeb4 309
roryhand 3:6169aeeaeeb4 310
roryhand 3:6169aeeaeeb4 311 //function prototypes
roryhand 45:0e8e1f2ec5d2 312 classSoundFile ReadFileInfo(classSoundFile Sound, FILE * wav_file);
roryhand 3:6169aeeaeeb4 313 classSoundFile LoadFileStream(classSoundFile FileInfo, string filename);
roryhand 3:6169aeeaeeb4 314 void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo);
roryhand 32:6ee488c97dcc 315 void Play_WaveFileDual(FILE * my_wav, WAV_FILE_STRUCT FileInfo);
roryhand 59:8e7c25a915a0 316 void Play_WaveFileLoop(classSoundFile Sound1, FILE* wavfile1,classPositionIndicators Positions);
roryhand 0:e89d7a0bfa3b 317
roryhand 1:aac37edee302 318 int main()
roryhand 1:aac37edee302 319 {
roryhand 44:a9e84d333a6a 320
roryhand 0:e89d7a0bfa3b 321 NotchUp.mode(PullUp);
roryhand 38:3b4c05af5f36 322 NotchDown.mode(PullUp);
roryhand 0:e89d7a0bfa3b 323
roryhand 0:e89d7a0bfa3b 324 pc.printf("Beginning of program\n");
roryhand 32:6ee488c97dcc 325
roryhand 13:8e93396a27c5 326
roryhand 13:8e93396a27c5 327
roryhand 4:55fbbb049bae 328
roryhand 25:5336e1cf38d6 329 printf("Do we even get to this stupid bloody point\n\r");
roryhand 0:e89d7a0bfa3b 330 //Populate our class instances with some data (is there an implicit way to do this?)
roryhand 28:6b2353fad12d 331
roryhand 1:aac37edee302 332
roryhand 3:6169aeeaeeb4 333 printf("hello\n\r");
roryhand 0:e89d7a0bfa3b 334 //Set up the wolfson Audio Codec board
roryhand 0:e89d7a0bfa3b 335 wm8731_Config_setup();
roryhand 0:e89d7a0bfa3b 336 //i2s audio data transfer code??
roryhand 0:e89d7a0bfa3b 337 i2s.stereomono(I2S_STEREO);
roryhand 0:e89d7a0bfa3b 338 i2s.masterslave(I2S_MASTER);
roryhand 0:e89d7a0bfa3b 339 led3 = 1;
roryhand 0:e89d7a0bfa3b 340 led2 = 1;
roryhand 45:0e8e1f2ec5d2 341 printf("Hello i2s has started!");
roryhand 30:4a8e80b243c4 342 i2s.start();
roryhand 0:e89d7a0bfa3b 343 sampletick.attach(&isr,1.0/sampling_freq); //1/16000
roryhand 54:606a83fff291 344
roryhand 58:a174e7a8f5f2 345 classPositionIndicators Positions;
roryhand 61:212d2db45c56 346 slice1 = Positions.notch7_start_pt;
roryhand 60:36df2997de3d 347 FILE* wavfile1 = fopen("/sd/mydir/SoundDecoder_second/All_eight_notches.wav","rb");
roryhand 60:36df2997de3d 348 //FILE* wavfile1 = fopen("/sd/mydir/SoundDecoder_second/01.wav","rb");
roryhand 58:a174e7a8f5f2 349 classSoundFile Sound1;
roryhand 58:a174e7a8f5f2 350 Sound1 = ReadFileInfo(Sound1, wavfile1);
roryhand 61:212d2db45c56 351 fseek(wavfile1,Positions.notch7_start_pt,SEEK_SET);
roryhand 20:9cc7d825c07b 352 printf("about to play wav file\n\r");
roryhand 59:8e7c25a915a0 353 Play_WaveFileLoop(Sound1,wavfile1,Positions);
roryhand 20:9cc7d825c07b 354 printf("finished playing Wav file\n\r");
roryhand 54:606a83fff291 355
roryhand 54:606a83fff291 356
roryhand 31:0f8c3adf09c3 357 timer_open.reset();
roryhand 31:0f8c3adf09c3 358 timer_open.start();
roryhand 45:0e8e1f2ec5d2 359 fclose(wavfile1);
roryhand 31:0f8c3adf09c3 360 timer_open.stop();
roryhand 31:0f8c3adf09c3 361 printf("It took %d useconds to close file\n\r",timer_open.read_us());
roryhand 54:606a83fff291 362
roryhand 54:606a83fff291 363
roryhand 54:606a83fff291 364
roryhand 54:606a83fff291 365
roryhand 9:dd9cae06b202 366 /************************************PLAY WAV FILE LOOP*******************/
roryhand 9:dd9cae06b202 367 /************************************END OF PLAY WAV FILE LOOP*************/
roryhand 13:8e93396a27c5 368
roryhand 13:8e93396a27c5 369
roryhand 1:aac37edee302 370 i2s.stop();
roryhand 0:e89d7a0bfa3b 371
roryhand 0:e89d7a0bfa3b 372 }
roryhand 0:e89d7a0bfa3b 373
roryhand 0:e89d7a0bfa3b 374
roryhand 3:6169aeeaeeb4 375
roryhand 3:6169aeeaeeb4 376
roryhand 3:6169aeeaeeb4 377
roryhand 3:6169aeeaeeb4 378
roryhand 45:0e8e1f2ec5d2 379 classSoundFile ReadFileInfo(classSoundFile Sound, FILE * wav_file)
roryhand 0:e89d7a0bfa3b 380 {
roryhand 0:e89d7a0bfa3b 381 fseek(wav_file,20,SEEK_SET);
roryhand 22:706e86dc0d45 382 printf("We have just seeked through this file\n\r");
roryhand 45:0e8e1f2ec5d2 383 fread(&Sound.FileInfo.FileFormat,sizeof(Sound.FileInfo.FileFormat),1,wav_file);
roryhand 1:aac37edee302 384 //printf("wav_format.sample_rate: %d\n\r",FileInfo.FileFormat.sample_rate);
roryhand 1:aac37edee302 385
roryhand 45:0e8e1f2ec5d2 386 fread(&Sound.FileInfo.FileData,sizeof(Sound.FileInfo.FileData),1,wav_file);
roryhand 55:5a441d3b0d57 387 printf("wav_data.subchunk2_size: %d\n\r",Sound.FileInfo.FileData.subchunk2_size);
roryhand 45:0e8e1f2ec5d2 388 Sound.FileInfo.slice_buf = ( char *)malloc(Sound.FileInfo.FileFormat.block_align);
roryhand 59:8e7c25a915a0 389 printf("Wav File Block Align (number of bytes per sample!!: %d\n\r", Sound.FileInfo.FileFormat.block_align);
roryhand 45:0e8e1f2ec5d2 390 fread(Sound.FileInfo.slice_buf,Sound.FileInfo.FileFormat.block_align,1,wav_file); //This isnt actually required, its just a test
roryhand 45:0e8e1f2ec5d2 391 Sound.FileInfo.num_slices = Sound.FileInfo.FileData.subchunk2_size/Sound.FileInfo.FileFormat.block_align;
roryhand 1:aac37edee302 392 //printf("Number of Slices: %d\n\r",FileInfo.num_slices);
roryhand 45:0e8e1f2ec5d2 393 return Sound;
roryhand 0:e89d7a0bfa3b 394 }
roryhand 1:aac37edee302 395
roryhand 1:aac37edee302 396
roryhand 1:aac37edee302 397
roryhand 1:aac37edee302 398
roryhand 1:aac37edee302 399
roryhand 0:e89d7a0bfa3b 400
roryhand 0:e89d7a0bfa3b 401 void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo)
roryhand 0:e89d7a0bfa3b 402 {
roryhand 1:aac37edee302 403 while(slice<FileInfo.num_slices) {
roryhand 1:aac37edee302 404 fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,my_wav);
roryhand 1:aac37edee302 405 data_sptr=(short *)FileInfo.slice_buf; // 16 bit samples
roryhand 1:aac37edee302 406 for (channel=0; channel<FileInfo.FileFormat.num_channels; channel++) {
roryhand 1:aac37edee302 407 if(flag1 == 1) {
roryhand 1:aac37edee302 408 Buffer1[place_hold1] = data_sptr[channel];
roryhand 1:aac37edee302 409 place_hold1 = place_hold1 + 1;
roryhand 1:aac37edee302 410 if(place_hold1 >= BufferLen) {
roryhand 1:aac37edee302 411 while(1) {
roryhand 1:aac37edee302 412 if(flag1 == 0) {
roryhand 0:e89d7a0bfa3b 413
roryhand 1:aac37edee302 414 break;
roryhand 0:e89d7a0bfa3b 415 }
roryhand 1:aac37edee302 416
roryhand 0:e89d7a0bfa3b 417 }
roryhand 1:aac37edee302 418 }
roryhand 1:aac37edee302 419
roryhand 1:aac37edee302 420 } else if(flag2 == 1) {
roryhand 1:aac37edee302 421 Buffer2[place_hold2] = data_sptr[channel];
roryhand 1:aac37edee302 422 place_hold2 = place_hold2 + 1;
roryhand 1:aac37edee302 423 if(place_hold2 >= BufferLen) {
roryhand 1:aac37edee302 424
roryhand 1:aac37edee302 425 while(1) {
roryhand 1:aac37edee302 426 if(flag2 == 0) {
roryhand 1:aac37edee302 427
roryhand 1:aac37edee302 428 break;
roryhand 1:aac37edee302 429 }
roryhand 0:e89d7a0bfa3b 430 }
roryhand 1:aac37edee302 431 }
roryhand 0:e89d7a0bfa3b 432 }
roryhand 1:aac37edee302 433
roryhand 1:aac37edee302 434 }
roryhand 1:aac37edee302 435 slice = slice + 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 38:3b4c05af5f36 442 //***************************************************************************//
roryhand 38:3b4c05af5f36 443
roryhand 38:3b4c05af5f36 444 //**************************************************************************//
roryhand 38:3b4c05af5f36 445
roryhand 38:3b4c05af5f36 446
roryhand 38:3b4c05af5f36 447
roryhand 38:3b4c05af5f36 448
roryhand 38:3b4c05af5f36 449
roryhand 59:8e7c25a915a0 450
roryhand 44:a9e84d333a6a 451
roryhand 57:0c76b15cabaf 452 void Play_WaveFileLoop(classSoundFile Sound1, FILE *wavfile1, classPositionIndicators Positions)
roryhand 45:0e8e1f2ec5d2 453 {
roryhand 45:0e8e1f2ec5d2 454 while(1) { //might have to change this to a while(1) loop?
roryhand 44:a9e84d333a6a 455
roryhand 2:957d3b2afff4 456
roryhand 44:a9e84d333a6a 457
roryhand 44:a9e84d333a6a 458
roryhand 54:606a83fff291 459
roryhand 44:a9e84d333a6a 460 //Sound1=======================================================================================
roryhand 61:212d2db45c56 461 if( slice1 == (Positions.notch8_start_pt) ) {
roryhand 61:212d2db45c56 462 slice1 = Positions.notch7_start_pt;
roryhand 61:212d2db45c56 463 fseek(wavfile1,Positions.notch7_start_pt,SEEK_SET);
roryhand 2:957d3b2afff4 464 }
roryhand 57:0c76b15cabaf 465
roryhand 44:a9e84d333a6a 466 fread(Sound1.FileInfo.slice_buf,Sound1.FileInfo.FileFormat.block_align,1,wavfile1);
roryhand 44:a9e84d333a6a 467 Sound1.data_sptr=(short *)Sound1.FileInfo.slice_buf; // 16 bit samples
roryhand 44:a9e84d333a6a 468 //=============================================================================================
roryhand 44:a9e84d333a6a 469
roryhand 58:a174e7a8f5f2 470
roryhand 1:aac37edee302 471
roryhand 1:aac37edee302 472
roryhand 44:a9e84d333a6a 473
roryhand 45:0e8e1f2ec5d2 474 for (channel=0; channel<Sound1.FileInfo.FileFormat.num_channels; channel++) {
roryhand 45:0e8e1f2ec5d2 475 switch (Sound1.FileInfo.FileFormat.sig_bps) {
roryhand 0:e89d7a0bfa3b 476 case 16:
roryhand 1:aac37edee302 477 if(flag1 == 1) {
roryhand 45:0e8e1f2ec5d2 478 Buffer1[place_hold1] = Sound1.data_sptr[channel];
roryhand 1:aac37edee302 479 place_hold1 = place_hold1 + 1;
roryhand 1:aac37edee302 480 if(place_hold1 >= BufferLen) {
roryhand 1:aac37edee302 481 while(1) {
roryhand 1:aac37edee302 482 if(flag1 == 0) {
roryhand 1:aac37edee302 483 break;
roryhand 1:aac37edee302 484 }//if(flag1 == 0)
roryhand 1:aac37edee302 485
roryhand 1:aac37edee302 486
roryhand 1:aac37edee302 487 }//while(1)
roryhand 1:aac37edee302 488 }//if(place_hold1 > = BufferLen)
roryhand 0:e89d7a0bfa3b 489
roryhand 1:aac37edee302 490 } else if(flag2 == 1) {
roryhand 45:0e8e1f2ec5d2 491 Buffer2[place_hold2] = Sound1.data_sptr[channel];
roryhand 1:aac37edee302 492 place_hold2 = place_hold2 + 1;
roryhand 1:aac37edee302 493 if(place_hold2 >= BufferLen) {
roryhand 1:aac37edee302 494 while(1) {
roryhand 1:aac37edee302 495
roryhand 1:aac37edee302 496 if(flag2 == 0) {
roryhand 1:aac37edee302 497 break;
roryhand 1:aac37edee302 498 }
roryhand 1:aac37edee302 499 }
roryhand 0:e89d7a0bfa3b 500 }
roryhand 1:aac37edee302 501
roryhand 1:aac37edee302 502 }
roryhand 0:e89d7a0bfa3b 503 }
roryhand 0:e89d7a0bfa3b 504 }
roryhand 59:8e7c25a915a0 505 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 506 slice2 = slice2 + 1;
roryhand 45:0e8e1f2ec5d2 507 slice3 = slice3 + 1;
roryhand 0:e89d7a0bfa3b 508 }
roryhand 0:e89d7a0bfa3b 509 }
roryhand 0:e89d7a0bfa3b 510
roryhand 0:e89d7a0bfa3b 511
roryhand 0:e89d7a0bfa3b 512
roryhand 0:e89d7a0bfa3b 513
roryhand 0:e89d7a0bfa3b 514
roryhand 0:e89d7a0bfa3b 515
roryhand 59:8e7c25a915a0 516
roryhand 59:8e7c25a915a0 517