comparison src/matlab/Sound.m @ 0:c52bc3e8d3ad tip

user: boblsturm branch 'default' added README.md added assets/.DS_Store added assets/playButton.jpg added assets/stopButton.png added assets/swapButton.jpg added data/.DS_Store added data/fiveoctaves.mp3 added data/glock2.wav added data/sinScale.mp3 added data/speech_female.mp3 added data/sweep.wav added nimfks.m.lnk added src/.DS_Store added src/matlab/.DS_Store added src/matlab/AnalysisCache.m added src/matlab/CSS.m added src/matlab/DataHash.m added src/matlab/ExistsInCache.m added src/matlab/KLDivCost.m added src/matlab/LoadFromCache.m added src/matlab/SA_B_NMF.m added src/matlab/SaveInCache.m added src/matlab/Sound.m added src/matlab/SynthesisCache.m added src/matlab/chromagram_E.m added src/matlab/chromagram_IF.m added src/matlab/chromagram_P.m added src/matlab/chromsynth.m added src/matlab/computeSTFTFeat.m added src/matlab/controller.m added src/matlab/decibelSliderReleaseCallback.m added src/matlab/drawClickCallBack.m added src/matlab/fft2chromamx.m added src/matlab/hz2octs.m added src/matlab/ifgram.m added src/matlab/ifptrack.m added src/matlab/istft.m added src/matlab/nimfks.fig added src/matlab/nimfks.m added src/matlab/nmfFn.m added src/matlab/nmf_beta.m added src/matlab/nmf_divergence.m added src/matlab/nmf_euclidean.m added src/matlab/prune_corpus.m added src/matlab/rot_kernel.m added src/matlab/templateAdditionResynth.m added src/matlab/templateDelCb.m added src/matlab/templateScrollCb.m
author boblsturm
date Sun, 18 Jun 2017 06:26:13 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c52bc3e8d3ad
1 classdef Sound < handle
2 properties
3 Filename
4 Directory
5 Sampling_rate
6 Bits_per_sample
7 Audioplayer
8 Time_length
9 Signal
10 Features
11 end
12
13 methods
14 function obj = Sound(varargin)
15 if nargin == 1
16 [pathstr, name, ext] = fileparts(varargin{1});
17 obj.Filename = strcat(name, ext);
18 obj.Directory = pathstr;
19 elseif nargin == 2
20 obj.Signal = varargin{1};
21 obj.Sampling_rate = varargin{2};
22 end
23
24 obj.init;
25 end
26
27 function obj = init(obj)
28 if ~isempty(obj.Filename)
29 [Y, Fs] = audioread([obj.Directory filesep obj.Filename]);
30
31 %Convert to Monophonic sound
32 if(size(Y, 2) ~= 1)
33 Y = (Y(:,1)+Y(:,2))/2;
34 end
35
36 obj.Signal = Y;
37 obj.Sampling_rate = Fs;
38 end
39
40 obj.Time_length = length(obj.Signal)/obj.Sampling_rate;
41
42 obj.Audioplayer= audioplayer(obj.Signal, obj.Sampling_rate);
43 obj.Bits_per_sample = obj.Audioplayer.BitsPerSample;
44 end
45 end
46
47 methods
48 function control_audio(obj, action)
49 switch action
50 case 'play'
51 play(obj.Audioplayer);
52 case 'stop'
53 stop(obj.Audioplayer);
54 case 'pause'
55 obj.Audioplayer.pause;
56 case 'resume'
57 obj.Audioplayer.resume;
58 end
59 end
60
61 function save_audio(obj)
62 handles = guidata(gcf);
63 [file,path] = uiputfile({'*.wav'},'Save Sound As');
64 audiowrite([path filesep file], handles.SynthesisObject.Synthesis, handles.Sound_corpus.Sampling_rate);
65 end
66
67 function plot_spectrogram(obj, varargin)
68 if nargin > 1
69 mindB = varargin{1};
70 else
71 mindB = 80;
72 end
73
74 S = obj.Features.STFT.S;
75 F = obj.Features.STFT.F;
76 T = obj.Features.STFT.T;
77
78 dB = 20*log10(abs(S)/max(max(abs(S))));
79 sonodB = max(-mindB, dB);
80 imagesc(T,F./1000,sonodB);
81 cmap = colormap('jet');
82 cmap(1,:) = 0*ones(1,3);
83 colormap((cmap));
84 colorbar
85 axis xy; grid on;
86 axis([0 T(end) 0.01 10]);
87 set(gca,'XTick',[0:0.5:T(end)],'XTickLabel','');
88 set(gca, 'Layer', 'top');
89 ylabel('Frequency (kHz)');
90 grid on;
91 set(gca,'FontSize',16);
92 end
93
94 function plot_chromagram()
95 end
96
97 function plot_templates(obj)
98 W=abs(obj.Features.STFT.S);
99 F=abs(obj.Features.STFT.F);
100 hold on; grid on;
101 [~,I]=max(W);
102 [~,Ix] = sort(I,'ascend');
103 for jj=1:size(W,2)
104 specdB=W(:,Ix(jj))/max(max(W));
105 handle=plot3(jj*ones(size(W,1),1),F/1000,specdB, ...
106 'Color',power((size(W,2)-jj)/(size(W,2)+1),0.65)*ones(3,1), ...
107 'LineWidth',8*(2+size(W,2)-jj)/(size(W,2)));
108 end
109 ylabel('Frequency (kHz)');
110 xlabel('Template');
111 zlabel('Magnitude');
112 view(105,26);
113 end
114
115 function plot_signal(obj)
116 plot([1:length(obj.Signal)]/obj.Sampling_rate, obj.Signal, 'Color', [0, 0, 0]);
117 end
118
119 function obj = computeFeatures(obj, window, analysis)
120 obj.Features.window = window;
121
122 if(strcmp(analysis, 'STFT'))
123 obj.Features.STFT = computeSTFTFeat(obj.Signal, obj.Sampling_rate, obj.Features.window);
124 elseif(strcmp(analysis, 'CQT'))
125
126 elseif(strcmp(analysis, 'Chroma'))
127
128 end
129 end
130
131 function obj = concat(obj, sound)
132 obj.Signal = [ obj.Signal; sound.Signal ];
133
134 obj.Time_length = length(obj.Signal)/obj.Sampling_rate;
135
136 obj.Audioplayer= audioplayer(obj.Signal, obj.Sampling_rate);
137 obj.Bits_per_sample = obj.Audioplayer.BitsPerSample;
138 end
139 end
140 end