-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAudioEditor.m
1419 lines (1196 loc) · 55 KB
/
AudioEditor.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function varargout = AudioEditor(varargin)
% AUDIOEDITOR MATLAB code for AudioEditor.fig
% AUDIOEDITOR, by itself, creates a new AUDIOEDITOR or raises the existing
% singleton*.
%
% H = AUDIOEDITOR returns the handle to a new AUDIOEDITOR or the handle to
% the existing singleton*.
%
% AUDIOEDITOR('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in AUDIOEDITOR.M with the given input arguments.
%
% AUDIOEDITOR('Property','Value',...) creates a new AUDIOEDITOR or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before AudioEditor_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to AudioEditor_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help AudioEditor
% Last Modified by GUIDE v2.5 01-Jan-2021 20:43:35
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @AudioEditor_OpeningFcn, ...
'gui_OutputFcn', @AudioEditor_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before AudioEditor is made visible.
function AudioEditor_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to AudioEditor (see VARARGIN)
% Choose default command line output for AudioEditor
addpath(genpath('Audio Recorder\functions'))
addpath(genpath('functions'))
handles.Y = [];
handles.FS = 16000;
handles.NUMCHAN = 1;
handles.BPS = 8;
handles.output = hObject;
handles.window_length = 0.030;
handles.noverlap = 0.015;
handles.time_start = 0;
handles.time_end = 1;
handles.window_type = 0;
handles.pe_coeff = 0.95;
handles.max_freq = [];
handles.player = [];
handles.num_gm = 5;
handles.y_train = [];
handles.f_train_labels = [];
handles.y_test = [];
handles.f_test_labels = [];
handles.is_trained=0;
handles.wl_sr = 0.030;
handles.no_sr = 0.015;
handles.init_tm = "Left to Right";
set(handles.recordBtn,'Enable','off')
set(handles.pauserecordBtn,'Enable','off')
set(handles.stoprecordBtn,'Enable','off')
check_sr_state('off', handles)
check_state('off', handles)
check_data_availability(false, handles)
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes AudioEditor wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = AudioEditor_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in openBtn.
function openBtn_Callback(hObject, eventdata, handles)
% hObject handle to openBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile({'*.wav'}, 'File Selector');
if filename==0
return
end
handles.player = [];
check_state('read', handles);
check_data_availability(true, handles)
[y, fs] = audioread(fullfile(pathname, filename));
a_info = audioinfo(fullfile(pathname, filename));
handles.ORIGINAL_FS = fs; handles.FS = fs;
handles.ORIGINAL_NUMCHAN = size(y,2); handles.NUMCHAN = size(y,2);
handles.ORIGINAL_LENGTH = size(y,1)/fs; handles.LENGTH = size(y,1)/fs;
handles.ORIGINAL_BPS = a_info.BitsPerSample;
handles.BPS = a_info.BitsPerSample;
y = y(:,1)./max(abs(y(:,1)));
handles.Y = reshape(y, [1,length(y)]);
handles.fullpathname = strcat(pathname, filename);
handles.time_start = 0;
handles.time_end = handles.LENGTH;
set(handles.time_start_txtedit, 'String', num2str(handles.time_start))
set(handles.time_end_txtedit, 'String', num2str(handles.time_end))
set_information(hObject, eventdata, handles)
display_signal(hObject, eventdata, handles)
display_spectrogram(hObject, eventdata, handles)
update_bps_box(hObject, eventdata, handles)
update_numchan_box(hObject, eventdata, handles)
update_fs_slider(hObject, eventdata, handles)
display_features_info(hObject, eventdata, handles)
set(handles.time_settings_refresh_btn,'Enable','on')
set(handles.specgram_settings_refresh_btn,'Enable','on')
guidata(hObject, handles);
% --- Executes on slider movement.
function fs_slider_Callback(hObject, eventdata, handles)
% hObject handle to fs_slider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.FS = round(get(hObject,'Value'))*1000;
FS_str = strcat(num2str(handles.FS/1000), 'KHz');
set(handles.fs_txt, 'String', FS_str);
handles.player = [];
if ~isempty(handles.Y)
handles.LENGTH = length(handles.Y)/handles.FS;
handles.time_end = handles.LENGTH;
set(handles.time_end_txtedit, 'String', num2str(handles.time_end));
time_settings_refresh_btn_Callback(hObject, eventdata, handles);
display_signal(hObject, eventdata, handles)
display_spectrogram(hObject, eventdata, handles)
end
guidata(hObject, handles);
function set_information(hObject, eventdata, handles)
set(handles.address_box, 'String', handles.fullpathname);
set(handles.audio_duration, ...
'String', strcat(num2str(handles.ORIGINAL_LENGTH), 's'));
function display_signal(hObject, eventdata, handles)
dt = 1/handles.FS;
t = 0:dt:(length(handles.Y)*dt)-dt;
axes(handles.audio_wave);
plot(t, handles.Y);
title('Audio Signal')
xlabel('Time (s)')
xlim([handles.time_start handles.time_end]);
guidata(hObject, handles);
function display_spectrogram(hObject, eventdata, handles)
y = handles.Y;
pe_y = PreEmphasis(y, handles.pe_coeff);
stride = handles.window_length-handles.noverlap;
[FrameMat, t] = FrameBlocking(pe_y,handles.window_length,stride,handles.FS);
wFrames = Windowing(FrameMat,handles.window_type);
[Spec, f] = GetDFTMagnitudes(wFrames, handles.FS);
axes(handles.audio_specgram);
PlotSpectrogram(Spec, t, f);
title('Spectrogram')
xlabel('Time (s)')
colorbar('off')
colormap(flipud(gray));
xlim([handles.time_start handles.time_end]);
if ~isempty(handles.max_freq)
ylim([0 handles.max_freq]);
end
guidata(hObject, handles);
function update_fs_slider(hObject, eventdata, handles)
FS_str = strcat(num2str(handles.FS/1000), 'KHz');
set(handles.fs_txt, 'String', FS_str);
set(handles.fs_slider, 'Value', handles.FS/1000);
guidata(hObject, handles);
function update_numchan_box(hObject, eventdata, handles)
switch handles.NUMCHAN
case 1
set(handles.numchan1_rb, 'Value', 1);
set(handles.numchan2_rb, 'Value', 0);
case 2
set(handles.numchan1_rb, 'Value', 0);
set(handles.numchan2_rb, 'Value', 1);
otherwise
set(handles.numchan1_rb, 'Value', 0);
set(handles.numchan2_rb, 'Value', 0);
end
function update_bps_box(hObject, eventdata, handles)
switch handles.BPS
case 1
set(handles.bps8_rb, 'Value', 1);
set(handles.bps16_rb, 'Value', 0);
set(handles.bps24_rb, 'Value', 0);
case 2
set(handles.bps8_rb, 'Value', 0);
set(handles.bps16_rb, 'Value', 1);
set(handles.bps24_rb, 'Value', 0);
otherwise
set(handles.bps8_rb, 'Value', 0);
set(handles.bps16_rb, 'Value', 1);
set(handles.bps24_rb, 'Value', 0);
end
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function fs_slider_CreateFcn(hObject, eventdata, handles)
% hObject handle to fs_slider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), ...
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes when selected object is changed in numchan_btn_gp.
function numchan_btn_gp_SelectionChangedFcn(hObject, eventdata, handles)
% hObject handle to the selected object in numchan_btn_gp
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
try
numchan1 = get(handles.numchan1_rb, 'Value');
numchan2 = get(handles.numchan2_rb, 'Value');
handles.NUMCHAN = 1*numchan1 + 2*numchan2;
catch ME
disp(ME)
end
guidata(hObject, handles);
% --- Executes on button press in numchan1_rb.
function numchan1_rb_Callback(hObject, eventdata, handles)
% hObject handle to numchan1_rb (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of numchan1_rb
function window_length_txtedit_Callback(hObject, eventdata, handles)
% hObject handle to window_length_txtedit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of window_length_txtedit as text
% str2double(get(hObject,'String')) returns contents of window_length_txtedit as a double
% --- Executes during object creation, after setting all properties.
function window_length_txtedit_CreateFcn(hObject, eventdata, handles)
% hObject handle to window_length_txtedit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), ...
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function noverlap_txtedit_Callback(hObject, eventdata, handles)
% hObject handle to noverlap_txtedit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of noverlap_txtedit as text
% str2double(get(hObject,'String')) returns contents of noverlap_txtedit as a double
% --- Executes during object creation, after setting all properties.
function noverlap_txtedit_CreateFcn(hObject, eventdata, handles)
% hObject handle to noverlap_txtedit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), ...
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in specgram_settings_refresh_btn.
function specgram_settings_refresh_btn_Callback(hObject, eventdata, handles)
% hObject handle to specgram_settings_refresh_btn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
window_length = get(handles.window_length_txtedit, 'String');
noverlap = get(handles.noverlap_txtedit,'String');
handles.window_length = str2double(window_length)/1000;
handles.noverlap = str2double(noverlap)/1000;
if handles.noverlap>=handles.window_length
handles.noverlap = 0;
set(handles.noverlap_txtedit,'String', num2str(handles.noverlap*1000));
end
window_type_p1 = get(handles.window_type_popup, 'Value');
handles.window_type = window_type_p1-1;
pe_corr_coef = get(handles.pre_emphasis_corr_radio_button, 'Value');
pe_manu_coef = get(handles.pre_emphasis_manual_radio_button, 'Value');
if pe_manu_coef==1
pe_coeff = get(handles.pre_emphasis_manual_text, 'String');
handles.pe_coeff = str2double(pe_coeff);
elseif pe_corr_coef==1
coefs = getCORR(handles.Y);
handles.pe_coeff = coefs(2)/coefs(1);
end
max_freq_str = get(handles.max_freq_field, 'String');
handles.max_freq = str2double(max_freq_str);
if isempty(max_freq_str)
handles.max_freq = [];
end
display_spectrogram(hObject, eventdata, handles);
guidata(hObject, handles);
% --- Executes on button press in specgram_settings_def_btn.
function specgram_settings_def_btn_Callback(hObject, eventdata, handles)
% hObject handle to specgram_settings_def_btn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.window_length_txtedit, 'String', 30);
set(handles.noverlap_txtedit,'String', 15);
handles.window_length = 0.030;
handles.noverlap = 0.015;
set(handles.window_type_popup, 'Value', 1);
handles.window_type = 0;
set(handles.pre_emphasis_corr_radio_button, 'Value', 0);
set(handles.pre_emphasis_manual_radio_button, 'Value', 1);
set(handles.pre_emphasis_manual_text, 'String', 0.95);
handles.pe_coeff = 0.95;
set(handles.max_freq_field, 'String', '');
handles.max_freq = [];
display_spectrogram(hObject, eventdata, handles);
function time_start_txtedit_Callback(hObject, eventdata, handles)
% hObject handle to time_start_txtedit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of time_start_txtedit as text
% str2double(get(hObject,'String')) returns contents of time_start_txtedit as a double
% --- Executes during object creation, after setting all properties.
function time_start_txtedit_CreateFcn(hObject, eventdata, handles)
% hObject handle to time_start_txtedit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), ...
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function time_end_txtedit_Callback(hObject, eventdata, handles)
% hObject handle to time_end_txtedit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of time_end_txtedit as text
% str2double(get(hObject,'String')) returns contents of time_end_txtedit as a double
% --- Executes during object creation, after setting all properties.
function time_end_txtedit_CreateFcn(hObject, eventdata, handles)
% hObject handle to time_end_txtedit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), ...
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in time_settings_refresh_btn.
function time_settings_refresh_btn_Callback(hObject, eventdata, handles)
% hObject handle to time_settings_refresh_btn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
time_start = get(handles.time_start_txtedit, 'String');
time_end = get(handles.time_end_txtedit,'String');
handles.time_start = str2double(time_start);
handles.time_end = str2double(time_end);
if handles.time_start>=handles.time_end
handles.time_start = handles.time_end-0.1;
set(handles.time_start_txtedit,'String', num2str(handles.time_start));
end
display_signal(hObject, eventdata, handles);
display_spectrogram(hObject, eventdata, handles);
display_features_info(hObject, eventdata, handles);
guidata(hObject, handles);
function address_box_Callback(hObject, eventdata, handles)
% hObject handle to address_box (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of address_box as text
% str2double(get(hObject,'String')) returns contents of address_box as a double
% --- Executes during object creation, after setting all properties.
function address_box_CreateFcn(hObject, eventdata, handles)
% hObject handle to address_box (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), ...
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in saveBtn.
function saveBtn_Callback(hObject, eventdata, handles)
% hObject handle to saveBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp(handles.FS)
disp(handles.BPS)
disp(handles.NUMCHAN)
handles.fullpathname = get(handles.address_box, 'String');
audiowrite(handles.fullpathname, handles.Y,...
handles.FS, 'BitsPerSample',handles.BPS)
% --- Executes on button press in playBtn.
function playBtn_Callback(hObject, eventdata, handles)
% hObject handle to playBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isempty(handles.Y)
return;
end
if isempty(handles.player)
handles.player = audioplayer(handles.Y, handles.FS);
end
resume(handles.player);
guidata(hObject, handles);
% --- Executes on button press in pauseBtn.
function pauseBtn_Callback(hObject, eventdata, handles)
% hObject handle to pauseBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)\
if isempty(handles.player)
return;
end
pause(handles.player);
guidata(hObject, handles);
% --- Executes on button press in stopBtn.
function stopBtn_Callback(hObject, eventdata, handles)
% hObject handle to stopBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isempty(handles.player)
return;
end
stop(handles.player);
handles.player = [];
guidata(hObject, handles);
% --- Executes on button press in numchan_def.
function numchan_def_Callback(hObject, eventdata, handles)
% hObject handle to numchan_def (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.NUMCHAN = handles.ORIGINAL_NUMCHAN;
update_numchan_box(hObject, eventdata, handles);
guidata(hObject, handles);
% --- Executes on button press in sf_def.
function sf_def_Callback(hObject, eventdata, handles)
% hObject handle to sf_def (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.FS = handles.ORIGINAL_FS;
handles.player = [];
if ~isempty(handles.Y)
handles.LENGTH = length(handles.Y)/handles.FS;
handles.time_end = handles.LENGTH;
set(handles.time_end_txtedit, 'String', num2str(handles.time_end));
time_settings_refresh_btn_Callback(hObject, eventdata, handles);
update_fs_slider(hObject, eventdata, handles);
display_signal(hObject, eventdata, handles)
display_spectrogram(hObject, eventdata, handles)
end
guidata(hObject, handles);
% --- Executes when selected object is changed in bps_btn_gp.
function bps_btn_gp_SelectionChangedFcn(hObject, eventdata, handles)
% hObject handle to the selected object in bps_btn_gp
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
try
bps8 = get(handles.bps8_rb, 'Value');
bps16 = get(handles.bps16_rb, 'Value');
bps24 = get(handles.bps24_rb, 'Value');
handles.BPS = 8*bps8 + 16*bps16 + 24*bps24;
catch ME
disp(ME)
end
guidata(hObject, handles);
% --- Executes on button press in bps_def.
function bps_def_Callback(hObject, eventdata, handles)
% hObject handle to bps_def (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.BPS = handles.ORIGINAL_BPS;
update_bps_box(hObject, eventdata, handles)
guidata(hObject, handles);
% --- Executes on button press in newBtn.
function newBtn_Callback(hObject, eventdata, handles)
% hObject handle to newBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
check_state('write', handles);
check_data_availability(false, handles)
handles.player = [];
handles.ORIGINAL_LENGTH = '-';
handles.fullpathname = '';
set_information(hObject, eventdata, handles)
handles.recObj = audiorecorder(handles.FS, handles.BPS, handles.NUMCHAN);
clear_features_info(hObject, eventdata, handles)
guidata(hObject, handles);
% --- Executes on button press in recordBtn.
function recordBtn_Callback(hObject, eventdata, handles)
% hObject handle to recordBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
resume(handles.recObj);
% --- Executes on button press in stoprecordBtn.
function pauserecordBtn_Callback(hObject, eventdata, handles)
% hObject handle to stoprecordBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
pause(handles.recObj);
% --- Executes on button press in pauserecordBtn.
function stoprecordBtn_Callback(hObject, eventdata, handles)
% hObject handle to pauserecordBtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
try
stop(handles.recObj);
y = getaudiodata(handles.recObj);
catch ME
return
end
check_state('read', handles);
check_data_availability(true, handles)
handles.ORIGINAL_FS = handles.FS;
handles.ORIGINAL_NUMCHAN = handles.NUMCHAN;
handles.LENGTH = size(y,1)/handles.FS;
handles.ORIGINAL_LENGTH = handles.LENGTH;
handles.fullpathname = strcat(pwd, '\Untitled.wav');
y = y(:,1)./max(abs(y(:,1)));
handles.Y = reshape(y, [1,length(y)]);
handles.time_end = handles.LENGTH;
set(handles.time_end_txtedit, 'String', num2str(handles.time_end))
set_information(hObject, eventdata, handles)
display_signal(hObject, eventdata, handles)
display_spectrogram(hObject, eventdata, handles)
update_numchan_box(hObject, eventdata, handles)
update_fs_slider(hObject, eventdata, handles)
update_bps_box(hObject, eventdata, handles)
display_features_info(hObject, eventdata, handles)
set(handles.time_settings_refresh_btn,'Enable','on')
set(handles.specgram_settings_refresh_btn,'Enable','on')
guidata(hObject, handles);
function check_state(state, handles)
switch state
case 'write'
set(handles.recordBtn,'Enable','on')
set(handles.pauserecordBtn,'Enable','on')
set(handles.stoprecordBtn,'Enable','on')
set(handles.playBtn,'Enable','off')
set(handles.pauseBtn,'Enable','off')
set(handles.stopBtn,'Enable','off')
case 'read'
set(handles.recordBtn,'Enable','off')
set(handles.pauserecordBtn,'Enable','off')
set(handles.stoprecordBtn,'Enable','off')
set(handles.playBtn,'Enable','on')
set(handles.pauseBtn,'Enable','on')
set(handles.stopBtn,'Enable','on')
otherwise
set(handles.recordBtn,'Enable','off')
set(handles.pauserecordBtn,'Enable','off')
set(handles.stoprecordBtn,'Enable','off')
set(handles.playBtn,'Enable','off')
set(handles.pauseBtn,'Enable','off')
set(handles.stopBtn,'Enable','off')
axes(handles.audio_wave);
plot([],[])
axes(handles.audio_wave);
plot([],[])
end
function check_data_availability(data_availability, handles)
switch data_availability
case false
set(handles.audio_wave,'Visible','off')
set(handles.audio_specgram,'Visible','off')
set(handles.sigHidder,'Visible','on')
set(handles.specHidder,'Visible','on')
set(handles.auxHidder,'Visible','on')
set(handles.time_settings_refresh_btn,'Enable','off')
set(handles.specgram_settings_refresh_btn,'Enable','off')
set(handles.aux_plot_refresh,'Enable','off')
case true
set(handles.audio_wave,'Visible','on')
set(handles.audio_specgram,'Visible','on')
set(handles.sigHidder,'Visible','off')
set(handles.specHidder,'Visible','off')
set(handles.auxHidder,'Visible','off')
set(handles.time_settings_refresh_btn,'Enable','on')
set(handles.specgram_settings_refresh_btn,'Enable','on')
set(handles.aux_plot_refresh,'Enable','on')
end
% --- Executes on slider movement.
function time_slider_Callback(hObject, eventdata, handles)
% hObject handle to time_slider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function time_slider_CreateFcn(hObject, eventdata, handles)
% hObject handle to time_slider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), ...
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on button press in time_settings_def.
function time_settings_def_Callback(hObject, eventdata, handles)
% hObject handle to time_settings_def (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
disp(handles.LENGTH)
handles.time_end = handles.LENGTH;
handles.time_start = 0;
set(handles.time_end_txtedit, 'String', num2str(handles.time_end));
set(handles.time_start_txtedit, 'String', num2str(0));
time_settings_refresh_btn_Callback(hObject, eventdata, handles);
display_signal(hObject, eventdata, handles);
display_spectrogram(hObject, eventdata, handles);
guidata(hObject, handles);
function max_freq_field_Callback(hObject, eventdata, handles)
% hObject handle to max_freq_field (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of max_freq_field as text
% str2double(get(hObject,'String')) returns contents of max_freq_field as a double
% --- Executes during object creation, after setting all properties.
function max_freq_field_CreateFcn(hObject, eventdata, handles)
% hObject handle to max_freq_field (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in freq_settings_refresh.
function freq_settings_refresh_Callback(hObject, eventdata, handles)
% hObject handle to freq_settings_refresh (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
max_freq_str = get(handles.max_freq_field, 'String');
if isempty(max_freq_str)
return
end
handles.max_freq = str2double(max_freq_str);
display_spectrogram(hObject, eventdata, handles);
% --- Executes on selection change in window_type_popup.
function window_type_popup_Callback(hObject, eventdata, handles)
% hObject handle to window_type_popup (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns window_type_popup contents as cell array
% contents{get(hObject,'Value')} returns selected item from window_type_popup
% --- Executes during object creation, after setting all properties.
function window_type_popup_CreateFcn(hObject, eventdata, handles)
% hObject handle to window_type_popup (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function pre_emphasis_manual_text_Callback(hObject, eventdata, handles)
% hObject handle to pre_emphasis_manual_text (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of pre_emphasis_manual_text as text
% str2double(get(hObject,'String')) returns contents of pre_emphasis_manual_text as a double
% --- Executes during object creation, after setting all properties.
function pre_emphasis_manual_text_CreateFcn(hObject, eventdata, handles)
% hObject handle to pre_emphasis_manual_text (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in temcbx.
function plot_specs_cbx_Callback(hObject, eventdata, handles)
% hObject handle to temcbx (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
display_features_info(hObject, eventdata, handles)
% Hint: get(hObject,'Value') returns toggle state of temcbx
% --- Executes on button press in temcbx.
function plot_ceps_cbx_Callback(hObject, eventdata, handles)
% hObject handle to temcbx (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
display_features_info(hObject, eventdata, handles)
% Hint: get(hObject,'Value') returns toggle state of temcbx
% --- Executes on button press in temcbx.
function plot_corr_cbx_Callback(hObject, eventdata, handles)
% hObject handle to temcbx (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
display_features_info(hObject, eventdata, handles)
% Hint: get(hObject,'Value') returns toggle state of temcbx
% --- Executes on button press in temcbx.
function plot_amdf_cbx_Callback(hObject, eventdata, handles)
% hObject handle to temcbx (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
display_features_info(hObject, eventdata, handles)
% Hint: get(hObject,'Value') returns toggle state of temcbx
% --- Executes on button press in aux_plot_refresh.
function aux_plot_refresh_Callback(hObject, eventdata, handles)
% hObject handle to aux_plot_refresh (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
display_features_info(hObject, eventdata, handles)
function clear_features_info(hObject, eventdata, handles)
set(handles.energy_val, 'String','-')
set(handles.zcr_val, 'String','-')
set(handles.f1_field, 'String', '-');
set(handles.f2_field, 'String', '-');
set(handles.f3_field, 'String', '-');
cla(handles.aux_plot)
function display_features_info(hObject, eventdata, handles)
cla(handles.aux_plot)
start_index = max(1,floor(handles.time_start*handles.FS));
end_index = min(ceil(handles.time_end*handles.FS),length(handles.Y));
frame = handles.Y(start_index:end_index);
frame = Windowing(frame, 3);
energy = getEnergy(frame);
zcr = getZCR(frame);
[f_vals, f_locs, smoothed_signal]=getFORMANTS(frame, handles.FS);
set(handles.f1_field, 'String', round(f_locs(1)));
set(handles.f2_field, 'String', round(f_locs(2)));
set(handles.f3_field, 'String', round(f_locs(3)));
set(handles.energy_val, 'String',energy)
set(handles.zcr_val, 'String',zcr)
if get(handles.plot_specs_cbx, 'Value')
[spec, f] = getSPEC(frame, handles.FS);
axes(handles.aux_plot);
plot(f, spec, 'magenta');
title('DFT Magnitudes')
xlabel('Frequency')
end
if get(handles.plot_ceps_cbx, 'Value')
ceps = getCEPSTRAL(frame);
axes(handles.aux_plot);
plot(ceps, 'magenta');
title('Cepstral Coefficients')
xlabel('Number of Sample')
end
if get(handles.plot_corr_cbx, 'Value')
corr = getCORR(frame);
axes(handles.aux_plot);
plot(corr, 'magenta');
title('Correlation Coefficients')
xlabel('Number of Sample')
end
if get(handles.plot_amdf_cbx, 'Value')
amdf = getAMDF(frame);
axes(handles.aux_plot);
plot(amdf, 'magenta');
title('AMDF Coefficients')
xlabel('Number of Sample')
end
guidata(hObject, handles);
% --- Executes on selection change in formants_field.
function formants_field_Callback(hObject, eventdata, handles)
% hObject handle to formants_field (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns formants_field contents as cell array
% contents{get(hObject,'Value')} returns selected item from formants_field
% --- Executes during object creation, after setting all properties.
function formants_field_CreateFcn(hObject, eventdata, handles)
% hObject handle to formants_field (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
%%%%%%%%%%%%Speech Recognition%%%%%%%%%%%%%%%%
function trainfileloc_Callback(hObject, eventdata, handles)
% hObject handle to trainfileloc (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of trainfileloc as text
% str2double(get(hObject,'String')) returns contents of trainfileloc as a double
% --- Executes during object creation, after setting all properties.
function trainfileloc_CreateFcn(hObject, eventdata, handles)
% hObject handle to trainfileloc (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function trainlabelsloc_Callback(hObject, eventdata, handles)
% hObject handle to trainlabelsloc (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of trainlabelsloc as text
% str2double(get(hObject,'String')) returns contents of trainlabelsloc as a double
% --- Executes during object creation, after setting all properties.
function trainlabelsloc_CreateFcn(hObject, eventdata, handles)
% hObject handle to trainlabelsloc (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function testfileloc_Callback(hObject, eventdata, handles)
% hObject handle to testfileloc (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of testfileloc as text
% str2double(get(hObject,'String')) returns contents of testfileloc as a double
% --- Executes during object creation, after setting all properties.
function testfileloc_CreateFcn(hObject, eventdata, handles)
% hObject handle to testfileloc (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function testlabelsloc_Callback(hObject, eventdata, handles)