Skip to content
Snippets Groups Projects
Commit e67ed00d authored by Michael Kohnen's avatar Michael Kohnen
Browse files

deleted old name conversion für ambisonics, VR_Loudspeaker_position and ita_panVBAP

parent 2ebc3c98
Branches
Tags v1.0.0
No related merge requests found
function pos = VR_loudspeaker_position(varargin)
% Give back the position, in meters, of the 8 loudspeakers in the VR lab.
% See options for more details
% Author: Michael Kohnen -- Email: mko@akustik.rwth-aachen.de
% Date: 03-May-2017
% Options
opts.virtualSpeaker = false; % true || Indicates whether to add virtual speaker achieve a more regular distribution (stabilizes the pseudoinverse in Ambisonics Decoding)
opts.coordSystem = 'itaCoordinates'; % 'openGL' || indicates in which coordinate system the output is
opts.isItaCoordinates = true; % true || indicates whether the output is a itaCoordinate or not (warning: if combined with coordSystem='opneGL', the angles for azimuth and elevation are not correct
opts.heightCorrection = 0.0597; % in meter || ensures that the loudspeakers are around the point (0 0 0), standard value is height of the bigger loudspeaker in the horizontal plane
opts=ita_parse_arguments(opts, varargin);
% X Y Z (openGL)
pos = itaCoordinates(zeros(12,3));
pos.r= 2.28;
pos.phi_deg=[45 315 225 135 0 270 180 90 0 270 180 90];
pos.theta_deg=[88.5 88.5 88.5 88.5 60 60 60 60 118 118 118 118];
if opts.virtualSpeaker
pos.cart = [pos.cart;...
0 0 -2.3;... % virtual speaker
0 0 2.3]; % virtual speaker
end
% Correction of head height
pos.z=pos.z-opts.heightCorrection;
if strcmpi(opts.coordSystem,'opengl')
pos.cart = ita_matlab2openGL(pos);
end
if (~opts.isItaCoordinates)
pos = pos.cart;
end
\ No newline at end of file
function [ OutputSignals ] = ita_decodeAmbisonics( Bformat, LoudspeakerPos, varargin )
%ITA_DECODEAMBISONICS Summary of this function goes here
% Detailed explanation goes here
% BFormat<nmax,LS>
opts.decoding='remax'; % Decoding strategy (remax,inphase,plane)
% opts.decoding='none';
opts = ita_parse_arguments(opts,varargin);
% Initializing further parameters
if isa(Bformat, 'itaAudio')
nmax=max(Bformat.nChannels);
else
nmax=size(Bformat,2);
end
N=floor(sqrt(nmax)-1);
% Weighting for Inphase/ReMax
g_re=ones(nmax,1); %init weighting factors for ReMax
g_in=g_re; %init weighting factors for InPhase
% ReMax Decoding
if(sum(strcmp(lower(opts.decoding),{'remax' 'both'})))
% Calculates the B-Format channel weights for ReMax-Decoding
% see J.Daniel Thesis p.312 A.67/A.68
weightsReMax=zeros(nmax,1); % init weights
% g_m=P_m(r_E) with n=0 for P
% r_E is largest root of P_(order+1)
syms x;
f=1/2^(N+1)/factorial(N+1)*diff(((x^2-1)^(N+1)),(N+1));%Legendre Polynom n=0 m=order+1
maxroot=max(eval(solve(f))); %find maximum root(Nullstelle)
for k=1:nmax
leggie=legendre(ita_sph_linear2degreeorder(k),abs(maxroot)); % g_m=P_m(r_E)
weightsReMax(k)=leggie(1);% pick n=0
end
g_re=weightsReMax;
end
% Inphase Decoding
if(sum(strcmp(lower(opts.decoding),{'inphase' 'both'})))
% Calculates the B-format channel weights for InPhase-Decoding
weightsInPhase=zeros(nmax,1);
%Dissertation J.Daniel p.314, 'preserve Energy' in 0. order
%g_0=sqrt[N*(2*M+1)/(M+1)^2]
weightsInPhase(1)=sqrt(N*(2*N+1)/(N+1)^2);
for k=2:nmax
m=ita_sph_linear2degreeorder(k);
% Dissertation J.Daniel p.314
% g_m=M!*(M+1)!/[(M+m+1)!*(M-n)!]
weightsInPhase(k)=factorial(N)*factorial(N+1)/factorial(m+N+1)/factorial(N-m);
end
g_in=weightsInPhase;
end
weights=g_in.*g_re; % merge weighting factors
%% Applying weighting to BFormat
if isa(Bformat,'itaAudio')
for k=1:Bformat.nChannels
Bformat.time(:,k)=Bformat.time(:,k).*weights(k);
end
else
for k=1:numel(weights)
Bformat(:,k)=weights(k).*Bformat(:,k);
end
end
%% SH and inversion of loudspeaker set-up
Y = ita_sph_base(LoudspeakerPos, N, 'real'); % generate basefunctions
Yinv=pinv(Y); % calculate Pseudoinverse, moore penrose, svd
if isa(Bformat,'itaAudio')
for k=1:LoudspeakerPos.nPoints
for l=1:nmax
temp(l)=Bformat.ch(l)*Yinv(l,k);
end
OutputSignals(k)=sum(temp);
end
OutputSignals=ita_merge(OutputSignals(:));
OutputSignals.channelCoordinates=LoudspeakerPos;
else
OutputSignals=Bformat*Yinv;
end
end
function [ audioOut ] = ita_encodeAmbisonics( audioIn, order, sourcePos )
%ITA_ENCODEAMBISONICS Encodes a itaAudio with channel coordinates or a
% itaCoordinate with source positions into ambisonics channels
%
% Detailed explanation goes here
%% Init
if isa(audioIn, 'itaAudio')
aud=true;
elseif isa(audioIn, 'itaCoordinates')
aud=false;
sourcePos=audioIn;
if nargin>2
error('For itaCoordinates no additional source positions can be given!');
end
else
error('itaAudio or itaCoordinates has to be the first input!');
end
if nargin<2
warning('SH Truncation order missing, assuming order of one');
order=1;
end
if nargin<3 && aud
sourcePos=audioIn.channelCoordinates;
if sourcePos.nPoints<1 || ~isa(sourcePos,'itaCoordinates')
error('No sourcePos found or it is not itaCoordinates! Add channelCoordinates to itaAudio!')
end
end
%% Encode Source
if ~aud
audioOut=ita_sph_base(sourcePos, order, 'real');
end
%% Applying audio data
if aud
audioOut=itaAudio;
audioOut_temp=itaAudio;
for idxCh=1:audioIn.nChannels
Bformat = ita_sph_base(sourcePos(idxCh), order, 'real');
for idxCoeff=1:numel(Bformat)
audioOut_temp(idxCoeff)=audioIn.ch(idxCh)*Bformat(idxCoeff);
end
if idxCh==1
audioOut=ita_merge(audioOut_temp);
else
audioOut=audioOut+ita_merge(audioOut_temp);
end
end
end
\ No newline at end of file
function weights = panVBAP(pos_LS,pos_VS)
%panVBAP - Calculate weights for VBAP
%
% This function receives the position of the loudspeakers and the position
% of the virtual source. Both input must be given as objects of the class
% itaCoordinates.
%
% The output is the set of frequency independent weights used to pan the
% virtual source on the given array.
%
% Call: weights = panVBAP(pos_LS,pos_VS)
%
% Author: Michael Kohnen -- Email: mko@akustik.rwth-aachen.de
% Former author: Bruno Masiero -- Email: bma@akustik.rwth-aachen.de
% Created: 13-Jun-2011
% Last modified: 04-May-2017
%$ENDHELP$
%% Preliminary tests
% if pos_LS.isPlane
% Number_of_active_loudspeakers = 2; %Extended Stereo
% else
Number_of_active_loudspeakers = 3;
% end
weights = zeros(pos_VS.nPoints,pos_LS.nPoints);
if pos_VS.r == 0
error('No direction for Virtual Source was given!')
end
%% Find the closest loudspeakers
% Calculate the distance of each loudspeaker to the virtual source with the
% help of the itaCoordinate overloaded function itaCoordinate.r.
% To sort the distance in ascending value, use the function sort.
aux = pos_LS - pos_VS;
dist = aux.r;
[junk,index] = sort(dist,'ascend');
index = index(1:Number_of_active_loudspeakers);
active_loudspeakers = pos_LS.n(index);
%% Calculate the weights for the active loudspeakers
% Create a base matrix with the direction of the active loudspeakers and
% multiply the direction of the virtual source with the inverse of this
% matrix.
% Don't forget to normalize yor results with C = 1;
for idx = 1:pos_VS.nPoints
p = pos_VS.n(idx).cart;
L = active_loudspeakers.cart;
g = p*pinv(L);
% Re-normalize.
g = abs(g)/norm(g);
weights(idx,index) = g;
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment