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

  ViewVC Help
Powered by ViewVC