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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2434 - (hide annotations) (download) (as text)
Thu Mar 7 19:23:24 2013 UTC (11 years, 1 month ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 7196 byte(s)
* Started to spread new C++ keyword "override" over the code base
  (keyword introduced with C++11 standard).

1 schoenebeck 200 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 2434 * Copyright (C) 2005 - 2013 Christian Schoenebeck *
7 schoenebeck 200 * *
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 schoenebeck 880 #include "../../common/Exception.h"
32 schoenebeck 200 #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 schoenebeck 1001 * @code
41 schoenebeck 200 * AudioChannel c1(512); // create unnamed channel
42     * AudioChannel c2(512, "Effect send mono channel"); // create named channel
43 schoenebeck 1001 * @endcode
44 schoenebeck 200 * 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 schoenebeck 1001 * @code
48 schoenebeck 200 * AudioChannel mono_chan(512, "Effect send channel"); // real channel
49     * AudioChannel mix_chan(&mono_chan, "Effect send mono channel"); // mix channel
50 schoenebeck 1001 * @endcode
51 schoenebeck 200 * 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 schoenebeck 2434 virtual String Description() OVERRIDE { return "Arbitrary name"; }
62     virtual bool Fix() OVERRIDE { return false; }
63     virtual std::vector<String> PossibilitiesAsString() OVERRIDE { return std::vector<String>(); }
64     virtual void OnSetValue(String s) OVERRIDE { /* nothing to do */ }
65 schoenebeck 200 };
66    
67     class ParameterIsMixChannel : public DeviceRuntimeParameterBool {
68     public:
69     ParameterIsMixChannel(bool b) : DeviceRuntimeParameterBool(b) {}
70 schoenebeck 2434 virtual String Description() OVERRIDE { return "Whether real channel or mixed to another channel"; }
71     virtual bool Fix() OVERRIDE { return true; }
72     virtual void OnSetValue(bool b) throw (Exception) OVERRIDE { /* cannot happen, as parameter is fix */ }
73 schoenebeck 200 };
74    
75     class ParameterMixChannelDestination : public DeviceRuntimeParameterInt {
76     public:
77     ParameterMixChannelDestination(int i) : DeviceRuntimeParameterInt(i) {}
78 schoenebeck 2434 virtual String Description() OVERRIDE { return "Destination channel of this mix channel"; }
79     virtual bool Fix() OVERRIDE { return true; }
80     virtual optional<int> RangeMinAsInt() OVERRIDE { return optional<int>::nothing; /*TODO: needs to be implemented */ }
81     virtual optional<int> RangeMaxAsInt() OVERRIDE { return optional<int>::nothing; /*TODO: needs to be implemented */ }
82     virtual std::vector<int> PossibilitiesAsInt() OVERRIDE { return std::vector<int>(); /*TODO: needs to be implemented */ }
83     virtual void OnSetValue(int i) throw (Exception) OVERRIDE { /*TODO: needs to be implemented */ }
84 schoenebeck 200 };
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 persson 1748 void SetBuffer(float* pBuffer) { this->pBuffer = pBuffer; }
92 schoenebeck 200 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 persson 1748 inline void Clear(uint Samples) { memset(pBuffer, 0, Samples * sizeof(float)); } ///< Reset audio buffer with silence
95 schoenebeck 1001 void CopyTo(AudioChannel* pDst, const uint Samples);
96     void CopyTo(AudioChannel* pDst, const uint Samples, const float fLevel);
97 schoenebeck 1037 void MixTo(AudioChannel* pDst, const uint Samples);
98     void MixTo(AudioChannel* pDst, const uint Samples, const float fLevel);
99 schoenebeck 200 std::map<String,DeviceRuntimeParameter*> ChannelParameters();
100 schoenebeck 226
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 schoenebeck 200 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