%% Apply Specified Sequential Augmentations
% Read in an audio signal and listen to it.

[audioIn,fs] = audioread("Counting-16-44p1-mono-15secs.wav");
sound(audioIn,fs)

% Create an audioDataAugmenter object that applies time stretching, pitch shifting, and noise corruption in cascade. Specify the time stretch speedup factors as 0.9, 1.1, and 1.2. Specify the pitch shifting in semitones as -2, -1, 1, and 2. Specify the noise corruption SNR as 10 dB and 15 dB.

augmenter = audioDataAugmenter( ...
    "AugmentationMode","sequential", ...
    "AugmentationParameterSource","specify", ...
    "SpeedupFactor",[0.9,1.1,1.2], ...
    "ApplyTimeStretch",true, ...
    "ApplyPitchShift",true, ...
    "SemitoneShift",[-2,-1,1,2], ...
    "SNR",[10,15], ...
    "ApplyVolumeControl",false, ...
    "ApplyTimeShift",false)

%
% Call augment on the audio to create 24 augmentations. The augmentations represent every combination of the specified augmentation parameters (3\times 4\times 2=24).

data = augment(augmenter,audioIn,fs)

%
% You can check the parameter configuration of each augmentation using the AugmentationInfo table variable.

augmentationToInspect = 1;
data.AugmentationInfo(augmentationToInspect)

%
% Listen to the augmentation you are inspecting. Plot the time-domain representation of the original and augmented signals.

augmentation = data.Audio{augmentationToInspect};
sound(augmentation,fs)

t = (0:(numel(audioIn)-1))/fs;
taug = (0:(numel(augmentation)-1))/fs;
plot(t,audioIn,taug,augmentation)
legend("Original Audio","Augmented Audio")
ylabel("Amplitude")
xlabel("Time (s)")

% Copyright 2019 The MathWorks, Inc.