function [ datae , fse] = getdata(labels)
% reads in wave sound clips from the data folder and converts them to time 
% series matrix

data_folder = './data/';  % base location of wav files and configuration

% each wav file has a label that groups it and a number, so in the 
% data_folder, the files look like:
%   a1.wav a2.wav a3.wav .... c1.wav c2.wav
%
% IMPORTANT - wav files are all 10-second clips, single channel

% data array (gets pruned down eventually)
data = zeros(600000,50); 

% some stuff about the data
numsamples = 0;
minsize = 600000;

% for every label, read in the wav files available
for label = 1:size(labels)
    samplenum = 1;
    % make the filename
    filename = [data_folder labels(label) int2str(samplenum) '.wav'];
    
    % this loop continues while the file exists
    while (fopen(filename) ~= -1)        
        % we're in here, it must exist...
        [y, Fs, nbits] = wavread(filename);
        
        fprintf('file %s: sampling rate %d, %d bits, %d samples\n', filename, Fs, nbits, size(y,1));
                
        numsamples = numsamples + 1;
        
        data(1:size(y,1),numsamples) = y;
        
        if size(y,1) < minsize  % update seen minimum, we trim everything else to that size
            minsize = size(y,1);
        end
        
        % go to the next filename
        samplenum = samplenum + 1;
        filename = [data_folder labels(label) int2str(samplenum) '.wav'];
    end
    
end

% trim data down.  We lose some, but not much.
datae = data(1:minsize,1:numsamples);
fse = Fs;

return
