CSL  5.2
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 }