CSL
5.2
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
SpatialPanner.cpp
Go to the documentation of this file.
1
//
2
// SpatialPanner.cpp -- Specification of the abstract framework for panner/spatializers
3
// See the copyright notice and acknowledgment of authors in the file COPYRIGHT
4
// Created by Jorge Castellanos on 3/29/06. Hacked 8/09 by STP.
5
//
6
7
#include "
SpatialPanner.h
"
8
9
using namespace
csl;
10
11
SpatialPanner::SpatialPanner
(
SpeakerLayout
*layout)
12
:
UnitGenerator
(
CGestalt
::frameRate(), 2),
13
mSpeakerLayout(NULL) {
14
// mSources = (SpatialSource **) malloc(64 * sizeof(SpatialSource*));
15
mTempBuffer
.
setSize
(1,
CGestalt::blockSize
());
// mono buffer for operations
16
mTempBuffer
.
allocateBuffers
();
17
setSpeakerLayout
(layout);
// Grab the default layout.
18
}
19
20
SpatialPanner::~SpatialPanner
() {
21
mSpeakerLayout
->
detachObserver
(
this
);
// Remove yourself from the list of observers.
22
mTempBuffer
.
freeBuffers
();
23
}
24
25
void
SpatialPanner::setSpeakerLayout
(
SpeakerLayout
*aLayout) {
26
// TO DO: FIRST CHECK TO MAKE SURE THERE'S A LAYOUT,
27
// THEN DETACH AS OBSERVER OF PREVIOUS AND ATTACH TO NEWER ONE!
28
if
(aLayout ==
mSpeakerLayout
)
// If user is just setting the same layout again, do nothing.
29
return
;
30
31
if
(
mSpeakerLayout
!= NULL)
// If still alive, remove yourself as an observer.
32
mSpeakerLayout
->
detachObserver
(
this
);
33
34
mSpeakerLayout
= aLayout;
35
mSpeakerLayout
->
attachObserver
(
this
);
// Tell the speaker layout to inform you of any changes
36
this->
speakerLayoutChanged
();
37
}
38
39
// add a source and create a cache object
40
41
void
SpatialPanner::addSource
(
SpatialSource
&soundSource) {
42
// unsigned which = mSources.size();
43
// for (unsigned i = 0; i < which; i++) {
44
// if (mSources[i] == NULL) {
45
// which = i;
46
// break;
47
// }
48
// }
49
// mSources[which] = &soundSource;
50
mSources
.push_back(&soundSource);
51
mCache
.push_back(this->
cache
());
52
}
53
54
// delete from the list, shifting if necessary
55
56
void
SpatialPanner::removeSource
(
SpatialSource
&soundSource) {
57
// unsigned count = mSources.size();
58
for
(
unsigned
i = 0; i <
mSources
.size(); i++) {
59
if
(
mSources
[i] == &soundSource) {
60
// mSources[i] = NULL;
61
mSources
.erase(
mSources
.begin() + i);
62
mCache
.erase(
mCache
.begin() + i);
63
break
;
64
}
65
}
66
#ifdef CSL_DEBUG
67
logMsg
(
"Panner::removeSource"
);
68
#endif
69
return
;
70
}
71
72
void
*
SpatialPanner::cache
() {
73
return
(
void
*)
new
float;
// Returns a pointer to an alocated cache data for its own use.
74
}
75
76
/**
77
Called when the speaker layout changes, so panners update their data.
78
This method is implemented only by the Panner class, and depending on the message sent, it calls
79
the appropriate method implemented by subclasses. For example, when the speaker layout changes,
80
the method calls "speakerLayoutChanged()", which should be implemented by subclasses interested to
81
react to such change.
82
*/
83
void
SpatialPanner::update
(
void
* arg) {
84
// cout << "Panner::Updated Speaker Layout!" << mNumTriplets << endl;
85
// Re-calculate all the stuff.
86
if
(
mSpeakerLayout
== NULL)
// If it was destroyed get the default layout
87
setSpeakerLayout
(
SpeakerLayout::defaultSpeakerLayout
());
88
// Update any info that depends on the layout
89
this->
speakerLayoutChanged
();
90
}
CSL
Spatializers
SpatialPanner.cpp
Generated on Thu Nov 15 2012 22:01:10 for CSL by
1.8.1.1