%%%
%%%  Example invocations of the function speaker_matrix()
%%%    and some handy constants and functions
%%%
%%%  Aaron J. Heller <heller@ai.sri.com>
%%%  Last update: $Date: 2006-10-16 17:44:02 -0700 (Mon, 16 Oct 2006) $"
%%%

% the three decodes
k_velocity  = 1

k_energy_2d = sqrt(1/2)
k_energy_3d = sqrt(1/3)

k_cardioid  = 1/2

%% some utility functions to allow us to enter speaker locations as
%% azimuths and azimuth elevations

function retval = az2dir(az)
% AZ2DIR - convert azimuth in degrees to direction cosines
%   
  [ x  y ] = pol2cart( az * pi/180, 1 );
  retval = [ x y ];
endfunction

function retval = azel2dir(az, el)
% AZEL2DIR - convert azimuth and elevation in degrees to direction cosines
%   
  [ x y z ] = sph2cart( az * pi/180, el * pi/180, 1 );
  retval = [ x y z ];
endfunction

%%% standard speaker layouts

printf("\n\n ----- rV decodes -----\n");
k = k_velocity

s_square = [ 1 1; 1 -1]
speaker_matrix( s_square, k )

% or as angles
s_square_a = [ az2dir(45); az2dir(-45) ]
speaker_matrix( s_square_a, k )

s_wide_rectangle = [ az2dir(60); az2dir(-60) ]
speaker_matrix( s_wide_rectangle, k )

s_narrow_rectangle = [ az2dir(30); az2dir(-30) ]
speaker_matrix( s_narrow_rectangle, k )

s_hexagon_30 = [az2dir(30); az2dir(90); az2dir(150) ]
speaker_matrix( s_hexagon_30, k )

s_hexagon_0 = [az2dir(0); az2dir(60); az2dir(120) ]
speaker_matrix( s_hexagon_0, k )

s_cube = [ 1 1 1; 1 -1 1; -1 -1 1; -1 1 1]
speaker_matrix( s_cube, k )

s_shoebox = [ 2 1 1; 2 -1 1; -2 -1 1; -2 1 1]
speaker_matrix( s_shoebox, k )

printf("\n\n ----- rE max decodes -----\n");
k = k_energy_2d

s_square = [ 1 1; 1 -1]
speaker_matrix( s_square, k )

s_square_a = [ az2dir(45); az2dir(-45) ]
speaker_matrix( s_square_a, k )

s_wide_rectangle = [ az2dir(60); az2dir(-60) ]
speaker_matrix( s_wide_rectangle, k )

s_narrow_rectangle = [ az2dir(30); az2dir(-30) ]
speaker_matrix( s_narrow_rectangle, k )

s_narrow_rectangle = [2 1; 2 -1]
speaker_matrix( s_narrow_rectangle, k )

k = k_energy_3d

s_cube = [ 1 1 1; 1 -1 1; -1 -1 1; -1 1 1]
speaker_matrix( s_cube, k )

s_shoebox = [ 2 1 1; 2 -1 1; -2 -1 1; -2 1 1]
speaker_matrix( s_shoebox, k )


printf("\n\n ----- cardioid -----\n");

k = k_cardioid

s_square = [ 1 1; 1 -1]
speaker_matrix( s_square, k )

s_square_a = [ az2dir(45); az2dir(-45) ]
speaker_matrix( s_square_a, k )

s_wide_rectangle = [ az2dir(60); az2dir(-60) ]
speaker_matrix( s_wide_rectangle, k )

s_narrow_rectangle = [ az2dir(30); az2dir(-30) ]
speaker_matrix( s_narrow_rectangle, k )

s_cube = [ 1 1 1; 1 -1 1; -1 -1 1; -1 1 1]
speaker_matrix( s_cube, k )

s_shoebox = [ 2 1 1; 2 -1 1; -2 -1 1; -2 1 1]
speaker_matrix( s_shoebox, k )

%%%% EOF

%%% SVN info
%%%   $Id: speaker_matrix_examples.m 10713 2006-10-17 00:44:02Z heller $
%%%   $HeadURL: https://svn.ai.sri.com/svn/heller/audio/bf-decode/speaker_matrix_examples.m $
