soundtouch change rate matlab implementation
soundtouch implement of changing rate in a way same with resample(SRC).
When rate < 1, it need interpolate sample. and delete samples when rate > 1.
After interpolation, there may be introduce high frequency. To avoid aliase, we usally apply a low pass filter on interpolated signal.
For the case of deleting samples, some signal may contains high frequecy, the difference between sample may be very sharp. Therefore, we use low pass filter before deleting samples.
When design fir low pass filter, we usaully use "w" (rad/s) as the main parameter instead freqence "f".
The relationship of "w" and "f" as following:
w = 2*pi * f/ fs;
For cutoff frequency, wc = 2*pi * fc / fs = 2 * pi * fc/(2*fn) = pi * fc / fn, where fc is cutoff frequency, fn is Nywuist frequency.
For fc = = fn, wc = pi;
We use cubic method to interplate sample, the principle of cubic interpolation refer to https://www.paulinternet.nl/?page=bicubic
%calc low pass filter coefficient. The low pass filter based on sinc function with hamming window.
function coeff = calCoeffs(cutoffFreq, len)
coeff = zeros(len ,1);
wc = 2 * pi * cutoffFreq;
tempCoeff = 2 * pi / len;
sum = 0;
for i = 0 : 1 : len -1
cntTemp = (i - len/2);
temp = cntTemp * wc;
% sinc function
if temp ~=0
h = sin(temp) / temp;
else
h = 1;
end
%hamming window
w = 0.54 + 0.46 * cos(tempCoeff * cntTemp);
coeff(i+1) = w * h;
sum = sum + coeff(i+1);
end
coeff = coeff / sum;
end
function output = firfilter(input, coeff)
inputLen = length(input(:, 1));
filterLen = length(coeff(:, 1));
output = zeros(inputLen ,1 );
outputLen = inputLen - filterLen;
for i = 1: 1: outputLen
inpos = i;
sum = 0;
for j = 1:1:filterLen
sum = sum + input(inpos ,1) * coeff(j, 1);
inpos = inpos + 1;
end
output(i, 1) = sum;
end
end
function output = cubicInterpolation(input, rate)
inputLen = length(input(:,1));
outputLen = floor(inputLen / rate);
output = zeros(outputLen ,1);
inputIdx = 1;
fract = 0;
outputIdx = 1;
while inputIdx < inputLen - 4
x1 = fract;
x2 = x1 * x1;
x3 = x1 * x2;
p0 = input(inputIdx , 1);
p1 = input(inputIdx + 1 , 1);
p2 = input(inputIdx + 2, 1);
p3 = input(inputIdx + 3, 1);
output(outputIdx ,1) = (-0.5*p0 + 1.5*p1 -1.5 *p2 + 0.5*p3) * x3 +(p0 - 2.5*p1 + 2*p2 -0.5*p3) *x2 + (-0.5*p0 + 0.5*p2) * x1 + p1;
outputIdx = outputIdx + 1;
fract = fract + rate;
whole = floor(fract);
fract = fract - whole;
inputIdx = inputIdx + whole;
end
end
function output = linearInterpolation(input, rate)
inputLen = length(input(:,1));
outputLen = floor(inputLen / rate);
output = zeros(outputLen ,1);
inputIdx = 1;
fract = 0;
outputIdx = 1;
while inputIdx < inputLen - 4
p0 = input(inputIdx , 1);
p1 = input(inputIdx + 1 , 1);
output(outputIdx ,1) = (1-fract) * po + fract * p1;
outputIdx = outputIdx + 1;
fract = fract + rate;
whole = floor(fract);
fract = fract - whole;
inputIdx = inputIdx + whole;
end
end
function output = changeRate(input, rate, interpMethod)
inputLen = length(input(:, 1));
outputLen = floor(inputLen / rate);
output = zeros(outputLen, 1);
if rate > 1
cutoffFreq = 0.5 / rate;
else
cutoffFreq = 0.5 * rate;
end
filterLen = 64;
coeff = calCoeffs(cutoffFreq, filterLen);
if rate < 1
%slow down, need interpolation first;
if strcmp(interMethod, 'cubic')
output = cubicInterpolation(input, rate);
else
output = linearInterpolation(input, rate);
end
output = firfilter(output, coeff);
else
%fast, need filter out the high freqency, then delete samples
output = firfilter(input, coeff);
if strcmp(interMethod, 'cubic')
output = cubicInterpolation(output, rate);
else
output = linearInterpolation(output, rate);
end
end
end
main.m:
clc;
clear all;
[input fs] = wavread('input.wav');
%if do SRC, rate = inputfs / outputfs;
rate = 0.5;
output = changeRate(input, rate, 'cubic');
wavwrite(output, fs, 'output.wav);
soundtouch change rate matlab implementation的更多相关文章
- soundtouch change pitch matlab implementation
function output = changePitch(input, pitchInSemitones) % one octave is 12 semitones octave = pitchIn ...
- soundtouch 变速算法matlab实现
soundtouch变速主要采用WSOLA算法来进行变速. http://www.surina.net/soundtouch/ https://blog.csdn.net/suhetao/articl ...
- Viola–Jones object detection framework--Rapid Object Detection using a Boosted Cascade of Simple Features中文翻译 及 matlab实现(见文末链接)
ACCEPTED CONFERENCE ON COMPUTER VISION AND PATTERN RECOGNITION 2001 Rapid Object Detection using a B ...
- MATLAB绘图
matlab绘制散点图 clc,clear x=[11.9,11.5,14.5,15.2,15.9,16.3,14.6,12.9,15.8,14.1]; y=[196.84,196.84,197.14 ...
- VS Code中Matlab插件安装设置
Install the extension in VS Code Open the command palette using Ctrl+Shift+P Type ext install Matlab ...
- Frequency-tuned Salient Region Detection MATLAB代码出错修改方法
论文:Frequency-tuned Salient Region Detection.CVPR.2009 MATLAB代码运行出错如下: Error using makecform>parse ...
- `GLIBCXX_3.4.15' not found when using mex file in matlab (linux)
from: http://www.360doc.com/content/14/0314/16/175261_360565922.shtml Invalid MEX-file '*/*/*.mexa64 ...
- {ICIP2014}{收录论文列表}
This article come from HEREARS-L1: Learning Tuesday 10:30–12:30; Oral Session; Room: Leonard de Vinc ...
- 计算机视觉code与软件
Research Code A rational methodology for lossy compression - REWIC is a software-based implementatio ...
随机推荐
- 并发编程之J.U.C的第一篇
并发编程之J.U.C AQS 原理 ReentrantLock 原理 1. 非公平锁实现原理 2)可重入原理 3. 可打断原理 5) 条件变量实现原理 3. 读写锁 3.1 ReentrantRead ...
- flutter常用插件(持续更新)
flutter插件官网地址:https://pub.dartlang.org/packages/ 1. image_picker 一个可以从图库选择图片,并可以用相机拍摄新照片的flutter插件 2 ...
- 数据库设计工具-powerdesigner
一.PowerDesigner导出SQL,注释为空时以name代替 操作步骤 1. 2. 3.将Value中的内容全部替换为如下 %:COLUMN% [%National%?national ]%DA ...
- Codeforces Round #578 (Div. 2) 二维差分 可做模板
题意: 在n*n的矩阵中,你可以选择一个k*k的子矩阵,然后将这个子矩阵中的所有B全部变为W,问你怎么选择这个子矩阵使得最终的矩阵中某一行全是W或者某一列全是W的个数最多 题解:考虑每一行和每一列,对 ...
- R 分析回归(一元回归)
x <- c(,,,,,,,,,) # build X(predictor) y <- c(,,,,,,,,,) # build Y(dependent variable) mode(x) ...
- python中的__dict__和dir()的区别
Python下一切皆对象,每个对象都有多个属性(attribute),Python对属性有一套统一的管理方案. __dict__与dir()的区别: dir()是一个函数,返回的是list: __di ...
- laravel框架用使用session 和cookie
1.介绍 cookie 位于用户的计算机上,用来维护用户计算机中的信息,直到用户删除.比如我们在网页上登录某个软件时输入用户名及密码时如果保存为cookie,则每次我们访问的时候就不需要登录网站了.我 ...
- Deep Clustering Algorithms
Deep Clustering Algorithms 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 本文研究路线:深度自编码器(Deep Autoen ...
- java中类的构造方法出错点
大家请看下面的这个代码 package ppt_test; public class test1 { public static void main(String args[]) { Foo obj1 ...
- centos8 apache+mysql+php
apache安装 dnf install httpd httpd-tools 开机启动 systemctl enable httpd 立即启动 systemctl start httpd 查看状态 s ...