addpath('../scatnet-v0.2.1');
addpath_scatnet;


directory = '../SCATT_BIRD_50mostE_perfile_april2014_RB_HG/';

opt.averaging_length = [2048 32768];
opt.nFilters_per_octave = 16;
opt.quality_factor = 16;
opt.compression_exponent = 1;
opt.nFreq_filters_per_octave = 4;
opt.freq_quality_factor = 4;
opt.frequency_transposition_invariance = 32; % i.e. two octaves for Q=16
opt.fr_oversampling = 1;
opt.j2 = 7;

nCategories = 1;

for category_index = 1:nCategories
	subdirectory = sprintf('%d/',category_index);
	mkdir(subdirectory);
	file_name_array = dir([directory subdirectory '*.wav']);
	nFiles = length(file_name_array);
	for file_index = 1:nFiles
		% make sure that ssh was launched with -X option
		file_name = file_name_array(file_index).name;
		file_path = [directory subdirectory file_name];
		joint_matrix = computeJointMatrix(file_path,opt);
		j1_range = 0:size(joint_matrix,1)-1;
		fr_j_range = -(size(joint_matrix,2)-1)/2:(size(joint_matrix,2)-1)/2;
		imagesc(joint_matrix);
		drawnow;
		% skip beginning and extension
		file_random_number = file_name(32:end-4);
		export_name = ...
			 [subdirectory ...
			 file_random_number ...
			 '_Q' int2str(opt.nFilters_per_octave) ...
			 '_Qf' int2str(opt.nFreq_filters_per_octave) ...
			 '_inv' int2str(opt.frequency_transposition_invariance) ...
			 '_jtwo' int2str(opt.j2) ...
			 ];
		print('-dpng',[export_name '.png']);
		save([export_name '.txt'],'joint_matrix','-ascii');
	end
end
