Subsections

パンポット / Panpot

スピーカー用 / for loudspeakers

function y = panpot(x, p)
%PANPOT   Constant-power Panpot
%   y=panpot(x,p) creates stereo signal y from monoaural signal x.
%   p = left (-1) -- center (0) -- right (+1)

%   2010-07-06 MARUI Atsushi

theta = (p+1)/2 * 90 * pi/180;
yL = x * cos(theta);
yR = x * sin(theta);
y = [yL yR];

ヘッドホン用 / for headphones

ヘッドホンでの使用を考え、ILD(両耳間レベル差)とITD(両耳間時間差)を使ったパンポット。両耳の間隔で全指向マイクを置いたような状況です。本来は頭による遮蔽・回折を考えたり、頭部伝達関数を用いるのが理想ですが、ここでは物理的な正確さはあまり考えていません。

function y = panpot(x, pan, fs)
%PANPOT   set panning of a sound
%   y=panpot(x,pan,fs) locates a sound x (sampled in fs Hz) in user
%   specified lateral location between left and right.
%
%   pan: -1 (hard left) -- 0 (center) -- +1 (hard right)
%
%   This routine manipulates both ILD (interaural level difference) and ITD
%   (interaural time difference) to achieve the better localization
%   results over headphone playback.

%   2005-08-28 MARUI Atsushi

% flags to use ITD and/or ILD
do_itd = true;
do_ild = true;

% input signal validation
if ndims(x)>2
  y = NaN;
  return;
end
if size(x,1)<size(x,2)
  x = x';
end
if size(x,2)==1
  x = [x x];
end
x1 = x(:,1);
x2 = x(:,2);

% adjust effect of pan
pan = sign(pan) * abs(pan).^2;

% apply ITD
if do_itd
  delay = round(abs(pan) * fs / 1000);
  if pan<0
    x1 = [x1 ; zeros(delay,1)];
    x2 = [zeros(delay,1) ; x2];
  elseif pan>0
    x1 = [zeros(delay,1) ; x1];
    x2 = [x2 ; zeros(delay,1)];
  else
    x1 = x1;
    x2 = x2;
  end
end

% apply ILD
if do_ild
  x1 = x1 * sqrt((1-pan)/2);
  x2 = x2 * sqrt((1+pan)/2);
end

% result
y = [x1 x2];



MARUI Atsushi
2023-12-05