/[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 1748 - (show annotations) (download) (as text)
Sun Jun 22 14:46:46 2008 UTC (15 years, 9 months ago) by persson
File MIME type: text/x-c++hdr
File size: 7079 byte(s)
* bugfix: notes triggered at position 0 in the audio buffer were
  sometimes wrongly killed in the same buffer, causing no sound to be
  played
* fixes for audio drivers with varying buffer sizes
* Makefile fix: JACK_CFLAGS wasn't used
* JACK driver: use jack_client_open instead of the deprecated
  jack_client_new

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 void SetBuffer(float* pBuffer) { this->pBuffer = pBuffer; }
92 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.
93 inline void Clear() { memset(pBuffer, 0, uiBufferSize * sizeof(float)); } ///< Reset audio buffer with silence
94 inline void Clear(uint Samples) { memset(pBuffer, 0, Samples * sizeof(float)); } ///< Reset audio buffer with silence
95 void CopyTo(AudioChannel* pDst, const uint Samples);
96 void CopyTo(AudioChannel* pDst, const uint Samples, const float fLevel);
97 void MixTo(AudioChannel* pDst, const uint Samples);
98 void MixTo(AudioChannel* pDst, const uint Samples, const float fLevel);
99 std::map<String,DeviceRuntimeParameter*> ChannelParameters();
100
101 // constructors / destructor
102 AudioChannel(uint ChannelNr, uint BufferSize);
103 AudioChannel(uint ChannelNr, float* pBuffer, uint BufferSize);
104 AudioChannel(uint ChannelNr, AudioChannel* pMixChannelDestination);
105 virtual ~AudioChannel();
106 protected:
107 uint ChannelNr;
108 std::map<String,DeviceRuntimeParameter*> Parameters;
109 private:
110 float* pBuffer;
111 uint uiBufferSize;
112 AudioChannel* pMixChannel;
113 bool UsesExternalBuffer;
114 };
115 }
116
117 #endif // __LS_AUDIOCHANNEL_H__

  ViewVC Help
Powered by ViewVC