main content

time-凯发k8网页登录

time-stretch audio

since r2019b

description

example

audioout = stretchaudio(audioin,alpha) applies time scale modification (tsm) on the input audio by the tsm factor alpha.

example

audioout = stretchaudio(audioin,alpha,name,value) specifies options using one or more name,value pair arguments.

examples

read in an audio signal. listen to the audio signal and plot it over time.

[audioin,fs] = audioread("counting-16-44p1-mono-15secs.wav");
t = (0:size(audioin,1)-1)/fs;
plot(t,audioin)
xlabel('time (s)')
ylabel('amplitude')
title('original signal')
axis tight
grid on

figure contains an axes object. the axes object with title original signal, xlabel time (s), ylabel amplitude contains an object of type line.

sound(audioin,fs)

use stretchaudio to apply a 1.5 speedup factor. listen to the modified audio signal and plot it over time. the sample rate remains the same, but the duration of the signal has decreased.

audioout = stretchaudio(audioin,1.5);
t = (0:size(audioout,1)-1)/fs;
plot(t,audioout)
xlabel('time (s)')
ylabel('amplitude')
title('modified signal, speedup factor = 1.5')
axis tight
grid on

figure contains an axes object. the axes object with title modified signal, speedup factor = 1.5, xlabel time (s), ylabel amplitude contains an object of type line.

sound(audioout,fs)

slow down the original audio signal by a 0.75 factor. listen to the modified audio signal and plot it over time. the sample rate remains the same as the original audio, but the duration of the signal has increased.

audioout = stretchaudio(audioin,0.75);
t = (0:size(audioout,1)-1)/fs;
plot(t,audioout)
xlabel('time (s)')
ylabel('amplitude')
title('modified signal, speedup factor = 0.75')
axis tight
grid on

figure contains an axes object. the axes object with title modified signal, speedup factor = 0.75, xlabel time (s), ylabel amplitude contains an object of type line.

sound(audioout,fs)

stretchaudio supports tsm on frequency-domain audio when using the default vocoder method. applying tsm to frequency-domain audio enables you to reuse your stft computation for multiple tsm factors.

read in an audio signal. listen to the audio signal and plot it over time.

[audioin,fs] = audioread('femalespeech-16-8-mono-3secs.wav');
sound(audioin,fs)
t = (0:size(audioin,1)-1)/fs;
plot(t,audioin)
xlabel('time (s)')
ylabel('amplitude')
title('original signal')
axis tight
grid on

figure contains an axes object. the axes object with title original signal, xlabel time (s), ylabel amplitude contains an object of type line.

convert the audio signal to the frequency domain.

win = sqrt(hann(256,'periodic'));
ovrlp = 192;
s = stft(audioin,'window',win,'overlaplength',ovrlp,'centered',false);

speed up the audio signal by a factor of 1.4. specify the window and overlap length used to create the frequency-domain representation.

alpha = 1.4;
audioout = stretchaudio(s,alpha,'window',win,'overlaplength',ovrlp);
sound(audioout,fs)
t = (0:size(audioout,1)-1)/fs;
plot(t,audioout)
xlabel('time (s)')
ylabel('amplitude')
title('modified signal, tsm factor = 1.4')
axis tight
grid on

figure contains an axes object. the axes object with title modified signal, tsm factor = 1.4, xlabel time (s), ylabel amplitude contains an object of type line.

slow down the audio signal by a factor of 0.8. specify the window and overlap length used to create the frequency-domain representation.

alpha = 0.8;
audioout = stretchaudio(s,alpha,'window',win,'overlaplength',ovrlp);
sound(audioout,fs)
t = (0:size(audioout,1)-1)/fs;
plot(t,audioout)
xlabel('time (s)')
ylabel('amplitude')
title('modified signal, tsm factor = 0.8')
axis tight
grid on

figure contains an axes object. the axes object with title modified signal, tsm factor = 0.8, xlabel time (s), ylabel amplitude contains an object of type line.

the default tsm method (vocoder) enables you to additionally apply phase-locking to increase the fidelity to the original audio.

read in an audio signal. listen to the audio signal and plot it over time.

[audioin,fs] = audioread("speechdft-16-8-mono-5secs.wav");
sound(audioin,fs)
t = (0:size(audioin,1)-1)/fs;
plot(t,audioin)
xlabel('time (s)')
ylabel('amplitude')
title('original signal')
axis tight
grid on

phase-locking adds a nontrivial computational load to tsm and is not always required. by default, phase-locking is disabled. apply a speedup factor of 1.8 to the input audio signal. listen to the audio signal and plot it over time.

alpha = 1.8;
tic
audioout = stretchaudio(audioin,alpha);
processingtimewithoutphaselocking = toc
processingtimewithoutphaselocking = 0.0798
sound(audioout,fs)
t = (0:size(audioout,1)-1)/fs;
plot(t,audioout)
xlabel('time (s)')
ylabel('amplitude')
title('modified signal, alpha = 1.8, lockphase = false')
axis tight
grid on

apply the same 1.8 speedup factor to the input audio signal, this time enabling phase-locking. listen to the audio signal and plot it over time.

tic
audioout = stretchaudio(audioin,alpha,"lockphase",true);
processingtimewithphaselocking = toc
processingtimewithphaselocking = 0.1154
sound(audioout,fs)
t = (0:size(audioout,1)-1)/fs;
plot(t,audioout)
xlabel('time (s)')
ylabel('amplitude')
title('modified signal, alpha = 1.8, lockphase = true')
axis tight
grid on

