time-凯发k8网页登录
time-stretch audio
since r2019b
description
examples
apply tsm
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
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
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
sound(audioout,fs)
apply tsm to frequency-domain audio
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
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
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
increase fidelity using phase-locking
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
increase fidelity using wsola delta
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
audioin
— input signal
column vector | matrix | 3-d array
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
alpha
— tsm factor
positive scalar
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
— method used to time-scale audio
'vocoder'
(default) | 'wsola'
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
— window applied in time domain
sqrt(hann(1024,'periodic'))
(default) | real vector
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(
]. the number of elements in
the vector must also be greater than audioin
,1)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
overlaplength
— number of samples overlapped between adjacent windows
round(0.75*numel(window
))
(default) | scalar in the range [0
numel(window
)
)
window
))window
)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
lockphase
— apply identity phase-locking
false
(default) | true
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
wsoladelta
— maximum samples used to search for best signal alignment
numel(window
)-overlaplength
(default) | nonnegative scalar
window
)-overlaplength
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
audioout
— time-scale modified audio
column vector | matrix
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:
the algorithm windows a time-domain signal at interval η, where
η = numel(
. the windows are then converted to the frequency domain.window
) -overlaplength
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.
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 totrue
.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(
. to construct the time-scale modified
output audio, the windows are spaced at interval δ, where δ ≈ η/α. α is the tsm factor
specified by the window
) -
overlaplength
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™.
gpu arrays
accelerate code by running on a graphics processing unit (gpu) using parallel computing toolbox™.
usage notes and limitations:
method
must be set to'vocoder'
.lockphase
must be set tofalse
.using
gpuarray
(parallel computing toolbox) input withstretchaudio
is only recommended for a gpu with compute capability 7.0 ("volta") or above. other hardware might not offer any performance advantage. to check your gpu compute capability, seecomputecompability
in the output from thegpudevice
(parallel computing toolbox) function. for more information, see gpu computing requirements (parallel computing toolbox).
for an overview of gpu usage in matlab®, see run matlab functions on a gpu (parallel computing toolbox).
version history
introduced in r2019b
打开示例
您曾对此示例进行过修改。是否要打开带有您的编辑的示例?
matlab 命令
您点击的链接对应于以下 matlab 命令:
请在 matlab 命令行窗口中直接输入以执行命令。web 浏览器不支持 matlab 命令。
select a web site
choose a web site to get translated content where available and see local events and offers. based on your location, we recommend that you select: .
you can also select a web site from the following list:
how to get best site performance
select the china site (in chinese or english) for best site performance. other mathworks country sites are not optimized for visits from your location.
americas
- (español)
- (english)
- (english)
europe
- (english)
- (english)
- (deutsch)
- (español)
- (english)
- (français)
- (english)
- (italiano)
- (english)
- (english)
- (english)
- (deutsch)
- (english)
- (english)
- switzerland
- (english)
asia pacific
- (english)
- (english)
- (english)
- 中国
- (日本語)
- (한국어)