function [matOut,numFrames]=createMat(x,frameSize,hopSize)

% create a matrix of frames of input x
%
% Input:
%   - x: 1 or 2 column vector (audio data)
%   - frameSize: size of frames
%   - hopSize: number of samples overlap
%
% Output:
%   - matOut: matrix of frames, either (frameSize x numFrames) for 1
%   channel or (framSize x 2 x numFrames) for stereo
%   - numFrames: number of frames in matOut
%
% Developer:  - Alice Clifford (alice.clifford@eecs.qmul.ac.uk)

sizeX=size(x);

if sizeX(1)==1 || sizeX(1)==2
    x=x'; %make columns
end

sizeX=size(x);

if sizeX(2)==1
    fileType='mono';
elseif sizeX(2)==2
    fileType='stereo';
else
    error('Input is neither mono or stereo')
end


numFrames=(floor(length(x)/hopSize));

for n=1:numFrames
    
    xStart=(n-1)*(hopSize)+1;
    xEnd=(n-1)*(hopSize)+frameSize;
    
    %Break if frame index goes over length of x
    if(xEnd>length(x))
        break
    end
    
    
    if strcmp(fileType,'stereo')
        xframe=x(xStart:xEnd,:);
        matOut(:,:,n)=xframe;
        
    elseif strcmp(fileType,'mono')
        xframe=x(xStart:xEnd);
        matOut(:,n)=xframe;
    else
        error('File type unknown')
    end
 
end

sMat=size(matOut);

if strcmp(fileType,'stereo')
    
    numFrames=sMat(3);
    
elseif strcmp(fileType,'mono')
    
    numFrames=sMat(2);
end