shift audio pitch -凯发k8网页登录
shift audio pitch
since r2019b
description
shifts the pitch of the audio input by the specified number of semitones,
audioout
= shiftpitch(audioin
,nsemitones
)nsemitones
.
specifies options using one or more audioout
= shiftpitch(audioin
,nsemitones
,name,value
)name,value
pair arguments.
examples
apply pitch-shifting to time-domain audio
read in an audio file and listen to it.
[audioin,fs] = audioread('counting-16-44p1-mono-15secs.wav');
sound(audioin,fs)
increase the pitch by 3 semitones and listen to the result.
nsemitones = 3; audioout = shiftpitch(audioin,nsemitones); sound(audioout,fs)
decrease the pitch of the original audio by 3 semitones and listen to the result.
nsemitones = -3; audioout = shiftpitch(audioin,nsemitones); sound(audioout,fs)
apply pitch-shifting to frequency-domain audio
read in an audio file and listen to it.
[audioin,fs] = audioread("speechdft-16-8-mono-5secs.wav");
sound(audioin,fs)
convert the audio signal to a time-frequency representation using . use a 512-point with 75% overlap.
win = kbdwin(512); overlaplength = 0.75*numel(win); s = stft(audioin, ... "window",win, ... "overlaplength",overlaplength, ... "centered",false);
increase the pitch by 8 semitones and listen to the result. specify the window and overlap length you used to compute the stft.
nsemitones = 8; lockphase = false; audioout = shiftpitch(s,nsemitones, ... "window",win, ... "overlaplength",overlaplength, ... "lockphase",lockphase); sound(audioout,fs)
decrease the pitch of the original audio by 8 semitones and listen to the result. specify the window and overlap length you used to compute the stft.
nsemitones = -8; lockphase = false; audioout = shiftpitch(s,nsemitones, ... "window",win, ... "overlaplength",overlaplength, ... "lockphase",lockphase); sound(audioout,fs)
increase fidelity using phase locking
read in an audio file and listen to it.
[audioin,fs] = audioread('femalespeech-16-8-mono-3secs.wav');
sound(audioin,fs)
increase the pitch by 6 semitones and listen to the result.
nsemitones = 6; lockphase = false; audioout = shiftpitch(audioin,nsemitones, ... 'lockphase',lockphase); sound(audioout,fs)
to increase fidelity, set lockphase
to true
. apply pitch shifting, and listen to the results.
lockphase = true; audioout = shiftpitch(audioin,nsemitones, ... 'lockphase',lockphase); sound(audioout,fs)
increase fidelity using formant preservation
read in the first 11.5 seconds of an audio file and listen to it.
[audioin,fs] = audioread('rainbow-16-8-mono-114secs.wav',[1,8e3*11.5]);
sound(audioin,fs)
increase the pitch by 4 semitones and apply phase locking. listen to the results. the resulting audio has a "chipmunk effect" that sounds unnatural.
nsemitones = 4; lockphase = true; audioout = shiftpitch(audioin,nsemitones, ... "lockphase",lockphase); sound(audioout,fs)
to increase fidelity, set preserveformants
to true
. use the default cepstral order of 30
. listen to the result.
cepstralorder = 30; audioout = shiftpitch(audioin,nsemitones, ... "lockphase",lockphase, ... "preserveformants",true, ... "cepstralorder",cepstralorder); sound(audioout,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
:
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.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.
data types: single
| double
complex number support: yes
nsemitones
— number of semitones to shift audio by
real scalar
number of semitones to shift the audio by, specified as a real scalar.
the range of nsemitones
depends on the window length
(numel(
) and the overlap length
(window
)overlaplength
):
-12*log2(numel(
≤ window
)-overlaplength
)nsemitones
≤
-12*log2((numel(
window
)-overlaplength
)/numel(window
))
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)
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 shiftpitch
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 shiftpitch
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
.
data types: logical
preserveformants
— preserve formants
false
(default) | true
preserves formants, specified as the comma-separated pair consisting of
'preserveformants'
and true
or
false
. formant preservation is attempted using spectral envelope
estimation with cepstral analysis.
data types: logical
cepstralorder
— cepstral order used for formant preservation
30 (default) | nonnegative integer
cepstral order used for formant preservation, specified as the comma-separated
pair consisting of 'cepstralorder'
and a nonnegative
integer.
dependencies
to enable this name-value pair argument, set
preserveformants
to true
.
data types: single
| double
output arguments
audioout
— pitch-shifted audio
column vector | matrix
pitch-shifted audio, returned as a column vector or matrix of independent channels.
algorithms
to apply pitch shifting, shiftpitch
modifies the time-scale of audio
using a phase vocoder and then resamples the modified audio. the time scale modification
algorithm is based on [1] and [2] and is implemented as in
stretchaudio
.
after time-scale modification, shiftpitch
performs sample rate
conversion using an interpolation factor equal to the analysis hop length and a decimation
factor equal to the synthesis hop length. the interpolation and decimation factors of the
resampling stage are selected as follows: the analysis hop length is determined as
analysishoplength =
numel(
. the
window
)-overlaplength
shiftpitch
function assumes that there are 12 semitones in an octave,
so the speedup factor used to stretch the audio is speedupfactor =
2^(-
. the speedup factor and analysis hop
length determine the synthesis hop length for time-scale modification as
nsemitones
/12)synthesishoplength = round((1/speedupfactor)*analysishoplength)
.
the achievable pitch shift is determined by the window length
(numel(
) and
window
)overlaplength
. to see the relationship, note that the equation for
speedup factor can be rewritten as:
, and the equation for synthesis hop length can be
rewritten as nsemitones
=
-12*log2(speedupfactor)speedupfactor = analysishoplengh/synthesishoplength
. using
simple substitution, nsemitones =
-12*log2(analysishoplength/synthesishoplength)
. the practical range of a synthesis
hop length is [1, numel(
]. the range of
achievable pitch shifts is:window
)
max number of semitones lowered:
-12*log2(numel(
window
)-overlaplength
)max number of semitones raised:
-12*log2((numel(
window
)-overlaplength
)/numel(window
))
formant preservation
pitch shifting can alter the spectral envelope of the pitch-shifted signal. to diminish
this effect, you can set preserveformants
to true
.
if preserveformants
is set to true
, the algorithm
attempts to estimate the spectral envelope using an iterative procedure in the cepstral
domain, as described in [3] and [4]. for both the original
spectrum, x, and the pitch-shifted spectrum, y, the
algorithm estimates the spectral envelope as follows.
for the first iteration, envxa is set to x. then, the algorithm repeats these two steps in a loop:
lowpass filters the cepstral representation of envxa to get a new estimate, envxb. the
cepstralorder
parameter controls the quefrency bandwidth.to update the current best fit, the algorithm takes the element-by-element maximum of the current spectral envelope estimate and the previous spectral envelope estimate:
the loop ends if either a maximum number of iterations
(100
) is reached, or if all bins of the estimated log envelope are
within a given tolerance of the original log spectrum. the tolerance is set to
log(10^(1/20))
.
finally, the algorithm scales the spectrum of the pitch-shifted audio by the ratio of estimated envelopes, element-wise:
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.
[3] axel roebel, and xavier rodet. "efficient spectral envelope estimation and its application to pitch shifting and envelope preservation." international conference on digital audio effects, pp. 30–35. madrid, spain, september 2005. hal-01161334
[4] s. imai, and y. abe. "spectral envelope extraction by improved cepstral method." electron. and commun. in japan. vol. 62-a, issue 4, 1997, pp. 10–17.
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:
lockphase
must be set tofalse
.using
gpuarray
(parallel computing toolbox) input withshiftpitch
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
see also
打开示例
您曾对此示例进行过修改。是否要打开带有您的编辑的示例?
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)
- 中国
- (日本語)
- (한국어)