Tau ReSpeaker Setup V01

Dependencies:   MbedJSONValue mbed

Fork of TAU_ReSpeaker_DSP_Test by Yossi_Students

Revision:
1:574b54755983
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Matlab_Script/wav2sounddata.txt	Sun Feb 11 15:13:52 2018 +0000
@@ -0,0 +1,49 @@
+%Script for preparation of predefined signal code from wav file
+% Generates file sounddata.h which should be uploaded into mbed environment
+% and compiled together with C++ file
+
+% this line should be corrected depended on location of WAV file
+mainfilename ='C:\Users\Igor\OneDrive\dev\Bats\tests\kuhlii_like_chirp.wav';
+% this line should be corrected depended on desired location of sounddata.h file
+sounddatafilename = 'C:\Users\Igor\OneDrive\dev\Bats\tests\sounddata.h'
+
+[ybat,Fs] = audioread(mainfilename,'double');
+len = length(ybat);
+
+fprintf('Amount of samples: %d; Sampling frequency %d\n',len, Fs)
+num_of_leading_zeros=0;
+num_of_trailing_zeros = 0;
+count_leading_zeros = true;
+count_trailing_zeros = true;
+for i = 1:len
+    if (ybat(i) == 0.0 && count_leading_zeros)
+        num_of_leading_zeros = num_of_leading_zeros + 1;
+    else
+        count_leading_zeros = false;
+    end
+    if (ybat(len-i+1) == 0.0 && count_trailing_zeros)
+        num_of_trailing_zeros = num_of_trailing_zeros + 1;
+    else
+        count_trailing_zeros = false;
+    end
+end
+
+fprintf('Amount of leading zeros: %d\n',num_of_leading_zeros);
+fprintf('Amount of trailing zeros: %d\n',num_of_trailing_zeros);
+fprintf('Amount of significant signal samples: %d\n',len - num_of_trailing_zeros - num_of_leading_zeros);
+
+fileID = fopen(sounddatafilename,'w');
+fprintf(fileID, '#define SAMPLING_FREQUENCY %d\n', Fs);
+fprintf(fileID, '#define AMOUNT_OF_LEADING_ZEROS %d\n', num_of_leading_zeros);
+fprintf(fileID, '#define AMOUNT_OF_TRAILING_ZEROS %d\n', num_of_trailing_zeros);
+fprintf(fileID, '#define AMOUNT_OF_SIGNIFICANT_SAMPLES %d\n', len - num_of_leading_zeros - num_of_trailing_zeros + 1);
+fprintf(fileID, 'float sounddata[AMOUNT_OF_SIGNIFICANT_SAMPLES] = {\n');
+
+for i = num_of_leading_zeros+1 : len - num_of_trailing_zeros
+    fprintf(fileID,'%f,', ybat(i));
+    if (mod(i,12) == 0) 
+        fprintf(fileID,'\n');
+    end
+end
+fprintf(fileID, '0.0};\n');
+fclose(fileID);