將5.1 ch的數據通過hrtf處理,而後downmix到2ch,使得2ch的數據有virtual surround的效果。input
function output = hrir_process(input)it
hrtf = load("E:\CIPIC_hrtf_database\standard_hrir_database\subject_21\hrir_final.mat");io
Ls = [1 9];function
L = [8 9];數據
R= [17 9];filter
Rs = [25 9];tab
C = [13 9]vi
%source from 5.1 to L chprocess
h_l_l = squeeze(hrtf.hrir_l(L(1), L(2), :));data
h_r_l = squeeze(hrtf.hrir_l(R(1), R(2), :));
h_ls_l = squeeze(hrtf.hrir_l(Ls(1), Ls(2), :));
h_rs_l = squeeze(hrtf.hrir_l(Rs(1), Rs(2), :));
h_c_l = squeeze(hrtf.hrir_l(C(1), C(2), :));
%source from 5.1 to R ch
h_l_r = squeeze(hrtf.hrir_r(L(1), L(2), :));
h_r_r = squeeze(hrtf.hrir_r(R(1), R(2), :));
h_ls_r = squeeze(hrtf.hrir_r(Ls(1), Ls(2), :));
h_rs_r = squeeze(hrtf.hrir_r(Rs(1), Rs(2), :));
h_c_r = squeeze(hrtf.hrir_r(C(1), C(2), :));
[input, fs] = wavread('input.wav');
h_l = zeros(length(h_l_l), 6);
h_l(:, 1) = h_l_l;
h_l(:, 2) = h_r_l;
h_l(:, 3) = h_c_l;
h_l(:, 5) = h_ls_l;
h_l(:, 6) = h_rs_l;
h_r = zeros(length(h_l_r), 6);
h_r(:, 1) = h_l_r;
h_r(:, 2) = h_r_r;
h_r(:, 3) = h_c_r;
h_r(:, 5) = h_ls_r;
h_r(:, 6) = h_rs_r;
hrir_out_l = zeros(length(input(:, 1), length(1, :));
hrir_out_r = zeros(length(input(:, 1), length(1, :));
for ch = 1:1:6
hrir_out_l(:, ch) = filter(h_l(:, ch), 1, input(:, ch));
hrir_out_r(:, ch) = filter(h_r(:, ch), 1, input(:, ch));
end
cmix = 0.707/2;
surmix = 1.0 / 2;
xsurmix = 0.5 /2;
%downmix to 2ch.
%output(:,1) = hrir_out_l(:, 1) + hrir_out_l(:, 3) * cmix - hrir_out_l(:, 5) * surmix - hrir_out_l(:, 6) * xsurmix ;
%output(:,2) = hrir_out_r(:, 2) + hrir_out_r(:, 3) * cmix +hrir_out_r(:, 6) * surmix + hrir_out_r(:, 5) * xsurmix;
%output(:,1) = hrir_out_l(:, 1) + hrir_out_l(:, 3) * cmix + hrir_out_l(:, 5) * surmix + hrir_out_l(:, 2) * xsurmix ;
%output(:,2) = hrir_out_r(:, 2) + hrir_out_r(:, 3) * cmix +hrir_out_r(:, 6) * surmix + hrir_out_r(:, 1) * xsurmix;
output(:,1) = hrir_out_l(:, 1) + hrir_out_l(:, 3) * cmix +hrir_out_l(:, 5) * surmix;
output(:,2) = hrir_out_r(:, 2) + hrir_out_r(:, 3) * cmix +hrir_out_r(:, 6) * surmix;
end
function [loro ltrt] = downmix(input)
cmix = 0.707/2;
surmix = 1.0 / 2;
xsurmix = 0.5 /2;
L = input(:, 1);
R = input(:, 2);
C = input(: 3);
Ls = input(: 5);
Rs = input(: 6);
loro(:, 1) = L + cmix * C + surmix * Ls;
loro(:, 2) = R + cmix * C + surmix * Rs;
ltrt(:, 1) = L + cmix* C - surmix* Ls - xsurmix * Rs;
ltrt(:, 2) = R + cmix * C + surmix * Ls + xsurmix * Rs;
end
main.m:
clc:
clear all;
[input, fs] = wavread('input.wav');
y = hrir_process(input);
[loro ltrt] = dowmix('input.wav');
wavwrite(y, fs, 'output.wav');
wavwrite(loro, fs, 'loro.wav');
wavwrite(ltrt, fs, 'ltrt.wav');