当前位置:网站首页>Phase Vocoder的补充完善,Matlab音频变速不变调、变调不变速
Phase Vocoder的补充完善,Matlab音频变速不变调、变调不变速
2022-08-03 05:24:00 【zdlwhereyougo】
之前有站内朋友介绍了国外的Phase Vocoder,Matlab音频变速不变调、变调不变速(Phase Vocoder)_cyz0612的博客-CSDN博客_matlab变调不变速代码参考这篇文章,我成功实现了变速不变调,我将其命名为speedShift函数,放在下面供后来的朋友交流学习。
function [outputVector] = speedShift(inputVector, windowSize, hopSize, t)
%% Parameters
% Window size
winSize = windowSize;
% Space between windows
hop = hopSize;
%t是函数的输入
step=12*log2(1/t);
% Pitch scaling factor
alpha = 2^(step/12);
% Intermediate constants
hopOut = round(alpha*hop);
% Hanning window for overlap-add
wn = hann(winSize*2+1);
wn = wn(2:2:end);
%% Source file
x = inputVector;
% Rotate if needed
if size(x,1) < size(x,2)
x = transpose(x);
end
x = [zeros(hop*3,1) ; x];
%% Initialization
% Create a frame matrix for the current input
[y,numberFramesInput] = createFrames(x,hop,winSize);
% Create a frame matrix to receive processed frames
numberFramesOutput = numberFramesInput;
outputy = zeros(numberFramesOutput,winSize);
% Initialize cumulative phase
phaseCumulative = 0;
% Initialize previous frame phase
previousPhase = 0;
for index=1:numberFramesInput
%% Analysis
% Get current frame to be processed
currentFrame = y(index,:);
% Window the frame
currentFrameWindowed = currentFrame .* wn' / sqrt(((winSize/hop)/2));
% Get the FFT
currentFrameWindowedFFT = fft(currentFrameWindowed);
% Get the magnitude
magFrame = abs(currentFrameWindowedFFT);
% Get the angle
phaseFrame = angle(currentFrameWindowedFFT);
%% Processing
% Get the phase difference
deltaPhi = phaseFrame - previousPhase;
previousPhase = phaseFrame;
% Remove the expected phase difference
deltaPhiPrime = deltaPhi - hop * 2*pi*(0:(winSize-1))/winSize;
% Map to -pi/pi range
deltaPhiPrimeMod = mod(deltaPhiPrime+pi, 2*pi) - pi;
% Get the true frequency
trueFreq = 2*pi*(0:(winSize-1))/winSize + deltaPhiPrimeMod/hop;
% Get the final phase
phaseCumulative = phaseCumulative + hopOut * trueFreq;
% Remove the 60 Hz noise. This is not done for now but could be
% achieved by setting some bins to zero.
%% Synthesis
% Get the magnitude
outputMag = magFrame;
% Produce output frame
outputFrame = real(ifft(outputMag .* exp(j*phaseCumulative)));
% Save frame that has been processed
outputy(index,:) = outputFrame .* wn' / sqrt(((winSize/hopOut)/2));
end
%% Finalize
% Return the result
outputVector =fusionFrames(outputy,hopOut);
return
代码下载:Guitar Pitch Shifter - Performances
使用方式非常简单,只需要将下载的三个m文件放到工作目录下面直接调用就行了,需要注意的就是新版的matlab在读取wav文件时,不能使用旧的函数,使用新的audioread函数,播放函数也需要更新为sound函数。而且调用pitchShift和speedShift函数的时候,如果wav信号是双声道的信号,应该先进行左右声道的平均,即将双声道转换成单声道再输入。
[x,Fs]=audioread('sample.wav');%读入wav音频文件
leftChannel = x(:,1);
rightChannel = x(:,2);
averageBoth = (leftChannel + rightChannel) / 2;%左右声道求平均
播放函数:
sound(x,Fs); %播放原信号音频
边栏推荐
猜你喜欢
神经网络之感知机
自监督论文阅读笔记FIAD net: a Fast SAR ship detection network based on feature integration attention and self
[frp intranet penetration]
【第一周】深度学习和pytorch基础
电子元器件的分类有哪些?
联邦学习摘录
ucos任务调度原理
自监督论文阅读笔记 Incremental-DETR:Incremental Few-Shot Object Detection via Self-Supervised Learning
神经网络基础
Let small program development into ` tailwind jit ` era
随机推荐
自监督论文阅读笔记Index Your Position: A Novel Self-Supervised Learning Method for Remote Sensing Images Sema
中国水环境治理行业投融资分析及“十四五”规划建议报告2022~2028年
B.1#【编程语言】—1 arm 汇编指令
Oracle 分区索引详解(local、global)
中国水煤浆行业“十四五”规划与运营模式分析报告2022~2028年
稳压二极管的工作原理及稳压二极管使用电路图
东南亚跨境电商
Qlik Sense 赋值详解(Set、Let)
中国食品微生物检测行业深度监测及投资战略规划建议报告2022~2028年
浮点型数据在内存中存储的表示
softmax和最大熵
[frp intranet penetration]
微信小程序 自定义tabBar
Gradle插件与代理服务器导致Sync Project失败的问题
cmdline -[command line,__fdt_pointer,initial_boot_params] boot_command_line 获取
设备树解析源码分析<devicetree>-1.基础结构
快速的将结构体各成员清零
Kettle 从资源库中载入新的转换出错(Invalid byte 1 of 1-byte UTF-8 sequence)
Kotlin 中的泛型介绍
优雅的拦截TabLayout的点击事件