close all;clear all;clc

rt = linspace(0.2,0.8,40);  % Uniformly generating the 
x = linspace(4.5,5.5,40);   % Uniformaly initializing     
y = linspace(3.5,4.5,40);
z = linspace(5.5,6.5,40);
for roomno = 1:40
%File for generating data based on Room parameters
c = 340;                    % Sound velocity (m/s)
fs = 16000;                 % Sampling Frequency (Hz)
r = [2 1.5 2];              % Receiver position [x y z] (m)
s = [2 3.5 2];              % Source position [x y z] (m)
L = [x(roomno) y(roomno) z(roomno)];  %Room dimensions [x y z] (m)
beta  = rt(roomno);         % Reverberation time (s)
n = 2500;                   % Number of samples
l = 1;
%Generating the RIR
h = rir_generator(c, fs, r, s, L, beta, n);
h = transpose(h);
index = 1;
for i = 1:30
%Reading the audio file
index = int8(1 + 120*rand());
if index < 10
    filename = sprintf('data/arctic_a000%d.wav',index);
elseif index < 100
    filename = sprintf('data/arctic_a00%d.wav',index);
else 
    filename = sprintf('data/arctic_a0%d.wav',index);
end
[speech,fs] = audioread(filename);
l = length(speech);
speech = speech(100:48100);
%Calculating the reverberant speech
reverberant_speech = fconv(speech,h);
%subplot(3,1,3);plot(reverberant_speech);
trainData(:,roomno,i) = reverberant_speech;
%audiowrite(sprintf('genData/Room_%d_rec_%d.wav',roomno,i),reverberant_speech,fs);
fprintf('Processed %d %d\n',roomno,i);
end
end
save trainData.mat trainData