/[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 1481 - (hide annotations) (download)
Wed Nov 14 23:42:15 2007 UTC (16 years, 5 months ago) by senoner
File size: 7325 byte(s)
* win32 port work in progress:
* - implemented win32 support in the following classes:
* Thread, Condition, Mutex, Path, LscpServer
* - lscp.y use DONTCARE instead of VOID
*  (a win32 symbol defined)
* - completed win32 editor plugin loader

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

  ViewVC Help
Powered by ViewVC