clear
close all
addpath(genpath('Data'));
addpath(genpath('Functions'));
addpath(genpath('Objects'));

input = 'measurement';
fName = 'test_pw.dat';             % file name

fs = 48000;
blockSize = 1024;

N = 3;
rmic = 0.1;
micArray = spherical_design('File','firthenmike.dat',rmic);

outputDevice = audioDeviceWriter;
set(outputDevice,'SampleRate',fs);
set(outputDevice,'BufferSize',blockSize);

numChannels = 24;
inputIndices = 1:numChannels;
mcdmex('open', '10.0.0.4', inputIndices-1, 5*fs,128);
mcdmex('start');

n = 0;
try
    while true
        data = mcdmex('read', blockSize)';
        status = mcdmex('status');
        disp(status);

        outputDevice(mean(data,2));
    end
catch E
    disp(E.message)
end

release(outputDevice);
mcdmex('stop');
mcdmex('close');