-
Notifications
You must be signed in to change notification settings - Fork 1
/
Cuki_IR_gen1s.m
1534 lines (1384 loc) · 48.9 KB
/
Cuki_IR_gen1s.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
% Acoustic guitar IR generator "light" 1.0
% Author: Kien Phan Huy on the 14th of July 2020. Copyright 2020
% Uses the Min Phase response computation from J.O. Smith, 1982-2002
% Uses amodified versiona of Oct_spectrum from M. Buzzoni, Dec. 2018
% Uses IIR butterworth coefficient computation from Neil Robertson , 12/29/17
% Uses embbeded waitbar Yuanfei (2020). Embedding Waitbar Inside A GUI (https://www.mathworks.com/matlabcentral/fileexchange/47896-embedding-waitbar-inside-a-gui), MATLAB Central File Exchange. Retrieved July 15, 2020.
% See copyrights for subfunctions and roaotine below
% Graphic user interface updated to Octave 7.1 by pokibg
function Cuki_IR_gen1s()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Position ui controls
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f=[143 129 1024 768];
Nu=[1024 768 1024 768];
u1=[305 115 665 430]./Nu; % set(gca,'units','pixels','position',[305 115 665 430])
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
u2=[20 740 280 30]./Nu;
u3=[300 740 300 30]./Nu;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hh=-15; % decalage tout sauf d?but
h2=-30; % d?calage sous interface audio
dd=100; % d?calage droite interface audio
u4=[450 635+hh+h2 500 20]./Nu;;
u5=[20 710+hh 500 30]./Nu;
u6=[50 680+hh dd 30]./Nu;
u7=[20+dd 680+hh 500 30]./Nu;
u8=[50 640+hh dd 30]./Nu;
u9=[20+dd 640+hh 500 30]./Nu;
u10=[550+dd 710+hh 250 30]./Nu; % uicontrol('style','text', 'string','3) Choose Frequency sampling:', ...
u11=[550+dd 680+hh 250 30]./Nu;
u12=[550+dd 640+hh 250 30]./Nu;
u13=[20 630+hh+h2 400 30]./Nu;
u14=[20 600+hh+h2 150 30]./Nu;
u15=[20 550+hh+h2 220 30]./Nu;
u16=[150 520+hh+h2 100 30]./Nu;
u17=[20 520+hh+h2 100 30]./Nu;
u18=[20 470+hh+h2 200 30]./Nu;
u19=[20 440+hh+h2 200 30]./Nu;
u20=[20 390+hh+h2 200 30]./Nu;
u21=[20 360+hh+h2 150 30]./Nu; % uicontrol(dlg, 'style','pushbutton', 'string','Compute IR', 'position',[20 360+hh+h2 150 30]
u22=[20 310+hh+h2 200 30]./Nu;
u23=[20 280+hh+h2 70 30]./Nu;
u24=[100 280+hh+h2 70 30]./Nu;
u25=[180 280+hh+h2 70 30]./Nu;
u26=[20 230+hh+h2 200 30]./Nu;
u27=[20 200+hh+h2 230 30]./Nu;
u28=[20 160+hh+h2 150 30]./Nu;
u29=[20 160+hh+h2 72 30]./Nu;
u30=[100 160+hh+h2 150 30]./Nu; % uicontrol(dlg, 'style','pushbutton', 'string','Save',
u31=[20 120+hh+h2 150 30]./Nu;
u32=[20 20 150 30]./Nu;
u33=[200 20 150 30]./Nu;
u34=[730 20 500 30]./Nu;
u35=[800 740 150 30]./Nu;
## %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Creation figure
dlg = figure('name','Cuki IR generator light v1.0', 'position',f, 'menubar','none', 'numbertitle','off');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Creation axes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%axes1=axes(dlg,'position',[200,100,640,480])
%h=plot(dlg,1:10,1:10,'-o')
ax = axes('NextPlot', 'add');
grid (ax, 'minor');
%set(gca,'position',[0.3 0.15 0.65 0.6])
set(gca,'position',u1)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
uicontrol('style','text', 'string','1) Select your configuration:', ...
'units','normalized','position',u2, ...
'foregroundcolor', 'b', 'backgroundcolor','w', ...
'fontangle','italic', 'horizontalalignment','left');
% Creation du menu deroulant
icfg=uicontrol(dlg,'style','popupmenu', 'string',{'Pickup in CH1, Mic in CH2','Pickup in CH2, Mic in CH1'}, ...
'units','normalized','position',u3);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
hh=-15; % decalage tout sauf d?but
h2=-30; % d?calage sous interface audio
dd=100; % d?calage droite interface audio
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Wait bar
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ax2=axes('NextPlot', 'add');
set(gca,'Position',u4);
%ax2=axes(dlg,'Position',[0.45 0.8 0.4 0.03]);
set(ax2,'Xtick',[],'Ytick',[],'Xlim',[0 1000]);
box on;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Creation liste des interface audio
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
uicontrol('style','text', 'string','2) Choose audio interface+driver:', ...
'units','normalized','position',u5, ...
'foregroundcolor', 'b', 'backgroundcolor','w', ...
'fontangle','italic', 'horizontalalignment','left');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
nDevices = audiodevinfo(0);
devinfo = audiodevinfo();
mot=['liste= {''',devinfo.input(1).Name,''''];
for i=2:size(devinfo.input,2),
mot=[mot,',''',devinfo.input(i).Name,''''];
end
mot=[mot,'};'];
eval(mot);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
uicontrol('style','text', 'string','Input:', ...
'units','normalized','position',u6, ...
'foregroundcolor', 'b', 'backgroundcolor','w', ...
'fontangle','italic', 'horizontalalignment','left');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Creation du menu deroulant INPUT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ai=uicontrol(dlg,'style','popupmenu', 'string',liste, ...
'units','normalized','position',u7, 'callback', @cbk_popupmenu);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
mot=['liste2= {''',devinfo.output(1).Name,''''];
for i=2:size(devinfo.output,2),
mot=[mot,',''',devinfo.output(i).Name,''''];
end
mot=[mot,'};'];
eval(mot);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
uicontrol('style','text', 'string','Output:', ...
'units','normalized','position',u8, ...
'foregroundcolor', 'b', 'backgroundcolor','w', ...
'fontangle','italic', 'horizontalalignment','left');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Creation du menu deroulant OUTPUT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ao=uicontrol(dlg,'style','popupmenu', 'string',liste2, ...
'units','normalized','position',u9);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Creation liste des frequences d'echantillonage
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
uicontrol('style','text', 'string','3) Choose Frequency sampling:', ...
'units','normalized','position',u10, ...
'foregroundcolor', 'b', 'backgroundcolor','w', ...
'fontangle','italic', 'horizontalalignment','left');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fsliste=uicontrol(dlg,'style','popupmenu', 'string',{'44100','48000'}, ...
'units','normalized','position',u11);
bitdepth=uicontrol(dlg,'style','popupmenu', 'string',{'16 bits','24 bits'}, ...
'units','normalized','position',u12,'value',2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Record quick, test levels
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
uicontrol('style','text', 'string','4) Test recording and check levels (optional):', ...
'units','normalized','position',u13, ...
'foregroundcolor', 'b', 'backgroundcolor','w', ...
'fontangle','italic', 'horizontalalignment','left');
uicontrol(dlg, 'style','pushbutton', 'string','Record 10s','units','normalized', 'position',u14, 'callback',{@record20s, ax,ai,devinfo,fsliste,ax2,bitdepth });
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Record long to make IR
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
uicontrol('style','text', 'string','5) Record for IR generation:', ...
'units','normalized','position',u15, ...
'foregroundcolor', 'b', 'backgroundcolor','w', ...
'fontangle','italic', 'horizontalalignment','left');
Trec=uicontrol(dlg,'style','popupmenu', 'string',{'1 min','2 min'}, ...
'units','normalized','position',u16);
uicontrol(dlg, 'style','pushbutton', 'string','Record','units','normalized', 'position',u17, 'callback',{@record2mn, ax,ai,devinfo,fsliste,Trec,ax2,bitdepth});
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Creation liste des formats de sortie
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
uicontrol('style','text', 'string','6) IR file format:', ...
'units','normalized','position',u18, ...
'foregroundcolor', 'b', 'backgroundcolor','w', ...
'fontangle','italic', 'horizontalalignment','left');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
listfmt={'1024 pts, 16 bits','2048 pts, 16 bits','8096 pts, 16 bits','1024 pts, 24 bits','2048 pts, 24 bits','8096 pts, 24 bits'};
fsfmt=uicontrol(dlg,'style','popupmenu', 'string',listfmt, ...
'units','normalized','position',u19,'value',2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Compute IR
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
uicontrol('style','text', 'string','7) Compute IR:', ...
'units','normalized','position',u20, ...
'foregroundcolor', 'b', 'backgroundcolor','w', ...
'fontangle','italic', 'horizontalalignment','left');
uicontrol(dlg, 'style','pushbutton', 'string','Compute IR','units','normalized', 'position',u21, 'callback',{@Go, ax,ai,devinfo,fsfmt,icfg,ax2});
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Listen
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
uilisten=uicontrol('style','text', 'string','8) Listen:', ...
'units','normalized','position',u22, ...
'foregroundcolor', 'b', 'backgroundcolor','w', ...
'fontangle','italic', 'horizontalalignment','left','value',0);
uicontrol(dlg, 'style','togglebutton', 'string','Mic','units','normalized', 'position',u23, 'callback',{@Mic,ax,ai,devinfo,fsfmt,icfg,ao,uilisten});
uicontrol(dlg, 'style','togglebutton', 'string','Pickup','units','normalized', 'position',u24, 'callback',{@Pickup,ax,ai,devinfo,fsfmt,icfg,ao,uilisten});
uicontrol(dlg, 'style','togglebutton', 'string','IR','units','normalized', 'position',u25, 'callback',{@IR,ax,ai,devinfo,fsfmt,icfg,ao,uilisten});
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Save IR
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
uicontrol('style','text', 'string','8) Save IR file:', ...
'units','normalized','position',u26, ...
'foregroundcolor', 'b', 'backgroundcolor','w', ...
'fontangle','italic', 'horizontalalignment','left');
Svfmt=uicontrol(dlg,'style','popupmenu', 'string',{'Standard','Various flavours','Feedback friendly','JF45 Copyright: Jon Fields'}, ...
'units','normalized','position',u27);
if ispc
uicontrol(dlg, 'style','pushbutton', 'string','Save','units','normalized', 'position',u28, 'callback',{@Save,ax,ai,devinfo,fsfmt,icfg,listfmt,Svfmt});
endif
if ismac
uicontrol('style','text', 'string','Filename:', ...
'units','normalized','position',u29, ...
'foregroundcolor', 'b', 'backgroundcolor','w', ...
'fontangle','italic', 'horizontalalignment','left');
Fnam=uicontrol('style','edit', 'string','IR.wav', ...
'units','normalized','position',u30, ...
'foregroundcolor', 'b', 'backgroundcolor','w', ...
'fontangle','italic', 'horizontalalignment','left');
uicontrol(dlg, 'style','pushbutton', 'string','Save','units','normalized', 'position',u31, 'callback',{@Save,ax,ai,devinfo,fsfmt,icfg,listfmt,Svfmt,Fnam});
endif
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Close dlg
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
uicontrol(dlg, 'style','pushbutton', 'string','Close', 'units','normalized', 'position',u32, 'callback',{@Close,ax,dlg});
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Donate
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
uicontrol(dlg, 'style','pushbutton', 'string','Donate','units','normalized', 'position',u33, 'callback',{@Donate,dlg});
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Paypal gift
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
uicontrol('style','text', 'string','Copyright: Kien Phan Huy, July 2020', ...
'units','normalized', 'position',u34, ...
'foregroundcolor', 'b', 'backgroundcolor','w', ...
'fontangle','italic', 'horizontalalignment','left');
#### %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#### % Load file (DEBUG button)
#### %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
## uicontrol(dlg, 'style','pushbutton', 'string','Load File', 'position',[800 740 150 30], 'callback',{@Load,ax,ai,devinfo,fsfmt,icfg,ao,bitdepth});
#### %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
## pause(0.1);
## set(dlg,'position',[143 129 1024 768]); % pour Mac
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Load y file debug
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function Load(hObject, eventdata,ax,ai,devinfo,fsfmt,icfg,ao,bitdepth)
[filename, pathname] = uigetfile({'*.wav','wav files'}, 'Choose a y file');
%Fname='rec24_48000GtL_MicR_.wav';
[y,FS]=audioread([pathname,filename]);
%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Set bitdepth
%%%%%%%%%%%%%%%%%%%%%%%%%%%
indxbits=get(bitdepth,'value');
if indxbits==1
nbits=16;
else
nbits=24;
endif;
handles.nbits=nbits;
handles.y=y;
handles.fs=FS;
guidata(hObject,handles);
end;
function cbk_popupmenu(hObject, eventdata)
% menu_itemms = get(h,'string');
% disp(menu_itemms{get(hObject,'value')})
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Recording 10 sec
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function record20s(hObject, eventdata,ax,ai,devinfo,fsliste,ax2,bitdepth)
% disp('record')
indx=get(ai,'value');
id=devinfo.input(indx).ID;
channels=2;
%nbits=24;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
indxfs=get(fsliste,'value');
if indxfs==1
fs=44100;
%display('44100');
else
fs=48000;
%display('48000');
endif;
%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Set bitdepth
%%%%%%%%%%%%%%%%%%%%%%%%%%%
indxbits=get(bitdepth,'value');
if indxbits==1
nbits=16;
else
nbits=24;
endif;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
recorder = audiorecorder (fs, nbits, channels, id);
length=10;
record(recorder);
frac=0;
%h = waitbar (frac,'Recording...');
for i=1:length
axes(ax2)
cla
rectangle('Position',[0,0,(round(1000*i/length))+1,20],'FaceColor','b');
text(480,10,[num2str(round(100*i/length)),'%']);
%waitbar (i/length, h);
pause(1)
end;
stop(recorder)
%close(h)
y = getaudiodata (recorder);
Nb=size(y,1);
t=(1:Nb)/fs;
nnn=1:100:Nb;
axes(ax)
cla
set(ax, 'XScale', 'linear')
xticks('auto')
xticklabels('auto')
xlim([0 10])
ylim([-1 1])
xlabel('time(s)')
ylabel('amplitude (a.u.)')
plot(ax,t(nnn),y(nnn,1),t(nnn),y(nnn,2));
plot(ax,xlim,[0.1 0.1],'Color','k','linewidth',3)
plot(ax,xlim,[-0.1 -0.1],'Color','k','linewidth',3)
if max(max(abs(y)))<=0.1
title('The signal is too weak (within black lines), increase the gain','Color',[1 0 0])
elseif max(max(abs(y)))>=1
title('Distortion decteted: decrease the gain','Color',[1 0 0])
else
title('Check the signal is not too weak (see black lines)','Color',[0 0 0])
endif;
clear recorder
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Recording 1-2 min
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function record2mn(hObject, eventdata,ax,ai,devinfo,fsliste,Trec,ax2,bitdepth)
% disp('record')
indx=get(ai,'value');
id=devinfo.input(indx).ID;
channels=2;
%nbits=24;
%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Set frequency sampling
%%%%%%%%%%%%%%%%%%%%%%%%%%%
indxfs=get(fsliste,'value');
if indxfs==1
fs=44100;
%display('44100');
else
fs=48000;
%display('48000');
endif;
%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Set bitdepth
%%%%%%%%%%%%%%%%%%%%%%%%%%%
indxbits=get(bitdepth,'value');
if indxbits==1
nbits=16;
else
nbits=24;
endif;
%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Set Rec time
%%%%%%%%%%%%%%%%%%%%%%%%%%%
T=get(Trec,'value');
if T==1
length=1*60;
else
length=2*60;
endif;
recorder = audiorecorder (fs, nbits, channels, id);
record(recorder);
frac=0;
%h = waitbar (frac,'Recording...');
for i=1:length
%waitbar (i/length, h);
axes(ax2)
cla
rectangle('Position',[0,0,(round(1000*i/length))+1,20],'FaceColor','b');
text(480,10,[num2str(round(100*i/length)),'%']);
pause(1)
end;
stop(recorder)
%close(h)
y = getaudiodata (recorder);
Nb=size(y,1);
t=(1:Nb)/fs;
nnn=1:1000:Nb;
axes(ax)
cla
set(ax, 'XScale', 'linear')
xticks('auto')
xticklabels('auto')
xlim([0 length])
ylim([-1 1])
xlabel('time(s)')
ylabel('amplitude (a.u.)')
plot(ax,xlim,[0.1 0.1],'Color','k','linewidth',3)
plot(ax,xlim,[-0.1 -0.1],'Color','k','linewidth',3)
plot(ax,t(nnn),y(nnn,1),t(nnn),y(nnn,2));
## if max(max(abs(y)))<=0.1
## title('The signal is too weak (within black lines), increase the gain','Color',[1 0 0])
## elseif max(max(abs(y)))>=1
## title('Distortion decteted: decrease the gain','Color',[1 0 0])
## else
## title('Check the signal is not too weak (see black lines)','Color',[0 0 0])
## endif;
clear recorder
handles.y=y;
handles.fs=fs;
handles.nbits=nbits;
guidata(hObject,handles);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Go: Compute IR
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function Go(hObject, eventdata,ax,ai,devinfo,fsfmt,icfg,ax2)
frac=0;
%h = waitbar (frac,'Computing...');
axes(ax2)
cla
rectangle('Position',[0,0,(round(1000*0))+1,20],'FaceColor','b');
text(480,10,[num2str(round(100*0)),'%']);
pause(0.01)
handles = guidata(hObject);
y=handles.y;
fs=handles.fs;
nbits=handles.nbits;
Nb=size(y,1);
indxinput=get(icfg,'value');
if indxinput==1
MIC=y(:,2); %mic;
PIC=y(:,1); %pic;
else
MIC=y(:,1); %mic;
PIC=y(:,2); %pic;
endif
Nb=size(y,1);
indxfmt=get(fsfmt,'value');
if (indxfmt == 1)||(indxfmt == 4)
NbF=1024;
endif
if (indxfmt == 2)||(indxfmt == 5)
NbF=2048;
endif
if (indxfmt == 3)||(indxfmt == 6)
NbF=8096;
endif
Nbuff=fs;
Nbmax=floor(Nb/Nbuff)-10;
FS=fs;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FIR calculaiton
FIR1 =zeros(NbF,1);
clear alice;
for n=1:Nbmax, % 200
q=n;
i=2*FS;
i=i+n*Nbuff;
% window = (.42-.5*cos(2*pi*(0:Nbuff-1)/(Nbuff-1))+.08*cos(4*pi*(0:Nbuff-1)/(Nbuff-1)))';
% FIR=fft(MIC(i:i+Nbuff-1).*window,NbF)./fft(PIC(i:i+Nbuff-1).*window,NbF);
FIR=fft(MIC(i:i+Nbuff-1),NbF)./fft(PIC(i:i+Nbuff-1),NbF);
IR=zeros(Nbuff,1);
IR(1:NbF)=real(ifft(FIR));
IR=IR/max(abs(IR));
if ((max(isinf(FIR))==1)||(max(isnan(FIR))==1))
IR=zeros(Nbuff,1);
IR(1)=1;
FIR=fft(IR,NbF);
display('NaN or Inf');
end;
alice(1:NbF,q)=FIR;
FIR1=FIR1+FIR;
if mod(round(n/Nbmax*100),10)==0
%round(n/Nbmax*100)
%waitbar (n/Nbmax/3, h);
axes(ax2)
cla
rectangle('Position',[0,0,(round(1000*n/Nbmax/3))+1,20],'FaceColor','b');
text(480,10,[num2str(round(100*n/Nbmax/3)),'%']);
pause(0.01)
%waitbar(n/Nbmax,f,'Processing...');
end;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Post selection Processing
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NN=size(alice,1);
for i=1:NN, % POur chaque frequence
a=alice(i,:);
A=a(abs(abs(a)-mean(a))<2*std(a)); % On ne garde que les echantillons compris dans 2 ecarts types
ALICE(i)=mean(A);
if isnan(mean(A)),
%display('Algorithm Failed: Increase the recording length and/or improve the S/N ratio');
ALICE(i)=1;
end
Q(i)=length(A);
if mod(round(i/NN*100),10)==0
%round(n/Nbmax*100)
%waitbar (1/3+i/NN/3, h);
axes(ax2)
cla
rectangle('Position',[0,0,(round(1000*(1/3+i/NN/3)))+1,20],'FaceColor','b');
text(480,10,[num2str(round(100*(1/3+i/NN/3))),'%']);
pause(0.01)
%waitbar(n/Nbmax,f,'Processing...');
end;
end;
dnuX=FS/NbF;
nuX=(-NbF/2:NbF/2-1)*dnuX;
nn=NbF/2+1:NbF;
window = (.42-.5*cos(2*pi*(0:2*NbF-1)/(2*NbF-1))+.08*cos(4*pi*(0:2*NbF-1)/(2*NbF-1)))';
blackmanwin=window(NbF+1:end);
ir2=ifft(ALICE);
ir2=ir2.*blackmanwin';
ir2=ir2/max(abs(ir2))*0.95;
IR2(1:NbF,1)=real(ir2);% raw IR generated
%plot(IR2)
IR0=IR2;
nn=(10*FS+1:20*FS);
MS=MIC(nn,1);
PS=PIC(nn,1);
%waitbar(0.6, h);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Generate Two Octave spectrum (Mic & Pic convolved)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%pkg load signal;
PS=conv(PIC(nn,1),IR0,'same');
[p,cf,overall_lev,overall_levA,sfilt] = oct_spectrum2(MS/max(abs(MS)),FS,3,1,1,0);
[p2,cf2,overall_lev,overall_levA,sfilt] = oct_spectrum2(PS/max(abs(PS)),FS,3,1,1,0);
pp=[p+100;p2+100];
##figure(10)
##c=bar(log10(cf),pp')
##%c=bar(log10(cf),p+100)
##grid on
##legend('Mic','Convolved Pickup')
## xlabel('Frequency 10^n (Hz)')
##ylabel('dB')
##figure(3)
##plot(10*log10(cf),p-p2)
g0=p-p2; % SB-SB2;
%dgain=zeros(31,1); % il est l? le probl?me
dgain=zeros(length(cf),1); % il est l? le probl?me
for qq=1:3, % iteration GEQ fit
IRX=zeros(NbF,1);
IRX(1)=1;
IR1=IR0;
for i=1:length(p) % Browse each frequency of the octave spectrum
g=g0(i)+dgain(i); % dgain terme correctif GEQ fit
Q=4;
fc=cf(i);
% IIR coefficient calculation
g=10^(g/20);
t0=2*pi*fc/fs;
if g >= 1
beta=t0/(2*Q);
else
beta=t0/(2*g*Q);
endif
a2=-0.5*(1-beta)/(1+beta);
a1=(0.5-a2)*cos(t0);
b0=(g-1)*(0.25+0.5*a2)+0.5;
b1=-a1;
b2=-(g-1)*(0.25+0.5*a2)-a2;
% SOS Form
b=2*[b0 b1 b2];
a=[1 -2*a1 -2*a2];
IRX=filter(b,a,IRX); % test
IR1=filter(b,a,IR1); % final
mot=['b',num2str(i,'%02d'),'=b;'];
eval(mot);
mot=['a',num2str(i,'%02d'),'=a;'];
eval(mot);
end;
dnuX=FS/NbF;
nuX=(-NbF/2:NbF/2-1)*dnuX;
nn=NbF/2+1:NbF;
s0=20*log10(abs(fftshift(fft(IRX)))); % compute the GEQ spectrum
## figure(1)
## plot(10*log10(nuX(nn)),s0(nn))
dxx=(nuX(2)-nuX(1))/2;
for i=1:length(cf)
n=(abs(nuX-cf(i))<dxx);
gainGEQ(i)=s0(n); % compute the GEQ spectrum at the octave frequencies
end;
## %cl=lines(qq+1);
## figure(3)
## hold on
## %plot(10*log10(cf),gainGEQ,'o-')
## plot(10*log10(nuX(nn)),s0(nn))
## hold off
dgain=dgain-(gainGEQ'-g0')/2;
%waitbar(2/3+qq*0.1, h);
axes(ax2)
cla
rectangle('Position',[0,0,(round(1000*(2/3+qq*0.1)))+1,20],'FaceColor','b');
text(480,10,[num2str(round(100*(2/3+qq*0.1))),'%']);
pause(0.01)
end;
## figure(2)
## plot(10*log10(nuX(nn)),s0(nn))
## hold on
## plot(10*log10(cf),p-p2)
## hold off
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
axes(ax)
cla
xticks([20 50 100 200 400 800 1600 3200 6400 12000 20000])
xticklabels({'20Hz','50Hz','100Hz','200Hz','400Hz','800Hz','1.6kHz','3.2kHz','6.4kHz','12kHz','20kHz'})
xlim('auto')
ylim('auto')
xlim([20 22050])
xlabel('frequency (Hz)')
ylabel('dB')
IR1=IR1/max(abs(IR1))*0.95;
s1=20*log10(abs(fftshift(fft(IR1)))); % compute the GEQ spectrum
n2=NbF/2+2:NbF;
semilogx(ax,nuX(n2),s1(n2));
%semilogx(nuX(n2),s1(n2));
n800=(abs(nuX)<800);
nuX2=nuX(n800);
s12=s1(n800);
[pks idx] = max(s12);
f_mx=abs(nuX2(idx))
%[pks idx] = max(s1);
%f_mx=abs(nuX(idx));
plot(ax,xlim,[0 0],'Color','k','linewidth',1,'linestyle',':')
plot(ax,f_mx,pks,'or')
%plot(f_mx,pks,'or')
text(f_mx+50,pks,[num2str(f_mx,'%3.0f'),'Hz']);
mot=['IR spectrum, feedback frequency is: ',num2str(f_mx,'%3.0f'),'Hz'];
title(mot)
handles.IR1=IR1; % GEQ IR
handles.IR2=IR2; % Raw IR
guidata(hObject,handles);
%waitbar(1, h);
axes(ax2)
%cla
rectangle('Position',[0,0,(round(1000*(1)))+1,20],'FaceColor','b');
text(480,10,[num2str(round(100*(1))),'%']);
pause(1)
%close(h)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Listen to Mic
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function Mic(hObject, eventdata,ax,ai,devinfo,fsfmt,icfg,ao,uilisten)
if (get(hObject,'value')&&(get(uilisten,'value')==0)) % ?gal ? 1 => true
set(uilisten,'value',1);
handles = guidata(hObject);
y=handles.y;
fs=handles.fs;
nbits=handles.nbits;
Nb=size(y,1);
n3=10*fs:20*fs;
indxinput=get(icfg,'value');
if indxinput==1
MIC=y(:,2); %mic;
PIC=y(:,1); %pic;
else
MIC=y(:,1); %mic;
PIC=y(:,2); %pic;
endif
indx=get(ao,'value');
id=devinfo.output(indx).ID;
player = audioplayer (MIC(n3), fs, nbits, id);
play(player);
%soundsc(MIC(n3),fs,nbits);
pause(10.5)
clear player;
set(hObject,'value',0);
set(uilisten,'value',0);
elseif (get(hObject,'value')&&(get(uilisten,'value')==1))
set(hObject,'value',0);
else
set(hObject,'value',1);
endif;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Listen to Pickup
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function Pickup(hObject, eventdata,ax,ai,devinfo,fsfmt,icfg,ao,uilisten)
if (get(hObject,'value')&&(get(uilisten,'value')==0)) % ?gal ? 1 => true
set(uilisten,'value',1);
handles = guidata(hObject);
y=handles.y;
fs=handles.fs;
nbits=handles.nbits;
Nb=size(y,1);
n3=10*fs:20*fs;
indxinput=get(icfg,'value');
if indxinput==1
MIC=y(:,2); %mic;
PIC=y(:,1); %pic;
else
MIC=y(:,1); %mic;
PIC=y(:,2); %pic;
endif
%soundsc(PIC(n3),fs,nbits);
indx=get(ao,'value');
id=devinfo.output(indx).ID;
player = audioplayer (PIC(n3), fs, nbits, id);
play(player);
pause(10.5)
clear player;
set(hObject,'value',0);
set(uilisten,'value',0);
elseif (get(hObject,'value')&&(get(uilisten,'value')==1))
set(hObject,'value',0);
else
set(hObject,'value',1);
endif;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Listen to IR
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function IR(hObject, eventdata,ax,ai,devinfo,fsfmt,icfg,ao,uilisten)
if (get(hObject,'value')&&(get(uilisten,'value')==0)) % ?gal ? 1 => true
set(uilisten,'value',1);
handles = guidata(hObject);
y=handles.y;
fs=handles.fs;
nbits=handles.nbits;
IRGEQ=handles.IR1;
Nb=size(y,1);
n3=10*fs:20*fs;
indxinput=get(icfg,'value');
if indxinput==1
MIC=y(:,2); %mic;
PIC=y(:,1); %pic;
else
MIC=y(:,1); %mic;
PIC=y(:,2); %pic;
endif
PS=conv(PIC(n3),IRGEQ,'same');
PS=PS/max(abs(PS))*max(abs(PIC(n3)));
%soundsc(PS,fs,nbits);
indx=get(ao,'value');
id=devinfo.output(indx).ID;
player = audioplayer (PS, fs, nbits, id);
play(player);
pause(10.5)
clear player;
set(hObject,'value',0);
set(uilisten,'value',0);
elseif (get(hObject,'value')&&(get(uilisten,'value')==1))
set(hObject,'value',0);
else
set(hObject,'value',1);
endif;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Save IR file
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function Save(hObject, eventdata,ax,ai,devinfo,fsfmt,icfg,listfmt,Svfmt,Fnam)
handles = guidata(hObject);
rawIR=handles.IR2;
IRGEQ=handles.IR1;
fs=handles.fs;
nbits=handles.nbits;
Nb=size(IRGEQ,1);
indxfmt=get(fsfmt,'value');
if (indxfmt <= 3)
nbits=16;
else
nbits=24;
endif
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% SMooth the high end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FS=fs;
NbF=Nb;
dnuX1=FS/NbF;
nuX1=(-NbF/2:NbF/2-1)*dnuX1;
wi = FS/2/1e4*logspace(1,4,NbF);
w=sort([-wi,0,wi],2);
%plot(w)
%grid on
s=fftshift(fft(IRGEQ));
ss=interp1(nuX1,s,w); % On interpole sur une grille/echelle log en frequence (perte d'info dans le haut du spectre
##figure
##plot(nuX1,abs(s),w,abs(ss))
##grid on
##title('amplitude')
##
##figure
##plot(nuX1,abs(s),w,abs(ss))
##grid on
##title('phase')
snew=interp1(w,ss,nuX1); % On retourne sur une grille lineaire
%snew=interp1(w,ss,nuX1,'spline');
% On vire les NaN
for i=1:length(IRGEQ)
if isnan(snew(i))
snew(i)=s(i);
end;
end;
##s1new=20*log10(abs(snew));
##
##figure(1)
##%hold on
##plot(nuX1,s1,nuX1,s1new);
##grid on
##set(gca,'Xscale','log')
##xlim([20 20e3])
##ylim([-60 40])
##xlabel('Frequency (Hz)')
##ylabel('dB')
##%hold off
yy=real(ifft(ifftshift(snew)));
%IR0old=IR0;
IRITP=yy/max(abs(yy))*0.95;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Standard
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if ispc
[filename, pathname] = uiputfile('*.wav', 'Save as','IR_std.wav');
Fname=[pathname,filename];
audiowrite(Fname,IRGEQ/max(abs(IRGEQ))*0.95,fs,'BitsPerSample',nbits);
[filename, pathname] = uiputfile('*.wav', 'Save as','IR_itp.wav');
Fname=[pathname,filename];
audiowrite(Fname,IRITP/max(abs(IRITP))*0.95,fs,'BitsPerSample',nbits);
end
if ismac
Fname=get(Fnam,'string');
audiowrite(Fname,IRGEQ/max(abs(IRGEQ))*0.95,fs,'BitsPerSample',nbits);
Fname2=[Fname(1:end-4),'_ITP.wav'];
audiowrite(Fname2,IRITP/max(abs(IRITP))*0.95,fs,'BitsPerSample',nbits);
end
Fname2=[Fname(1:end-4),'.jpg'];
print(gcf,Fname2,'-djpeg','-r300');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Options
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SAVEfmt=get(Svfmt,'value');
if SAVEfmt==2
% Raw
Fname2=[Fname(1:end-4),'_raw.wav'];
audiowrite(Fname2,rawIR/max(abs(rawIR))*0.95,fs,'BitsPerSample',nbits);
% GEQ+Blend
IR0=zeros(Nb,1);
IR0(1)=1;
IRblend=(IR0+IRGEQ)/2;
Fname2=[Fname(1:end-4),'_Bld.wav'];
audiowrite(Fname2,IRblend/max(abs(IRblend))*0.95,fs,'BitsPerSample',nbits);
% Minimum Phase
s=fft(IRGEQ);
sm = exp( fft( fold( ifft( log( clipdb(s,-100) )))));
IRmph=real(ifft(sm));
Fname2=[Fname(1:end-4),'_MPh.wav'];
audiowrite(Fname2,IRmph/max(abs(IRmph))*0.95,fs,'BitsPerSample',nbits);
end;
if SAVEfmt==3 % Feedback friendly
y=handles.y;
fs=handles.fs;
%nbits=handles.nbits;
Nb=size(y,1);
FS=fs;
indxinput=get(icfg,'value');
if indxinput==1
MIC=y(:,2); %mic;
PIC=y(:,1); %pic;
else
MIC=y(:,1); %mic;
PIC=y(:,2); %pic;
endif
nn=(10*FS+1:20*FS);
MS=MIC(nn,1);
PS=PIC(nn,1);
% COmpute Feedback frequency
NbF=Nb;
dnuX=FS/NbF;
nuX=(-NbF/2:NbF/2-1)*dnuX;
s1=20*log10(abs(fftshift(fft(IRGEQ)))); % compute the GEQ spectrum
n800=(abs(nuX)<800);
nuX2=nuX(n800);
s12=s1(n800);
[pks idx] = max(s12);
f_mx=abs(nuX2(idx))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% generate PEQ
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
g=-6; % -6dB ? la resonance
Q=3;
fc=f_mx;
% IIR coefficient calculation
g=10^(g/20);
t0=2*pi*fc/fs;
if g >= 1
beta=t0/(2*Q);
else
beta=t0/(2*g*Q);
endif
a2=-0.5*(1-beta)/(1+beta);
a1=(0.5-a2)*cos(t0);
b0=(g-1)*(0.25+0.5*a2)+0.5;
b1=-a1;
b2=-(g-1)*(0.25+0.5*a2)-a2;
% SOS Form
b=2*[b0 b1 b2];
a=[1 -2*a1 -2*a2];
IRX=filter(b,a,IRGEQ); % FIltre IR
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% generate Shelf EQ
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
g=-1; % -1dB en shelf