使用耳机听双通道stereophonic material不同于使用 loudspeaker 进行监听。
clear ;
% 利用简单的头传递函数,生成虚拟声源
% 对生成的音频使用耳机监听;
% 角度控制参数: theta
[x, Fs] = audioread('song.wav');
theta = 0 ;
HRIRl=simpleHRIR(theta,Fs);
HRIRr=simpleHRIR(-theta,Fs);
outsigL= conv(HRIRl,x);
outsigR= conv(HRIRr,x);
y = [outsigL outsigR];
audiowrite('out.wav' ,y , Fs ) ;
function [output] = simpleHRIR(theta, Fs)
% [output] = simpleHRIR(theta, Fs)
% Author: F. Fontana and D. Rocchesso, V.Pulkki
%
% computes simplified HRTFs with only simple ITD-ILD approximations
% theta is the azimuth angle in degrees
% Fs is the sample rate
%
%--------------------------------------------------------------------------
% This source code is provided without any warranties as published in
% DAFX book 2nd edition, copyright Wiley & Sons 2011, available at
% http://www.dafx.de. It may be used for educational purposes and not
% for commercial applications without further permission.
%--------------------------------------------------------------------------
theta = theta + 90;
theta0 = 150 ;
alfa_min = 0.05 ;
c = 334; % speed of sound
a = 0.08; % radius of head
w0 = c/a;
input=zeros(round(0.003*Fs),1); input(1)=1;
alfa = 1+ alfa_min/2 + (1- alfa_min/2)* cos(theta/ theta0* pi) ;
B = [(alfa+w0/Fs)/(1+w0/Fs), (-alfa+w0/Fs)/(1+w0/Fs)] ;
% numerator of Transfer Function
A = [1, -(1-w0/Fs)/(1+w0/Fs)] ;
% denominator of Transfer Function
if (abs(theta) < 90)
gdelay = round(- Fs/w0*(cos(theta*pi/180) - 1)) ;
else
gdelay = round(Fs/w0*((abs(theta) - 90)*pi/180 + 1) );
end
out_magn = filter(B, A, input);
output = [zeros(gdelay,1); out_magn(1:end-gdelay); ];
end