Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed SDFileSystem_Copy_of_mbed_version I2S
NotchingDemo.cpp@57:0c76b15cabaf, 2019-09-27 (annotated)
- Committer:
- roryhand
- Date:
- Fri Sep 27 19:15:46 2019 +0000
- Branch:
- LargeFile_Tests
- Revision:
- 57:0c76b15cabaf
- Parent:
- 56:3755c53ac4c6
- Child:
- 58:a174e7a8f5f2
WIP - part way through changing this to work for one large "Notch Sounds" 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 | 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 | 57:0c76b15cabaf | 144 | class PositionIndicators |
| roryhand | 57:0c76b15cabaf | 145 | { |
| roryhand | 57:0c76b15cabaf | 146 | public: |
| roryhand | 57:0c76b15cabaf | 147 | int notch1_indicator, notch2_indicator, notch3_indicator, notch4_indicator; |
| roryhand | 57:0c76b15cabaf | 148 | int notch5_indicator, notch6_indicator, notch7_indicator, notch8_indicator; |
| roryhand | 57:0c76b15cabaf | 149 | int notch1_start_pt, notch2_start_pt, notch3_start_pt, notch4_start_pt; |
| roryhand | 57:0c76b15cabaf | 150 | int notch5_start_pt, notch6_start_pt, notch7_start_pt, notch8_start_pt; |
| roryhand | 57:0c76b15cabaf | 151 | PositionIndicators() |
| roryhand | 57:0c76b15cabaf | 152 | { |
| roryhand | 57:0c76b15cabaf | 153 | notch1_start_pt = 44; |
| roryhand | 57:0c76b15cabaf | 154 | notch2_start_pt = 220884+44; |
| roryhand | 57:0c76b15cabaf | 155 | notch3_start_pt = notch2_start_pt+217698; |
| roryhand | 57:0c76b15cabaf | 156 | notch4_start_pt = notch3_start_pt + 193060; |
| roryhand | 57:0c76b15cabaf | 157 | notch5_start_pt = notch4_start_pt + 92010; |
| roryhand | 57:0c76b15cabaf | 158 | notch6_start_pt = notch5_start_pt + 216642; |
| roryhand | 57:0c76b15cabaf | 159 | notch7_start_pt = notch6_start_pt + 250316; |
| roryhand | 57:0c76b15cabaf | 160 | notch8_start_pt = notch7_start_pt + 165084; |
| roryhand | 57:0c76b15cabaf | 161 | notch1_indicator = notch1_start_pt; |
| roryhand | 57:0c76b15cabaf | 162 | notch2_indicator = notch2_start_pt; |
| roryhand | 57:0c76b15cabaf | 163 | notch3_indicator = notch3_start_pt; |
| roryhand | 57:0c76b15cabaf | 164 | notch4_indicator = notch4_start_pt; |
| roryhand | 57:0c76b15cabaf | 165 | notch5_indicator = notch5_start_pt; |
| roryhand | 57:0c76b15cabaf | 166 | notch6_indicator = notch6_start_pt; |
| roryhand | 57:0c76b15cabaf | 167 | notch7_indicator = notch7_start_pt; |
| roryhand | 57:0c76b15cabaf | 168 | notch8_indicator = notch8_start_pt; |
| roryhand | 57:0c76b15cabaf | 169 | |
| roryhand | 57:0c76b15cabaf | 170 | } |
| roryhand | 57:0c76b15cabaf | 171 | }; |
| roryhand | 57:0c76b15cabaf | 172 | |
| roryhand | 57:0c76b15cabaf | 173 | |
| roryhand | 57:0c76b15cabaf | 174 | |
| roryhand | 57:0c76b15cabaf | 175 | |
| roryhand | 0:e89d7a0bfa3b | 176 | class classSoundFile |
| roryhand | 0:e89d7a0bfa3b | 177 | { |
| roryhand | 1:aac37edee302 | 178 | public: |
| roryhand | 1:aac37edee302 | 179 | |
| roryhand | 44:a9e84d333a6a | 180 | //add a class constructor at some point in the future (perform tests in visual studio) |
| roryhand | 1:aac37edee302 | 181 | WAV_FILE_STRUCT FileInfo; |
| roryhand | 2:957d3b2afff4 | 182 | short * data_sptr; |
| roryhand | 36:569ec4335f92 | 183 | string file_location; |
| roryhand | 1:aac37edee302 | 184 | //classSoundFile(string filename);//this is the constructor |
| roryhand | 1:aac37edee302 | 185 | //string filename; |
| roryhand | 0:e89d7a0bfa3b | 186 | }; |
| roryhand | 0:e89d7a0bfa3b | 187 | |
| roryhand | 1:aac37edee302 | 188 | //class constructor; |
| roryhand | 1:aac37edee302 | 189 | /*classSoundFile::classSoundFile(string filename) |
| roryhand | 1:aac37edee302 | 190 | { |
| roryhand | 1:aac37edee302 | 191 | //Declare RootFolder and the directory for the appropriate file. |
| roryhand | 1:aac37edee302 | 192 | //How we index into filename[] from the outside of this class is another |
| roryhand | 1:aac37edee302 | 193 | //issue... |
| roryhand | 1:aac37edee302 | 194 | FileInfo.WavFile = fopen("/sd/mydir/645Engine/Startup.wav","rb"); |
| roryhand | 1:aac37edee302 | 195 | fseek(FileInfo.WavFile,20,SEEK_SET); |
| roryhand | 1:aac37edee302 | 196 | fread(&FileInfo.FileFormat,sizeof(FileInfo.FileFormat),1,FileInfo.WavFile); |
| roryhand | 1:aac37edee302 | 197 | printf("wav_format.sample_rate: %d\n\r",FileInfo.FileFormat.sample_rate); |
| roryhand | 1:aac37edee302 | 198 | fread(&FileInfo.FileData,sizeof(FileInfo.FileData),1,FileInfo.WavFile); |
| roryhand | 1:aac37edee302 | 199 | printf("wav_data.subchunk2_size: %d\n\r",FileInfo.FileData.subchunk2_size); |
| roryhand | 1:aac37edee302 | 200 | FileInfo.slice_buf = ( char *)malloc(FileInfo.FileFormat.block_align); |
| roryhand | 1:aac37edee302 | 201 | fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,FileInfo.WavFile); //This isnt actually required, its just a test |
| roryhand | 1:aac37edee302 | 202 | FileInfo.num_slices = FileInfo.FileData.subchunk2_size/FileInfo.FileFormat.block_align; |
| roryhand | 1:aac37edee302 | 203 | }*/ |
| roryhand | 54:606a83fff291 | 204 | int OneOff = 0; |
| roryhand | 38:3b4c05af5f36 | 205 | int notch_flag = 0; |
| roryhand | 0:e89d7a0bfa3b | 206 | int i = 0; |
| roryhand | 0:e89d7a0bfa3b | 207 | int h = 0; |
| roryhand | 0:e89d7a0bfa3b | 208 | short bufflen = 1; |
| roryhand | 0:e89d7a0bfa3b | 209 | int buffer[1]; |
| roryhand | 1:aac37edee302 | 210 | int AudioFormat, NumChannels, SampleRate, BitsPerSample ; |
| roryhand | 0:e89d7a0bfa3b | 211 | char *slice_buf; |
| roryhand | 0:e89d7a0bfa3b | 212 | short *data_sptr; |
| roryhand | 0:e89d7a0bfa3b | 213 | short *data_sptr_horn; |
| roryhand | 0:e89d7a0bfa3b | 214 | short *data_sptr_IdleN2; |
| roryhand | 0:e89d7a0bfa3b | 215 | short * data_sptr_bell; |
| roryhand | 0:e89d7a0bfa3b | 216 | short * data_sptr_N2; |
| roryhand | 0:e89d7a0bfa3b | 217 | short * data_sptr_Flange; |
| roryhand | 0:e89d7a0bfa3b | 218 | unsigned char *data_bptr; |
| roryhand | 0:e89d7a0bfa3b | 219 | int *data_wptr; |
| roryhand | 0:e89d7a0bfa3b | 220 | unsigned channel; |
| roryhand | 45:0e8e1f2ec5d2 | 221 | long slice, slice1, slice2, slice3, num_slices; |
| roryhand | 0:e89d7a0bfa3b | 222 | int verbosity = 0; |
| roryhand | 0:e89d7a0bfa3b | 223 | int verbosity2 = 0; |
| roryhand | 0:e89d7a0bfa3b | 224 | int verbosity3 = 0; |
| roryhand | 0:e89d7a0bfa3b | 225 | int verbosity4 = 0; |
| roryhand | 0:e89d7a0bfa3b | 226 | int verbosity5 = 0; |
| roryhand | 0:e89d7a0bfa3b | 227 | int interrupt_condition = 1; |
| roryhand | 0:e89d7a0bfa3b | 228 | int sampling_freq = 11025; |
| roryhand | 0:e89d7a0bfa3b | 229 | const int BufferLen = 2000; |
| roryhand | 0:e89d7a0bfa3b | 230 | short Buffer1[BufferLen]; |
| roryhand | 0:e89d7a0bfa3b | 231 | short Buffer2[BufferLen]; |
| roryhand | 0:e89d7a0bfa3b | 232 | short place_hold1 = 0; |
| roryhand | 0:e89d7a0bfa3b | 233 | short place_hold2 = 0; |
| roryhand | 0:e89d7a0bfa3b | 234 | |
| roryhand | 3:6169aeeaeeb4 | 235 | |
| roryhand | 3:6169aeeaeeb4 | 236 | string FOLDER; |
| roryhand | 3:6169aeeaeeb4 | 237 | string RootFolder = "/sd/mydir/SoundDecoder/"; |
| roryhand | 3:6169aeeaeeb4 | 238 | string filename[25]; |
| roryhand | 3:6169aeeaeeb4 | 239 | classSoundFile Sound[22]; |
| roryhand | 3:6169aeeaeeb4 | 240 | |
| roryhand | 0:e89d7a0bfa3b | 241 | volatile int flag1 = 1; |
| roryhand | 0:e89d7a0bfa3b | 242 | volatile int flag2 = 0; |
| roryhand | 0:e89d7a0bfa3b | 243 | volatile int flag3 = 1; |
| roryhand | 0:e89d7a0bfa3b | 244 | volatile int flag4 = 0; |
| roryhand | 0:e89d7a0bfa3b | 245 | int FLAGBUFF1 = 0; |
| roryhand | 0:e89d7a0bfa3b | 246 | int FLAGBUFF2 = 0; |
| roryhand | 0:e89d7a0bfa3b | 247 | int BellFlag = 0; |
| roryhand | 0:e89d7a0bfa3b | 248 | int BellFlag2 = 0; |
| roryhand | 0:e89d7a0bfa3b | 249 | int FadeFlag = 0; |
| roryhand | 54:606a83fff291 | 250 | int BlockFlag = 0; |
| roryhand | 32:6ee488c97dcc | 251 | int FileSwitchFlag = 0; |
| roryhand | 0:e89d7a0bfa3b | 252 | |
| roryhand | 0:e89d7a0bfa3b | 253 | |
| roryhand | 0:e89d7a0bfa3b | 254 | short value[1]; |
| roryhand | 0:e89d7a0bfa3b | 255 | FILE *HornWav; |
| roryhand | 0:e89d7a0bfa3b | 256 | FILE *edsheeran_wav; |
| roryhand | 0:e89d7a0bfa3b | 257 | FILE *Startup_wav; |
| roryhand | 0:e89d7a0bfa3b | 258 | FILE *IdleN2Wav; |
| roryhand | 0:e89d7a0bfa3b | 259 | FILE *N2Wav; |
| roryhand | 0:e89d7a0bfa3b | 260 | FILE *BellWav; |
| roryhand | 0:e89d7a0bfa3b | 261 | FILE *FlangeWav; |
| roryhand | 16:5e3420d0509b | 262 | FILE *HeyWav; |
| roryhand | 0:e89d7a0bfa3b | 263 | //long long slice_value; |
| roryhand | 0:e89d7a0bfa3b | 264 | int slice_value[1]; |
| roryhand | 0:e89d7a0bfa3b | 265 | |
| roryhand | 0:e89d7a0bfa3b | 266 | |
| roryhand | 45:0e8e1f2ec5d2 | 267 | FILE *wavfile1; |
| roryhand | 45:0e8e1f2ec5d2 | 268 | FILE *wavfile2; |
| roryhand | 45:0e8e1f2ec5d2 | 269 | FILE *wavfile3; |
| roryhand | 45:0e8e1f2ec5d2 | 270 | |
| roryhand | 45:0e8e1f2ec5d2 | 271 | classSoundFile Sound1; |
| roryhand | 45:0e8e1f2ec5d2 | 272 | classSoundFile Sound2; |
| roryhand | 45:0e8e1f2ec5d2 | 273 | classSoundFile Sound3; |
| roryhand | 45:0e8e1f2ec5d2 | 274 | |
| roryhand | 0:e89d7a0bfa3b | 275 | WAV_FILE_STRUCT WavInfo_Horn; |
| roryhand | 0:e89d7a0bfa3b | 276 | WAV_FILE_STRUCT WavInfo_IdleN2; |
| roryhand | 0:e89d7a0bfa3b | 277 | WAV_FILE_STRUCT WavInfo_N2; |
| roryhand | 0:e89d7a0bfa3b | 278 | WAV_FILE_STRUCT WavInfo_Bell; |
| roryhand | 0:e89d7a0bfa3b | 279 | WAV_FILE_STRUCT WavInfo_Flange; |
| roryhand | 20:9cc7d825c07b | 280 | WAV_FILE_STRUCT WavInfo_Hey; |
| roryhand | 32:6ee488c97dcc | 281 | WAV_FILE_STRUCT WavInfo_N3; |
| roryhand | 16:5e3420d0509b | 282 | WAV_FILE_STRUCT WavInfo_Frustration; |
| roryhand | 0:e89d7a0bfa3b | 283 | Ticker flipper; |
| roryhand | 0:e89d7a0bfa3b | 284 | char * slice_buf_bell; |
| roryhand | 0:e89d7a0bfa3b | 285 | char * slice_buf_ed; |
| roryhand | 0:e89d7a0bfa3b | 286 | char * slice_buf_startup; |
| roryhand | 0:e89d7a0bfa3b | 287 | char * slice_buf_N2; |
| roryhand | 1:aac37edee302 | 288 | Notch_STRUCT NotchingSet; |
| roryhand | 0:e89d7a0bfa3b | 289 | //test |
| roryhand | 0:e89d7a0bfa3b | 290 | //short *data_sptr_bell = 0; |
| roryhand | 0:e89d7a0bfa3b | 291 | short *data_sptr_ed = 0; |
| roryhand | 0:e89d7a0bfa3b | 292 | short *data_sptr_startup = 0; |
| roryhand | 32:6ee488c97dcc | 293 | FILE *StartupWav; |
| roryhand | 32:6ee488c97dcc | 294 | FILE *N3Wav; |
| roryhand | 33:a75f0a30fbdc | 295 | int temp = 0; |
| roryhand | 1:aac37edee302 | 296 | void flip() |
| roryhand | 1:aac37edee302 | 297 | { |
| roryhand | 0:e89d7a0bfa3b | 298 | led2 = !led2; |
| roryhand | 0:e89d7a0bfa3b | 299 | } |
| roryhand | 0:e89d7a0bfa3b | 300 | |
| roryhand | 0:e89d7a0bfa3b | 301 | |
| roryhand | 0:e89d7a0bfa3b | 302 | void isr() |
| roryhand | 0:e89d7a0bfa3b | 303 | { |
| roryhand | 54:606a83fff291 | 304 | //timer_interrupt.start(); |
| roryhand | 1:aac37edee302 | 305 | if(flag1 == 0) { |
| roryhand | 0:e89d7a0bfa3b | 306 | value[0] = Buffer1[place_hold1]>>4; |
| roryhand | 0:e89d7a0bfa3b | 307 | i2s.write(value,1);//Send next PWM value to amp |
| roryhand | 0:e89d7a0bfa3b | 308 | place_hold1 = place_hold1 + 1; |
| roryhand | 1:aac37edee302 | 309 | if( (place_hold1 >= BufferLen)) { |
| roryhand | 0:e89d7a0bfa3b | 310 | led2 = !led2; |
| roryhand | 0:e89d7a0bfa3b | 311 | place_hold1 = 0; |
| roryhand | 0:e89d7a0bfa3b | 312 | place_hold2 = 0; |
| roryhand | 0:e89d7a0bfa3b | 313 | flag1 = 1; |
| roryhand | 0:e89d7a0bfa3b | 314 | flag2 = 0; |
| roryhand | 1:aac37edee302 | 315 | } |
| roryhand | 1:aac37edee302 | 316 | } else if(flag2 == 0) { |
| roryhand | 0:e89d7a0bfa3b | 317 | value[0] = Buffer2[place_hold2]>>4; |
| roryhand | 0:e89d7a0bfa3b | 318 | i2s.write(value,1);//Send next PWM value to amp |
| roryhand | 0:e89d7a0bfa3b | 319 | place_hold2 = place_hold2 + 1; |
| roryhand | 1:aac37edee302 | 320 | if( (place_hold2 >= BufferLen) ) { |
| roryhand | 0:e89d7a0bfa3b | 321 | led2 = !led2; |
| roryhand | 0:e89d7a0bfa3b | 322 | place_hold1 = 0; |
| roryhand | 0:e89d7a0bfa3b | 323 | place_hold2 = 0; |
| roryhand | 0:e89d7a0bfa3b | 324 | flag1 = 0; |
| roryhand | 1:aac37edee302 | 325 | flag2 = 1; |
| roryhand | 0:e89d7a0bfa3b | 326 | FLAGBUFF2 = 0; |
| roryhand | 1:aac37edee302 | 327 | } |
| roryhand | 0:e89d7a0bfa3b | 328 | } |
| roryhand | 54:606a83fff291 | 329 | |
| roryhand | 54:606a83fff291 | 330 | //timer_interrupt.stop(); |
| roryhand | 54:606a83fff291 | 331 | |
| roryhand | 0:e89d7a0bfa3b | 332 | } |
| roryhand | 1:aac37edee302 | 333 | |
| roryhand | 0:e89d7a0bfa3b | 334 | void horn_sound() |
| roryhand | 0:e89d7a0bfa3b | 335 | { |
| roryhand | 0:e89d7a0bfa3b | 336 | BellFlag = 1; |
| roryhand | 0:e89d7a0bfa3b | 337 | fseek(HornWav,44,SEEK_SET); |
| roryhand | 0:e89d7a0bfa3b | 338 | fseek(BellWav,44,SEEK_SET); |
| roryhand | 0:e89d7a0bfa3b | 339 | fseek(FlangeWav,44,SEEK_SET); |
| roryhand | 0:e89d7a0bfa3b | 340 | fseek(N2Wav,44,SEEK_SET); |
| roryhand | 0:e89d7a0bfa3b | 341 | } |
| roryhand | 0:e89d7a0bfa3b | 342 | |
| roryhand | 0:e89d7a0bfa3b | 343 | |
| roryhand | 32:6ee488c97dcc | 344 | void FileSwitch_isr() |
| roryhand | 0:e89d7a0bfa3b | 345 | { |
| roryhand | 32:6ee488c97dcc | 346 | FileSwitchFlag = 1; |
| roryhand | 33:a75f0a30fbdc | 347 | temp = 1; |
| roryhand | 33:a75f0a30fbdc | 348 | /*FILE* testwav = fopen("/sd/mydir/SoundDecoder_second/05.wav","rb"); |
| roryhand | 33:a75f0a30fbdc | 349 | if(N3Wav == NULL) { |
| roryhand | 33:a75f0a30fbdc | 350 | printf("Cannot Open testwav\n\r"); |
| roryhand | 33:a75f0a30fbdc | 351 | } |
| roryhand | 33:a75f0a30fbdc | 352 | */ |
| roryhand | 32:6ee488c97dcc | 353 | fseek(N3Wav,44,SEEK_SET); |
| roryhand | 32:6ee488c97dcc | 354 | // fclose(StartupWav); |
| roryhand | 0:e89d7a0bfa3b | 355 | } |
| roryhand | 0:e89d7a0bfa3b | 356 | |
| roryhand | 0:e89d7a0bfa3b | 357 | |
| roryhand | 0:e89d7a0bfa3b | 358 | void FadeOutIsr() |
| roryhand | 0:e89d7a0bfa3b | 359 | { |
| roryhand | 1:aac37edee302 | 360 | FadeFlag = 1; |
| roryhand | 54:606a83fff291 | 361 | OneOff = 1; |
| roryhand | 54:606a83fff291 | 362 | /* |
| roryhand | 54:606a83fff291 | 363 | wavfile2 = fopen("/sd/mydir/SoundDecoder_second/09.wav","rb"); |
| roryhand | 54:606a83fff291 | 364 | if(wavfile2 == NULL) { |
| roryhand | 54:606a83fff291 | 365 | printf("Cannot Open wavfile2\n\r"); |
| roryhand | 54:606a83fff291 | 366 | } |
| roryhand | 54:606a83fff291 | 367 | */ |
| roryhand | 54:606a83fff291 | 368 | |
| roryhand | 54:606a83fff291 | 369 | |
| roryhand | 54:606a83fff291 | 370 | |
| roryhand | 54:606a83fff291 | 371 | /* |
| roryhand | 54:606a83fff291 | 372 | wavfile3 = fopen("/sd/mydir/SoundDecoder_second/02.wav","rb"); |
| roryhand | 54:606a83fff291 | 373 | if(wavfile3 == NULL) { |
| roryhand | 54:606a83fff291 | 374 | printf("Cannot Open wavfile3\n\r"); |
| roryhand | 54:606a83fff291 | 375 | } |
| roryhand | 54:606a83fff291 | 376 | */ |
| roryhand | 54:606a83fff291 | 377 | /* |
| roryhand | 54:606a83fff291 | 378 | FILE* wavfile4 = fopen("/sd/mydir/SoundDecoder_second/04.wav","rb"); |
| roryhand | 54:606a83fff291 | 379 | if(wavfile4 == NULL) { |
| roryhand | 54:606a83fff291 | 380 | printf("Cannot Open wavfile3\n\r"); |
| roryhand | 54:606a83fff291 | 381 | } |
| roryhand | 54:606a83fff291 | 382 | */ |
| roryhand | 54:606a83fff291 | 383 | //fseek(wavfile2,44,SEEK_SET); |
| roryhand | 54:606a83fff291 | 384 | //fseek(wavfile3,44,SEEK_SET); |
| roryhand | 54:606a83fff291 | 385 | slice2 = 0; |
| roryhand | 54:606a83fff291 | 386 | slice3 = 0; |
| roryhand | 54:606a83fff291 | 387 | BlockFlag = 1; |
| roryhand | 47:9334a8f54997 | 388 | //printf("We are inside the FadeOut interrupt routine\n\r"); |
| roryhand | 1:aac37edee302 | 389 | |
| roryhand | 0:e89d7a0bfa3b | 390 | } |
| roryhand | 38:3b4c05af5f36 | 391 | |
| roryhand | 38:3b4c05af5f36 | 392 | |
| roryhand | 38:3b4c05af5f36 | 393 | |
| roryhand | 38:3b4c05af5f36 | 394 | |
| roryhand | 0:e89d7a0bfa3b | 395 | |
| roryhand | 3:6169aeeaeeb4 | 396 | classFade FadeDataInitialise(classFade FadeData); |
| roryhand | 3:6169aeeaeeb4 | 397 | |
| roryhand | 3:6169aeeaeeb4 | 398 | |
| roryhand | 3:6169aeeaeeb4 | 399 | |
| roryhand | 3:6169aeeaeeb4 | 400 | |
| roryhand | 3:6169aeeaeeb4 | 401 | |
| roryhand | 3:6169aeeaeeb4 | 402 | //function prototypes |
| roryhand | 45:0e8e1f2ec5d2 | 403 | classSoundFile ReadFileInfo(classSoundFile Sound, FILE * wav_file); |
| roryhand | 3:6169aeeaeeb4 | 404 | classSoundFile LoadFileStream(classSoundFile FileInfo, string filename); |
| roryhand | 3:6169aeeaeeb4 | 405 | |
| roryhand | 3:6169aeeaeeb4 | 406 | float FadeOut(void); |
| roryhand | 3:6169aeeaeeb4 | 407 | void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo); |
| roryhand | 32:6ee488c97dcc | 408 | void Play_WaveFileDual(FILE * my_wav, WAV_FILE_STRUCT FileInfo); |
| roryhand | 3:6169aeeaeeb4 | 409 | //void Play_WaveFileLoop(FILE * my_wav, WAV_FILE_STRUCT FileInfo); |
| roryhand | 3:6169aeeaeeb4 | 410 | //*********************INTERRUPT ROUTINE FOR NOTCHING*************************** |
| roryhand | 0:e89d7a0bfa3b | 411 | |
| roryhand | 1:aac37edee302 | 412 | void NotchUpIsr() |
| roryhand | 0:e89d7a0bfa3b | 413 | { |
| roryhand | 1:aac37edee302 | 414 | if(1 <= NotchingSet.Notch < 8) { |
| roryhand | 1:aac37edee302 | 415 | |
| roryhand | 1:aac37edee302 | 416 | NotchingSet.Notch = NotchingSet.Notch + 1; |
| roryhand | 1:aac37edee302 | 417 | NotchingSet.NotchTransUp = NotchingSet.Notch + 7; |
| roryhand | 1:aac37edee302 | 418 | NotchingSet.NotchDirection = 1; |
| roryhand | 3:6169aeeaeeb4 | 419 | FadeDataInitialise(NotchFadeIn); |
| roryhand | 3:6169aeeaeeb4 | 420 | FadeDataInitialise(NotchFadeOut); |
| roryhand | 1:aac37edee302 | 421 | } |
| roryhand | 0:e89d7a0bfa3b | 422 | } |
| roryhand | 0:e89d7a0bfa3b | 423 | |
| roryhand | 0:e89d7a0bfa3b | 424 | void NotchDownIsr() |
| roryhand | 0:e89d7a0bfa3b | 425 | { |
| roryhand | 1:aac37edee302 | 426 | if(1 < NotchingSet.Notch <= 8) { |
| roryhand | 1:aac37edee302 | 427 | NotchingSet.Notch = NotchingSet.Notch - 1; |
| roryhand | 1:aac37edee302 | 428 | NotchingSet.NotchTransDown = NotchingSet.Notch + 15;; |
| roryhand | 1:aac37edee302 | 429 | NotchingSet.NotchDirection = 0; |
| roryhand | 3:6169aeeaeeb4 | 430 | FadeDataInitialise(NotchFadeIn); |
| roryhand | 3:6169aeeaeeb4 | 431 | FadeDataInitialise(NotchFadeOut); |
| roryhand | 1:aac37edee302 | 432 | } |
| roryhand | 1:aac37edee302 | 433 | } |
| roryhand | 0:e89d7a0bfa3b | 434 | |
| roryhand | 0:e89d7a0bfa3b | 435 | |
| roryhand | 3:6169aeeaeeb4 | 436 | /**********************END OF INTERRUPT ROUTINE FOR NOTCHING*******************/ |
| roryhand | 3:6169aeeaeeb4 | 437 | |
| roryhand | 3:6169aeeaeeb4 | 438 | |
| roryhand | 1:aac37edee302 | 439 | |
| roryhand | 0:e89d7a0bfa3b | 440 | |
| roryhand | 3:6169aeeaeeb4 | 441 | |
| roryhand | 3:6169aeeaeeb4 | 442 | |
| roryhand | 44:a9e84d333a6a | 443 | void Play_WaveFileLoop(classSoundFile Sound1, classSoundFile Sound2, classSoundFile Sound3, FILE* wavfile1,FILE* wavfile2, FILE* wavfile3); |
| roryhand | 1:aac37edee302 | 444 | int main() |
| roryhand | 1:aac37edee302 | 445 | { |
| roryhand | 44:a9e84d333a6a | 446 | |
| roryhand | 0:e89d7a0bfa3b | 447 | NotchUp.mode(PullUp); |
| roryhand | 38:3b4c05af5f36 | 448 | NotchDown.mode(PullUp); |
| roryhand | 0:e89d7a0bfa3b | 449 | |
| roryhand | 0:e89d7a0bfa3b | 450 | pc.printf("Beginning of program\n"); |
| roryhand | 32:6ee488c97dcc | 451 | |
| roryhand | 13:8e93396a27c5 | 452 | |
| roryhand | 13:8e93396a27c5 | 453 | |
| roryhand | 4:55fbbb049bae | 454 | |
| roryhand | 25:5336e1cf38d6 | 455 | printf("Do we even get to this stupid bloody point\n\r"); |
| roryhand | 0:e89d7a0bfa3b | 456 | //Populate our class instances with some data (is there an implicit way to do this?) |
| roryhand | 28:6b2353fad12d | 457 | |
| roryhand | 1:aac37edee302 | 458 | |
| roryhand | 3:6169aeeaeeb4 | 459 | printf("hello\n\r"); |
| roryhand | 0:e89d7a0bfa3b | 460 | //Set up the wolfson Audio Codec board |
| roryhand | 0:e89d7a0bfa3b | 461 | wm8731_Config_setup(); |
| roryhand | 0:e89d7a0bfa3b | 462 | //i2s audio data transfer code?? |
| roryhand | 0:e89d7a0bfa3b | 463 | i2s.stereomono(I2S_STEREO); |
| roryhand | 0:e89d7a0bfa3b | 464 | i2s.masterslave(I2S_MASTER); |
| roryhand | 0:e89d7a0bfa3b | 465 | led3 = 1; |
| roryhand | 0:e89d7a0bfa3b | 466 | led2 = 1; |
| roryhand | 45:0e8e1f2ec5d2 | 467 | printf("Hello i2s has started!"); |
| roryhand | 30:4a8e80b243c4 | 468 | i2s.start(); |
| roryhand | 0:e89d7a0bfa3b | 469 | sampletick.attach(&isr,1.0/sampling_freq); //1/16000 |
| roryhand | 45:0e8e1f2ec5d2 | 470 | //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 | 471 | //not convinced we need this above line at the moment!! |
| roryhand | 54:606a83fff291 | 472 | |
| roryhand | 54:606a83fff291 | 473 | |
| roryhand | 54:606a83fff291 | 474 | |
| roryhand | 54:606a83fff291 | 475 | |
| roryhand | 57:0c76b15cabaf | 476 | |
| roryhand | 13:8e93396a27c5 | 477 | |
| roryhand | 57:0c76b15cabaf | 478 | |
| roryhand | 45:0e8e1f2ec5d2 | 479 | |
| roryhand | 45:0e8e1f2ec5d2 | 480 | |
| roryhand | 45:0e8e1f2ec5d2 | 481 | |
| roryhand | 45:0e8e1f2ec5d2 | 482 | TickFadeOut.attach(&FadeOutIsr,10.0); |
| roryhand | 45:0e8e1f2ec5d2 | 483 | |
| roryhand | 54:606a83fff291 | 484 | |
| roryhand | 54:606a83fff291 | 485 | //timer_interrupt.reset(); |
| roryhand | 57:0c76b15cabaf | 486 | fopen("/sd/); |
| roryhand | 20:9cc7d825c07b | 487 | printf("about to play wav file\n\r"); |
| roryhand | 57:0c76b15cabaf | 488 | Play_WaveFileLoop(Sound1,wavfile1,PositionIndicators); |
| roryhand | 45:0e8e1f2ec5d2 | 489 | //Play_WaveFileDual(StartupWav,WavInfo_Startup); |
| roryhand | 20:9cc7d825c07b | 490 | printf("finished playing Wav file\n\r"); |
| roryhand | 54:606a83fff291 | 491 | |
| roryhand | 54:606a83fff291 | 492 | |
| roryhand | 31:0f8c3adf09c3 | 493 | timer_open.reset(); |
| roryhand | 31:0f8c3adf09c3 | 494 | timer_open.start(); |
| roryhand | 45:0e8e1f2ec5d2 | 495 | fclose(wavfile1); |
| roryhand | 31:0f8c3adf09c3 | 496 | timer_open.stop(); |
| roryhand | 31:0f8c3adf09c3 | 497 | printf("It took %d useconds to close file\n\r",timer_open.read_us()); |
| roryhand | 54:606a83fff291 | 498 | |
| roryhand | 54:606a83fff291 | 499 | |
| roryhand | 54:606a83fff291 | 500 | |
| roryhand | 54:606a83fff291 | 501 | |
| roryhand | 9:dd9cae06b202 | 502 | /************************************PLAY WAV FILE LOOP*******************/ |
| roryhand | 20:9cc7d825c07b | 503 | //Play_WaveFileLoop(Sound, NotchingSet); |
| roryhand | 9:dd9cae06b202 | 504 | /************************************END OF PLAY WAV FILE LOOP*************/ |
| roryhand | 13:8e93396a27c5 | 505 | |
| roryhand | 13:8e93396a27c5 | 506 | |
| roryhand | 1:aac37edee302 | 507 | i2s.stop(); |
| roryhand | 0:e89d7a0bfa3b | 508 | |
| roryhand | 0:e89d7a0bfa3b | 509 | } |
| roryhand | 0:e89d7a0bfa3b | 510 | |
| roryhand | 0:e89d7a0bfa3b | 511 | |
| roryhand | 3:6169aeeaeeb4 | 512 | |
| roryhand | 3:6169aeeaeeb4 | 513 | |
| roryhand | 3:6169aeeaeeb4 | 514 | |
| roryhand | 3:6169aeeaeeb4 | 515 | |
| roryhand | 45:0e8e1f2ec5d2 | 516 | classSoundFile ReadFileInfo(classSoundFile Sound, FILE * wav_file) |
| roryhand | 0:e89d7a0bfa3b | 517 | { |
| roryhand | 0:e89d7a0bfa3b | 518 | fseek(wav_file,20,SEEK_SET); |
| roryhand | 22:706e86dc0d45 | 519 | printf("We have just seeked through this file\n\r"); |
| roryhand | 45:0e8e1f2ec5d2 | 520 | fread(&Sound.FileInfo.FileFormat,sizeof(Sound.FileInfo.FileFormat),1,wav_file); |
| roryhand | 1:aac37edee302 | 521 | //printf("wav_format.sample_rate: %d\n\r",FileInfo.FileFormat.sample_rate); |
| roryhand | 1:aac37edee302 | 522 | |
| roryhand | 45:0e8e1f2ec5d2 | 523 | fread(&Sound.FileInfo.FileData,sizeof(Sound.FileInfo.FileData),1,wav_file); |
| roryhand | 55:5a441d3b0d57 | 524 | printf("wav_data.subchunk2_size: %d\n\r",Sound.FileInfo.FileData.subchunk2_size); |
| roryhand | 45:0e8e1f2ec5d2 | 525 | Sound.FileInfo.slice_buf = ( char *)malloc(Sound.FileInfo.FileFormat.block_align); |
| roryhand | 45:0e8e1f2ec5d2 | 526 | fread(Sound.FileInfo.slice_buf,Sound.FileInfo.FileFormat.block_align,1,wav_file); //This isnt actually required, its just a test |
| roryhand | 45:0e8e1f2ec5d2 | 527 | Sound.FileInfo.num_slices = Sound.FileInfo.FileData.subchunk2_size/Sound.FileInfo.FileFormat.block_align; |
| roryhand | 1:aac37edee302 | 528 | //printf("Number of Slices: %d\n\r",FileInfo.num_slices); |
| roryhand | 45:0e8e1f2ec5d2 | 529 | return Sound; |
| roryhand | 0:e89d7a0bfa3b | 530 | } |
| roryhand | 1:aac37edee302 | 531 | |
| roryhand | 1:aac37edee302 | 532 | classSoundFile LoadFileStream(classSoundFile Sound, string filename) |
| roryhand | 1:aac37edee302 | 533 | { |
| roryhand | 1:aac37edee302 | 534 | //Declare RootFolder and the directory for the appropriate file. |
| roryhand | 1:aac37edee302 | 535 | //How we index into filename[] from the outside of this class is another |
| roryhand | 1:aac37edee302 | 536 | //issue... |
| roryhand | 1:aac37edee302 | 537 | //printf("FileName: %s\n\r",filename); |
| roryhand | 1:aac37edee302 | 538 | //string RootFolder = "/sd/mydir/SoundDecoder/"; |
| roryhand | 1:aac37edee302 | 539 | //string Directory = RootFolder + "01.wav";// + filename[0]; |
| roryhand | 1:aac37edee302 | 540 | //printf("%s\n\r",Directory); |
| roryhand | 1:aac37edee302 | 541 | //const char* DirectoryChar = Directory.c_str(); |
| roryhand | 1:aac37edee302 | 542 | //Sound.FileInfo.WavFile = fopen(DirectoryChar,"rb"); |
| roryhand | 1:aac37edee302 | 543 | Sound.FileInfo.WavFile = fopen("/sd/mydir/645Engine/Startup.wav","rb"); |
| roryhand | 1:aac37edee302 | 544 | fseek(Sound.FileInfo.WavFile,20,SEEK_SET); |
| roryhand | 1:aac37edee302 | 545 | fread(&Sound.FileInfo.FileFormat,sizeof(Sound.FileInfo.FileFormat),1,Sound.FileInfo.WavFile); |
| roryhand | 1:aac37edee302 | 546 | printf("wav_format.sample_rate: %d\n\r",Sound.FileInfo.FileFormat.sample_rate); |
| roryhand | 1:aac37edee302 | 547 | fread(&Sound.FileInfo.FileData,sizeof(Sound.FileInfo.FileData),1,Sound.FileInfo.WavFile); |
| roryhand | 1:aac37edee302 | 548 | printf("wav_data.subchunk2_size: %d\n\r",Sound.FileInfo.FileData.subchunk2_size); |
| roryhand | 1:aac37edee302 | 549 | Sound.FileInfo.slice_buf = ( char *)malloc(Sound.FileInfo.FileFormat.block_align); |
| roryhand | 1:aac37edee302 | 550 | 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 | 551 | Sound.FileInfo.num_slices = Sound.FileInfo.FileData.subchunk2_size/Sound.FileInfo.FileFormat.block_align; |
| roryhand | 1:aac37edee302 | 552 | printf("Number of Slices: %d\n\r",Sound.FileInfo.num_slices); |
| roryhand | 1:aac37edee302 | 553 | return Sound; |
| roryhand | 1:aac37edee302 | 554 | } |
| roryhand | 1:aac37edee302 | 555 | |
| roryhand | 1:aac37edee302 | 556 | |
| roryhand | 0:e89d7a0bfa3b | 557 | classFade FadeDataInitialise(classFade FadeData) |
| roryhand | 0:e89d7a0bfa3b | 558 | { |
| roryhand | 1:aac37edee302 | 559 | FadeData.DecayFactor = 1.3; |
| roryhand | 0:e89d7a0bfa3b | 560 | FadeData.FadeIteration = 1; |
| roryhand | 0:e89d7a0bfa3b | 561 | //FadeData.Denom = 11025*FadeData.DecayFactor; |
| roryhand | 0:e89d7a0bfa3b | 562 | FadeData.Denom = 11025*FadeData.DecayFactor; |
| roryhand | 0:e89d7a0bfa3b | 563 | FadeData.Natural_Exp = 2.7183; |
| roryhand | 0:e89d7a0bfa3b | 564 | FadeData.Length = 11025*FadeData.LengthSecs; |
| roryhand | 0:e89d7a0bfa3b | 565 | //FadeData.Natural_Exp = 2.7; |
| roryhand | 0:e89d7a0bfa3b | 566 | return FadeData; |
| roryhand | 0:e89d7a0bfa3b | 567 | } |
| roryhand | 0:e89d7a0bfa3b | 568 | |
| roryhand | 0:e89d7a0bfa3b | 569 | //Playing Files Code |
| roryhand | 46:de390e45c2af | 570 | /* |
| roryhand | 45:0e8e1f2ec5d2 | 571 | float FadeIn(void) |
| roryhand | 0:e89d7a0bfa3b | 572 | { |
| roryhand | 0:e89d7a0bfa3b | 573 | powervalFadeIn = FadeIterationIn/denom; |
| roryhand | 0:e89d7a0bfa3b | 574 | FadeCoeffFadeIn |
| roryhand | 1:aac37edee302 | 575 | |
| roryhand | 1:aac37edee302 | 576 | |
| roryhand | 45:0e8e1f2ec5d2 | 577 | } |
| roryhand | 45:0e8e1f2ec5d2 | 578 | float FadeOut(void) |
| roryhand | 0:e89d7a0bfa3b | 579 | { |
| roryhand | 0:e89d7a0bfa3b | 580 | powerval = -FadeIteration/denom; |
| roryhand | 0:e89d7a0bfa3b | 581 | FadeCoeff = pow(natural_exp,powerval); |
| roryhand | 1:aac37edee302 | 582 | FadeIteration = FadeIteration + 1; |
| roryhand | 1:aac37edee302 | 583 | return FadeCoeff; |
| roryhand | 1:aac37edee302 | 584 | |
| roryhand | 45:0e8e1f2ec5d2 | 585 | } |
| roryhand | 46:de390e45c2af | 586 | */ |
| roryhand | 0:e89d7a0bfa3b | 587 | |
| roryhand | 0:e89d7a0bfa3b | 588 | void Play_WaveFile(FILE * my_wav, WAV_FILE_STRUCT FileInfo) |
| roryhand | 0:e89d7a0bfa3b | 589 | { |
| roryhand | 1:aac37edee302 | 590 | while(slice<FileInfo.num_slices) { |
| roryhand | 1:aac37edee302 | 591 | fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,my_wav); |
| roryhand | 1:aac37edee302 | 592 | data_sptr=(short *)FileInfo.slice_buf; // 16 bit samples |
| roryhand | 1:aac37edee302 | 593 | for (channel=0; channel<FileInfo.FileFormat.num_channels; channel++) { |
| roryhand | 1:aac37edee302 | 594 | if(flag1 == 1) { |
| roryhand | 1:aac37edee302 | 595 | Buffer1[place_hold1] = data_sptr[channel]; |
| roryhand | 1:aac37edee302 | 596 | place_hold1 = place_hold1 + 1; |
| roryhand | 1:aac37edee302 | 597 | if(place_hold1 >= BufferLen) { |
| roryhand | 1:aac37edee302 | 598 | while(1) { |
| roryhand | 1:aac37edee302 | 599 | if(flag1 == 0) { |
| roryhand | 0:e89d7a0bfa3b | 600 | |
| roryhand | 1:aac37edee302 | 601 | break; |
| roryhand | 0:e89d7a0bfa3b | 602 | } |
| roryhand | 1:aac37edee302 | 603 | |
| roryhand | 0:e89d7a0bfa3b | 604 | } |
| roryhand | 1:aac37edee302 | 605 | } |
| roryhand | 1:aac37edee302 | 606 | |
| roryhand | 1:aac37edee302 | 607 | } else if(flag2 == 1) { |
| roryhand | 1:aac37edee302 | 608 | Buffer2[place_hold2] = data_sptr[channel]; |
| roryhand | 1:aac37edee302 | 609 | place_hold2 = place_hold2 + 1; |
| roryhand | 1:aac37edee302 | 610 | if(place_hold2 >= BufferLen) { |
| roryhand | 1:aac37edee302 | 611 | |
| roryhand | 1:aac37edee302 | 612 | while(1) { |
| roryhand | 1:aac37edee302 | 613 | if(flag2 == 0) { |
| roryhand | 1:aac37edee302 | 614 | |
| roryhand | 1:aac37edee302 | 615 | break; |
| roryhand | 1:aac37edee302 | 616 | } |
| roryhand | 0:e89d7a0bfa3b | 617 | } |
| roryhand | 1:aac37edee302 | 618 | } |
| roryhand | 0:e89d7a0bfa3b | 619 | } |
| roryhand | 1:aac37edee302 | 620 | |
| roryhand | 1:aac37edee302 | 621 | } |
| roryhand | 1:aac37edee302 | 622 | slice = slice + 1; |
| roryhand | 0:e89d7a0bfa3b | 623 | } |
| roryhand | 0:e89d7a0bfa3b | 624 | } |
| roryhand | 0:e89d7a0bfa3b | 625 | |
| roryhand | 0:e89d7a0bfa3b | 626 | |
| roryhand | 0:e89d7a0bfa3b | 627 | |
| roryhand | 0:e89d7a0bfa3b | 628 | |
| roryhand | 32:6ee488c97dcc | 629 | void Play_WaveFileDual(FILE * my_wav, WAV_FILE_STRUCT FileInfo) |
| roryhand | 32:6ee488c97dcc | 630 | { |
| roryhand | 32:6ee488c97dcc | 631 | while(slice<FileInfo.num_slices) { |
| roryhand | 32:6ee488c97dcc | 632 | if(FileSwitchFlag == 1) { |
| roryhand | 35:4469b508dda3 | 633 | |
| roryhand | 33:a75f0a30fbdc | 634 | if(temp == 1) { |
| roryhand | 34:26118c8f2e48 | 635 | printf("Does it go to this point\n\r"); |
| roryhand | 35:4469b508dda3 | 636 | N3Wav = fopen("/sd/mydir/SoundDecoder_second/03.wav","rb"); |
| roryhand | 33:a75f0a30fbdc | 637 | if(N3Wav == NULL) { |
| roryhand | 33:a75f0a30fbdc | 638 | printf("Cannot Open testwav\n\r"); |
| roryhand | 33:a75f0a30fbdc | 639 | } |
| roryhand | 33:a75f0a30fbdc | 640 | fclose(StartupWav); |
| roryhand | 33:a75f0a30fbdc | 641 | temp = 0; |
| roryhand | 33:a75f0a30fbdc | 642 | } |
| roryhand | 35:4469b508dda3 | 643 | fread(WavInfo_N3.slice_buf,WavInfo_N3.FileFormat.block_align,1,N3Wav); |
| roryhand | 35:4469b508dda3 | 644 | data_sptr=(short*)WavInfo_N3.slice_buf; |
| roryhand | 32:6ee488c97dcc | 645 | } else { |
| roryhand | 32:6ee488c97dcc | 646 | fread(FileInfo.slice_buf,FileInfo.FileFormat.block_align,1,my_wav); |
| roryhand | 32:6ee488c97dcc | 647 | data_sptr=(short *)FileInfo.slice_buf; // 16 bit samples |
| roryhand | 32:6ee488c97dcc | 648 | } |
| roryhand | 32:6ee488c97dcc | 649 | for (channel=0; channel<FileInfo.FileFormat.num_channels; channel++) { |
| roryhand | 32:6ee488c97dcc | 650 | if(flag1 == 1) { |
| roryhand | 32:6ee488c97dcc | 651 | Buffer1[place_hold1] = data_sptr[channel]; |
| roryhand | 32:6ee488c97dcc | 652 | place_hold1 = place_hold1 + 1; |
| roryhand | 32:6ee488c97dcc | 653 | if(place_hold1 >= BufferLen) { |
| roryhand | 32:6ee488c97dcc | 654 | while(1) { |
| roryhand | 32:6ee488c97dcc | 655 | if(flag1 == 0) { |
| roryhand | 0:e89d7a0bfa3b | 656 | |
| roryhand | 32:6ee488c97dcc | 657 | break; |
| roryhand | 32:6ee488c97dcc | 658 | } |
| roryhand | 32:6ee488c97dcc | 659 | |
| roryhand | 32:6ee488c97dcc | 660 | } |
| roryhand | 32:6ee488c97dcc | 661 | } |
| roryhand | 32:6ee488c97dcc | 662 | |
| roryhand | 32:6ee488c97dcc | 663 | } else if(flag2 == 1) { |
| roryhand | 32:6ee488c97dcc | 664 | Buffer2[place_hold2] = data_sptr[channel]; |
| roryhand | 32:6ee488c97dcc | 665 | place_hold2 = place_hold2 + 1; |
| roryhand | 32:6ee488c97dcc | 666 | if(place_hold2 >= BufferLen) { |
| roryhand | 32:6ee488c97dcc | 667 | |
| roryhand | 32:6ee488c97dcc | 668 | while(1) { |
| roryhand | 32:6ee488c97dcc | 669 | if(flag2 == 0) { |
| roryhand | 32:6ee488c97dcc | 670 | |
| roryhand | 32:6ee488c97dcc | 671 | break; |
| roryhand | 32:6ee488c97dcc | 672 | } |
| roryhand | 32:6ee488c97dcc | 673 | } |
| roryhand | 32:6ee488c97dcc | 674 | } |
| roryhand | 32:6ee488c97dcc | 675 | } |
| roryhand | 32:6ee488c97dcc | 676 | |
| roryhand | 32:6ee488c97dcc | 677 | } |
| roryhand | 32:6ee488c97dcc | 678 | slice = slice + 1; |
| roryhand | 32:6ee488c97dcc | 679 | } |
| roryhand | 32:6ee488c97dcc | 680 | } |
| roryhand | 0:e89d7a0bfa3b | 681 | |
| roryhand | 38:3b4c05af5f36 | 682 | //***************************************************************************// |
| roryhand | 38:3b4c05af5f36 | 683 | |
| roryhand | 38:3b4c05af5f36 | 684 | //**************************************************************************// |
| roryhand | 38:3b4c05af5f36 | 685 | |
| roryhand | 38:3b4c05af5f36 | 686 | |
| roryhand | 38:3b4c05af5f36 | 687 | |
| roryhand | 38:3b4c05af5f36 | 688 | |
| roryhand | 38:3b4c05af5f36 | 689 | |
| roryhand | 1:aac37edee302 | 690 | |
| roryhand | 44:a9e84d333a6a | 691 | |
| roryhand | 57:0c76b15cabaf | 692 | void Play_WaveFileLoop(classSoundFile Sound1, FILE *wavfile1, classPositionIndicators Positions) |
| roryhand | 45:0e8e1f2ec5d2 | 693 | { |
| roryhand | 45:0e8e1f2ec5d2 | 694 | while(1) { //might have to change this to a while(1) loop? |
| roryhand | 45:0e8e1f2ec5d2 | 695 | //New format!! This should be (roughly) the way that this is done, with the new structures and classes |
| roryhand | 44:a9e84d333a6a | 696 | |
| roryhand | 45:0e8e1f2ec5d2 | 697 | //Block 1 of code. We need to pass in 3x classSoundFile objects, and 3x FILE* pointer objects. |
| roryhand | 45:0e8e1f2ec5d2 | 698 | //This will allow us to switch between the 3 different files (using "cross-fades") as needed. |
| roryhand | 45:0e8e1f2ec5d2 | 699 | /*Remember that these will need to be global varaibles to work properly*/ |
| roryhand | 45:0e8e1f2ec5d2 | 700 | |
| roryhand | 45:0e8e1f2ec5d2 | 701 | |
| roryhand | 2:957d3b2afff4 | 702 | //make sure we are reading in the correct "notch" here |
| roryhand | 2:957d3b2afff4 | 703 | |
| roryhand | 44:a9e84d333a6a | 704 | |
| roryhand | 44:a9e84d333a6a | 705 | |
| roryhand | 54:606a83fff291 | 706 | |
| roryhand | 44:a9e84d333a6a | 707 | //Sound1======================================================================================= |
| roryhand | 57:0c76b15cabaf | 708 | if( slice == (PositionIndicators.notch2_start_pt) ) { |
| roryhand | 44:a9e84d333a6a | 709 | slice1 = 0; |
| roryhand | 57:0c76b15cabaf | 710 | fseek(Engine,notch1_start_pt,SEEK_SET); |
| roryhand | 2:957d3b2afff4 | 711 | } |
| roryhand | 57:0c76b15cabaf | 712 | |
| roryhand | 44:a9e84d333a6a | 713 | fread(Sound1.FileInfo.slice_buf,Sound1.FileInfo.FileFormat.block_align,1,wavfile1); |
| roryhand | 44:a9e84d333a6a | 714 | Sound1.data_sptr=(short *)Sound1.FileInfo.slice_buf; // 16 bit samples |
| roryhand | 44:a9e84d333a6a | 715 | //============================================================================================= |
| roryhand | 44:a9e84d333a6a | 716 | |
| roryhand | 57:0c76b15cabaf | 717 | /********************END OF DATA ASSIGNMENT SECTION*********************************************** |
| roryhand | 1:aac37edee302 | 718 | |
| roryhand | 1:aac37edee302 | 719 | |
| roryhand | 44:a9e84d333a6a | 720 | |
| roryhand | 44:a9e84d333a6a | 721 | /**********************************************************************************************************/ |
| roryhand | 44:a9e84d333a6a | 722 | /****************************DATA OUTPUT SECTION***********************************************************/ |
| roryhand | 44:a9e84d333a6a | 723 | /**********************************************************************************************************/ |
| roryhand | 45:0e8e1f2ec5d2 | 724 | for (channel=0; channel<Sound1.FileInfo.FileFormat.num_channels; channel++) { |
| roryhand | 45:0e8e1f2ec5d2 | 725 | switch (Sound1.FileInfo.FileFormat.sig_bps) { |
| roryhand | 0:e89d7a0bfa3b | 726 | case 16: |
| roryhand | 1:aac37edee302 | 727 | if(flag1 == 1) { |
| roryhand | 45:0e8e1f2ec5d2 | 728 | Buffer1[place_hold1] = Sound1.data_sptr[channel]; |
| roryhand | 1:aac37edee302 | 729 | place_hold1 = place_hold1 + 1; |
| roryhand | 1:aac37edee302 | 730 | if(place_hold1 >= BufferLen) { |
| roryhand | 1:aac37edee302 | 731 | while(1) { |
| roryhand | 1:aac37edee302 | 732 | if(flag1 == 0) { |
| roryhand | 1:aac37edee302 | 733 | break; |
| roryhand | 1:aac37edee302 | 734 | }//if(flag1 == 0) |
| roryhand | 1:aac37edee302 | 735 | |
| roryhand | 1:aac37edee302 | 736 | |
| roryhand | 1:aac37edee302 | 737 | }//while(1) |
| roryhand | 1:aac37edee302 | 738 | }//if(place_hold1 > = BufferLen) |
| roryhand | 0:e89d7a0bfa3b | 739 | |
| roryhand | 1:aac37edee302 | 740 | } else if(flag2 == 1) { |
| roryhand | 45:0e8e1f2ec5d2 | 741 | Buffer2[place_hold2] = Sound1.data_sptr[channel]; |
| roryhand | 1:aac37edee302 | 742 | place_hold2 = place_hold2 + 1; |
| roryhand | 1:aac37edee302 | 743 | if(place_hold2 >= BufferLen) { |
| roryhand | 1:aac37edee302 | 744 | while(1) { |
| roryhand | 1:aac37edee302 | 745 | |
| roryhand | 1:aac37edee302 | 746 | if(flag2 == 0) { |
| roryhand | 1:aac37edee302 | 747 | break; |
| roryhand | 1:aac37edee302 | 748 | } |
| roryhand | 1:aac37edee302 | 749 | } |
| roryhand | 0:e89d7a0bfa3b | 750 | } |
| roryhand | 1:aac37edee302 | 751 | |
| roryhand | 1:aac37edee302 | 752 | } |
| roryhand | 0:e89d7a0bfa3b | 753 | } |
| roryhand | 0:e89d7a0bfa3b | 754 | } |
| roryhand | 45:0e8e1f2ec5d2 | 755 | slice1 = slice1 + 1; |
| roryhand | 45:0e8e1f2ec5d2 | 756 | slice2 = slice2 + 1; |
| roryhand | 45:0e8e1f2ec5d2 | 757 | slice3 = slice3 + 1; |
| roryhand | 0:e89d7a0bfa3b | 758 | } |
| roryhand | 0:e89d7a0bfa3b | 759 | } |
| roryhand | 0:e89d7a0bfa3b | 760 | |
| 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 | 9:dd9cae06b202 | 767 |