%% Enumeration for Logical Properties Parameter Mapping
% The following class definition uses enumeration parameter mapping to define the relationship between a property and a parameter. You can use the plugin created from this class to block or pass through the audio signal by tuning the PassThrough parameter.
% classdef pluginWithLogicalEnumMapping < audioPlugin
%     properties
%         PassThrough = true;
%     end
%     properties (Constant)
%         PluginInterface = audioPluginInterface( ...
%             audioPluginParameter('PassThrough', ...
%             'Mapping', {'enum','Block signal','Pass through'}, ...
%             'Layout',[1,1], ...
%             'Style','vtoggle', ...
%             'DisplayNameLocation','none'), ...
%             audioPluginGridLayout);
%     end
%     methods
%         function out = process(plugin,in)
%             if plugin.PassThrough
%                 out = in;
%             else
%                 out = zeros(size(in));
%             end
%         end
%     end
% end
%
% To run the plugin, save the class definition to a local folder and then create an audio I/O stream loop.
%
% First, create objects to read from a file and write to your device.

fileReader = dsp.AudioFileReader('Engine-16-44p1-stereo-20sec.wav');
deviceWriter = audioDeviceWriter('SampleRate',fileReader.SampleRate);

%
% Create a plugin object and set the sample rate to the sample rate of the file.

passThrough = pluginWithLogicalEnumMapping;
setSampleRate(passThrough,fileReader.SampleRate)

%
% Open a parameterTuner so that you can toggle the logical parameter of the plugin while stream processing.

parameterTuner(passThrough)

%
% While the file contains unread data:
% Read a frame from the file.
% Feed the frame through the plugin
% Write the processed audio to your device.
% While the audio stream runs, toggle the PassThrough parameter and listen to the effect.

while ~isDone(fileReader)
    audioIn = fileReader();
    
    audioOut = process(passThrough,audioIn);
    
    deviceWriter(audioOut);
    
    drawnow limitrate
end

%
% Copyright 2012 The MathWorks, Inc.