Mercurial > hg > nimfks
changeset 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
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,5 @@ +# Sound Synthesis Using Non-Negative Matrix Factorization Techniques + +Guide: + +Run the application by starting the "nimfks.m" file within a Matlab environment (preferably version 2016a to avoid any error). The file is located in "src/matlab/". \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/AnalysisCache.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,34 @@ + classdef AnalysisCache < handle + properties + Corpus + Target + WinType + Window + Hop + Hash + end + + methods + function obj = AnalysisCache(varargin) + % [Corpus Target Window Hop] + if nargin == 5 + obj.Corpus = varargin{1}; + obj.Target = varargin{2}; + obj.Window = varargin{3}; + obj.WinType = varargin{4}; + obj.Hop = varargin{5}; + end + end + + function obj = GenerateHash(obj) + ArrayToHash = [obj.Corpus; obj.Target; obj.WinType; obj.Window; obj.Hop]; + Opt = struct( 'Method', 'SHA-1' ); + try + obj.Hash = ['id', char(DataHash(ArrayToHash, Opt))]; + catch ME + disp( ME ); + obj.Hash = abs( floor( 1000*randn ) ); + end + end + end +end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/CSS.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,126 @@ +classdef CSS < handle + properties + NMF_features + Activations + Cost + Synthesis_method + Synthesis + end + + methods + function obj = CSS(varargin) + if nargin == 2 + obj.NMF_features = varargin{1}; + obj.Synthesis_method = varargin{2}; + end + end + end + + methods + function obj = nmf(obj, corpus_sound, target_sound, varargin) + if( nargin == 4 ) + pct_prune = varargin{1} + else + pct_prune = 1 + end + nmf_alg = obj.NMF_features.Algorithm; + target_spect = abs(target_sound.Features.STFT.S); + corpus_spect = abs(corpus_sound.Features.STFT.S); + [corpus_spect, pruned_frames, frames_to_keep] = prune_corpus( target_spect, corpus_spect, pct_prune ); + + switch nmf_alg + case 'Euclidean' + if length(fieldnames(obj.NMF_features)) > 1 + [H, obj.Cost] = nmf_euclidean(target_spect, corpus_spect, obj.NMF_features); + else + [H, obj.Cost] = nmf_euclidean(target_spect, corpus_spect); + end + case 'Divergence' + if length(fieldnames(obj.NMF_features)) > 1 + [H, obj.Cost] = nmf_divergence(target_spect, corpus_spect, obj.NMF_features); + else + [H, obj.Cost] = nmf_divergence(target_spect, corpus_spect); + end + case 'Sparse NMF' + if length(fieldnames(obj.NMF_features)) > 1 + [~, H, deleted, obj.Cost] = SA_B_NMF(target_spect, corpus_spect, 5, obj.NMF_features); + else + [~, H, deleted, obj.Cost] = SA_B_NMF(target_spect, corpus_spect, 5 ); + end + + H( deleted, : ) = 0; + obj.Activations = H; + end + + if size( frames_to_keep ) > 0 + tmp = zeros( size( corpus_sound.Features.STFT.S,2 ), size( target_spect,2 ) ); + for i = 1:length( frames_to_keep ) + tmp(frames_to_keep(i), :) = H(i,:); + end + H = tmp; + end +% H( pruned_frames, : ) = 0; +% % Pad activations to size of corpus frames +% % since pruned frames maximum can be < size of corpus +% H( setdiff( 1:( size( corpus_spect, 2 ) + length( pruned_frames ) ), 1:size( H, 1 ) ), : ) = 0; + obj.Activations = H; + end + + function obj = synthesize(obj, corpus_sound) + synth_method = obj.Synthesis_method; + win = corpus_sound.Features.window; + W = abs(corpus_sound.Features.STFT.S); + H = obj.Activations; + + switch synth_method + case 'ISTFT' + parameters = []; + parameters.synHop = win.Hop; + parameters.win = window(lower(win.Type), win.Length); + + reconstruction = W*H; + padding = size(reconstruction, 1)*2 - win.Length - 2; + if padding >= 0 + parameters.zeroPad = padding; + end + + obj.Synthesis = istft(reconstruction, parameters); + case 'Template Addition' + obj.Synthesis = templateAdditionResynth(corpus_sound.Signal, H, win); + end + end + + function plot_activations(obj, varargin) + if(nargin > 1) + maxDb = varargin{1}; + else + maxDb = -45; + end + + H = obj.Activations; + + HdB = 20*log10(H./max(max(H))); + HdB = HdB - maxDb; + HdB(HdB < 0) = 0; + imagesc(HdB); + cmap = colormap('gray'); + cmap(1,:) = 0*ones(1,3); + colormap(flipud(cmap)) + colorbar + axis xy; grid on; + set(gca, 'Layer', 'top'); + ylabel('Template'); + xlabel('Time'); + grid on; + set(gca,'FontSize',16); + end + + function plot_cost(obj) + plot(obj.Cost); + xlabel('Iteration'); + ylabel('Cost'); + title('Cost vs. Iteration'); + grid on + end + end +end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/DataHash.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,484 @@ +function Hash = DataHash(Data, Opt) +% DATAHASH - Checksum for Matlab array of any type +% This function creates a hash value for an input of any type. The type and +% dimensions of the input are considered as default, such that UINT8([0,0]) and +% UINT16(0) have different hash values. Nested STRUCTs and CELLs are parsed +% recursively. +% +% Hash = DataHash(Data, Opt) +% INPUT: +% Data: Array of these built-in types: +% (U)INT8/16/32/64, SINGLE, DOUBLE, (real/complex, full/sparse) +% CHAR, LOGICAL, CELL (nested), STRUCT (scalar or array, nested), +% function_handle. +% Opt: Struct to specify the hashing algorithm and the output format. +% Opt and all its fields are optional. +% Opt.Method: String, known methods for Java 1.6 (Matlab 2011b): +% 'SHA-1', 'SHA-256', 'SHA-384', 'SHA-512', 'MD2', 'MD5'. +% Call DataHash without inputs to get a list of available methods. +% Default: 'MD5'. +% Opt.Format: String specifying the output format: +% 'hex', 'HEX': Lower/uppercase hexadecimal string. +% 'double', 'uint8': Numerical vector. +% 'base64': Base64 encoded string, only printable ASCII +% characters, shorter than 'hex', no padding. +% Default: 'hex'. +% Opt.Input: Type of the input as string, not case-sensitive: +% 'array': The contents, type and size of the input [Data] are +% considered for the creation of the hash. Nested CELLs +% and STRUCT arrays are parsed recursively. Empty arrays of +% different type reply different hashs. +% 'file': [Data] is treated as file name and the hash is calculated +% for the files contents. +% 'bin': [Data] is a numerical, LOGICAL or CHAR array. Only the +% binary contents of the array is considered, such that +% e.g. empty arrays of different type reply the same hash. +% 'ascii': Same as 'bin', but only the 8-bit ASCII part of the 16-bit +% Matlab CHARs is considered. +% Default: 'array'. +% +% OUTPUT: +% Hash: String, DOUBLE or UINT8 vector. The length depends on the hashing +% method. +% +% EXAMPLES: +% % Default: MD5, hex: +% DataHash([]) % 5b302b7b2099a97ba2a276640a192485 +% % MD5, Base64: +% Opt = struct('Format', 'base64', 'Method', 'MD5'); +% DataHash(int32(1:10), Opt) % +tJN9yeF89h3jOFNN55XLg +% % SHA-1, Base64: +% S.a = uint8([]); +% S.b = {{1:10}, struct('q', uint64(415))}; +% Opt.Method = 'SHA-1'; +% Opt.Format = 'HEX'; +% DataHash(S, Opt) % 18672BE876463B25214CA9241B3C79CC926F3093 +% % SHA-1 of binary values: +% Opt = struct('Method', 'SHA-1', 'Input', 'bin'); +% DataHash(1:8, Opt) % 826cf9d3a5d74bbe415e97d4cecf03f445f69225 +% % SHA-256, consider ASCII part only (Matlab's CHAR has 16 bits!): +% Opt.Method = 'SHA-256'; +% Opt.Input = 'ascii'; +% DataHash('abc', Opt) +% % ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad +% % Or equivalently: +% Opt.Input = 'bin'; +% DataHash(uint8('abc'), Opt) +% +% NOTES: +% Function handles and user-defined objects cannot be converted uniquely: +% - The subfunction ConvertFuncHandle uses the built-in function FUNCTIONS, +% but the replied struct can depend on the Matlab version. +% - It is tried to convert objects to UINT8 streams in the subfunction +% ConvertObject. A conversion by STRUCT() might be more appropriate. +% Adjust these subfunctions on demand. +% +% MATLAB CHARs have 16 bits! Use Opt.Input='ascii' for comparisons with e.g. +% online hash generators. +% +% Matt Raum suggested this for e.g. user-defined objects: +% DataHash(getByteStreamFromArray(Data) +% This works very well, but unfortunately getByteStreamFromArray is +% undocumented, such that it might vanish in the future or reply different +% output. +% +% For arrays the calculated hash value might be changed in new versions. +% Calling this function without inputs replies the version of the hash. +% +% The C-Mex function GetMD5 is 2 to 100 times faster, but obtains MD5 only: +% http://www.mathworks.com/matlabcentral/fileexchange/25921 +% +% Tested: Matlab 7.7, 7.8, 7.13, 8.6, WinXP/32, Win7/64 +% Author: Jan Simon, Heidelberg, (C) 2011-2016 matlab.2010(a)n(MINUS)simon.de +% +% See also: TYPECAST, CAST. +% +% Michael Kleder, "Compute Hash", no structs and cells: +% http://www.mathworks.com/matlabcentral/fileexchange/8944 +% Tim, "Serialize/Deserialize", converts structs and cells to a byte stream: +% http://www.mathworks.com/matlabcentral/fileexchange/29457 + +% $JRev: R-H V:033 Sum:R+m7rAPNLvlw Date:18-Jun-2016 14:33:17 $ +% $License: BSD (use/copy/change/redistribute on own risk, mention the author) $ +% $File: Tools\GLFile\DataHash.m $ +% History: +% 001: 01-May-2011 21:52, First version. +% 007: 10-Jun-2011 10:38, [Opt.Input], binary data, complex values considered. +% 011: 26-May-2012 15:57, Fixed: Failed for binary input and empty data. +% 014: 04-Nov-2012 11:37, Consider Mex-, MDL- and P-files also. +% Thanks to David (author 243360), who found this bug. +% Jan Achterhold (author 267816) suggested to consider Java objects. +% 016: 01-Feb-2015 20:53, Java heap space exhausted for large files. +% Now files are process in chunks to save memory. +% 017: 15-Feb-2015 19:40, Collsions: Same hash for different data. +% Examples: zeros(1,1) and zeros(1,1,0) +% complex(0) and zeros(1,1,0,0) +% Now the number of dimensions is included, to avoid this. +% 022: 30-Mar-2015 00:04, Bugfix: Failed for strings and [] without TYPECASTX. +% Ross found these 2 bugs, which occur when TYPECASTX is not installed. +% If you need the base64 format padded with '=' characters, adjust +% fBase64_enc as you like. +% 026: 29-Jun-2015 00:13, Changed hash for STRUCTs. +% Struct arrays are analysed field by field now, which is much faster. +% 027: 13-Sep-2015 19:03, 'ascii' input as abbrev. for Input='bin' and UINT8(). +% 028: 15-Oct-2015 23:11, Example values in help section updated to v022. +% 029: 16-Oct-2015 22:32, Use default options for empty input. +% 031: 28-Feb-2016 15:10, New hash value to get same reply as GetMD5. +% New Matlab version (at least 2015b) use a fast method for TYPECAST, such +% that calling James Tursa's TYPECASTX is not needed anymore. +% Matlab 6.5 not supported anymore: MException for CATCH. +% 033: 18-Jun-2016 14:28, BUGFIX: Failed on empty files. +% Thanks to Christian (AuthorID 2918599). + +% OPEN BUGS: +% Nath wrote: +% function handle refering to struct containing the function will create +% infinite loop. Is there any workaround ? +% Example: +% d= dynamicprops(); +% addprop(d,'f'); +% d.f= @(varargin) struct2cell(d); +% DataHash(d.f) % infinite loop +% This is caught with an error message concerning the recursion limit now. + +% Main function: =============================================================== +% Default options: ------------------------------------------------------------- +Method = 'MD5'; +OutFormat = 'hex'; +isFile = false; +isBin = false; + +% Check number and type of inputs: --------------------------------------------- +nArg = nargin; +if nArg == 2 + if isa(Opt, 'struct') == 0 % Bad type of 2nd input: + Error_L('BadInput2', '2nd input [Opt] must be a struct.'); + end + + % Specify hash algorithm: + if isfield(Opt, 'Method') && ~isempty(Opt.Method) % Short-circuiting + Method = upper(Opt.Method); + end + + % Specify output format: + if isfield(Opt, 'Format') && ~isempty(Opt.Format) % Short-circuiting + OutFormat = Opt.Format; + end + + % Check if the Input type is specified - default: 'array': + if isfield(Opt, 'Input') && ~isempty(Opt.Input) % Short-circuiting + if strcmpi(Opt.Input, 'File') + if ischar(Data) == 0 + Error_L('CannotOpen', '1st input FileName must be a string'); + end + isFile = true; + + elseif strncmpi(Opt.Input, 'bin', 3) % Accept 'binary' also + if (isnumeric(Data) || ischar(Data) || islogical(Data)) == 0 || ... + issparse(Data) + Error_L('BadDataType', ... + '1st input must be numeric, CHAR or LOGICAL for binary input.'); + end + isBin = true; + + elseif strncmpi(Opt.Input, 'asc', 3) % 8-bit ASCII characters + if ~ischar(Data) + Error_L('BadDataType', ... + '1st input must be a CHAR for the input type ASCII.'); + end + isBin = true; + Data = uint8(Data); + end + end + +elseif nArg == 0 % Reply version of this function: + R = Version_L; + + if nargout == 0 + disp(R); + else + Hash = R; + end + + return; + +elseif nArg ~= 1 % Bad number of arguments: + Error_L('BadNInput', '1 or 2 inputs required.'); +end + +% Create the engine: ----------------------------------------------------------- +try + Engine = java.security.MessageDigest.getInstance(Method); +catch + Error_L('BadInput2', 'Invalid algorithm: [%s].', Method); +end + +% Create the hash value: ------------------------------------------------------- +if isFile + % Open the file: + FID = fopen(Data, 'r'); + if FID < 0 + % Check existence of file: + Found = FileExist_L(Data); + if Found + Error_L('CantOpenFile', 'Cannot open file: %s.', Data); + else + Error_L('FileNotFound', 'File not found: %s.', Data); + end + end + + % Read file in chunks to save memory and Java heap space: + Chunk = 1e6; % Fastest for 1e6 on Win7/64, HDD + Count = Chunk; % Dummy value to satisfy WHILE condition + while Count == Chunk + [Data, Count] = fread(FID, Chunk, '*uint8'); + if Count ~= 0 % Avoid error for empty file + Engine.update(Data); + end + end + fclose(FID); + + % Calculate the hash: + Hash = typecast(Engine.digest, 'uint8'); + +elseif isBin % Contents of an elementary array, type tested already: + if isempty(Data) % Nothing to do, Engine.update fails for empty input! + Hash = typecast(Engine.digest, 'uint8'); + else % Matlab's TYPECAST is less elegant: + if isnumeric(Data) + if isreal(Data) + Engine.update(typecast(Data(:), 'uint8')); + else + Engine.update(typecast(real(Data(:)), 'uint8')); + Engine.update(typecast(imag(Data(:)), 'uint8')); + end + elseif islogical(Data) % TYPECAST cannot handle LOGICAL + Engine.update(typecast(uint8(Data(:)), 'uint8')); + elseif ischar(Data) % TYPECAST cannot handle CHAR + Engine.update(typecast(uint16(Data(:)), 'uint8')); + % Bugfix: Line removed + end + Hash = typecast(Engine.digest, 'uint8'); + end +else % Array with type: + Engine = CoreHash(Data, Engine); + Hash = typecast(Engine.digest, 'uint8'); +end + +% Convert hash specific output format: ----------------------------------------- +switch OutFormat + case 'hex' + Hash = sprintf('%.2x', double(Hash)); + case 'HEX' + Hash = sprintf('%.2X', double(Hash)); + case 'double' + Hash = double(reshape(Hash, 1, [])); + case 'uint8' + Hash = reshape(Hash, 1, []); + case 'base64' + Hash = fBase64_enc(double(Hash)); + otherwise + Error_L('BadOutFormat', ... + '[Opt.Format] must be: HEX, hex, uint8, double, base64.'); +end + +% return; + +% ****************************************************************************** +function Engine = CoreHash(Data, Engine) +% This methods uses the slower TYPECAST of Matlab + +% Consider the type and dimensions of the array to distinguish arrays with the +% same data, but different shape: [0 x 0] and [0 x 1], [1,2] and [1;2], +% DOUBLE(0) and SINGLE([0,0]): +% < v016: [class, size, data]. BUG! 0 and zeros(1,1,0) had the same hash! +% >= v016: [class, ndims, size, data] +Engine.update([uint8(class(Data)), ... + typecast(uint64([ndims(Data), size(Data)]), 'uint8')]); + +if issparse(Data) % Sparse arrays to struct: + [S.Index1, S.Index2, S.Value] = find(Data); + Engine = CoreHash(S, Engine); +elseif isstruct(Data) % Hash for all array elements and fields: + F = sort(fieldnames(Data)); % Ignore order of fields + for iField = 1:length(F) % Loop over fields + aField = F{iField}; + Engine.update(uint8(aField)); + for iS = 1:numel(Data) % Loop over elements of struct array + Engine = CoreHash(Data(iS).(aField), Engine); + end + end +elseif iscell(Data) % Get hash for all cell elements: + for iS = 1:numel(Data) + Engine = CoreHash(Data{iS}, Engine); + end +elseif isempty(Data) % Nothing to do +elseif isnumeric(Data) + if isreal(Data) + Engine.update(typecast(Data(:), 'uint8')); + else + Engine.update(typecast(real(Data(:)), 'uint8')); + Engine.update(typecast(imag(Data(:)), 'uint8')); + end +elseif islogical(Data) % TYPECAST cannot handle LOGICAL + Engine.update(typecast(uint8(Data(:)), 'uint8')); +elseif ischar(Data) % TYPECAST cannot handle CHAR + Engine.update(typecast(uint16(Data(:)), 'uint8')); +elseif isa(Data, 'function_handle') + Engine = CoreHash(ConvertFuncHandle(Data), Engine); +elseif (isobject(Data) || isjava(Data)) && ismethod(Data, 'hashCode') + Engine = CoreHash(char(Data.hashCode), Engine); +else % Most likely a user-defined object: + try + BasicData = ConvertObject(Data); + catch ME + error(['JSimon:', mfilename, ':BadDataType'], ... + '%s: Cannot create elementary array for type: %s\n %s', ... + mfilename, class(Data), ME.message); + end + + try + Engine = CoreHash(BasicData, Engine); + catch ME + if strcmpi(ME.identifier, 'MATLAB:recursionLimit') + ME = MException(['JSimon:', mfilename, ':RecursiveType'], ... + '%s: Cannot create hash for recursive data type: %s', ... + mfilename, class(Data)); + end + throw(ME); + end +end + +% return; + +% ****************************************************************************** +function FuncKey = ConvertFuncHandle(FuncH) +% The subfunction ConvertFuncHandle converts function_handles to a struct +% using the Matlab function FUNCTIONS. The output of this function changes +% with the Matlab version, such that DataHash(@sin) replies different hashes +% under Matlab 6.5 and 2009a. +% An alternative is using the function name and name of the file for +% function_handles, but this is not unique for nested or anonymous functions. +% If the MATLABROOT is removed from the file's path, at least the hash of +% Matlab's toolbox functions is (usually!) not influenced by the version. +% Finally I'm in doubt if there is a unique method to hash function handles. +% Please adjust the subfunction ConvertFuncHandles to your needs. + +% The Matlab version influences the conversion by FUNCTIONS: +% 1. The format of the struct replied FUNCTIONS is not fixed, +% 2. The full paths of toolbox function e.g. for @mean differ. +FuncKey = functions(FuncH); + +% Include modification file time and file size. Suggested by Aslak Grinsted: +if ~isempty(FuncKey.file) + d = dir(FuncKey.file); + if ~isempty(d) + FuncKey.filebytes = d.bytes; + FuncKey.filedate = d.datenum; + end +end + +% ALTERNATIVE: Use name and path. The <matlabroot> part of the toolbox functions +% is replaced such that the hash for @mean does not depend on the Matlab +% version. +% Drawbacks: Anonymous functions, nested functions... +% funcStruct = functions(FuncH); +% funcfile = strrep(funcStruct.file, matlabroot, '<MATLAB>'); +% FuncKey = uint8([funcStruct.function, ' ', funcfile]); + +% Finally I'm afraid there is no unique method to get a hash for a function +% handle. Please adjust this conversion to your needs. + +% return; + +% ****************************************************************************** +function DataBin = ConvertObject(DataObj) +% Convert a user-defined object to a binary stream. There cannot be a unique +% solution, so this part is left for the user... + +try % Perhaps a direct conversion is implemented: + DataBin = uint8(DataObj); + + % Matt Raum had this excellent idea - unfortunately this function is + % undocumented and might not be supported in te future: + % DataBin = getByteStreamFromArray(DataObj); + +catch % Or perhaps this is better: + WarnS = warning('off', 'MATLAB:structOnObject'); + DataBin = struct(DataObj); + warning(WarnS); +end + +% return; + +% ****************************************************************************** +function Out = fBase64_enc(In) +% Encode numeric vector of UINT8 values to base64 string. +% The intention of this is to create a shorter hash than the HEX format. +% Therefore a padding with '=' characters is omitted on purpose. + +Pool = [65:90, 97:122, 48:57, 43, 47]; % [0:9, a:z, A:Z, +, /] +v8 = [128; 64; 32; 16; 8; 4; 2; 1]; +v6 = [32, 16, 8, 4, 2, 1]; + +In = reshape(In, 1, []); +X = rem(floor(In(ones(8, 1), :) ./ v8(:, ones(length(In), 1))), 2); +Y = reshape([X(:); zeros(6 - rem(numel(X), 6), 1)], 6, []); +Out = char(Pool(1 + v6 * Y)); + +% return; + +% ****************************************************************************** +function Ex = FileExist_L(FileName) +% A more reliable version of EXIST(FileName, 'file'): +dirFile = dir(FileName); +if length(dirFile) == 1 + Ex = ~(dirFile.isdir); +else + Ex = false; +end + +% return; + +% ****************************************************************************** +function R = Version_L() +% The output differs between versions of this function. So give the user a +% chance to recognize the version: +% 1: 01-May-2011, Initial version +% 2: 15-Feb-2015, The number of dimensions is considered in addition. +% In version 1 these variables had the same hash: +% zeros(1,1) and zeros(1,1,0), complex(0) and zeros(1,1,0,0) +% 3: 29-Jun-2015, Struct arrays are processed field by field and not element +% by element, because this is much faster. In consequence the hash value +% differs, if the input contains a struct. +% 4: 28-Feb-2016 15:20, same output as GetMD5 for MD5 sums. Therefore the +% dimensions are casted to UINT64 at first. +R.HashVersion = 4; +R.Date = [2016, 2, 28]; + +R.HashMethod = {}; +try + Provider = java.security.Security.getProviders; + for iProvider = 1:numel(Provider) + S = char(Provider(iProvider).getServices); + Index = strfind(S, 'MessageDigest.'); + for iDigest = 1:length(Index) + Digest = strtok(S(Index(iDigest):end)); + Digest = strrep(Digest, 'MessageDigest.', ''); + R.HashMethod = cat(2, R.HashMethod, {Digest}); + end + end +catch ME + fprintf(2, '%s\n', ME.message); + R.HashMethod = 'error'; +end + +% return; + +% ****************************************************************************** +function Error_L(ID, varargin) + +error(['JSimon:', mfilename, ':', ID], ['*** %s: ', varargin{1}], ... + mfilename, varargin{2:nargin - 1}); + +% return;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/ExistsInCache.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,16 @@ +function [bool] = ExistsInCache(Hash, handles, cacheType ) + + switch cacheType + case 'Analysis' + cacheTypeMap = 'AnalysisCacheMap'; + case 'Synthesis' + cacheTypeMap = 'SynthesisCacheMap'; + end + + if( isfield( handles, 'Cache' ) ) + bool = isfield(handles.Cache.(cacheTypeMap), Hash); + else + AppCache = matfile('nimfks_cache.mat'); + bool = isfield(AppCache.(cacheTypeMap), Hash); + end +end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/KLDivCost.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,12 @@ +function [cost] = KLDivCost(A , B) + +% dim=size(A); +% cost=0; + +cost = sum(sum(A.*log10(A./B)-A+B)); + +% for i=1:dim(1) +% for j=1:dim(2) +% cost = cost + A(i,j)*log10(A(i,j)/B(i,j))-A(i,j)+B(i,j); +% end +% end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/LoadFromCache.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,13 @@ +function [FromCache] = LoadFromCache(Hash, cacheType) + + switch cacheType + case 'Analysis' + cacheTypeMap = 'AnalysisCacheMap'; + case 'Synthesis' + cacheTypeMap = 'SynthesisCacheMap'; + end + + AppCache = matfile('nimfks_cache.mat'); + Map = AppCache.(cacheTypeMap); + FromCache = Map.(Hash); +end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/SA_B_NMF.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,154 @@ +% Author: Dr. Elio Quinton + +function [ W, H, deleted, finalCost ] = SA_B_NMF(V, W, lambda, varargin ) +%SENMF Summary of this function goes here +% Detailed explanation goes here +if nargin > 2 + nmf_params = varargin{1}; + iterations = nmf_params.Iterations; + lambda = nmf_params.Lambda; +elseif nargin == 2 + iterations = 500; + lambda = 5; +end + +waitbarHandle = waitbar(0, 'Starting sparse NMF synthesis...'); + +targetDim=size(V); +sourceDim=size(W); +K=sourceDim(2); +M=targetDim(2); +H=random('unif',0, 1, K, M); + +deleted = []; +H = 0.01 * ones(size(H));% + (0.01 * rand(size(H))); +cost = get_cost(V, W, H, lambda); % Function get_cost defined at the end of this file. + +converged = 0; +convergence_threshold = 50; % Note that this is a threshold on the derivative of the cost, i.e. how much it decays at each iteration. This value might not be ideal for our use case. + +myeps = 10e-3; % A bigger eps here helps pruning out unused components +V = V + myeps; % Note that V here is the `target' audio magnitude spectrogram + +% num_h_iter = 1; +err = 0.0001; +% max_iter = 1000; +max_iter = iterations; + + + +iter = 0; +omit = 0; + +while ~converged && iter < max_iter + + waitbar(iter/(iterations-1), waitbarHandle, ['Computing approximation...Iteration: ', num2str(iter), '/', num2str(iterations-1)]) + iter = iter + 1; + %% sparse NMF decomposition + if iter > 0 + + % Update H. + R = W*H+eps; + RR = 1./R; + RRR = RR.^2; + RRRR = sqrt(R); + + pen = lambda./(sqrt(H + eps)); + + H = H .* (((W' * (V .* RRR.* RRRR)) ./ ((W' * (RR .* RRRR) + pen))).^(1/3)); + + + %Update W: REMOVE THIS FOR OUR USE CASE +% nn = sum(sqrt(H')); +% NN = lambda * repmat(nn,size(V,1),1); +% NNW = NN.*W; +% +% R = W*H+eps; +% RR = 1./R; +% RRR = RR.^2; +% RRRR = sqrt(R); +% W = W .* ( ((V .* RRR.* RRRR)*H') ./ ( ((RR .* RRRR)*H') + NNW + eps)).^(1/3); + % Update W: stop deleting here + + + else + % Non-sparse first iteration. Not sure it is necessary + % in our particular use case. We might want to get rid of + % it later, but it should not harm anyway. + R = W*H; + RR = 1./R; + RRR = RR.^2; + RRRR = sqrt(R); + H = H .* (((W' * (V .* RRR.* RRRR)) ./ (W' * (RR .* RRRR) + eps)).^(1/3)); + + %Update W: REMOVE THIS FOR OUR USE CASE +% R = W*H + myeps; +% RR = 1./R; +% RRR = RR.^2; +% RRRR = sqrt(R); +% W = W .* ((((V .* RRR.* RRRR)*H') ./ (((RR .* RRRR)*H') + eps)).^(1/3)); + % Update W: stop deleting here + end + + %% normalise and prune templates if their total activation reaches 0. + todel = []; + shifts = []; + for i = 1:size(W,2) +% nn = norm(W(:,i)); % W is not being updated so this is of no use + nn = sum(H(i,:)); % Check if norm of rows of H get to zero instead. + if nn == 0 + todel = [todel i]; +% disp(['Deleting ' int2str(length(todel))]); % This is printing a message everytime templates are deleted + else + nn = norm(W(:,i)); % Still normalise against norm of Templates to avoid division by zero. + W(:,i) = W(:,i) / nn; + H(i,:) = H(i,:) * nn; + end + end + + if( length(deleted) == 0 ) + deleted = [deleted todel]; + else + shifts = zeros(1, length(todel)); + for i = 1:length(shifts) + shifts(i) = length( deleted( deleted >= todel(i) ) ); + end + deleted = [deleted todel+shifts]; + end + W(:,todel) = []; + H(todel,:) = []; + + %% get the cost and monitor convergence + if (mod(iter, 5) == 0) || (iter == 1) + + new_cost = get_cost(V, W, H, lambda); + + if omit == 0 && cost - new_cost < cost * err & iter > convergence_threshold + converged = 0; + % + end + + cost = new_cost; + finalCost(iter) = cost; + omit = 0; + +% disp([int2str(iter) ' ' num2str(cost)]); % this prints the cost function at each iteration. Could be commented out (printing is slow in matlab) + elseif iter > 1 + finalCost(iter) = finalCost(iter - 1); + end + +end + +close(waitbarHandle); +end + + + +function cost = get_cost(V, W, H, lambda) +R = W*H+eps; +hcost = sum(sum( (sqrt(V) - sqrt(R).^2 )./sqrt(R) )); +nn = 2 * lambda * sum(sum(sqrt(H))); +cost = hcost + nn; + +end +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/SaveInCache.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,21 @@ +function [AppCache] = SaveInCache(cache, handles, cacheType, data) + + NimfksCache = matfile( 'nimfks_cache.mat', 'Writable', true ); + + switch cacheType + case 'Analysis' + cacheTypeMap = 'AnalysisCacheMap'; + case 'Synthesis' + cacheTypeMap = 'SynthesisCacheMap'; + end + + AppCache = matfile( 'nimfks_cache.mat' ); + + hash = cache.Hash; + + CacheMap = AppCache.(cacheTypeMap); + CacheMap.(hash) = data; + + NimfksCache.(cacheTypeMap) = CacheMap; +% save( 'nimfks_cache.mat', cacheTypeMap ); +end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/Sound.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,140 @@ +classdef Sound < handle + properties + Filename + Directory + Sampling_rate + Bits_per_sample + Audioplayer + Time_length + Signal + Features + end + + methods + function obj = Sound(varargin) + if nargin == 1 + [pathstr, name, ext] = fileparts(varargin{1}); + obj.Filename = strcat(name, ext); + obj.Directory = pathstr; + elseif nargin == 2 + obj.Signal = varargin{1}; + obj.Sampling_rate = varargin{2}; + end + + obj.init; + end + + function obj = init(obj) + if ~isempty(obj.Filename) + [Y, Fs] = audioread([obj.Directory filesep obj.Filename]); + + %Convert to Monophonic sound + if(size(Y, 2) ~= 1) + Y = (Y(:,1)+Y(:,2))/2; + end + + obj.Signal = Y; + obj.Sampling_rate = Fs; + end + + obj.Time_length = length(obj.Signal)/obj.Sampling_rate; + + obj.Audioplayer= audioplayer(obj.Signal, obj.Sampling_rate); + obj.Bits_per_sample = obj.Audioplayer.BitsPerSample; + end + end + + methods + function control_audio(obj, action) + switch action + case 'play' + play(obj.Audioplayer); + case 'stop' + stop(obj.Audioplayer); + case 'pause' + obj.Audioplayer.pause; + case 'resume' + obj.Audioplayer.resume; + end + end + + function save_audio(obj) + handles = guidata(gcf); + [file,path] = uiputfile({'*.wav'},'Save Sound As'); + audiowrite([path filesep file], handles.SynthesisObject.Synthesis, handles.Sound_corpus.Sampling_rate); + end + + function plot_spectrogram(obj, varargin) + if nargin > 1 + mindB = varargin{1}; + else + mindB = 80; + end + + S = obj.Features.STFT.S; + F = obj.Features.STFT.F; + T = obj.Features.STFT.T; + + dB = 20*log10(abs(S)/max(max(abs(S)))); + sonodB = max(-mindB, dB); + imagesc(T,F./1000,sonodB); + cmap = colormap('jet'); + cmap(1,:) = 0*ones(1,3); + colormap((cmap)); + colorbar + axis xy; grid on; + axis([0 T(end) 0.01 10]); + set(gca,'XTick',[0:0.5:T(end)],'XTickLabel',''); + set(gca, 'Layer', 'top'); + ylabel('Frequency (kHz)'); + grid on; + set(gca,'FontSize',16); + end + + function plot_chromagram() + end + + function plot_templates(obj) + W=abs(obj.Features.STFT.S); + F=abs(obj.Features.STFT.F); + hold on; grid on; + [~,I]=max(W); + [~,Ix] = sort(I,'ascend'); + for jj=1:size(W,2) + specdB=W(:,Ix(jj))/max(max(W)); + handle=plot3(jj*ones(size(W,1),1),F/1000,specdB, ... + 'Color',power((size(W,2)-jj)/(size(W,2)+1),0.65)*ones(3,1), ... + 'LineWidth',8*(2+size(W,2)-jj)/(size(W,2))); + end + ylabel('Frequency (kHz)'); + xlabel('Template'); + zlabel('Magnitude'); + view(105,26); + end + + function plot_signal(obj) + plot([1:length(obj.Signal)]/obj.Sampling_rate, obj.Signal, 'Color', [0, 0, 0]); + end + + function obj = computeFeatures(obj, window, analysis) + obj.Features.window = window; + + if(strcmp(analysis, 'STFT')) + obj.Features.STFT = computeSTFTFeat(obj.Signal, obj.Sampling_rate, obj.Features.window); + elseif(strcmp(analysis, 'CQT')) + + elseif(strcmp(analysis, 'Chroma')) + + end + end + + function obj = concat(obj, sound) + obj.Signal = [ obj.Signal; sound.Signal ]; + + obj.Time_length = length(obj.Signal)/obj.Sampling_rate; + + obj.Audioplayer= audioplayer(obj.Signal, obj.Sampling_rate); + obj.Bits_per_sample = obj.Audioplayer.BitsPerSample; + end + end +end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/SynthesisCache.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,48 @@ +classdef SynthesisCache < handle + properties + Iterations + Seed + Convergence + CostMetric + RepRestrict + PolyRestrict + ContRestrict + DiagPattern + Rotation + Endtime + Lambda + Prune + Hash + AnalysisHash + end + + methods + function obj = SynthesisCache(varargin) + if nargin == 13 + obj.Iterations = varargin{1}; + obj.Seed = varargin{2}; + obj.Convergence = varargin{3}; + obj.CostMetric = varargin{4}; + obj.RepRestrict = varargin{5}; + obj.PolyRestrict = varargin{6}; + obj.ContRestrict = varargin{7}; + obj.DiagPattern = varargin{8}; + obj.Rotation = varargin{9}; + obj.Endtime = varargin{10}; + obj.Lambda = varargin{11}; + obj.Prune = varargin{12}; + obj.AnalysisHash = varargin{13}; + end + end + + function obj = GenerateHash(obj) + ArrayToHash = [obj.Iterations; obj.Seed; obj.Convergence; obj.CostMetric; ... + obj.RepRestrict; obj.PolyRestrict; obj.ContRestrict; ... + obj.DiagPattern; obj.Rotation; obj.Endtime; obj.Lambda; obj.Prune ]; + + ArrayToHash = [ ArrayToHash; (1*obj.AnalysisHash)']; + Opt = struct( 'Method', 'SHA-1' ); + obj.Hash = ['id', char(DataHash(ArrayToHash, Opt))]; + end + end +end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/chromagram_E.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,28 @@ +function Y = chromagram_E(d,sr,fftlen,nbin,f_ctr,f_sd) +% Y = chromagram_E(d,sr,fftlen,nbin) +% Calculate a "chromagram" of the sound in d (at sampling rate sr) +% Use windows of fftlen points, hopped by ffthop points +% Divide the octave into nbin steps +% Weight with center frequency f_ctr (in Hz) and gaussian SD f_sd (in octaves) +% 2006-09-26 dpwe@ee.columbia.edu + +if nargin < 3; fftlen = 2048; end +if nargin < 4; nbin = 12; end +if nargin < 5; f_ctr = 1000; end +if nargin < 6; f_sd = 1; end + +fftwin = fftlen/2; +ffthop = fftlen/4; % always for this + +D = abs(specgram(d,fftlen,sr,fftwin,(fftwin-ffthop))); + +A0 = 27.5; % Hz +A440 = 440; % Hz + +f_ctr_log = log(f_ctr/A0) / log(2); + +CM = fft2chromamx(fftlen, nbin, sr, A440, f_ctr_log, f_sd); +% Chop extra dims +CM = CM(:,1:(fftlen/2)+1); + +Y = CM*D;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/chromagram_IF.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,78 @@ +function Y = chromagram_IF(d,sr,fftlen,nbin,f_ctr,f_sd) +% Y = chromagram_IF(d,sr,fftlen,nbin,f_ctr,f_sd) +% Calculate a "chromagram" of the sound in d (at sampling rate sr) +% Use windows of fftlen points, hopped by ffthop points +% Divide the octave into nbin steps +% Weight with center frequency f_ctr (in Hz) and gaussian SD f_sd +% (in octaves) +% Use instantaneous frequency to keep only real harmonics. +% 2006-09-26 dpwe@ee.columbia.edu + +% Copyright (c) 2006 Columbia University. +% +% This file is part of LabROSA-coversongID +% +% LabROSA-coversongID is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License version 2 as +% published by the Free Software Foundation. +% +% LabROSA-coversongID is distributed in the hope that it will be useful, but +% WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +% General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with LabROSA-coversongID; if not, write to the Free Software +% Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +% 02110-1301 USA +% +% See the file "COPYING" for the text of the license. + +if nargin < 3; fftlen = 2048; end +if nargin < 4; nbin = 12; end +if nargin < 5; f_ctr = 1000; end +if nargin < 6; f_sd = 1; end + +A0 = 27.5; % Hz +A440 = 440; % Hz +f_ctr_log = log(f_ctr/A0) / log(2); + +fminl = octs2hz(hz2octs(f_ctr)-2*f_sd); +fminu = octs2hz(hz2octs(f_ctr)-f_sd); +fmaxl = octs2hz(hz2octs(f_ctr)+f_sd); +fmaxu = octs2hz(hz2octs(f_ctr)+2*f_sd); + +ffthop = fftlen/4; +nchr = 12; + +% Calculate spectrogram and IF gram pitch tracks... +[p,m]=ifptrack(d,fftlen,sr,fminl,fminu,fmaxl,fmaxu); + +[nbins,ncols] = size(p); + +%disp(['ncols = ',num2str(ncols)]); + +% chroma-quantized IF sinusoids +Pocts = hz2octs(p+(p==0)); +Pocts(p(:)==0) = 0; +% Figure best tuning alignment +nzp = find(p(:)>0); +%hist(nchr*Pmapo(nzp)-round(nchr*Pmapo(nzp)),100) +[hn,hx] = hist(nchr*Pocts(nzp)-round(nchr*Pocts(nzp)),100); +centsoff = hx(find(hn == max(hn))); +% Adjust tunings to align better with chroma +Pocts(nzp) = Pocts(nzp) - centsoff(1)/nchr; + +% Quantize to chroma bins +PoctsQ = Pocts; +PoctsQ(nzp) = round(nchr*Pocts(nzp))/nchr; + +% map IF pitches to chroma bins +Pmapc = round(nchr*(PoctsQ - floor(PoctsQ))); +Pmapc(p(:) == 0) = -1; +Pmapc(Pmapc(:) == nchr) = 0; + +Y = zeros(nchr,ncols); +for t = 1:ncols; + Y(:,t)=(repmat([0:(nchr-1)]',1,size(Pmapc,1))==repmat(Pmapc(:,t)',nchr,1))*m(:,t); +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/chromagram_P.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,32 @@ +function Y = chromagram_P(d,sr,fftlen,nbin,f_ctr,f_sd) +% Y = chromagram_E(d,sr,fftlen,nbin) +% Calculate a "chromagram" of the sound in d (at sampling rate sr) +% Use windows of fftlen points, hopped by ffthop points +% Divide the octave into nbin steps +% Weight with center frequency f_ctr (in Hz) and gaussian SD f_sd (in octaves) +% 2006-09-26 dpwe@ee.columbia.edu + +if nargin < 3; fftlen = 2048; end +if nargin < 4; nbin = 12; end +if nargin < 5; f_ctr = 1000; end +if nargin < 6; f_sd = 1; end + +fftwin = fftlen/2; +ffthop = fftlen/4; % always for this + +D = abs(specgram(d,fftlen,sr,fftwin,(fftwin-ffthop))); + +[nr,nc] = size(D); + +A0 = 27.5; % Hz +A440 = 440; % Hz + +f_ctr_log = log(f_ctr/A0) / log(2); + +CM = fft2chromamx(fftlen, nbin, sr, A440, f_ctr_log, f_sd); +% Chop extra dims +CM = CM(:,1:(fftlen/2)+1); + +% Keep only local maxes in freq +Dm = (D > D([1,[1:nr-1]],:)) & (D >= D([[2:nr],nr],:)); +Y = CM*(D.*Dm);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/chromsynth.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,75 @@ +function [x,CF,CM] = chromsynth(F,bp,sr) +% [x,CF,CM] = chromsynth(F,bp,sr) +% Resynthesize a chroma feature vector to audio +% F is 12 rows x some number of columns, one per beat +% bp is the period of one beat in sec (or a vector of beat times) +% sr is the sampling rate of the output waveform +% x is returned as a 12 semitone-spaced sines modulated by F +% CF,CM return actual sinusoid matrices passed to synthtrax +% Actual Shepard tones now implemented! 2007-04-19 +% 2006-07-14 dpwe@ee.columbia.edu + +if nargin < 2; bp = 0.5; end % 120 bpm +if nargin < 3; sr = 22050; end + +[nchr,nbts] = size(F); + +% resynth +if length(bp) == 1 + bups = 8; % upsampling factor + framerate = bups/bp; + ncols = nbts*bups; + CMbu = zeros(nchr, ncols); + for i = 1:bups + CMbu = CMbu + upsample(F', bups, i-1)'; + end +else + % vector of beat times - quantize + framerate = 50; % frames per sec + nbeats = length(bp); + lastbeat = bp(nbeats) + (bp(nbeats) - bp(nbeats-1)); + ncols = round(lastbeat * framerate); + CMbu = zeros(nchr, ncols); + xF = [zeros(12,1),F]; + for i = 1:ncols + CMbu(:,i) = xF(:,max(find(i/framerate >= [0,bp]))); + end +end + +%CFbu = repmat(440*2.^([0:(nchr-1)]'/nchr),1,ncols); +%x = synthtrax(CFbu,CMbu,sr,round(sr/framerate)); +octs = 7; +basefrq = 27.5; % A1; +6 octaves = 3520 +CFbu = repmat(basefrq*2.^([0:(nchr-1)]'/nchr),1,ncols); +CF = []; +CM = []; +% what bin is the center freq? +f_ctr = 440; +f_sd = 0.5; +f_bins = basefrq*2.^([0:(nchr*octs - 1)]/nchr); +f_dist = log(f_bins/f_ctr)/log(2)/f_sd; +% actually just = ([0:(nchr*octs - 1)]/nchr-log2(f_ctr/basefrq))/f_sd +% Gaussian weighting centered of f_ctr, with f_sd +f_wts = exp(-0.5*f_dist.^2); +for oct = 1:octs + CF = [CF;(2^oct)*CFbu]; + % pick out particular weights + CM = [CM;diag(f_wts((oct-1)*nchr+[1:nchr]))*CMbu]; +end +% Remove sines above nyquist +CFok = (CF(:,1) < sr/2); +CF = CF(CFok,:); +CM = CM(CFok,:); +% Synth the sines +x = synthtrax(CF,CM,sr,round(sr/framerate)); + +% Playing synth along with audio: +%>> rdc = chromsynth(Dy.F(:,160+[1:300]),Dy.bts(160+[1:300]) - Dy.bts(160),sr); +%>> Dy.bts(161)*sr +%ans = +% 279104 +%>> size(rdc) +%ans = +% 1 498401 +%>> ddd = db(279104+[1:498401]); +%>> soundsc([ddd,rdc'/40],sr)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/computeSTFTFeat.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,22 @@ +function feature_struct = computeSTFTFeat(x, fs, win) + wintype = win.Type; + winlen = win.Length; + hop = win.Hop; + + analysis_window = createWindow(winlen, hop, wintype); + + [feature_struct.S, feature_struct.F, feature_struct.T]=spectrogram(x, analysis_window, hop, winlen, fs); +end + +function win = createWindow(winlen, hop, wintype) + switch wintype + case 'Hann' + win = window(@hann, winlen); + case 'Sine' + win = window(@sin, winlen); + case 'Tukey' + win = tukeywin(winlen, 0.75); + case 'Hamming' + win = window(@hamming, winlen); + end +end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/controller.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,239 @@ +function controller(action, handles) + +switch action + case 'openTarget' + [filename pathname] = uigetfile({'*.wav;*.mp3;'}, 'File Selector'); + targetpathname= strcat(pathname, filename); + handles.Sound_target = Sound(targetpathname); + set(handles.txt_targetfile, 'String', filename); + set(handles.txt_targetfile,'TooltipString',filename); + case 'openSource' + [filenames pathname]= uigetfile({'*.wav;*.mp3;'}, 'File Selector', 'MultiSelect','on'); + + if( iscell( filenames ) ) + for i = 1:length( filenames ) + sourcepathname = strcat(pathname, filenames{i}); + tmp_snd = Sound(sourcepathname); + if isfield(handles, 'Sound_corpus') + handles.Sound_corpus = handles.Sound_corpus.concat( tmp_snd ); + else + handles.Sound_corpus = tmp_snd; + end + end + + cat_files = strjoin(filenames,'\n'); + set(handles.txt_corpusfile, 'String', cat_files); + set(handles.txt_corpusfile,'TooltipString', char(cat_files)); + else + sourcepathname = strcat(pathname, filenames); + handles.Sound_corpus = Sound(sourcepathname); + set(handles.txt_corpusfile, 'String', filenames); + set(handles.txt_corpusfile,'TooltipString', filenames); + end + + case 'swapSourceAndTarget' + tmp = handles.Sound_target; + handles.Sound_target = handles.Sound_corpus; + handles.Sound_corpus = tmp; + + corpus_displayName = get( handles.txt_corpusfile, 'String' ); + corpus_tooltip = get( handles.txt_corpusfile, 'TooltipString' ); + target_displayName = get( handles.txt_targetfile, 'String' ); + target_tooltip = get( handles.txt_targetfile, 'TooltipString' ); + + set(handles.txt_targetfile, 'String', corpus_displayName); + set(handles.txt_targetfile,'TooltipString', corpus_tooltip); + set(handles.txt_corpusfile, 'String', target_displayName); + set(handles.txt_corpusfile,'TooltipString', target_tooltip); + case 'playTarget' + handles.Sound_target.control_audio('play'); + case 'stopTarget' + handles.Sound_target.control_audio('stop'); + case 'playSynthesis' + handles.Sound_synthesis.control_audio('play'); + case 'stopSynthesis' + handles.Sound_synthesis.control_audio('stop'); + case 'runAnalysis' + waitbarHandle = waitbar(0.15, 'Verifying parameters...'); + spectTypeSelected=get(handles.pop_specttype, 'Value'); + spectTypes=get(handles.pop_specttype, 'String'); + + winTypeSelected=get(handles.pop_wintype, 'Value'); + winTypes=get(handles.pop_wintype, 'String'); + + win.Length = str2num(get(handles.edt_winlen, 'String'))*44100/1000; + win.Hop = str2num(get(handles.edt_overlap, 'String'))*44100/1000; + win.Type = cell2mat(winTypes(winTypeSelected)); + + CacheObj = AnalysisCache(handles.Sound_corpus.Signal, handles.Sound_target.Signal, ... + winTypeSelected, win.Length, win.Hop); + handles.CurrentAnalysisCache = CacheObj; + if( strcmp(get(handles.tool_menu_dev_cacheEnable, 'Checked'), 'on') ) + waitbar(0.33, waitbarHandle,'Checking cache...'); + + GenerateHash(CacheObj); + Cached = ExistsInCache(CacheObj.Hash, handles, 'Analysis'); + + if( ~Cached ) + waitbar(0.66, waitbarHandle, 'Analyzing corpus...') + handles.Sound_corpus.computeFeatures(win, spectTypes(spectTypeSelected)); + + waitbar(0.95, waitbarHandle, 'Analyzing target...') + handles.Sound_target.computeFeatures(win, spectTypes(spectTypeSelected)); + + waitbar(0.98, waitbarHandle, 'Saving in cache...') + + DataToCache = struct( ... + 'Corpus', handles.Sound_corpus, ... + 'Target', handles.Sound_target ... + ); + handles.Cache = SaveInCache( CacheObj, handles, 'Analysis', DataToCache ); + else + waitbar(0.75, waitbarHandle, 'Hooray, exists in cache! Loading...') + FromCache = LoadFromCache( CacheObj.Hash, 'Analysis' ); + handles.Sound_corpus = FromCache.Corpus; + handles.Sound_target = FromCache.Target; + end + else + waitbar(0.66, waitbarHandle, 'Analyzing corpus...') + handles.Sound_corpus.computeFeatures(win, spectTypes(spectTypeSelected)); + + waitbar(0.95, waitbarHandle, 'Analyzing target...') + handles.Sound_target.computeFeatures(win, spectTypes(spectTypeSelected)); + end + close(waitbarHandle); + case 'runSynthesis' + waitbarHandle = waitbar(0.15, 'Checking cache...'); + costMetricSelected=get(handles.pop_cost, 'Value'); + costMetrics=get(handles.pop_cost, 'String'); + + actPatternSelected=get(handles.pop_pattern, 'Value'); + actPatterns=get(handles.pop_pattern, 'String'); + + nmf_params.Algorithm = cell2mat(costMetrics(costMetricSelected)); + nmf_params.Iterations = str2num(get(handles.edt_iter, 'String')); + nmf_params.Convergence_criteria = str2double(get(handles.edt_conv, 'String')); + nmf_params.Repition_restriction = str2double(get(handles.edt_mod_rep, 'String')); + nmf_params.Polyphony_restriction = str2double(get(handles.edt_mod_poly, 'String')); + nmf_params.Continuity_enhancement = str2double(get(handles.edt_mod_cont, 'String')); + nmf_params.Continuity_enhancement_rot = str2double(get(handles.edt_mod_cont_rot, 'String')); + nmf_params.Diagonal_pattern = cell2mat(actPatterns(actPatternSelected)); + nmf_params.Modification_application = get(handles.chk_endtime, 'Value'); + nmf_params.Random_seed = str2double(get(handles.edt_rand, 'String')); + nmf_params.Lambda = str2double(get(handles.edt_sparse_lambda, 'String')); + + resynthMethodSelected=get(handles.pop_synthmethod, 'Value'); + resynthMethods=get(handles.pop_synthmethod, 'String'); + + pct_prune = ( 100 - str2double(get(handles.edt_prune, 'String')) )/100; + synth = CSS(nmf_params, cell2mat(resynthMethods(resynthMethodSelected))); + + % Cache related operations +% if( strcmp(get(handles.tool_menu_dev_cacheEnable, 'Checked'), 'on') ) + GenerateHash(handles.CurrentAnalysisCache); + CacheObj = SynthesisCache( ... + nmf_params.Iterations, nmf_params.Random_seed, nmf_params.Convergence_criteria, ... + costMetricSelected, nmf_params.Repition_restriction, nmf_params.Polyphony_restriction, ... + nmf_params.Continuity_enhancement, actPatternSelected, nmf_params.Continuity_enhancement_rot, ... + nmf_params.Modification_application, nmf_params.Lambda, pct_prune, handles.CurrentAnalysisCache.Hash ); + + GenerateHash(CacheObj); + Cached = ExistsInCache(CacheObj.Hash, handles, 'Synthesis'); + disp( CacheObj.Hash ); + + if( ~Cached ) + waitbar(0.5, waitbarHandle, 'Not found in cache. Running NMF...') + synth.nmf(handles.Sound_corpus, handles.Sound_target, pct_prune); + + waitbar(0.75, waitbarHandle, 'Saving in cache...') + DataToCache = struct( ... + 'Activations', synth.Activations, ... + 'Cost', synth.Cost ... + ); + + handles.Cache = SaveInCache( CacheObj, handles, 'Synthesis', DataToCache ); + else + waitbar(0.75, waitbarHandle, 'Hooray, exists in cache! Loading...') + FromCache = LoadFromCache( CacheObj.Hash, 'Synthesis' ); + synth.Activations = FromCache.Activations; + synth.Cost = FromCache.Cost; + end +% else +% synth.nmf(handles.Sound_corpus, handles.Sound_target); +% end + + synth.synthesize(handles.Sound_corpus); + + winTypeSelected=get(handles.pop_wintype, 'Value'); + winTypes=get(handles.pop_wintype, 'String'); + + win.Length = str2num(get(handles.edt_winlen, 'String'))*44100/1000; + win.Hop = str2num(get(handles.edt_overlap, 'String'))*44100/1000; + win.Type = cell2mat(winTypes(winTypeSelected)); + + spectTypeSelected=get(handles.pop_specttype, 'Value'); + spectTypes=get(handles.pop_specttype, 'String'); + + handles.SynthesisObject = synth; + handles.Sound_synthesis = Sound(synth.Synthesis, handles.Sound_corpus.Sampling_rate); + handles.Sound_synthesis.computeFeatures(win, spectTypes(spectTypeSelected)); + + close(waitbarHandle); + case 'savePlot' + case 'exportResynth' + case 'switchPlot' + selectedPlot=get(handles.pop_plot, 'Value'); + plotOptions=get(handles.pop_plot, 'String'); + delete(handles.axes2.Children); + cla(gca,'reset') + plotRequest = plotOptions(selectedPlot); + switch(plotRequest{1}) + case 'Synthesis Plot' + view(gca, 2); + handles.Sound_synthesis.plot_signal; + set(handles.tbl_plotdata, 'Data', handles.Sound_synthesis.Signal'); + case 'Cost' + view(gca, 2); + handles.SynthesisObject.plot_cost; + set(handles.tbl_plotdata, 'Data', handles.SynthesisObject.Cost'); + case 'Activations' + view(gca, 2); + handles.SynthesisObject.plot_activations(get(handles.sld_maxdb, 'Value')); + set(handles.tbl_plotdata, 'Data', handles.SynthesisObject.Activations); + case 'Corpus Spectrogram' + view(gca, 2); + handles.Sound_corpus.plot_spectrogram; + set(handles.tbl_plotdata, 'Data', abs(handles.Sound_corpus.Features.STFT.S)); + case 'Target Spectrogram' + view(gca, 2); + handles.Sound_target.plot_spectrogram; + set(handles.tbl_plotdata, 'Data', abs(handles.Sound_target.Features.STFT.S)); + case 'Synthesis Spectrogram' + view(gca, 2); + handles.Sound_synthesis.plot_spectrogram; + set(handles.tbl_plotdata, 'Data', abs(handles.Sound_synthesis.Features.STFT.S)); + case 'Templates' + view(gca, 3); + handles.Sound_corpus.plot_templates; + set(handles.tbl_plotdata, 'Data', abs(handles.Sound_corpus.Features.STFT.S)); + end + case 'resynthesize' + synth = handles.SynthesisObject; + synth.synthesize(handles.Sound_corpus); + handles.SynthesisObject = synth; + handles.Sound_synthesis.Audioplayer = audioplayer(handles.SynthesisObject.Synthesis, handles.Sound_corpus.Sampling_rate); + case 'rerun' + resynthMethodSelected=get(handles.pop_synthmethod, 'Value'); + resynthMethods=get(handles.pop_synthmethod, 'String'); + nmf_params = handles.SynthesisObject.NMF_features; + + pct_prune = ( 100 - str2double(get(handles.edt_prune, 'String')) )/100; + synth = CSS(nmf_params, cell2mat(resynthMethods(resynthMethodSelected))); + synth.nmf(handles.Sound_corpus, handles.Sound_target, pct_prune); + synth.synthesize(handles.Sound_corpus); + + handles.SynthesisObject = synth; +end + +guidata(handles.figure1, handles); +end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/decibelSliderReleaseCallback.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,5 @@ +function decibelSliderReleaseCallback(src,callbackdata) + +handles = guidata(src); +maxDB = get(handles.slider4, 'Value'); +handles.SynthesisObject.NNMFSynthesis.showActivations(handles.SynthesisObject, maxDb); \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/drawClickCallBack.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,111 @@ +%Used for the plot drawing function +function drawClickCallBack(src,callbackdata, action) +matlabVer = version; +handles = guidata(src); +ah = handles.axes2; +if(strcmp(matlabVer, '9.0.0.341360 (R2016a)')) + xAxisProps = get(ah, 'XAxis'); + xLimits = get(xAxisProps, 'Limits') +else + xAxisProps = get(ah, 'Xlim'); + xLimits = xAxisProps +end + +acts = handles.SynthesisObject.Activations; + +yMax = size(acts, 1); +xMax = size(acts, 2); + +xUnit = xLimits/size(acts, 2); + +sliderHandle = handles.sld_actstrength; + +paintBrush = handles.grp_paintbrush.SelectedObject.String; +paintBrushSize = 0; + +if(strcmp(paintBrush, 'Large Brush')) + paintBrushSize = 1; +else(strcmp(paintBrush, 'Small Brush')) + paintBrushSize = 0; +end + +if(strcmp(action, 'Draw')) + src.Pointer = 'cross'; + fillValue = get(sliderHandle, 'Value') +elseif(strcmp(action, 'Erase')) + src.Pointer = 'circle'; + fillValue = 0; +end + +cp = ah.CurrentPoint; +cx = cp(1,1)/xUnit(2) +cy = cp(1,2) + +drawXMax = (ceil(cx) + paintBrushSize); +drawYMax = (ceil(cy) + paintBrushSize); +drawXMin = (ceil(cx) - paintBrushSize); +drawYMin = (ceil(cy) - paintBrushSize); + +if(drawXMax >= xMax) + drawXMax = xMax; +end + +if(drawYMax >= yMax) + drawYMax = yMax; +end + +if(drawXMin <=0) + drawXMin = 1; +end + +if(drawYMin <=0) + drawYMin = 1; +end + +acts(drawYMin:drawYMax, drawXMin:drawXMax) = fillValue; +handles.SynthesisObject.Activations = acts; +size(acts, 1) +guidata(src, handles); + +src.WindowButtonMotionFcn = @dragCallBack; +src.WindowButtonUpFcn = @releaseCallBack; + + function dragCallBack(src, callbackdata) + cp = ah.CurrentPoint; + cx = cp(1,1)/xUnit(2); + cy = cp(1,2); + + drawXMax = (ceil(cx) + paintBrushSize); + drawYMax = (ceil(cy) + paintBrushSize); + drawXMin = (ceil(cx) - paintBrushSize); + drawYMin = (ceil(cy) - paintBrushSize); + + if(drawXMax >= xMax) + drawXMax = xMax; + end + + if(drawYMax >= yMax) + drawYMax = yMax; + end + + if(drawXMin <=0) + drawXMin = 1; + end + + if(drawYMin <=0) + drawYMin = 1; + end + + % fprintf('X: %u Y: %u', ceil(cy), ceil(cx)) + acts(drawYMin:drawYMax, drawXMin:drawXMax) = fillValue; + handles.SynthesisObject.Activations = acts; + guidata(src, handles); + end + + function releaseCallBack(src, callbackdata) + controller('switchPlot', handles); + src.Pointer = 'arrow'; + src.WindowButtonMotionFcn = ''; + src.WindowButtonUpFcn = ''; + end +end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/fft2chromamx.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,64 @@ +function wts = fft2chromamx(nfft,nbins,sr,A440,ctroct,octwidth) +% wts = fft2chromamx(nfft,nbins,sr,A440,ctroct,octwidth) +% Create a wts matrix to convert FFT to Chroma +% A440 is optional ref frq for A +% ctroct, octwidth specify a dominance window - Gaussian +% weighting centered on ctroct (in octs, re A0 = 27.5Hz) and +% with a gaussian half-width of octwidth. Defaults to +% halfwidth = inf i.e. flat. +% 2006-06-29 dpwe@ee.columbia.edu + +if nargin < 2; nbins = 12; end +if nargin < 3; sr = 22050; end +if nargin < 4; A440 = 440; end +if nargin < 5; ctroct = 5; end +if nargin < 6; octwidth = 0; end + +wts = zeros(nbins, nfft); + +fftfrqbins = nbins*hz2octs([1:(nfft-1)]/nfft*sr,A440); + +% make up a value for the 0 Hz bin = 1.5 octaves below bin 1 +% (so chroma is 50% rotated from bin 1, and bin width is broad) +fftfrqbins = [fftfrqbins(1)-1.5*nbins,fftfrqbins]; + +binwidthbins = [max(1, fftfrqbins(2:nfft) - fftfrqbins(1:(nfft-1))), 1]; + +D = repmat(fftfrqbins,nbins,1) - repmat([0:(nbins-1)]',1,nfft); + +nbins2 = round(nbins/2); + +% Project into range -nbins/2 .. nbins/2 +% add on fixed offset of 10*nbins to ensure all values passed to rem are +ve +D = rem(D + nbins2 + 10*nbins, nbins) - nbins2; + +% Gaussian bumps - 2*D to make them narrower +wts = exp(-0.5*(2*D./repmat(binwidthbins,nbins,1)).^2); + +% normalize each column +wts = wts./repmat(sqrt(sum(wts.^2)),nbins,1); + +% remove aliasing columns +wts(:,[(nfft/2+2):nfft]) = 0; + +% Maybe apply scaling for fft bins +if octwidth > 0 + wts = wts.*repmat(exp(-0.5*(((fftfrqbins/nbins - ctroct)/octwidth).^2)), nbins, 1); +end + +%wts = binwidthbins; +%wts = fftfrqbins; + +function octs = hz2octs(freq, A440) +% octs = hz2octs(freq, A440) +% Convert a frequency in Hz into a real number counting +% the octaves above A0. So hz2octs(440) = 4.0 +% Optional A440 specifies the Hz to be treated as middle A (default 440). +% 2006-06-29 dpwe@ee.columbia.edu for fft2chromamx + +%if nargin < 2; A440 = 440; end + +% A4 = A440 = 440 Hz, so A0 = 440/16 Hz +octs = log(freq./(A440/16))./log(2); + +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/hz2octs.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,12 @@ +function octs = hz2octs(freq, A440) +% octs = hz2octs(freq, A440) +% Convert a frequency in Hz into a real number counting +% the octaves above A0. So hz2octs(440) = 4.0 +% Optional A440 specifies the Hz to be treated as middle A (default 440). +% 2006-06-29 dpwe@ee.columbia.edu for fft2chromamx + +if nargin < 2; A440 = 440; end + +% A4 = A440 = 440 Hz, so A0 = 440/16 Hz +octs = log(freq./(A440/16))./log(2); +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/ifgram.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,105 @@ +function [F,D] = ifgram(X, N, W, H, SR) +% [F,D] = ifgram(X, N, W, H, SR) Instantaneous frequency by phase deriv. +% X is a 1-D signal. Process with N-point FFTs applying a W-point +% window, stepping by H points; return (N/2)+1 channels with the +% instantaneous frequency (as a proportion of the sampling rate) +% obtained as the time-derivative of the phase of the complex spectrum +% as described by Toshihiro Abe et al in ICASSP'95, Eurospeech'97 +% Same arguments and some common code as dpwebox/stft.m. +% Calculates regular STFT as side effect - returned in D. +% after 1998may02 dpwe@icsi.berkeley.edu +% 2001-03-05 dpwe@ee.columbia.edu revised version +% 2001-12-13 dpwe@ee.columbia.edu Fixed to work when N != W +% $Header: $ + +% Copyright (c) 2006 Columbia University. +% +% This file is part of LabROSA-coversongID +% +% LabROSA-coversongID is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License version 2 as +% published by the Free Software Foundation. +% +% LabROSA-coversongID is distributed in the hope that it will be useful, but +% WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +% General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with LabROSA-coversongID; if not, write to the Free Software +% Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +% 02110-1301 USA +% +% See the file "COPYING" for the text of the license. + +if nargin < 2; N = 256; end +if nargin < 3; W = N; end +if nargin < 4; H = W/2; end +if nargin < 5; SR = 1; end + +s = length(X); +% Make sure it's a single row +if size(X,1) > 1 + X = X'; +end + +%win = [0,hanning(W-1)']; +win = 0.5*(1-cos([0:(W-1)]/W*2*pi)); + +% Window for discrete differentiation +T = W/SR; +dwin = -pi / T * sin([0:(W-1)]/W*2*pi); + +% sum(win) takes out integration due to window, 2 compensates for neg frq +norm = 2/sum(win); + +% How many complete windows? +nhops = 1 + floor((s - W)/H); + +F = zeros(1 + N/2, nhops); +D = zeros(1 + N/2, nhops); + +nmw1 = floor( (N-W)/2 ); +nmw2 = N-W - nmw1; + +ww = 2*pi*[0:(N-1)]*SR/N; + +for h = 1:nhops + u = X((h-1)*H + [1:W]); +% if(h==0) +% plot(u) +% end + % Apply windows now, while the length is right + wu = win.*u; + du = dwin.*u; + + % Pad or truncate samples if N != W + if N > W + wu = [zeros(1,nmw1),wu,zeros(1,nmw2)]; + du = [zeros(1,nmw1),du,zeros(1,nmw2)]; + end + if N < W + wu = wu(-nmw1+[1:N]); + du = du(-nmw1+[1:N]); + end + % FFTs of straight samples plus differential-weighted ones + t1 = fft(fftshift(du)); + t2 = fft(fftshift(wu)); + % Scale down to factor out length & window effects + D(:,h) = t2(1:(1 + N/2))'*norm; + + % Calculate instantaneous frequency from phase of differential spectrum + t = t1 + j*(ww.*t2); + a = real(t2); + b = imag(t2); + da = real(t); + db = imag(t); + instf = (1/(2*pi))*(a.*db - b.*da)./((a.*a + b.*b)+(abs(t2)==0)); + % 1/2pi converts rad/s into cycles/s + % sampling rate already factored in as constant in dwin & ww + % so result is in Hz + + F(:,h) = instf(1:(1 + N/2))'; + +end; +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/ifptrack.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,121 @@ +function [p,m,S] = ifptrack(d,w,sr,fminl,fminu,fmaxl,fmaxu) +% [p,m,S] = ifptrack(d,w,sr,fminl,fminu,fmaxl,fmaxu) +% Pitch track based on inst freq. +% Look for adjacent bins with same inst freq. +% d is the input waveform. sr is its sample rate +% w is the basic STFT DFT length (window is half, hop is 1/4) +% S returns the underlying complex STFT. +% fmin,fmax define ramps at edge of sensitivity +% 2006-05-03 dpwe@ee.columbia.edu + +% Copyright (c) 2006 Columbia University. +% +% This file is part of LabROSA-coversongID +% +% LabROSA-coversongID is free software; you can redistribute it and/or modify +% it under the terms of the GNU General Public License version 2 as +% published by the Free Software Foundation. +% +% LabROSA-coversongID is distributed in the hope that it will be useful, but +% WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +% General Public License for more details. +% +% You should have received a copy of the GNU General Public License +% along with LabROSA-coversongID; if not, write to the Free Software +% Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +% 02110-1301 USA +% +% See the file "COPYING" for the text of the license. + +% downweight fundamentals below here +if nargin < 4; fminl = 150; end +if nargin < 5; fminu = 300; end +% highest frequency we look to +if nargin < 6; fmaxl = 2000; end +if nargin < 7; fmaxu = 4000; end + + +% Calculate the inst freq gram +[I,S] = ifgram(d,w,w/2,w/4,sr); + +% Only look at bins up to 2 kHz +maxbin = round(fmaxu * (w/sr) ); +%maxbin = size(I,1) +minbin = round(fminl * (w/sr) ); + +% Find plateaus in ifgram - stretches where delta IF is < thr +ddif = [I(2:maxbin, :);I(maxbin,:)] - [I(1,:);I(1:(maxbin-1),:)]; + +% expected increment per bin = sr/w, threshold at 3/4 that +dgood = abs(ddif) < .75*sr/w; + +% delete any single bins (both above and below are zero); +dgood = dgood .* ([dgood(2:maxbin,:);dgood(maxbin,:)] > 0 | [dgood(1,:);dgood(1:(maxbin-1),:)] > 0); + +% check it out +%p = dgood; + +% reconstruct just pitchy cells? +%r = istft(p.*S,w,w/2,w/4); + +p = 0*dgood; +m = 0*dgood; + +% For each frame, extract all harmonic freqs & magnitudes +for t = 1:size(I,2) + ds = dgood(:,t)'; + lds = length(ds); + % find nonzero regions in this vector + st = find(([0,ds(1:(lds-1))]==0) & (ds > 0)); + en = find((ds > 0) & ([ds(2:lds),0] == 0)); + npks = length(st); + frqs = zeros(1,npks); + mags = zeros(1,npks); + for i = 1:length(st) + bump = abs(S(st(i):en(i),t)); + frqs(i) = (bump'*I(st(i):en(i),t))/(sum(bump)+(sum(bump)==0)); + mags(i) = sum(bump); + if frqs(i) > fmaxu + mags(i) = 0; + frqs(i) = 0; + elseif frqs(i) > fmaxl + mags(i) = mags(i) * max(0, (fmaxu - frqs(i))/(fmaxu-fmaxl)); + end + % downweight magnitudes below? 200 Hz + if frqs(i) < fminl + mags(i) = 0; + frqs(i) = 0; + elseif frqs(i) < fminu + % 1 octave fade-out + mags(i) = mags(i) * (frqs(i) - fminl)/(fminu-fminl); + end + if frqs(i) < 0 + mags(i) = 0; + frqs(i) = 0; + end + + end + +% then just keep the largest at each frame (for now) +% [v,ix] = max(mags); +% p(t) = frqs(ix); +% m(t) = mags(ix); + % No, keep them all + %bin = st; + bin = round((st+en)/2); + p(bin,t) = frqs; + m(bin,t) = mags; +end + +%% Pull out the max in each column +%[mm,ix] = max(m); +%% idiom to retrieve different element from each column +%[nr,nc] = size(p); +%pp = p((nr*[0:(nc-1)])+ix); +%mm = m((nr*[0:(nc-1)])+ix); +% r = synthtrax(pp,mm,sr,w/4); + +%p = pp; +%m = mm; +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/istft.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,170 @@ +function y = istft(spec,parameter, varargin) +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Name: istft +% Date: 03-2014 +% Programmer: Jonathan Driedger +% http://www.audiolabs-erlangen.de/resources/MIR/TSMtoolbox/ +% +% Computing the 'inverse' of the stft according to the paper "Signal +% Estimation from Modified Short-Time Fourier Transform" by Griffin and +% Lim. +% +% Input: spec a complex spectrogram generated by stft. +% parameter. +% synHop hop size of the synthesis window. +% win the synthesis window. +% zeroPad number of zeros that were padded to the +% window to increase the fft size and therefore +% the frequency resolution. +% numOfIter number of iterations the algorithm should +% perform to adapt the phase. +% origSigLen original length of the audio signal such that +% the output can be trimmed accordingly. +% restoreEnergy when windowing the synthesis frames, there is a +% potential for some energy loss. This option +% will rescale every windowed synthesis frame to +% compensate for this energy leakage. +% fftShift in case the stft was computed with an fftShift, +% setting this parameter to 1 will compensate for +% that by applying the same shifting operation +% again to each frame after the ifft. +% +% Output: y the time-domain signal. +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% Reference: +% If you use the 'TSM toolbox' please refer to: +% [DM14] Jonathan Driedger, Meinard Mueller +% TSM Toolbox: MATLAB Implementations of Time-Scale Modification +% Algorithms +% Proceedings of the 17th International Conference on Digital Audio +% Effects, Erlangen, Germany, 2014. +% +% License: +% This file is part of 'TSM toolbox'. +% +% 'TSM toolbox' is free software: you can redistribute it and/or modify it +% under the terms of the GNU General Public License as published by the +% the Free Software Foundation, either version 3 of the License, or (at +% your option) any later version. +% +% 'TSM toolbox' is distributed in the hope that it will be useful, but +% WITHOUT ANY WARRANTY; without even the implied warranty of +% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General +% Public License for more details. +% +% You should have received a copy of the GNU General Public License along +% with 'TSM toolbox'. If not, see http://www.gnu.org/licenses/. +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% check parameters +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +if nargin<2 + parameter=[]; +end + +if ~isfield(parameter,'synHop') + parameter.synHop = 2048; +end +if ~isfield(parameter,'win') + parameter.win = win(4096,2); % hann window +end +if ~isfield(parameter,'zeroPad') + parameter.zeroPad = 0; +end +if ~isfield(parameter,'numOfIter') + parameter.numOfIter = 1; +end +if ~isfield(parameter,'origSigLen') + parameter.origSigLen = -1; % no trimming +end +if ~isfield(parameter,'restoreEnergy') + parameter.restoreEnergy = 0; +end +if ~isfield(parameter,'fftShift') + parameter.fftShift = 0; +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% some pre calculations +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +numOfFrames = size(spec,2); +numOfIter = parameter.numOfIter; + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% audio calculation +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% first iteration +Yi = spec; +yi = LSEE_MSTFT(Yi,parameter); + +% remaining iterations +parStft.win = parameter.win; +parStft.numOfFrames = numOfFrames; +parStft.zeroPad = parameter.zeroPad; +parStft.anaHop = parameter.synHop; +for j = 2 : numOfIter + Yi = abs(spec) .* exp(1j*angle(stft(yi,parStft))); + yi = LSEE_MSTFT(Yi,parameter); +end +y = yi'; +y = y./max(y); + +% if the original Length of the signal is known, also remove the zero +% padding at the end +if parameter.origSigLen > 0 + y = y(1:parameter.origSigLen); +end + +end + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% the Griffin Lim procedure +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +function x = LSEE_MSTFT(X,parameter) +% some pre calculations +w = parameter.win; +w = w(:); +zp = parameter.zeroPad; +w = [zeros(floor(zp/2),1);w;zeros(floor(zp/2),1)]; +winLen = length(w); +winLenHalf = round(winLen/2); +synHop = parameter.synHop; +numOfFrames = size(X,2); +winPos = (0:numOfFrames-1) * synHop + 1; +signalLength = winPos(end) + winLen - 1; + +x = zeros(signalLength,1); % resynthesized signal +ow = zeros(signalLength,1); % sum of the overlapping windows +for i = 1 : numOfFrames + currSpec = X(:,i); + + % add the conjugate complex symmetric upper half of the spectrum + Xi = [currSpec;conj(currSpec(end-1:-1:2))]; + xi = real(ifft(Xi)); + if parameter.fftShift == 1 + xi = fftshift(xi); + end + xiw = xi .* w; + + if parameter.restoreEnergy == 1 + xiEnergy = sum(abs(xi)); + xiwEnergy = sum(abs(xiw)); + xiw = xiw * (xiEnergy/(xiwEnergy+eps)); + end + + x(winPos(i):winPos(i)+winLen-1) = ... + x(winPos(i):winPos(i)+winLen-1) + xiw; + + ow(winPos(i):winPos(i)+winLen-1) = ... + ow(winPos(i):winPos(i)+winLen-1) + w.^2; +end +ow(ow<10^-3) = 1; % avoid potential division by zero +x = x ./ ow; + +% knowing the zeropads that were added in the stft computation, we can +% remove them again now. But since we do not know exactly how many +% zeros were padded at the end of the signal, it is only safe to remove +% winLenHalf zeros. +x = x(winLenHalf+1:end-winLenHalf); +end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/nimfks.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,1836 @@ +function varargout = nimfks(varargin) +% nimfks MATLAB code for nimfks.fig +% nimfks, by itself, creates a new nimfks or raises the existing +% singleton*. +% +% H = nimfks returns the handle to a new nimfks or the handle to +% the existing singleton*. +% +% nimfks('CALLBACK',hObject,eventData,handles,...) calls the local +% function named CALLBACK in nimfks.M with the given input arguments. +% +% nimfks('Property','Value',...) creates a new nimfks or raises the +% existing singleton*. Starting from the left, property value pairs are +% applied to the nimfks before nimfks_OpeningFcn gets called. An +% unrecognized property name or invalid value makes property application +% stop. All inputs are passed to nimfks_OpeningFcn via varargin. +% +% *See nimfks Options on GUIDE's Tools menu. Choose "nimfks allows only one +% instance to run (singleton)". +% +% See also: GUIDE, GUIDATA, GUIHANDLES + +% Edit the above text to modify the response to help nimfks + +% Last Modified by GUIDE v2.5 22-Apr-2017 18:29:19 + +% Begin initialization code - DO NOT EDIT +gui_Singleton = 1; +gui_State = struct('gui_Name', mfilename, ... + 'gui_Singleton', gui_Singleton, ... + 'gui_OpeningFcn', @nimfks_OpeningFcn, ... + 'gui_OutputFcn', @nimfks_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 nimfks is made visible. +function nimfks_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 nimfks (see VARARGIN) + +set(gcf, 'units', 'normalized', 'position', [0.1 0.1 0.8 0.85]) +%Place "playback" symbol onto buttons +[a,map]=imread(['..' filesep '..' filesep 'assets' filesep 'playButton.jpg']); + +% [pathstr, ~, ~] = fileparts(pwd); +% addpath(genpath(strcat(pathstr, '/MFAMC', '/assets'))); +% [a,map]=imread('playButton.jpg'); + +[r,c,d]=size(a); +x=ceil(r/30); +y=ceil(c/30); +g=a(1:x:end,1:y:end,:); +g(g==255)=5.5*255; +set(handles.btn_play_2,'CData',g); +set(handles.btn_play_3,'CData',g); + +[swapButtonImg,swapBtnMap]=imread(['..' filesep '..' filesep 'assets' filesep 'swapButton.jpg']); +[r,c,d]=size(swapButtonImg); +x=ceil(r/20); +y=ceil(c/20); +g=swapButtonImg(1:x:end,1:y:end,:); +g(g==255)=5.5*255; +set(handles.btn_soundswap,'CData',g); + +%Set resynthesis file explorer and restriction parameters to invisible +set([handles.pnl_activation_sketching, handles.edt_mod_rep, handles.edt_mod_poly, handles.edt_mod_cont, ... + handles.draw_activations, handles.delete_activations, handles.template_manipulation_tool, handles.btn_play_3, ... + handles.tbl_plotdata, handles.btn_synthesis, handles.btn_play_2, handles.pop_pattern, handles.txt_pattern],'Visible','off'); + +%Initialize parameters +set(handles.edt_winlen,'String','100'); %Window length +set(handles.edt_overlap,'String','50'); %Overlap +% set(handles.edt_sndlen,'String','5'); %Length of synthesis +set(handles.edt_iter,'String','10'); %NNMF Iterations +set(handles.edt_rand,'String','0'); %NNMF Activations Random Seed +set(handles.edt_conv,'String','0'); %NNMF Convergence Criteria +set(handles.edt_mod_rep,'String','-1'); %Repitition restriction parameter +set(handles.edt_mod_poly,'String','-1'); %Polyphony restriction parameter +set(handles.edt_mod_cont,'String','-1'); %Continuity enhancement parameter +set(handles.edt_sparse_lambda,'String','5'); %Lambda (regularizer) for sparse NMF +set(handles.edt_prune,'String','0'); %Pruning parameter + +% fig=gcf; +% set(findall(fig,'-property','FontSize'),'FontSize',11) + +% if( strcmp(get(handles.tool_menu_dev_cacheEnable, 'Checked'), 'on') && ~exist('nimfks_cache.mat','file') ) +if( ~exist('nimfks_cache.mat','file') ) + AnalysisCacheMap = struct(); + SynthesisCacheMap = struct(); + save('nimfks_cache.mat', 'SynthesisCacheMap', 'AnalysisCacheMap'); +end + +% Choose default command line output for nimfks +handles.output = hObject; + +% Update handles structure +guidata(hObject, handles); + +% UIWAIT makes nimfks wait for user response (see UIRESUME) +% uiwait(handles.figure1); + + +% --- Outputs from this function are returned to the command line. +function varargout = nimfks_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 pushbutton1. +function pushbutton1_Callback(hObject, eventdata, handles) +% hObject handle to pushbutton1 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +InterfaceObj=findobj(handles.figure1,'Enable','on'); +set(InterfaceObj,'Enable','off'); +% SynthesisCtr('verifyParams', handles); + +waitbarHandle = waitbar(0, 'Starting Synthesis...'); +handles.waitbarHandle = waitbarHandle; +guidata(hObject, handles); + +if(strcmp(get(handles.tool_menu_dev_timer, 'Checked'), 'on')) + tic + SynthesisCtr('run', handles); + toc +else + SynthesisCtr('run', handles); +end + +set(InterfaceObj,'Enable','on'); +% guidata(gcf, handles); + +% enableReplay handles; +set([handles.pushbutton18 handles.text8 handles.text26],'Visible','on') +SynthesisCtr('configPlotlist', handles); +SynthesisCtr('openResynthesis', handles); + +if(strcmp(get(handles.tool_menu_dev_exportWorkspace, 'Checked'), 'on')) + synthObj = handles.SynthesisObject; + save('synth.mat','synthObj'); +end + +close(waitbarHandle) + + +% --- Executes on button press in pushbutton2. +function pushbutton2_Callback(hObject, eventdata, handles) +% hObject handle to pushbutton2 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +originalGui = ancestor(hObject, 'figure'); +delete(originalGui); +GUI; + +% --- Executes on button press in pushbutton3. +function pushbutton3_Callback(hObject, eventdata, handles) +% hObject handle to pushbutton3 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + + +% --- Executes on selection change in listbox1. +function listbox1_Callback(hObject, eventdata, handles) +% hObject handle to listbox1 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +SynthesisCtr('switchPlot', handles); +% Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents as cell array +% contents{get(hObject,'Value')} returns selected item from listbox1 + + +% --- Executes during object creation, after setting all properties. +function listbox1_CreateFcn(hObject, eventdata, handles) +% hObject handle to listbox1 (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 + + +% --- Executes on button press in pushbutton11. +function pushbutton11_Callback(hObject, eventdata, handles) +% hObject handle to pushbutton11 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +SynthesisCtr('playTarget', handles); + + +function edit5_Callback(hObject, eventdata, handles) +% hObject handle to text5 (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 text5 as text +% str2double(get(hObject,'String')) returns contents of text5 as a double + + +% --- Executes during object creation, after setting all properties. +function text5_CreateFcn(hObject, eventdata, handles) +% hObject handle to text5 (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 pushbutton15. +function pushbutton15_Callback(hObject, eventdata, handles) +% hObject handle to pushbutton15 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +SynthesisCtr('playSource', handles); + + +function edit7_Callback(hObject, eventdata, handles) +% hObject handle to text7 (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 text7 as text +% str2double(get(hObject,'String')) returns contents of text7 as a double + + +% --- Executes during object creation, after setting all properties. +function text7_CreateFcn(hObject, eventdata, handles) +% hObject handle to text7 (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 pushbutton16. +function pushbutton16_Callback(hObject, eventdata, handles) +% hObject handle to pushbutton16 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +SynthesisCtr('openSource', handles); + + + +% --- Executes on button press in pushbutton18. +function pushbutton18_Callback(hObject, eventdata, handles) +% hObject handle to pushbutton18 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +SynthesisCtr('playResynthesis', handles); + + +function edit8_Callback(hObject, eventdata, handles) +% hObject handle to text8 (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 text8 as text +% str2double(get(hObject,'String')) returns contents of text8 as a double + + +% --- Executes during object creation, after setting all properties. +function text8_CreateFcn(hObject, eventdata, handles) +% hObject handle to text8 (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 edit9_Callback(hObject, eventdata, handles) +% hObject handle to edit9 (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 edit9 as text +% str2double(get(hObject,'String')) returns contents of edit9 as a double + + +% --- Executes during object creation, after setting all properties. +function edit9_CreateFcn(hObject, eventdata, handles) +% hObject handle to edit9 (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 edit10_Callback(hObject, eventdata, handles) +% hObject handle to edit10 (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 edit10 as text +% str2double(get(hObject,'String')) returns contents of edit10 as a double + + +% --- Executes during object creation, after setting all properties. +function edit10_CreateFcn(hObject, eventdata, handles) +% hObject handle to edit10 (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 edit11_Callback(hObject, eventdata, handles) +% hObject handle to edit11 (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 edit11 as text +% str2double(get(hObject,'String')) returns contents of edit11 as a double + + +% --- Executes during object creation, after setting all properties. +function edit11_CreateFcn(hObject, eventdata, handles) +% hObject handle to edit11 (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 selection change in popupmenu1. +function popupmenu1_Callback(hObject, eventdata, handles) +% hObject handle to popupmenu1 (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 popupmenu1 contents as cell array +% contents{get(hObject,'Value')} returns selected item from popupmenu1 + + +% --- Executes during object creation, after setting all properties. +function popupmenu1_CreateFcn(hObject, eventdata, handles) +% hObject handle to popupmenu1 (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 + + +% --- Executes on selection change in popupmenu2. +function popupmenu2_Callback(hObject, eventdata, handles) +% hObject handle to popupmenu2 (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 popupmenu2 contents as cell array +% contents{get(hObject,'Value')} returns selected item from popupmenu2 + + +% --- Executes during object creation, after setting all properties. +function popupmenu2_CreateFcn(hObject, eventdata, handles) +% hObject handle to popupmenu2 (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 + + +% --- Executes on selection change in popupmenu3. +function popupmenu3_Callback(hObject, eventdata, handles) +% hObject handle to popupmenu3 (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 popupmenu3 contents as cell array +% contents{get(hObject,'Value')} returns selected item from popupmenu3 + + +% --- Executes during object creation, after setting all properties. +function popupmenu3_CreateFcn(hObject, eventdata, handles) +% hObject handle to popupmenu3 (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 + + +% --- Executes on selection change in popupmenu4. +function popupmenu4_Callback(hObject, eventdata, handles) +% hObject handle to popupmenu4 (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 popupmenu4 contents as cell array +% contents{get(hObject,'Value')} returns selected item from popupmenu4 + + +% --- Executes during object creation, after setting all properties. +function popupmenu4_CreateFcn(hObject, eventdata, handles) +% hObject handle to popupmenu4 (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 + + +% --- Executes on button press in checkbox1. +function checkbox1_Callback(hObject, eventdata, handles) +% hObject handle to checkbox1 (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 checkbox1 + + +% --- Executes on button press in checkbox2. +function checkbox2_Callback(hObject, eventdata, handles) +% hObject handle to checkbox2 (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 checkbox2 + + +% --- Executes on button press in checkbox3. +function checkbox3_Callback(hObject, eventdata, handles) +% hObject handle to checkbox3 (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 checkbox3 + + +% --- Executes on button press in checkbox4. +function checkbox4_Callback(hObject, eventdata, handles) +% hObject handle to checkbox4 (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 checkbox4 + + +% --- Executes on button press in checkbox5. +function checkbox5_Callback(hObject, eventdata, handles) +% hObject handle to checkbox5 (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 checkbox5 + + +% --- Executes on button press in checkbox6. +function checkbox6_Callback(hObject, eventdata, handles) +% hObject handle to checkbox6 (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 checkbox6 + + + +function edit12_Callback(hObject, eventdata, handles) +% hObject handle to edit12 (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 edit12 as text +% str2double(get(hObject,'String')) returns contents of edit12 as a double + + +% --- Executes during object creation, after setting all properties. +function edit12_CreateFcn(hObject, eventdata, handles) +% hObject handle to edit12 (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 edit13_Callback(hObject, eventdata, handles) +% hObject handle to edit13 (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 edit13 as text +% str2double(get(hObject,'String')) returns contents of edit13 as a double + + +% --- Executes during object creation, after setting all properties. +function edit13_CreateFcn(hObject, eventdata, handles) +% hObject handle to edit13 (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 edit14_Callback(hObject, eventdata, handles) +% hObject handle to edit14 (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 edit14 as text +% str2double(get(hObject,'String')) returns contents of edit14 as a double + + +% --- Executes during object creation, after setting all properties. +function edit14_CreateFcn(hObject, eventdata, handles) +% hObject handle to edit14 (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 checkbox7. +function checkbox7_Callback(hObject, eventdata, handles) +% hObject handle to checkbox7 (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 checkbox7 +if(get(hObject, 'Value')) + set(handles.edit19,'Visible','on') +else + set(handles.edit19,'Visible','off') +end + +% --- Executes on button press in checkbox9. +function checkbox8_Callback(hObject, eventdata, handles) +% hObject handle to checkbox9 (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 checkbox9 +if(get(hObject, 'Value')) + set(handles.edit20,'Visible','on') +else + set(handles.edit20,'Visible','off') +end + +% --- Executes on button press in checkbox9. +function checkbox9_Callback(hObject, eventdata, handles) +% hObject handle to checkbox9 (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 checkbox9 +if(get(hObject, 'Value')) + set(handles.edit21,'Visible','on') +else + set(handles.edit21,'Visible','off') +end + +function edit15_Callback(hObject, eventdata, handles) +% hObject handle to edit15 (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 edit15 as text +% str2double(get(hObject,'String')) returns contents of edit15 as a double + + +% --- Executes during object creation, after setting all properties. +function edit15_CreateFcn(hObject, eventdata, handles) +% hObject handle to edit15 (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 checkbox7. +function checkbox10_Callback(hObject, eventdata, handles) +% hObject handle to checkbox7 (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 checkbox7 + + +% --- Executes on button press in checkbox9. +function checkbox11_Callback(hObject, eventdata, handles) +% hObject handle to checkbox9 (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 checkbox9 + + +% --- Executes on button press in checkbox12. +function checkbox12_Callback(hObject, eventdata, handles) +% hObject handle to checkbox12 (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 checkbox12 + + +% --- Executes when entered data in editable cell(s) in uitable3. +function uitable3_CellEditCallback(hObject, eventdata, handles) +% hObject handle to uitable3 (see GCBO) +% eventdata structure with the following fields (see MATLAB.UI.CONTROL.TABLE) +% Indices: row and column indices of the cell(s) edited +% PreviousData: previous data for the cell(s) edited +% EditData: string(s) entered by the user +% NewData: EditData or its converted form set on the Data property. Empty if Data was not changed +% Error: error string when failed to convert EditData to appropriate value for Data +% handles structure with handles and user data (see GUIDATA) + + +% --- Executes during object creation, after setting all properties. +function uitable3_CreateFcn(hObject, eventdata, handles) +% hObject handle to uitable3 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + + +% --- Executes on selection change in popupmenu5. +function popupmenu5_Callback(hObject, eventdata, handles) +% hObject handle to popupmenu5 (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 popupmenu5 contents as cell array +% contents{get(hObject,'Value')} returns selected item from popupmenu5 + + +% --- Executes during object creation, after setting all properties. +function popupmenu5_CreateFcn(hObject, eventdata, handles) +% hObject handle to popupmenu5 (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 tool_menu_Callback(hObject, eventdata, handles) +% hObject handle to tool_menu (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + + +% -------------------------------------------------------------------- +function tool_menu_dev_Callback(hObject, eventdata, handles) +% hObject handle to tool_menu_dev (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + + +% -------------------------------------------------------------------- +function tool_menu_dev_timer_Callback(hObject, eventdata, handles) +% hObject handle to tool_menu_dev_timer (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +if strcmp(get(hObject,'Checked'),'on') + set(hObject,'Checked','off'); +else + set(hObject,'Checked','on'); +end + + +% -------------------------------------------------------------------- +function tool_menu_dev_timer_ButtonDownFcn(hObject, eventdata, handles) +% hObject handle to tool_menu_dev_timer (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + + + +function edit19_Callback(hObject, eventdata, handles) +% hObject handle to edit19 (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 edit19 as text +% str2double(get(hObject,'String')) returns contents of edit19 as a double + + +% --- Executes during object creation, after setting all properties. +function edit19_CreateFcn(hObject, eventdata, handles) +% hObject handle to edit19 (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 edit20_Callback(hObject, eventdata, handles) +% hObject handle to edit20 (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 edit20 as text +% str2double(get(hObject,'String')) returns contents of edit20 as a double + + +% --- Executes during object creation, after setting all properties. +function edit20_CreateFcn(hObject, eventdata, handles) +% hObject handle to edit20 (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 edit21_Callback(hObject, eventdata, handles) +% hObject handle to edit21 (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 edit21 as text +% str2double(get(hObject,'String')) returns contents of edit21 as a double + + +% --- Executes during object creation, after setting all properties. +function edit21_CreateFcn(hObject, eventdata, handles) +% hObject handle to edit21 (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 file_menu_Callback(hObject, eventdata, handles) +% hObject handle to file_menu (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + + +% -------------------------------------------------------------------- +function file_menu_export_Callback(hObject, eventdata, handles) +% hObject handle to file_menu_export (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +handles.Sound_synthesis.save_audio; + +% -------------------------------------------------------------------- +function uipushtool1_ClickedCallback(hObject, eventdata, handles) +% hObject handle to uipushtool1 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +SynthesisCtr('savePlot', handles); + + +% -------------------------------------------------------------------- +function file_menu_export_ButtonDownFcn(hObject, eventdata, handles) +% hObject handle to file_menu_export (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + + +% -------------------------------------------------------------------- +function draw_activations_OnCallback(hObject, eventdata, handles) +% hObject handle to draw_activations (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +set(gcf,'WindowButtonDownFcn',{@drawClickCallBack, 'Draw'}) + + +% -------------------------------------------------------------------- +function draw_activations_OffCallback(hObject, eventdata, handles) +% hObject handle to draw_activations (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +set(gcf,'WindowButtonDownFcn','') + + +% -------------------------------------------------------------------- +function delete_activations_OffCallback(hObject, eventdata, handles) +% hObject handle to delete_activations (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +set(gcf,'WindowButtonDownFcn','') + + +% -------------------------------------------------------------------- +function delete_activations_OnCallback(hObject, eventdata, handles) +% hObject handle to delete_activations (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +set(gcf,'WindowButtonDownFcn',{@drawClickCallBack, 'Erase'}) + + +% --- Executes on slider movement. +function slider3_Callback(hObject, eventdata, handles) +% hObject handle to slider3 (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 slider3_CreateFcn(hObject, eventdata, handles) +% hObject handle to slider3 (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 pushbutton19. +function pushbutton19_Callback(hObject, eventdata, handles) +% hObject handle to pushbutton19 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +controller('resynthesize', handles); + +% -------------------------------------------------------------------- +function draw_activations_ClickedCallback(hObject, eventdata, handles) +% hObject handle to draw_activations (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% acts = handles.SynthesisObject.NNMFSynthesis.Activations; +% set(handles.slider3, 'Value', floor(mean(acts))); +% set(handles.slider3, 'Max', floor(max(max(acts)))); +% set(handles.slider3, 'Min', floor(min(min(acts)))); +% set(handles.slider3, 'SliderStep', floor([min(min(acts)) mean(mean(acts))])); +% guidata(hObject, handles); + +acts = handles.SynthesisObject.Activations; +set(handles.sld_actstrength, 'Max', max(max(acts))); +set(handles.sld_actstrength, 'Value', mean(mean(acts))); +set(handles.sld_actstrength, 'Min', min(min(acts))); +set(handles.sld_actstrength, 'SliderStep', [mean(mean(acts)) mean(mean(acts))]); +guidata(hObject, handles); + + +% --- Executes on slider movement. +function slider4_Callback(hObject, eventdata, handles) +% hObject handle to slider4 (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 slider4_CreateFcn(hObject, eventdata, handles) +% hObject handle to slider4 (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 radiobutton4. +function radiobutton4_Callback(hObject, eventdata, handles) +% hObject handle to radiobutton4 (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 radiobutton4 + + +% --- Executes on button press in radiobutton5. +function radiobutton5_Callback(hObject, eventdata, handles) +% hObject handle to radiobutton5 (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 radiobutton5 + + +% -------------------------------------------------------------------- +function template_manipulation_tool_OffCallback(hObject, eventdata, handles) +% hObject handle to template_manipulation_tool (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +set(gcf,'WindowKeyPressFcn','') +set(gcf,'WindowScrollWheelFcn','') + +% -------------------------------------------------------------------- +function template_manipulation_tool_OnCallback(hObject, eventdata, handles) +% hObject handle to template_manipulation_tool (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +set(gcf,'WindowKeyPressFcn',@templateDelCb) +set(gcf,'WindowScrollWheelFcn',{@templateScrollCb, findobj(gca,'Type','line')}) + + +% -------------------------------------------------------------------- +function template_manipulation_tool_ClickedCallback(hObject, eventdata, handles) +% hObject handle to template_manipulation_tool (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +templates = handles.Sound_corpus.Features.STFT.S; +[~,I]=max(templates); +[~,Ix] = sort(I,'ascend'); +handles.templateIndices = Ix; +guidata(hObject, handles); + + +% -------------------------------------------------------------------- +function file_menu_exportWorkspace_Callback(hObject, eventdata, handles) +% hObject handle to file_menu_exportWorkspace_Callback (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +currentWorkspace = struct('Sound_corpus', handles.Sound_corpus, ... + 'Sound_target', handles.Sound_target, ... + 'Sound_synthesis', handles.Sound_synthesis, ... + 'SynthesisObject', handles.SynthesisObject); + +[file,path] = uiputfile('*.mat','Save Workspace As'); +save([path filesep file], '-struct', 'currentWorkspace'); + +% --- Executes on button press in pushbutton21. +function pushbutton21_Callback(hObject, eventdata, handles) +% hObject handle to pushbutton21 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +SynthesisCtr('rerun', handles); + + +% --- Executes on button press in checkbox14. +function checkbox14_Callback(hObject, eventdata, handles) +% hObject handle to checkbox14 (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 checkbox14 + + +% --- Executes on button press in pushbutton22. +function pushbutton22_Callback(hObject, eventdata, handles) +% hObject handle to pushbutton22 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +SynthesisCtr('Swap Sounds', handles); + + +% --- Executes on button press in btn_synthesis. +function btn_synthesis_Callback(hObject, eventdata, handles) +% hObject handle to btn_synthesis (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +if(strcmp(get(handles.tool_menu_dev_timer, 'Checked'), 'on')) + tic + controller('runSynthesis', handles); + toc +else + controller('runSynthesis', handles); +end + +handles = guidata(hObject); %Necessary to update handles + +set([handles.btn_play_3], 'Visible', 'on'); + +controller('switchPlot', handles); + +% --- Executes on button press in btn_analysis. +function btn_analysis_Callback(hObject, eventdata, handles) +% hObject handle to btn_analysis (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +guidata(hObject, handles); + +if(strcmp(get(handles.tool_menu_dev_timer, 'Checked'), 'on')) + tic + controller('runAnalysis', handles); + toc +else + controller('runAnalysis', handles); +end +set(handles.btn_synthesis, 'Visible', 'on'); + +% --- Executes on selection change in popupmenu11. +function popupmenu11_Callback(hObject, eventdata, handles) +% hObject handle to popupmenu11 (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 popupmenu11 contents as cell array +% contents{get(hObject,'Value')} returns selected item from popupmenu11 + + +% --- Executes during object creation, after setting all properties. +function popupmenu11_CreateFcn(hObject, eventdata, handles) +% hObject handle to popupmenu11 (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 + + +% --- Executes on selection change in pop_cost. +function pop_cost_Callback(hObject, eventdata, handles) +% hObject handle to pop_cost (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 pop_cost contents as cell array +% contents{get(hObject,'Value')} returns selected item from pop_cost +contents = cellstr(get(hObject,'String')); +cost = contents{get(hObject,'Value')}; +if( strcmp(cost, 'Sparse NMF')) + set([handles.edt_sparse_lambda handles.txt_sparse_lambda], 'Visible', 'on'); +else + set([handles.edt_sparse_lambda handles.txt_sparse_lambda], 'Visible', 'off'); +end + +% --- Executes during object creation, after setting all properties. +function pop_cost_CreateFcn(hObject, eventdata, handles) +% hObject handle to pop_cost (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 edt_winlen_Callback(hObject, eventdata, handles) +% hObject handle to edt_winlen (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 edt_winlen as text +% str2double(get(hObject,'String')) returns contents of edt_winlen as a double + + +% --- Executes during object creation, after setting all properties. +function edt_winlen_CreateFcn(hObject, eventdata, handles) +% hObject handle to edt_winlen (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 edt_overlap_Callback(hObject, eventdata, handles) +% hObject handle to edt_overlap (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 edt_overlap as text +% str2double(get(hObject,'String')) returns contents of edt_overlap as a double + + +% --- Executes during object creation, after setting all properties. +function edt_overlap_CreateFcn(hObject, eventdata, handles) +% hObject handle to edt_overlap (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 edt_sndlen_Callback(hObject, eventdata, handles) +% hObject handle to edt_sndlen (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 edt_sndlen as text +% str2double(get(hObject,'String')) returns contents of edt_sndlen as a double + + +% --- Executes during object creation, after setting all properties. +function edt_sndlen_CreateFcn(hObject, eventdata, handles) +% hObject handle to edt_sndlen (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 selection change in pop_wintype. +function pop_wintype_Callback(hObject, eventdata, handles) +% hObject handle to pop_wintype (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 pop_wintype contents as cell array +% contents{get(hObject,'Value')} returns selected item from pop_wintype + + +% --- Executes during object creation, after setting all properties. +function pop_wintype_CreateFcn(hObject, eventdata, handles) +% hObject handle to pop_wintype (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 + + +% --- Executes on button press in checkbox21. +function checkbox21_Callback(hObject, eventdata, handles) +% hObject handle to checkbox21 (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 checkbox21 + + +% --- Executes on selection change in pop_specttype. +function pop_specttype_Callback(hObject, eventdata, handles) +% hObject handle to pop_specttype (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 pop_specttype contents as cell array +% contents{get(hObject,'Value')} returns selected item from pop_specttype + + +% --- Executes during object creation, after setting all properties. +function pop_specttype_CreateFcn(hObject, eventdata, handles) +% hObject handle to pop_specttype (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 + + +% --- Executes on selection change in pop_synthmethod. +function pop_synthmethod_Callback(hObject, eventdata, handles) +% hObject handle to pop_synthmethod (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 pop_synthmethod contents as cell array +% contents{get(hObject,'Value')} returns selected item from pop_synthmethod + + +% --- Executes during object creation, after setting all properties. +function pop_synthmethod_CreateFcn(hObject, eventdata, handles) +% hObject handle to pop_synthmethod (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 + + +% --- Executes on button press in btn_play_3. +function btn_play_3_Callback(hObject, eventdata, handles) +% hObject handle to btn_play_3 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +if(isplaying(handles.Sound_synthesis.Audioplayer)) + controller('stopSynthesis', handles); + [a,map]=imread(['..' filesep '..' filesep 'assets' filesep 'playButton.jpg']); + [r,c,d]=size(a); + x=ceil(r/30); + y=ceil(c/30); + g=a(1:x:end,1:y:end,:); + g(g==255)=5.5*255; + set(handles.btn_play_3,'CData',g) +else + controller('playSynthesis', handles); + [a,map]=imread(['..' filesep '..' filesep 'assets' filesep 'stopButton.png']); + [r,c,d]=size(a); + x=ceil(r/30); + y=ceil(c/30); + g=a(1:x:end,1:y:end,:); + g(g==255)=5.5*255; + set(handles.btn_play_3,'CData',g); +end + +% --- Executes on selection change in pop_plot. +function pop_plot_Callback(hObject, eventdata, handles) +% hObject handle to pop_plot (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 pop_plot contents as cell array +% contents{get(hObject,'Value')} returns selected item from pop_plot +controller('switchPlot', handles); + +% --- Executes during object creation, after setting all properties. +function pop_plot_CreateFcn(hObject, eventdata, handles) +% hObject handle to pop_plot (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 + + +% --- Executes on button press in btn_play_2. +function btn_play_2_Callback(hObject, eventdata, handles) +% hObject handle to btn_play_2 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +if(isplaying(handles.Sound_target.Audioplayer)) + controller('stopTarget', handles); + [a,map]=imread(['..' filesep '..' filesep 'assets' filesep 'playButton.jpg']); + [r,c,d]=size(a); + x=ceil(r/30); + y=ceil(c/30); + g=a(1:x:end,1:y:end,:); + g(g==255)=5.5*255; + set(handles.btn_play_2,'CData',g) +else + controller('playTarget', handles); + [a,map]=imread(['..' filesep '..' filesep 'assets' filesep 'stopButton.png']); + [r,c,d]=size(a); + x=ceil(r/30); + y=ceil(c/30); + g=a(1:x:end,1:y:end,:); + g(g==255)=5.5*255; + set(handles.btn_play_2,'CData',g); +end + +% --- Executes on button press in btn_load_target. +function btn_load_target_Callback(hObject, eventdata, handles) +% hObject handle to btn_load_target (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +controller('openTarget', handles); +set(handles.btn_play_2, 'Visible', 'on'); + +% --- Executes on button press in btn_load_corpus. +function btn_load_corpus_Callback(hObject, eventdata, handles) +% hObject handle to btn_load_corpus (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +controller('openSource', handles); + +% --- Executes on button press in btn_post_processing_run. +function btn_post_processing_run_Callback(hObject, eventdata, handles) +% hObject handle to btn_post_processing_run (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +controller('rerun', handles); + +% --- Executes on slider movement. +function sld_maxdb_Callback(hObject, eventdata, handles) +% hObject handle to sld_maxdb (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +controller('switchPlot', handles); +% 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 sld_maxdb_CreateFcn(hObject, eventdata, handles) +% hObject handle to sld_maxdb (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 btn_resynthesis. +function btn_resynthesis_Callback(hObject, eventdata, handles) +% hObject handle to btn_resynthesis (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +controller('resynthesize', handles); + +% --- Executes on slider movement. +function sld_actstrength_Callback(hObject, eventdata, handles) +% hObject handle to sld_actstrength (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 sld_actstrength_CreateFcn(hObject, eventdata, handles) +% hObject handle to sld_actstrength (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 + + + +function edt_iter_Callback(hObject, eventdata, handles) +% hObject handle to edt_iter (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 edt_iter as text +% str2double(get(hObject,'String')) returns contents of edt_iter as a double + + +% --- Executes during object creation, after setting all properties. +function edt_iter_CreateFcn(hObject, eventdata, handles) +% hObject handle to edt_iter (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 edt_rand_Callback(hObject, eventdata, handles) +% hObject handle to edt_rand (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 edt_rand as text +% str2double(get(hObject,'String')) returns contents of edt_rand as a double + + +% --- Executes during object creation, after setting all properties. +function edt_rand_CreateFcn(hObject, eventdata, handles) +% hObject handle to edt_rand (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 edt_conv_Callback(hObject, eventdata, handles) +% hObject handle to edt_conv (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 edt_conv as text +% str2double(get(hObject,'String')) returns contents of edt_conv as a double + + +% --- Executes during object creation, after setting all properties. +function edt_conv_CreateFcn(hObject, eventdata, handles) +% hObject handle to edt_conv (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 chk_mod_rep. +function chk_mod_rep_Callback(hObject, eventdata, handles) +% hObject handle to chk_mod_rep (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 chk_mod_rep +if(get(hObject, 'Value')) + set([handles.edt_mod_rep],'Visible','on') +else + set([handles.edt_mod_rep],'Visible','off') + set([handles.edt_mod_rep],'String', '-1' ) +end + +% --- Executes on button press in chk_mod_poly. +function chk_mod_poly_Callback(hObject, eventdata, handles) +% hObject handle to chk_mod_poly (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 chk_mod_poly +if(get(hObject, 'Value')) + set([handles.edt_mod_poly],'Visible','on') +else + set([handles.edt_mod_poly],'Visible','off') + set([handles.edt_mod_poly],'String', '-1' ) +end + +% --- Executes on button press in chk_mod_cont. +function chk_mod_cont_Callback(hObject, eventdata, handles) +% hObject handle to chk_mod_cont (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 chk_mod_cont +if(get(hObject, 'Value')) + set([handles.edt_mod_cont, handles.pop_pattern, ... + handles.txt_pattern, handles.edt_mod_cont_rot, handles.txt_rot],'Visible','on') +else + set([handles.edt_mod_cont, handles.pop_pattern, ... + handles.txt_pattern, handles.edt_mod_cont_rot, handles.txt_rot],'Visible','off') + set([handles.edt_mod_cont],'String', '-1' ) +end + + +function edt_mod_rep_Callback(hObject, eventdata, handles) +% hObject handle to edt_mod_rep (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 edt_mod_rep as text +% str2double(get(hObject,'String')) returns contents of edt_mod_rep as a double + + +% --- Executes during object creation, after setting all properties. +function edt_mod_rep_CreateFcn(hObject, eventdata, handles) +% hObject handle to edt_mod_rep (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 edt_mod_poly_Callback(hObject, eventdata, handles) +% hObject handle to edt_mod_poly (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 edt_mod_poly as text +% str2double(get(hObject,'String')) returns contents of edt_mod_poly as a double + + +% --- Executes during object creation, after setting all properties. +function edt_mod_poly_CreateFcn(hObject, eventdata, handles) +% hObject handle to edt_mod_poly (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 edt_mod_cont_Callback(hObject, eventdata, handles) +% hObject handle to edt_mod_cont (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 edt_mod_cont as text +% str2double(get(hObject,'String')) returns contents of edt_mod_cont as a double + + +% --- Executes during object creation, after setting all properties. +function edt_mod_cont_CreateFcn(hObject, eventdata, handles) +% hObject handle to edt_mod_cont (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 edit37_Callback(hObject, eventdata, handles) +% hObject handle to edt_sndlen (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 edt_sndlen as text +% str2double(get(hObject,'String')) returns contents of edt_sndlen as a double + + +% --- Executes during object creation, after setting all properties. +function edit37_CreateFcn(hObject, eventdata, handles) +% hObject handle to edt_sndlen (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 chk_corpuslen. +function chk_corpuslen_Callback(hObject, eventdata, handles) +% hObject handle to chk_corpuslen (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 chk_corpuslen + + +% --- Executes during object creation, after setting all properties. +function txt_corpusfile_CreateFcn(hObject, eventdata, handles) +% hObject handle to txt_corpusfile (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + + +% --- Executes during object creation, after setting all properties. +function txt_targetfile_CreateFcn(hObject, eventdata, handles) +% hObject handle to txt_targetfile (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + + +% --- Executes during object creation, after setting all properties. +function chk_mod_rep_CreateFcn(hObject, eventdata, handles) +% hObject handle to chk_mod_rep (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + + +% --- Executes during object creation, after setting all properties. +function chk_mod_poly_CreateFcn(hObject, eventdata, handles) +% hObject handle to chk_mod_poly (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + + +% --- Executes during object creation, after setting all properties. +function chk_mod_cont_CreateFcn(hObject, eventdata, handles) +% hObject handle to chk_mod_cont (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + + +% --- Executes during object creation, after setting all properties. +function tbl_plotdata_CreateFcn(hObject, eventdata, handles) +% hObject handle to tbl_plotdata (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + + +% -------------------------------------------------------------------- +function tool_menu_activations_Callback(hObject, eventdata, handles) +% hObject handle to tool_menu_activations (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +set([handles.pnl_activation_sketching, handles.draw_activations, handles.delete_activations, handles.btn_resynthesis], 'Visible', 'on'); + +% -------------------------------------------------------------------- +function tool_menu_templates_Callback(hObject, eventdata, handles) +% hObject handle to tool_menu_templates (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +set([handles.template_manipulation_tool, handles.btn_post_processing_run], 'Visible', 'on'); + + +% -------------------------------------------------------------------- +function tool_menu_dev_plotData_Callback(hObject, eventdata, handles) +% hObject handle to tool_menu_dev_plotData (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +set(handles.tbl_plotdata, 'Visible', 'on'); + + +% --- Executes on selection change in pop_pattern. +function pop_pattern_Callback(hObject, eventdata, handles) +% hObject handle to pop_pattern (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 pop_pattern contents as cell array +% contents{get(hObject,'Value')} returns selected item from pop_pattern + + +% --- Executes during object creation, after setting all properties. +function pop_pattern_CreateFcn(hObject, eventdata, handles) +% hObject handle to pop_pattern (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 + + +% --- Executes on button press in chk_endtime. +function chk_endtime_Callback(hObject, eventdata, handles) +% hObject handle to chk_endtime (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 chk_endtime + + +% -------------------------------------------------------------------- +function file_menu_importWorkspace_Callback(hObject, eventdata, handles) +% hObject handle to file_menu_importWorkspace (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('*.mat','Select the workspace'); +importedWorkspace = load([PathName FileName]); + +handles.Sound_corpus = importedWorkspace.Sound_corpus; +handles.Sound_target = importedWorkspace.Sound_target; +handles.Sound_synthesis = importedWorkspace.Sound_synthesis; +handles.SynthesisObject = importedWorkspace.SynthesisObject; + +guidata(hObject, handles); + +set([handles.btn_play_2, handles.btn_play_3, handles.btn_synthesis], 'Visible', 'on'); +set(handles.txt_corpusfile, 'String', handles.Sound_corpus.Filename); +set(handles.txt_targetfile, 'String', handles.Sound_target.Filename); + + + +function edt_mod_cont_rot_Callback(hObject, eventdata, handles) +% hObject handle to edt_mod_cont_rot (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 edt_mod_cont_rot as text +% str2double(get(hObject,'String')) returns contents of edt_mod_cont_rot as a double + + +% --- Executes during object creation, after setting all properties. +function edt_mod_cont_rot_CreateFcn(hObject, eventdata, handles) +% hObject handle to edt_mod_cont_rot (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 edt_sparse_lambda_Callback(hObject, eventdata, handles) +% hObject handle to edt_sparse_lambda (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 edt_sparse_lambda as text +% str2double(get(hObject,'String')) returns contents of edt_sparse_lambda as a double + + +% --- Executes during object creation, after setting all properties. +function edt_sparse_lambda_CreateFcn(hObject, eventdata, handles) +% hObject handle to edt_sparse_lambda (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 tool_menu_dev_cacheEnable_Callback(hObject, eventdata, handles) +% hObject handle to tool_menu_dev_cacheEnable (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +if strcmp(get(hObject,'Checked'),'on') + set(hObject,'Checked','off'); +else + set(hObject,'Checked','on'); +end + + + +function edt_prune_Callback(hObject, eventdata, handles) +% hObject handle to edt_prune (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 edt_prune as text +% str2double(get(hObject,'String')) returns contents of edt_prune as a double + + +% --- Executes during object creation, after setting all properties. +function edt_prune_CreateFcn(hObject, eventdata, handles) +% hObject handle to edt_prune (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 btn_soundswap. +function btn_soundswap_Callback(hObject, eventdata, handles) +% hObject handle to btn_soundswap (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +controller('swapSourceAndTarget', handles); +set(handles.btn_play_2, 'Visible', 'on'); \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/nmfFn.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,13 @@ +function [H, cost] = nmfFn(nmf_params, corpus_analysis, target_analysis) + + nmf_alg = nmf_params.Algorithm; + target_spect = target_analysis.STFT.S; + corpus_spect = corpus_analysis.STFT.S; + + switch nmf_alg + case 'Euclidean' + [H, cost] = nmf_euclidean(nmf_params, target_spect, corpus_spect); + case 'Divergence' + [H, cost] = nmf_divergence(nmf_params, target_spect, corpus_spect); + end +end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/nmf_beta.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,35 @@ +function [ Y, cost ] = nmf_beta( V, W, varargin ) + +if nargin > 2 + nmf_params = varargin{1}; + iterations = nmf_params.Iterations; + lambda = nmf_params.Lambda; + beta = nmf_params.Beta % 1: KL Divergence; 2: Euclidean +end + +cost=0; +K=size(W, 2); +M=size(V, 2); + +H=random('unif',0, 1, K, M); + +V = V+1E-6; +W = W+1E-6; + +for l=1:L-1 + recon = W*H; + num = H.*(W'*(((recon).^(beta-2)).*V)); + den = W'*((recon).^(beta-1)); + H = num./den; +end + +fprintf('Iterations: %i/%i\n', l, L); +fprintf('Convergence Criteria: %i\n', convergence*100); +fprintf('Repitition: %i\n', r); +fprintf('Polyphony: %i\n', p); +fprintf('Continuity: %i\n', c); + +Y=H; +Y = Y./max(max(Y)); %Normalize activations + +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/nmf_divergence.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,122 @@ +function [Y, cost] = nmf_divergence(V, W, varargin) + +if nargin > 2 + nmf_params = varargin{1}; + L = nmf_params.Iterations; + convergence = nmf_params.Convergence_criteria; + r = nmf_params.Repition_restriction; + p = nmf_params.Polyphony_restriction; + c = nmf_params.Continuity_enhancement; + rot = nmf_params.Continuity_enhancement_rot; + pattern = nmf_params.Diagonal_pattern; + endtime = nmf_params.Modification_application; + rng(nmf_params.Random_seed); +elseif nargin == 2 + L = 10; + convergence = 0; + r = -1; + p = -1; + c = -1; + pattern = 'Diagonal'; + endtime = false; + rng('shuffle'); +end + +waitbarHandle = waitbar(0, 'Starting NMF synthesis...'); + +cost=0; +K=size(W, 2); +M=size(V, 2); + +H=random('unif',0, 1, K, M); + +P=zeros(K, M); +R=zeros(K, M); +C=zeros(K, M); + +V = V+1E-6; +W = W+1E-6; +den = sum(W); + +for l=1:L-1 + waitbar(l/(L-1), waitbarHandle, ['Computing approximation...Iteration: ', num2str(l), '/', num2str(L-1)]) + + recon = W*H; + for mm = 1:size(H,2) + num = V(:,mm).*(1./recon(:,mm)); + num2 = num'*W./den; + H(:,mm) = H(:, mm).*num2'; + end + + if((r > 0 && ~endtime) || (r > 0 && endtime && l==L-1)) + waitbar(l/(L-1), waitbarHandle, ['Repition Restriction...Iteration: ', num2str(l), '/', num2str(L-1)]) + for k = 1:size(H, 1) + for m = 1:size(H, 2) + if(m>r && (m+r)<=M && H(k,m)==max(H(k,m-r:m+r))) + R(k,m)=H(k,m); + else + R(k,m)=H(k,m)*(1-(l+1)/L); + end + end + end + + H = R; + end + + if((p > 0 && ~endtime) || (p > 0 && endtime && l==L-1)) + waitbar(l/(L-1), waitbarHandle, ['Polyphony Restriction...Iteration: ', num2str(l), '/', num2str(L-1)]) + P = zeros(size(H)); + mask = zeros(size(H,1),1); + for m = 1:size(H, 2) + [~, sortedIndices] = sort(H(:, m),'descend'); + mask(sortedIndices(1:p)) = 1; + mask(sortedIndices(p+1:end)) = (1-(l+1)/L); + P(:,m)=H(:,m).*mask; + end + H = P; + end + + if((c > 0 && ~endtime) || (c > 0 && endtime && l==L-1)) + waitbar(l/(L-1), waitbarHandle, ['Continuity Enhancement...Iteration: ', num2str(l), '/', num2str(L-1)]) + switch pattern + case 'Diagonal' + C = conv2(H, rot_kernel( eye(c), rot ), 'same'); %Default + case 'Reverse' + C = conv2(H, flip(eye(c)), 'same'); %Reverse + case 'Blur' + C = conv2(H, flip(ones(c)), 'same'); %Blurring + case 'Vertical' + M = zeros(c, c); %Vertical + M(:, floor(c/2)) = 1; + C = conv2(P, M, 'same'); + end + + H = C; + end + + if ~endtime + recon = W*H; + for mm = 1:size(H,2) + num = V(:,mm).*(1./recon(:,mm)); + num2 = num'*W./den; + H(:,mm) = H(:, mm).*num2'; + end + end + + cost(l)=KLDivCost(V, W*H); + if(l>3 && (abs(((cost(l)-cost(l-1)))/max(cost))<=convergence)) + break; + end +end + +fprintf('Iterations: %i/%i\n', l, L); +fprintf('Convergence Criteria: %i\n', convergence*100); +fprintf('Repitition: %i\n', r); +fprintf('Polyphony: %i\n', p); +fprintf('Continuity: %i\n', c); + +Y=H; +Y = Y./max(max(Y)); %Normalize activations + +close(waitbarHandle); +end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/nmf_euclidean.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,118 @@ +function [Y, cost] = nmf_euclidean(V, W, varargin) + +if nargin > 2 + nmf_params = varargin{1}; + L = nmf_params.Iterations; + convergence = nmf_params.Convergence_criteria; + r = nmf_params.Repition_restriction; + p = nmf_params.Polyphony_restriction; + c = nmf_params.Continuity_enhancement; + rot = nmf_params.Continuity_enhancement_rot; + pattern = nmf_params.Diagonal_pattern; + endtime = nmf_params.Modification_application; + + if nmf_params.Random_seed <= 0 + rng('shuffle'); + else + rng(nmf_params.Random_seed); + end +elseif nargin == 2 + L = 10; + convergence = 0; + r = 3; + p = 10; + c = 3; + pattern = 'Diagonal'; + endtime = false; + rng('shuffle'); +end + +waitbarHandle = waitbar(0, 'Starting NMF synthesis...'); + +cost=0; +targetDim=size(V); +sourceDim=size(W); +K=sourceDim(2); +M=targetDim(2); + +H=random('unif',0, 1, K, M); + +num=W'*V; +WTW = W'*W; + +for l=1:L-1 + waitbar(l/(L-1), waitbarHandle, ['Computing approximation...Iteration: ', num2str(l), '/', num2str(L-1)]) + + den=WTW*H; + H=H.*(num./den); + H(isnan(H))=0; + + if((r > 0 && ~endtime) || (r > 0 && endtime && l==L-1)) + waitbar(l/(L-1), waitbarHandle, ['Repition Restriction...Iteration: ', num2str(l), '/', num2str(L-1)]) + for k=1:K + %Updating H + for m=1:M + if(m>r && (m+r)<=M && H(k,m)==max(H(k,m-r:m+r))) + R(k,m)=H(k,m); + else + R(k,m)=H(k,m)*(1-(l+1)/L); + end + end + end + + H = R; + end + + if((p > 0 && ~endtime) || (p > 0 && endtime && l==L-1)) + waitbar(l/(L-1), waitbarHandle, ['Polyphony Restriction...Iteration: ', num2str(l), '/', num2str(L-1)]) + P = zeros(size(H)); + mask = zeros(size(H,1),1); + for m = 1:size(H, 2) + [~, sortedIndices] = sort(H(:, m),'descend'); + mask(sortedIndices(1:p)) = 1; + mask(sortedIndices(p+1:end)) = (1-(l+1)/L); + P(:,m)=H(:,m).*mask; + end + H = P; + end + + if((c > 0 && ~endtime) || (c > 0 && endtime && l==L-1)) + waitbar(l/(L-1), waitbarHandle, ['Continuity Enhancement...Iteration: ', num2str(l), '/', num2str(L-1)]) + switch pattern + case 'Diagonal' + C = conv2(H, rot_kernel( eye(c), rot ), 'same'); %Default + case 'Reverse' + C = conv2(H, flip(eye(c)), 'same'); %Reverse + case 'Blur' + C = conv2(H, flip(ones(c)), 'same'); %Blurring + case 'Vertical' + M = zeros(c, c); %Vertical + M(:, floor(c/2)) = 1; + C = conv2(P, M, 'same'); + end + H = C; + end + + if ~endtime + den=WTW*H; + H=H.*(num./den); + H(isnan(H))=0; + end + + cost(l)=norm(V-W*H, 'fro'); %Frobenius norm of a matrix + if(l > 5 && (cost(l) > cost(l-1) || abs(((cost(l)-cost(l-1)))/max(cost))<convergence)) + break; + end +end + +fprintf('Iterations: %i/%i\n', l, L); +fprintf('Convergence Criteria: %i\n', convergence*100); +fprintf('Repitition: %i\n', r); +fprintf('Polyphony: %i\n', p); +fprintf('Continuity: %i\n', c); + +Y=H; +Y = Y./max(max(Y)); + +close(waitbarHandle); +end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/prune_corpus.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,66 @@ +function [ Y, PrunedFrames, KeepCorpusFrames ] = prune_corpus( target, corpus, reduction_coef ) + + if reduction_coef == 1 + Y = corpus; + PrunedFrames = []; + KeepCorpusFrames = []; + return; + end + [targetRows, targetCols]= size( target ); + [corpusRows, corpusCols]= size( corpus ); + + % Matrix: distances of every target frame to every other target frame + % i.e. Self-similarity matrix + TargetSelfSimMat = zeros(targetCols); + + % Matrix: distances of every target frame to every corpus frame + % Matrix( i, j ) = Similarity of corpus frame i to target frame j +% TargetToCorpSimMat = -1*ones(WCols, targetCols); + + % Calculate self-similarity of target (euclidean dist) + X2 = sum(target.^2,1); + TargetSelfSimMat = bsxfun(@plus,X2,X2')-2*(target'*target); +% TargetSelfSimMat = exp(-(1/10) * DistanceMat); + + % Calculate the distance between each corpus frame to first target + % frame + KeepCorpusFrames = []; + RemainingTargetFrames = 1:targetCols; + RemainingCorpusFrames = 1:corpusCols; + + while ~isempty(RemainingTargetFrames) + Dist = repmat(target(:,RemainingTargetFrames(1)),1, ... + length(RemainingCorpusFrames)) - corpus(:,RemainingCorpusFrames); + Distances = sum(Dist.^2,1); + % compute mean distances + meanDistance = mean(Distances); + + % find those corpus frames closer than reduction_coef of mean + idxcorpuskeep = Distances < reduction_coef*meanDistance; + KeepCorpusFrames = [KeepCorpusFrames RemainingCorpusFrames(idxcorpuskeep)]; + + % find those target frames within twice that to next frame + distancetonext = TargetSelfSimMat(RemainingTargetFrames(1)+1,RemainingTargetFrames(1)); + idxtarget = TargetSelfSimMat(RemainingTargetFrames,RemainingTargetFrames(1)) ... + < 2*distancetonext; + + if ~any( idxtarget ) && distancetonext == 0 + idxtarget = RemainingTargetFrames(2); + end + + % shrink corpus + RemainingCorpusFrames = RemainingCorpusFrames(~idxcorpuskeep); + + % shrink target frames index + RemainingTargetFrames = RemainingTargetFrames(~idxtarget); + + fprintf( '%d remaining frames...\n', size( RemainingTargetFrames ) ); + end + +KeepCorpusFrames = sort( KeepCorpusFrames ); +Y = corpus( :, KeepCorpusFrames ); +PrunedFrames = setdiff( 1:corpusCols, KeepCorpusFrames ); + +fprintf( 'Pruned %d frames...\n', size( PrunedFrames ) ); + +end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/rot_kernel.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,80 @@ +function [Y] = rot_kernel(kernel, deg) + +N = size( kernel, 1 ); +max_rots = 4*(N-1); +deg_per_rot = 360 / max_rots; + +% deg = deg - mod( deg, deg_per_rot ); +deg = deg_per_rot * ( round( deg / deg_per_rot ) ); +num_of_rots = ceil( deg / deg_per_rot ); + +if num_of_rots < 1 + Y = kernel; + return +else + for r = 1:num_of_rots + if mod( r, 2 ) == 0 + kernel = rot_outer_layer( kernel ); + else + kernel = rot_inner_layer( kernel ); + end + end +end + +Y = kernel; + +end + +function [Y] = rot_outer_layer( A ) + dim = size( A, 1 ); + top = A( 1, : ); + right = A( 2:dim, dim )'; + bottom = fliplr( A( dim, 1:dim - 1 ) ); + left = fliplr( A( 2:dim - 1, 1 )' ); + shifted_layers = wshift('1D',[top,right,bottom,left],-1); + + top = shifted_layers( 1:length(top)); + last_ind = length( top ); + + right = shifted_layers( last_ind + 1 : last_ind + length(right)); + last_ind = last_ind + length( right ); + + bottom = shifted_layers( last_ind + 1 : last_ind + length(bottom)); + last_ind = last_ind + length( bottom ); + + left = shifted_layers( last_ind + 1 : end ); + + A( 1, : ) = top; + A( 2:dim, dim ) = right'; + A( dim, 1:dim - 1 ) = fliplr( bottom ); + A( 2:dim - 1, 1 ) = fliplr( left' ); + + Y = A; +end + +function [Y] = rot_inner_layer( kernel ) +% dim = size( kernel, 1 ); +% if dim < 2 +% Y = rot_outer_layer( kernel ) +% return; +% else +% Y = rot_inner_layer( kernel( 2:dim - 1, 2:dim - 1 ) ) +% end + dim = size( kernel, 1 ); + + if mod( dim / 2, 2 ) == 0 + max_rots = dim / 2 - 1; + else + max_rots = dim / 2 - 0.5; + end + + low = 2; + high = dim - 1; + for i = 1:max_rots + kernel( low:high, low:high ) = rot_outer_layer( kernel( low:high, low:high ) ); + low = low + 1; + high = high - 1; + end + + Y = kernel; +end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/templateAdditionResynth.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,43 @@ +function [output, segments] = templateAdditionResynth(X, H, varargin) + +if(nargin > 2) + win = varargin{1}; + windowLength = win.Length; + overlap = win.Hop; + winfn = lower(win.Type); + win = window(winfn, windowLength); +else + overlap = floor((length(X)/size(H, 2))/2); + windowLength = floor(2*overlap); + win = window(@hann,(windowLength)); +end + +windowhop = windowLength - overlap; +start_samples_in_corpus=[0:size(H,1)-1]*windowhop + 1; +end_samples_in_corpus = start_samples_in_corpus + windowLength - 1; +start_samples_in_synthesis=[0:size(H,2)-1]*windowhop + 1; +end_samples_in_synthesis = start_samples_in_synthesis + windowLength - 1; + +waitbarHandle = waitbar(0, 'Starting Template Addition Synthesis...'); + +output=zeros(windowhop*(size(H,2)-1)+windowLength,1); + +for kk=1:size(H, 2) + waitbar(kk/size(H, 2), waitbarHandle, ['Creating segments...', num2str(kk), '/', num2str(size(H, 2))]); + extracted=H(:,kk); + + for ii=find(extracted>1e-10)' + if length(X) > end_samples_in_corpus(ii) + output(start_samples_in_synthesis(kk):end_samples_in_synthesis(kk)) = ... + output(start_samples_in_synthesis(kk):end_samples_in_synthesis(kk)) + ... + win.*( ... + X(start_samples_in_corpus(ii):end_samples_in_corpus(ii))*extracted(ii)); + end + end +end + +output = output'; + +output = output./max(max(output)); +close(waitbarHandle) +end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/templateDelCb.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,12 @@ +function templateDelCb(src, callbackdata) + +if(strcmp(callbackdata.Key, 'delete')) + selectedTemplate = findobj(gca, 'Color', 'b'); + selectedTemplate.YData = zeros(1, length(selectedTemplate.YData)); + selectedTemplate.ZData = zeros(1, length(selectedTemplate.ZData)); + handles = guidata(src); + templates = handles.Sound_corpus.Features.STFT.S; + selectedIndex = handles.templateIndices(selectedTemplate.XData); + templates(:, selectedIndex) = 0; + handles.Sound_corpus.Features.STFT.S = templates; +end \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/matlab/templateScrollCb.m Sun Jun 18 06:26:13 2017 -0400 @@ -0,0 +1,22 @@ +function templateScrollCb(src, callbackdata, handles) + +selectedTemplate = findobj(gca, 'Color', 'b'); +if(callbackdata.VerticalScrollCount < 0 && size(selectedTemplate, 1) ~= 0) %Up scroll + newTemplateIndex = length(handles) - selectedTemplate.XData(1) + 2; + if(newTemplateIndex > length(handles)) + newTemplateIndex = 2; + end + neighbouringTemplate = newTemplateIndex + 1; +elseif(callbackdata.VerticalScrollCount > 0 && size(selectedTemplate, 1) ~= 0) %Down scroll + newTemplateIndex = length(handles) - selectedTemplate.XData(1); + if(newTemplateIndex < 1) + newTemplateIndex = length(handles); + end +end + +if(size(selectedTemplate, 1) == 0) + set(handles(1), 'Color', 'b'); +else + set(selectedTemplate, 'Color', get(handles(newTemplateIndex), 'Color')); + set(handles(newTemplateIndex), 'Color', 'b'); +end \ No newline at end of file