forked from alexanderlerch/ACA-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToolBlockAudio.m
31 lines (26 loc) · 1.04 KB
/
ToolBlockAudio.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
%blocks audio signal into overlapping blocks
%>
%> @param x: audio signal (dimension length x 1)
%> @param iBlockLength: target block size
%> @param iHopLength: target hopsize
%> @param f_s: sample rate
%>
%> @retval x_b (dimension iNumOfBlocks x iBlockLength)
%> @retval t time stamps for blocks
% ======================================================================
function [x_b, t] = ToolBlockAudio(x, iBlockLength, iHopLength, f_s)
% 预分配块的数量
iNumBlocks = ceil((size(x, 1) - iBlockLength)/iHopLength) + 1;
% 每个块开始的时间戳向量
t = ((0:iNumBlocks-1) * iHopLength) / f_s;
% 添加零以确保最后一个块完整
iNumZerosToPad = iBlockLength + (iNumBlocks-1) * iHopLength - size(x, 1);
xPadded = [x; zeros(iNumZerosToPad, 1)];
% 预分配矩阵以保存所有块
x_b = zeros(iNumBlocks, iBlockLength);
% 使用填充信号填充矩阵
for n = 1:iNumBlocks
iStart = (n-1)*iHopLength + 1;
x_b(n,:) = xPadded(iStart:iStart+iBlockLength-1);
end
end