the waveform similarity overlap-add (wsola) tsm method enables you to specify the maximum number of samples to search for the best signal alignment. by default, wsola delta is the number of samples in the analysis window minus the number of samples overlapped between adjacent analysis windows. increasing the wsola delta increases the computational load but might also increase fidelity.

read in an audio signal. listen to the first 10 seconds of the audio signal.

[audioin,fs] = audioread('rockguitar-16-96-stereo-72secs.flac');
sound(audioin(1:10*fs,:),fs)

apply a tsm factor of 0.75 to the input audio signal using the wsola method. listen to the first 10 seconds of the resulting audio signal.

alpha = 0.75;
tic
audioout = stretchaudio(audioin,alpha,"method","wsola");
processingtimewithdefaultwsoladelta = toc
processingtimewithdefaultwsoladelta = 19.4403
sound(audioout(1:10*fs,:),fs)

apply a tsm factor of 0.75 to the input audio signal, this time increasing the wsola delta to 1024. listen to the first 10 seconds of the resulting audio signal.

tic
audioout = stretchaudio(audioin,alpha,"method","wsola","wsoladelta",1024);
processingtimewithincreasedwsoladelta = toc
processingtimewithincreasedwsoladelta = 25.5306
sound(audioout(1:10*fs,:),fs)

input arguments

input signal, specified as a column vector, matrix, or 3-d array. how the function interprets audioin depends on the complexity of audioin and the value of method:

  • if audioin is real, audioin is interpreted as a time-domain signal. in this case, audioin must be a column vector or matrix. columns are interpreted as individual channels.

    this syntax applies when method is set to 'vocoder' or 'wsola'.

  • if audioin is complex, audioin is interpreted as a frequency-domain signal. in this case, audioin must be an l-by-m-by-n array, where l is the fft length, m is the number of individual spectra, and n is the number of channels.

    this syntax only applies when method is set to 'vocoder'.

data types: single | double
complex number support: yes

tsm factor, specified as a positive scalar.

data types: single | double

name-value arguments

specify optional pairs of arguments as name1=value1,...,namen=valuen, where name is the argument name and value is the corresponding value. name-value arguments must appear after other arguments, but the order of the pairs does not matter.

before r2021a, use commas to separate each name and value, and enclose name in quotes.

example: 'window',kbdwin(512)

method used to time-scale audio, specified as the comma-separated pair consisting of 'method' and 'vocoder' or 'wsola'. set 'method' to 'vocoder' to use the phase vocoder method. set 'method' to 'wsola' to use the wsola method.

if 'method' is set to 'vocoder', audioin can be real or complex. if 'method' is set to 'wsola', audioin must be real.

data types: single | double

window applied in the time domain, specified as the comma-separated pair consisting of 'window' and a real vector. the number of elements in the vector must be in the range [1, size(audioin,1)]. the number of elements in the vector must also be greater than overlaplength.

note

if using stretchaudio with frequency-domain input, you must specify window as the same window used to transform audioin to the frequency domain.

data types: single | double

number of samples overlapped between adjacent windows, specified as the comma-separated pair consisting of 'overlaplength' and an integer in the range [0, numel(window)).

note

if using stretchaudio with frequency-domain input, you must specify overlaplength as the same overlap length used to transform audioin to a time-frequency representation.

data types: single | double

apply identity phase-locking, specified as the comma-separated pair consisting of 'lockphase' and false or true.

dependencies

to enable this name-value pair argument, set method to 'vocoder'.

data types: logical

maximum number of samples used to search for the best signal alignment, specified as the comma-separated pair consisting of 'wsoladelta' and a nonnegative scalar.

dependencies

to enable this name-value pair argument, set method to 'wsola'.

data types: single | double

output arguments

time-scale modified audio, returned as a column vector or matrix of independent channels.

algorithms

phase vocoder

the phase vocoder algorithm is a frequency-domain approach to tsm [1][2]. the basic steps of the phase vocoder algorithm are:

  1. the algorithm windows a time-domain signal at interval η, where η = numel(window) - overlaplength. the windows are then converted to the frequency domain.

  2. to preserve horizontal (across time) phase coherence, the algorithm treats each bin as an independent sinusoid whose phase is computed by accumulating the estimates of its instantaneous frequency.

  3. to preserve vertical (across an individual spectrum) phase coherence, the algorithm locks the phase advance of groups of bins to the phase advance of local peaks. this step only applies if lockphase is set to true.

  4. the algorithm returns the modified spectrogram to the time domain, with windows spaced at intervals of δ, where δ ≈ η/α. α is the speedup factor specified by the alpha input argument.

wsola

the wsola algorithm is a time-domain approach to tsm [1][2]. wsola is an extension of the overlap and add (ola) algorithm. in the ola algorithm, a time-domain signal is windowed at interval η, where η = numel(window) - overlaplength. to construct the time-scale modified output audio, the windows are spaced at interval δ, where δ ≈ η/α. α is the tsm factor specified by the alpha input argument.

the ola algorithm does a good job of recreating the magnitude spectra but can introduce phase jumps between windows. the wsola algorithm attempts to smooth the phase jumps by searching wsoladelta samples around the η interval for a window that minimizes phase jumps. the algorithm searches for the best window iteratively, so that each successive window is chosen relative to the previously selected window.

if wsoladelta is set to 0, then the algorithm reduces to ola.

references

[1] driedger, johnathan, and meinard müller. "a review of time-scale modification of music signals." applied sciences. vol. 6, issue 2, 2016.

[2] driedger, johnathan. "time-scale modification algorithms for music audio signals", master's thesis, saarland university, saarbrücken, germany, 2011.

extended capabilities

c/c code generation
generate c and c code using matlab® coder™.

version history

introduced in r2019b

see also

| | |

topics

    网站地图