CSL  6.0
SpatialSource.cpp
Go to the documentation of this file.
1 //
2 // SpeakerSource.cpp -- Spatial Sound Source
3 // See the copyright notice and acknowledgment of authors in the file COPYRIGHT
4 // Created by Jorge Castellanos on 6/16/06. Hacked 8/09 by STP.
5 //
6 
7 #include "SpatialSource.h"
8 
9 #include <stdlib.h>
10 #include <iostream>
11 
12 using std::cout;
13 using std::endl;
14 
15 using namespace csl;
16 
17 // SpatialSource constructors
18 
19 SpatialSource::SpatialSource() : mPosition(NULL), mPositionChanged(true) { }
20 
21 SpatialSource::SpatialSource(UnitGenerator &input, float azi, float ele, float dist)
22  : mPosition(NULL),
23  mPositionChanged(true) {
24  if (input.numChannels() != 1)
25  throw LogicError("Adding a non-mono ugen to a spatial source");
26  mPosition = new CPoint(kPolar, (float)dist, (float)(azi * CSL_PI/180.0), (float)(ele * CSL_PI/180.0));
27  this->addInput(CSL_INPUT, input);
28 #ifdef CSL_DEBUG
29  logMsg("SpatialSource::input UG added");
30 #endif
31 }
32 
34  if (mPosition)
35  delete mPosition;
36 }
37 
38 // Geometry
39 
40 CPoint *SpatialSource::position(unsigned channelNum) {
41  if (mPosition == NULL)
42  mPosition = new CPoint(1.0, 0.0, 0.0);
43  return mPosition;
44 }
45 
47  mPosition = & pos;
48 }
49 
50 void SpatialSource::setPosition(float x, float y, float z) {
51  if (mPosition) {
52  mPosition->set(x, y, z );
53  mPositionChanged = true;
54  } else
55  mPosition = new CPoint(x, y, z);
56 }
57 
58 void SpatialSource::setPosition(double x, double y, double z) {
59  if (mPosition) {
60  mPosition->set(x, y, z );
61  mPositionChanged = true;
62  } else
63  mPosition = new CPoint(x, y, z);
64 }
65 
66 void SpatialSource::setPosition(char s, float azi, float ele, float dist) {
67  if (mPosition) {
68  mPosition->set(kPolar, (float)dist, (float)(azi * CSL_PI/180.0), (float)(ele * CSL_PI/180.0) );
69  mPositionChanged = true;
70  } else
71  mPosition = new CPoint(kPolar, (float)dist, (float)(azi * CSL_PI/180.0), (float)(ele * CSL_PI/180.0));
72 }
73 
74 void SpatialSource::setPosition(char s, double azi, double ele, double dist) {
75  if (mPosition) {
76  mPosition->set(kPolar, (float)dist, (float)(azi * CSL_PI/180.0), (float)(ele * CSL_PI/180.0) );
77  mPositionChanged = true;
78  } else
79  mPosition = new CPoint(kPolar, (float)dist, (float)(azi * CSL_PI/180.0), (float)(ele * CSL_PI/180.0));
80 }
81 
83 // cout << "x: " << mPosition->x << "\t" << "y: " << mPosition->y << "\t" << "z: " << mPosition->z << endl;
84 // cout << "\t\tradius: " << distance() << "\tazi: " << azimuth() << "\tele: " << elevation() << endl;
85  printf("\taz: %5.2f el: %5.2f dist: %4.2f\n",
86  azimuth(), // * CSL_DEGS_PER_RAD,
87  elevation(), // * CSL_DEGS_PER_RAD,
88  distance());
89 }
90 
91 // nextBuffer
92 
93 void SpatialSource::nextBuffer(Buffer &outputBuffer, unsigned outBufNum) throw (CException) {
94  Port *inPort = mInputs[CSL_INPUT];
95  inPort->mUGen->nextBuffer(outputBuffer); // get its UGen
96  mPositionChanged = false;
97 }
98 
99 void SpatialSource::nextBuffer(Buffer &outputBuffer) throw (CException) {
100 #ifdef CSL_DEBUG
101  logMsg("SpatialSource::nextBuffer");
102 #endif
103  nextBuffer(outputBuffer, 0);
104 }
void logMsg(const char *format,...)
These are the public logging messages.
Definition: CGestalt.cpp:292
float elevation()
Returns the horizontal angle.
Definition: SpatialSource.h:57
AdditiveInstrument.h – Sum-of-sines synthesis instrument class.
Definition: Accessor.h:17
CPoint * mPosition
source position
Definition: SpatialSource.h:71
virtual void nextBuffer(Buffer &outputBuffer)
get a buffer of Frames – this is the core CSL "pull" function; the given buffer can be written into...
Definition: CSL_Core.cpp:726
Impossible operation.
virtual void nextBuffer(Buffer &outputBuffer, unsigned outBufNum)
really compute the next buffer given an offset base channel; this is called by nextBuffer, possibly multiple times
#define kPolar
Definition: CPoint.h:31
float distance()
Returns the angle of elevation.
Definition: SpatialSource.h:58
#define CSL_PI
Definition: CSL_Types.h:334
CPoint * position(unsigned channelNum=0)
Returns the distance from the center.
virtual unsigned numChannels()
Definition: CSL_Core.h:252
#define CSL_INPUT
Definition: CSL_Types.h:275
float azimuth()
Sets the distance from the center.
Definition: SpatialSource.h:56
UnitGenerator * mUGen
my unit generator (pointer or NULL)
Definition: CSL_Core.h:320
SpatialSource()
constructors
Buffer – the multi-channel sample buffer class (passed around between generators and IO guys)...
Definition: CSL_Core.h:106
virtual void setPosition(CPoint pos)
Set the sound source position in cartesian coordinates.
Port – used to represent constant, control-rate or signal inputs and outputs in named maps; holds a ...
Definition: CSL_Core.h:312
void addInput(CSL_MAP_KEY name, UnitGenerator &ugen)
Plug in a unit generator to the named input slot.
Definition: CSL_Core.cpp:894
bool mPositionChanged
true if this source's position has changed recently
Definition: SpatialSource.h:72
forward declaration
Definition: CSL_Core.h:241
virtual ~SpatialSource()
void set(int a, int b)
Definition: CPoint.h:73
void dump()
pretty-print the receiver
Base class of CSL exceptions (written upper-case). Has a string message.