%% Perform Graphic Equalization
% Create objects to read from an audio file and write to your audio device. Use the sample rate of the reader as the sample rate of the writer.

frameLength = 512;
reader = dsp.AudioFileReader('RockDrums-48-stereo-11secs.mp3','SamplesPerFrame',frameLength);
player = audioDeviceWriter('SampleRate',reader.SampleRate);

%
% In an audio stream loop, read audio from a file and play the audio through your audio device.

while ~isDone(reader)
    x = reader();
    player(x);
end
release(reader)
release(player)

%
% Create a one-octave graphic equalizer implemented with a cascade structure. Use the sample rate of the reader as the sample rate of the equalizer.

equalizer = graphicEQ( ...
    'Bandwidth','1 octave', ...    
    'Structure','Cascade', ...
    'SampleRate',reader.SampleRate);

%
% Specify to increase the gain on low frequencies and then visualize the equalizer.

equalizer.Gains = [5,5,5,5,0,0,0,0,0,0];
visualize(equalizer)

%
%
% In an audio stream loop, read audio from a file, apply equalization, and then play the equalized audio through your audio device.

while ~isDone(reader)
    x = reader();
    y = equalizer(x);
    player(y);
end
release(reader)
release(player)

% Copyright 2012 The MathWorks, Inc.