Skip to content

Commit

Permalink
Merge branch 'remove-matrix-dependency'
Browse files Browse the repository at this point in the history
  • Loading branch information
joslloand committed Nov 8, 2016
2 parents e5041bd + 5a6e8a9 commit 3aff498
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 40 deletions.
50 changes: 37 additions & 13 deletions source/ATK/sc/Classes/ATKMatrix.sc
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ FoaSpeakerMatrix {
matrix {
var s, directions, pos, dir;

// scatter matrix accumulator
s = Matrix.newClear(m, m);
// scatter matrix accumulator
s = Matrix.newClear(m, m);

// output channel (speaker) directions matrix
// NOTE: this isn't the user supplied directions arg
directions = Matrix.newClear(m, n);
// NOTE: this isn't the user supplied directions arg
directions = Matrix.newClear(m, n);

n.do({ arg i;

Expand All @@ -152,7 +152,7 @@ FoaSpeakerMatrix {
});

// return resulting matrix
^sqrt(1/2) * n * k * ( s.inverse * directions);
^sqrt(1/2) * n * k * ( s.inverse * directions);
}

printOn { arg stream;
Expand All @@ -161,25 +161,49 @@ FoaSpeakerMatrix {
}

AtkMatrix {
var <kind; // copyArgs
// copyArgs
var <kind, <set = 'FOA', <type; // NOTE: 'set' default will change with addition of HOA

var <matrix;
var <filePath; // matrices from files only
var <fileParse; // data parsed from YAML file
var <op = 'matrix';
var <set = 'FOA'; // ... for now

// most typically called by subclass
*new { |mtxKind|
^super.newCopyArgs(mtxKind)
// *new { |mtxKind, set, mtxType|
*new { |kind, set, type|
^super.newCopyArgs(kind).init(set, type)
}

init { |argSet, argType|
if (argSet.notNil) {
set = argSet
} { // detect from class
if (this.class.asString.keep(3) == "Foa") {
set = 'FOA';
}
};
if (argType.notNil) {
type = argType
} { // detect from class
type = switch( this.class,
FoaEncoderMatrix, {'encoder'},
FoaEncoderKernel, {'encoder'},
FoaDecoderMatrix, {'decoder'},
FoaDecoderKernel, {'decoder'},
FoaXformerMatrix, {'xformer'}
);
};
}

// used when writing a Matrix to file:
// need to convert to AtkMatrix first
*newFromMatrix { |aMatrix|
^super.newCopyArgs('fromMatrix').initFromMatrix(aMatrix)
*newFromMatrix { |aMatrix, set, type|
^super.newCopyArgs('fromMatrix').initFromMatrix(aMatrix, set, type)
}

initFromMatrix { |aMatrix|
initFromMatrix { |aMatrix, argSet, argType|
this.init(argSet, argType);
matrix = aMatrix;
}

Expand Down Expand Up @@ -535,7 +559,7 @@ FoaDecoderMatrix : AtkMatrix {
}

*newPeri { arg numChanPairs = 4, elevation = 0.61547970867039,
orientation = 'flat', k = 'single';
orientation = 'flat', k = 'single';
^super.new('peri').initPeri(numChanPairs, elevation,
orientation, k);
}
Expand Down
13 changes: 13 additions & 0 deletions source/ATK/sc/Classes/extArray.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
+ Array {

// set: FOA, HOA1, HOA2, etc.
// type: \encoder, \decoder, \xformer
// NOTE: set and type aren't currently enforced, but it's a
// good idea to provide it for writing to file
asAtkMatrix { arg set, type;
var mtx;
mtx = Matrix.with(this.asArray);
^AtkMatrix.newFromMatrix(mtx, set, type);
}

}
16 changes: 0 additions & 16 deletions source/ATK/sc/Classes/extMatrix.sc

This file was deleted.

14 changes: 13 additions & 1 deletion source/ATK/sc/HelpSource/Classes/AtkMatrix.schelp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
TITLE:: AtkMatrix
summary:: A superclass to the Atk's various matrix classes.
categories:: Libraries>Ambisonic Toolkit>Internals
related:: Classes/FoaEncoderMatrix, Classes/FoaDecoderMatrix, Classes/FoaXformerMatrix, Classes/Matrix
related:: Classes/FoaEncoderMatrix, Classes/FoaDecoderMatrix, Classes/FoaXformerMatrix, Classes/Matrix, Guides/Guide-to-ATK-Matrix-Files

DESCRIPTION::
An AtkMatrix is not typically instantiated directly, but rather through one of its subclasses:
Expand All @@ -24,6 +24,18 @@ code::
Matrix.with([[row1],[row2],...[rowN]])
::

ARGUMENT:: set
code::'FOA', 'HOA1', 'HOA2', ... etc::.
Set describes both the signal set and the tool set, encompassing the Ambisonic order, as well as channel ordering and normalisation.

ARGUMENT:: type
code::'decoder', 'encoder', or 'xformer'::.

NOTE::
strong::set:: and strong::type:: will be required if the code::AtkMatrix:: will subsequently be written to a file.
::


INSTANCEMETHODS::

PRIVATE:: set, kind
Expand Down
21 changes: 11 additions & 10 deletions source/ATK/sc/HelpSource/Guides/Guide-to-ATK-Matrix-Files.schelp
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ the link::Classes/AtkMatrix:: subclasses. When writing from these objects, some
can be inferred from them, such as the strong::set:: (Ambisonic order,
channel ordering, channel normalisation, e.g. code::'FOA'::, code::'HOA3'::,
etc.) and strong::type:: of matrix (e.g. code::'encoder', 'decoder', 'xformer'::).
In the case of a raw matrix, this information can't be inferred and should be
explicitly set when writing to file.
In the case of a raw matrix, you must cast it to an code::AtkMatrix::, specifying the
strong::set:: and strong::type:: explicitly, before writing it to a file.

code::
( // Here's a raw A-to-B encoder matrix:
Expand Down Expand Up @@ -259,21 +259,22 @@ code::
)
::

Now be sure to list the proper info for the arguments when writing it to file. This is how the ATK will know where to store the file by default (unless a full path is provided to the file name argument).
Be sure to specify the strong::set:: and strong::type:: when creating an
code::AtkMatrix:: from your code::Matrix::. This is how the ATK will know where
to store the file by default (unless a full path is provided to the file name
argument).

code::
(
~matrix.writeToFile( "myA2B_flu_Matrix.yml", // be sure to use .yml for metadata
'FOA', // set
'encoder', // type
~note,
~properties
)
~atkMatrix = ~matrix.asAtkMatrix('FOA', 'encoder'); // set, type
// be sure to use .yml extension for metadata
~atkMatrix.writeToFile("myA2B_flu_Matrix.yml", ~note, ~properties);
)
::

NOTE:: If providing a file path relative to your code::/ATK/extension/matrices/...::
directory, strong::set:: and strong::type:: are necessary arguments to locate the
directory, strong::set:: and strong::type:: arguments are necessary when creating the
code::AtkMatrix:: from your code::Matrix:: in order to locate the
proper directory to store your file. If providing an absolute file path,
strong::set:: and strong::type:: are recommended but not strictly enforced. This
allows storing matrices outside the ATK paradigm, e.g. VBAP matrices, etc.
Expand Down

0 comments on commit 3aff498

Please sign in to comment.