/[svn]/linuxsampler/trunk/src/drivers/audio/AudioChannel.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/drivers/audio/AudioChannel.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1037 - (show annotations) (download) (as text)
Tue Jan 23 20:03:22 2007 UTC (17 years, 2 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 6865 byte(s)
* bugfix regarding FX Sends: when more than one sampler channel used FX
  sends, only the audio signal of the last sampler channel made it into the
  final output signal
* fixed small autoconf compilation issue on certain systems (complained
  about missing AM_PATH_ARTS macro)

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * Copyright (C) 2005 - 2007 Christian Schoenebeck *
7 * *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21 * MA 02111-1307 USA *
22 ***************************************************************************/
23
24 #ifndef __LS_AUDIOCHANNEL_H__
25 #define __LS_AUDIOCHANNEL_H__
26
27 #include <map>
28 #include <vector>
29 #include <string.h>
30 #include "../../common/global.h"
31 #include "../../common/Exception.h"
32 #include "../DeviceParameter.h"
33
34 namespace LinuxSampler {
35
36 /** Audio Channel (always mono)
37 *
38 * This class is used for routing audio signals between arbitrary sources
39 * and destinations. You can either create a normal channel like:
40 * @code
41 * AudioChannel c1(512); // create unnamed channel
42 * AudioChannel c2(512, "Effect send mono channel"); // create named channel
43 * @endcode
44 * Or you can create a mix channel, e.g. the following would create a
45 * normal channel first, and the second channel is just a copy of the
46 * first channel:
47 * @code
48 * AudioChannel mono_chan(512, "Effect send channel"); // real channel
49 * AudioChannel mix_chan(&mono_chan, "Effect send mono channel"); // mix channel
50 * @endcode
51 * So in the last example, when writing to 'mix_chan' the signal will
52 * actually be mixed to the 'mono_chan' channel, so this is an easy way
53 * to downmix a signal source which has more audio channels than the
54 * signal destination can offer.
55 */
56 class AudioChannel {
57 public:
58 class ParameterName : public DeviceRuntimeParameterString {
59 public:
60 ParameterName(String s) : DeviceRuntimeParameterString(s) {}
61 virtual String Description() { return "Arbitrary name"; }
62 virtual bool Fix() { return false; }
63 virtual std::vector<String> PossibilitiesAsString() { return std::vector<String>(); }
64 virtual void OnSetValue(String s) { /* nothing to do */ }
65 };
66
67 class ParameterIsMixChannel : public DeviceRuntimeParameterBool {
68 public:
69 ParameterIsMixChannel(bool b) : DeviceRuntimeParameterBool(b) {}
70 virtual String Description() { return "Whether real channel or mixed to another channel"; }
71 virtual bool Fix() { return true; }
72 virtual void OnSetValue(bool b) throw (Exception) { /* cannot happen, as parameter is fix */ }
73 };
74
75 class ParameterMixChannelDestination : public DeviceRuntimeParameterInt {
76 public:
77 ParameterMixChannelDestination(int i) : DeviceRuntimeParameterInt(i) {}
78 virtual String Description() { return "Destination channel of this mix channel"; }
79 virtual bool Fix() { return true; }
80 virtual optional<int> RangeMinAsInt() { return optional<int>::nothing; /*TODO: needs to be implemented */ }
81 virtual optional<int> RangeMaxAsInt() { return optional<int>::nothing; /*TODO: needs to be implemented */ }
82 virtual std::vector<int> PossibilitiesAsInt() { return std::vector<int>(); /*TODO: needs to be implemented */ }
83 virtual void OnSetValue(int i) throw (Exception) { /*TODO: needs to be implemented */ }
84 };
85
86 // attributes
87 //String Name; ///< Arbitrary name of this audio channel
88
89 // methods
90 inline float* Buffer() { return pBuffer; } ///< Audio signal buffer
91 inline AudioChannel* MixChannel() { return pMixChannel; } ///< In case this channel is a mix channel, then it will return a pointer to the real channel this channel refers to, NULL otherwise.
92 inline void Clear() { memset(pBuffer, 0, uiBufferSize * sizeof(float)); } ///< Reset audio buffer with silence
93 void CopyTo(AudioChannel* pDst, const uint Samples);
94 void CopyTo(AudioChannel* pDst, const uint Samples, const float fLevel);
95 void MixTo(AudioChannel* pDst, const uint Samples);
96 void MixTo(AudioChannel* pDst, const uint Samples, const float fLevel);
97 std::map<String,DeviceRuntimeParameter*> ChannelParameters();
98
99 // constructors / destructor
100 AudioChannel(uint ChannelNr, uint BufferSize);
101 AudioChannel(uint ChannelNr, float* pBuffer, uint BufferSize);
102 AudioChannel(uint ChannelNr, AudioChannel* pMixChannelDestination);
103 virtual ~AudioChannel();
104 protected:
105 uint ChannelNr;
106 std::map<String,DeviceRuntimeParameter*> Parameters;
107 private:
108 float* pBuffer;
109 uint uiBufferSize;
110 AudioChannel* pMixChannel;
111 bool UsesExternalBuffer;
112 };
113 }
114
115 #endif // __LS_AUDIOCHANNEL_H__

  ViewVC Help
Powered by ViewVC