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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1424 - (hide annotations) (download)
Sun Oct 14 22:00:17 2007 UTC (16 years, 6 months ago) by schoenebeck
File size: 7345 byte(s)
* code cleanup:
- global.h now only covers global definitions that are needed for the C++
  API header files, all implementation internal global definitions are now
  in global_private.h
- atomic.h is not exposed to the C++ API anymore (replaced the references
  in SynchronizedConfig.h for this with local definitions)
- no need to include config.h anymore for using LS's API header files
- DB instruments classes are not exposed to the C++ API
- POSIX callback functions of Thread.h are hidden
- the (optional) gig Engine benchmark compiles again
- updated Doxyfile.in
- fixed warnings in API doc generation
* preparations for release 0.5.0

1 schoenebeck 200 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 1037 * Copyright (C) 2005 - 2007 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     #include "AudioChannel.h"
25    
26 schoenebeck 1424 #include "../../common/global_private.h"
27    
28 schoenebeck 361 #if defined(__APPLE__)
29     # include <stdlib.h>
30     #else
31     # include <malloc.h>
32     #endif
33    
34    
35 schoenebeck 200 namespace LinuxSampler {
36    
37     /**
38     * Create real channel.
39     *
40 schoenebeck 226 * @param ChannelNr - channel number of this new channel
41 schoenebeck 200 * @param BufferSize - desired audio data buffer size
42     */
43 schoenebeck 226 AudioChannel::AudioChannel(uint ChannelNr, uint BufferSize) {
44     this->ChannelNr = ChannelNr;
45 schoenebeck 361 #if defined(__APPLE__)
46     this->pBuffer = (float *) malloc(BufferSize*sizeof(float));
47     #else
48 schoenebeck 319 this->pBuffer = (float *) memalign(16,BufferSize*sizeof(float));
49 schoenebeck 361 #endif
50 schoenebeck 200 this->uiBufferSize = BufferSize;
51     this->pMixChannel = NULL;
52     this->UsesExternalBuffer = false;
53    
54 schoenebeck 226 Parameters["NAME"] = new ParameterName("Channel " + ToString(ChannelNr));
55     Parameters["IS_MIX_CHANNEL"] = new ParameterIsMixChannel(false);
56 schoenebeck 200
57     Clear();
58     }
59    
60     /**
61     * Create channel with external (already existing) audio buffer.
62     *
63 schoenebeck 226 * @param ChannelNr - channel number of this new channel
64 schoenebeck 200 * @param pBuffer - external audio buffer
65 schoenebeck 1424 * @param BufferSize - size of the external buffer
66 schoenebeck 200 */
67 schoenebeck 226 AudioChannel::AudioChannel(uint ChannelNr, float* pBuffer, uint BufferSize) {
68     this->ChannelNr = ChannelNr;
69 schoenebeck 200 this->pBuffer = pBuffer;
70     this->uiBufferSize = BufferSize;
71     this->pMixChannel = NULL;
72     this->UsesExternalBuffer = true;
73    
74 schoenebeck 226 Parameters["NAME"] = new ParameterName("Channel " + ToString(ChannelNr));
75     Parameters["IS_MIX_CHANNEL"] = new ParameterIsMixChannel(false);
76 schoenebeck 200
77     Clear();
78     }
79    
80     /**
81     * Create mix channel.
82     *
83 schoenebeck 226 * @param ChannelNr - channel number of this new channel
84     * @param pMixChannelDestination - a real audio channel this new mix
85     * channel refers to
86 schoenebeck 200 */
87 schoenebeck 226 AudioChannel::AudioChannel(uint ChannelNr, AudioChannel* pMixChannelDestination) {
88     this->ChannelNr = ChannelNr;
89 senkov 331 this->pBuffer = pMixChannelDestination->Buffer();
90     this->uiBufferSize = pMixChannelDestination->uiBufferSize;
91     this->pMixChannel = pMixChannelDestination;
92 schoenebeck 200 this->UsesExternalBuffer = true;
93    
94 schoenebeck 226 Parameters["NAME"] = new ParameterName("Channel " + ToString(ChannelNr));
95     Parameters["IS_MIX_CHANNEL"] = new ParameterIsMixChannel(true);
96     //TODO: Parameters["MIX_CHANNEL_DESTINATION"] = new ParameterMixChannelDestination(dest_chan);
97 schoenebeck 200
98     Clear();
99     }
100    
101     /**
102     * Destructor
103     */
104     AudioChannel::~AudioChannel() {
105 schoenebeck 226 std::map<String,DeviceRuntimeParameter*>::iterator iter = Parameters.begin();
106     while (iter != Parameters.end()) { delete iter->second; iter++; }
107 schoenebeck 319 if (!UsesExternalBuffer) free(pBuffer);
108 schoenebeck 200 }
109    
110 schoenebeck 1001 /**
111     * Copies audio data (unmodified) from this AudioChannel to the given
112     * destination AudioChannel.
113     *
114 schoenebeck 1037 * @e Caution: This method will overwrite the content in the destination
115     * channel buffer.
116     *
117 schoenebeck 1001 * @param pDst - destination channel
118     * @param Samples - amount of sample points to be copied
119     */
120     void AudioChannel::CopyTo(AudioChannel* pDst, const uint Samples) {
121 schoenebeck 1004 memcpy(pDst->Buffer(), Buffer(), Samples * sizeof(float));
122 schoenebeck 1001 }
123    
124     /**
125     * Copies audio data from this AudioChannel to the given destination
126     * AudioChannel and applies the given volume coefficient to the
127     * destination audio signal.
128     *
129 schoenebeck 1037 * @e Caution: This method will overwrite the content in the destination
130     * channel buffer.
131     *
132 schoenebeck 1001 * @param pDst - destination channel
133     * @param Samples - amount of sample points to be copied
134     * @param fLevel - volume coefficient to be applied
135     */
136     void AudioChannel::CopyTo(AudioChannel* pDst, const uint Samples, const float fLevel) {
137     if (fLevel == 1.0f) CopyTo(pDst, Samples);
138     else {
139     float* pSrcBuf = Buffer();
140     float* pDstBuf = pDst->Buffer();
141     for (int i = 0; i < Samples; i++)
142     pDstBuf[i] = pSrcBuf[i] * fLevel;
143     }
144     }
145    
146 schoenebeck 1037 /**
147     * Copies audio data (unmodified) from this AudioChannel and mixes it to the
148     * given destination AudioChannel.
149     *
150     * @param pDst - destination channel
151     * @param Samples - amount of sample points to be mixed over
152     */
153     void AudioChannel::MixTo(AudioChannel* pDst, const uint Samples) {
154     //TODO: there's probably a more efficient way to do this ...
155     float* pSrcBuf = Buffer();
156     float* pDstBuf = pDst->Buffer();
157     for (int i = 0; i < Samples; i++)
158     pDstBuf[i] += pSrcBuf[i];
159     }
160    
161     /**
162     * Copies audio data from this AudioChannel, applies the given volume
163     * coefficient to the audio signal and mixes it to the given destination
164     * channel.
165     *
166     * @param pDst - destination channel
167     * @param Samples - amount of sample points to be mixed over
168     * @param fLevel - volume coefficient to be applied
169     */
170     void AudioChannel::MixTo(AudioChannel* pDst, const uint Samples, const float fLevel) {
171     if (fLevel == 1.0f) MixTo(pDst, Samples);
172     else {
173     float* pSrcBuf = Buffer();
174     float* pDstBuf = pDst->Buffer();
175     for (int i = 0; i < Samples; i++)
176     pDstBuf[i] += pSrcBuf[i] * fLevel;
177     }
178     }
179    
180 schoenebeck 200 std::map<String,DeviceRuntimeParameter*> AudioChannel::ChannelParameters() {
181 schoenebeck 226 return Parameters;
182 schoenebeck 200 }
183     }

  ViewVC Help
Powered by ViewVC