pathStr = mfilename('fullpath');

ind = find(pathStr == filesep);
pathStr = pathStr(1:ind(end)-1);

GSYS = load_awd(fullfile(pathStr, 'AutoAmpExample.awd'));

SYS = GSYS.SYS;

% Configure for non-real-time build
SYS.targetSpecificInfo.RT = 0;

% Build the system
SYS = build(SYS);

% Now iterative over the test data

blockSize = SYS.inputPin{1}.type.blockSize;
numInChannels = SYS.inputPin{1}.type.numChannels;

NUM_BLOCKS = 16;

OUT = [];
for i=1:NUM_BLOCKS
    % Generate random input data
    in = randn(blockSize, numInChannels);
    
    [SYS, out] = process(SYS, {in}, 1);
    out = out{1};
    
    OUT = [OUT; out];
    
    % Do the processing in Matlab.  The data is taken from
    % ExportSink and is written to ImportSource
    
    D = SYS.ExportSink.value;
    
    % Scale the data
    D = D * 2;
    
    % Send it back
    SYS.ImportSource.value = D;
    
    fprintf(1, 'Processed block %d\n', i);
end
