当前位置:网站首页>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); %播放原信号音频
边栏推荐
- 自监督论文阅读笔记 Incremental-DETR:Incremental Few-Shot Object Detection via Self-Supervised Learning
- 自监督论文阅读笔记 SimCLRV2 Big Self-Supervised Models are Strong Semi-Supervised Learners
- Qemu 搭建Armv8 平台
- 卷积神经网络入门
- 001_旭日X3派初探:开箱测试
- 自监督论文阅读笔记Reading and Writing: Discriminative and Generative Modelingfor Self-Supervised Text Recogn
- 东南亚跨境电商
- 自监督论文阅读笔记 DenseCL:Dense Contrastive Learning for Self-Supervised Visual Pre-Training
- Kotlin 中的泛型介绍
- 中国人力资源服务行业投资建议与前景战略规划研究报告2022~2028年
猜你喜欢
嵌入式实验二注意点
代码没写完,哪里有脸睡觉!17 张程序员壁纸推荐
自监督论文阅读笔记FIAD net: a Fast SAR ship detection network based on feature integration attention and self
微信小程序 自定义tabBar
Qlik Sense 聚合函数及范围详解(Sum、Count、All、ToTaL、{1})
001_旭日X3派初探:开箱测试
MySql 怎么查出符合条件的最新的数据行?
自监督论文阅读笔记 Self-Supervised Visual Representation Learning with Semantic Grouping
电容器和电池有什么不同?
寄存器常见指令
随机推荐
虚拟地址空间布局
微信小程序 自定义tabBar
A.1#【内存管理】——1.1.2 zone: struct zone
神经网络之感知机
中国石油行业并购重组趋势与投资战略规划建议报告2022~2028年
Qlik Sense 聚合函数及范围详解(Sum、Count、All、ToTaL、{1})
PCB设计经验之模拟电路和数字电路区别为何那么大
自监督论文阅读笔记FIAD net: a Fast SAR ship detection network based on feature integration attention and self
自监督论文阅读笔记 SimCLRV2 Big Self-Supervised Models are Strong Semi-Supervised Learners
进程间通信IPC - 信号量
东南亚跨境电商
极光推送 能否缓存 消息
联邦学习摘录
cmdline -[command line,__fdt_pointer,initial_boot_params] boot_command_line 获取
Kettle Spoon 安装配置详解
VCC(电源)和 GND(地)之间电容的作用
自监督论文阅读笔记Reading and Writing: Discriminative and Generative Modelingfor Self-Supervised Text Recogn
C# 数组之回溯法
嵌入式实验二
double型数据转字符串后通过MCU串口发送