diff AudioDegradationToolbox/degradationUnit_applyHarmonicDistortion.m @ 0:9d682f5e3927

put files here from the old repository
author matthiasm
date Thu, 08 Aug 2013 11:01:12 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/AudioDegradationToolbox/degradationUnit_applyHarmonicDistortion.m	Thu Aug 08 11:01:12 2013 +0100
@@ -0,0 +1,88 @@
+function [f_audio_out,timepositions_afterDegr] = degradationUnit_applyHarmonicDistortion(f_audio, samplingFreq, timepositions_beforeDegr, parameter)
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Name: degradation_applyHarmonicDistortion
+% Version: 1
+% Date: 2013-01-25
+% Programmer: Matthias Mauch
+%
+% Description:
+% - applies quadratic distortion to the audio
+% - f_audio_out is the distorted audio
+%
+% Input:
+%   f_audio      - audio signal \in [-1,1]^{NxC} with C being the number of
+%                  channels
+%   timepositions_beforeDegr - some degradations delay the input signal. If
+%                             some points in time are given via this
+%                             parameter, timepositions_afterDegr will
+%                             return the corresponding positions in the
+%                             output. Set to [] if unavailable. Set f_audio
+%                             and samplingFreq to [] to compute only
+%                             timepositions_afterDegr.
+%
+% Input (optional): parameter
+%   .nApplications = 3  - number of iterative applications. The higher the
+%                         stronger
+%   .normalizeOutputAudio = 1 - normalize audio
+%
+% Output:
+%   f_audio_out   - audio signal \in [-1,1]^{NxC} with C being the number
+%                   of channels
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Audio Degradation Toolbox
+%
+% Centre for Digital Music, Queen Mary University of London.
+% This file copyright 2013 Sebastian Ewert, Matthias Mauch and QMUL.
+%    
+% This program is free software; you can redistribute it and/or
+% modify it under the terms of the GNU General Public License as
+% published by the Free Software Foundation; either version 2 of the
+% License, or (at your option) any later version.  See the file
+% COPYING included with this distribution for more information.
+%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Check parameters
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+if nargin<4
+    parameter=[];
+end
+if nargin<3
+    timepositions_beforeDegr=[];
+end
+if nargin<2
+    error('Please specify input data');
+end
+
+if isfield(parameter,'nApplications')==0
+    parameter.nApplications = 3;
+end
+if isfield(parameter,'normalizeOutputAudio')==0
+    parameter.normalizeOutputAudio = 1;
+end
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% Main program
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+f_audio_out = [];
+if ~isempty(f_audio)
+    f_audio_out = f_audio;
+    for ii = 1:parameter.nApplications
+        f_audio_out = sin(f_audio_out * pi/2);
+    end
+    
+    if parameter.normalizeOutputAudio
+        f_audio_out = adthelper_normalizeAudio(f_audio_out, samplingFreq);
+    end
+    
+end
+
+% This degradation does not impose a delay
+timepositions_afterDegr = timepositions_beforeDegr;
+
+end