当前位置:网站首页>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); %播放原信号音频边栏推荐
- Let small program development into ` tailwind jit ` era
- Mysql 预准备语句详解(prepare、execute、deallocate)
- A.1#【内存管理】——1.1.3 page: struct page
- 自监督论文阅读笔记 Ship Detection in Sentinel 2 Multi-Spectral Images with Self-Supervised Learning
- 动漫:海贼王女
- Qlik Sense 临时处理表数据详解(Resident)
- Makefile自动推导的简单例程
- Qlik Sense 字符串截取和拼接详解(Left、Right、&)
- 该描述怎么写成SQL语句
- 代码没写完,哪里有脸睡觉!17 张程序员壁纸推荐
猜你喜欢

自监督论文阅读笔记 S3Net:Self-supervised Self-ensembling Network for Semi-supervised RGB-D Salient Object Det

IPC 通信 - IPC

【HQL】(二) 查询使用正则表达式做列选择

【第一周】深度学习和pytorch基础

自监督论文阅读笔记 Self-supervised Learning in Remote Sensing: A Review

MySql 怎么查出符合条件的最新的数据行?

VCC(电源)和 GND(地)之间电容的作用

自我监督学习和BERT模型

Router-view
深度学习理论课程第八、九、十章总结
随机推荐
Qlik Sense 赋值详解(Set、Let)
Let small program development into ` tailwind jit ` era
自监督论文阅读笔记 TASK-RELATED SELF-SUPERVISED LEARNING FOR REMOTE SENSING IMAGE CHANGE DETECTION
A.1#【内存管理】——1.1.4 node: 初始化
2021-03-22
二阶段提问总结
ASP.NET MVC3的伪静态实现
Dynamic adjustment subject web system?Look at this one is enough
中国人力资源服务行业投资建议与前景战略规划研究报告2022~2028年
opencv透视变化
关于梯度下降法的一些优化方法
中国磷化铟晶圆行业发展前景与投资规划分析报告2022~2028年
Qlik Sense 字符串截取和拼接详解(Left、Right、&)
enum和enum class的区别
时间盲注脚本
自监督论文阅读笔记Efficient Self-supervised Vision Pretraining with Local Masked Reconstruction
Qlik Sense 聚合函数及范围详解(Sum、Count、All、ToTaL、{1})
布尔盲注需简化代码
解决Gradle Download缓慢的百种方法
Qemu 搭建Armv8 平台