/[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 200 - (hide annotations) (download) (as text)
Tue Jul 13 22:04:16 2004 UTC (19 years, 9 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 7504 byte(s)
moved directory '/src/audiodriver' -> '/src/drivers/audio'

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

  ViewVC Help
Powered by ViewVC