当前位置:网站首页>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); %播放原信号音频
边栏推荐
- 设备树解析源码分析<devicetree>-1.基础结构
- HANA 常用数据类型详解
- ASP.NET MVC3的伪静态实现
- 自监督论文阅读笔记 Self-Supervised Deep Learning for Vehicle Detection in High-Resolution Satellite Imagery
- Oracle 分区索引详解(local、global)
- 卷积神经网络入门
- new / malloc / delete / free之间的区别
- 自监督论文阅读笔记 Self-Supervised Visual Representation Learning with Semantic Grouping
- 时间盲注脚本
- 2021-03-22
猜你喜欢
优雅的拦截TabLayout的点击事件
MMU 介绍-[TBL/page table work]
自监督论文阅读笔记Index Your Position: A Novel Self-Supervised Learning Method for Remote Sensing Images Sema
嵌入式实验四
Kettle Spoon 安装配置详解
MySql 怎么查出符合条件的最新的数据行?
采用Trench肖特基二极管,实现功率密度的显著提升
【IDEA】字体修改-护眼主题-文件注释头设置
进程间通信IPC - 信号量
自监督论文阅读笔记 TASK-RELATED SELF-SUPERVISED LEARNING FOR REMOTE SENSING IMAGE CHANGE DETECTION
随机推荐
布尔盲注需简化代码
Mysql 预准备语句详解(prepare、execute、deallocate)
A.1#【内存管理】——1.1.2 zone: struct zone
中国食品微生物检测行业深度监测及投资战略规划建议报告2022~2028年
【 command execution and middleware loopholes 】
建立平衡二叉树简单demo
自监督论文阅读笔记Reading and Writing: Discriminative and Generative Modelingfor Self-Supervised Text Recogn
嵌入式实验四
Oracle 分区索引详解(local、global)
中国生活服务O2O行业发展现状与市场规模预测报告2022~2028年
神经网络基础
自监督论文阅读笔记 Self-Supervised Visual Representation Learning with Semantic Grouping
【HQL】(二) 查询使用正则表达式做列选择
关于梯度下降法的一些优化方法
稳压二极管的工作原理及稳压二极管使用电路图
PCB设计经验之模拟电路和数字电路区别为何那么大
浮点型数据在内存中存储的表示
采用Trench肖特基二极管,实现功率密度的显著提升
自监督论文阅读笔记DisCo: Remedy Self-supervised Learning on Lightweight Models with Distilled Contrastive
002_旭日X3派初探:TogetherROS安装