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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 319 by schoenebeck, Mon Dec 13 00:46:42 2004 UTC revision 1913 by senoner, Sun Jun 7 16:24:55 2009 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6     *   Copyright (C) 2005 - 2007 Christian Schoenebeck                       *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   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  *   *   it under the terms of the GNU General Public License as published by  *
# Line 21  Line 22 
22   ***************************************************************************/   ***************************************************************************/
23    
24  #include "AudioChannel.h"  #include "AudioChannel.h"
25  #include <malloc.h>  
26    #include "../../common/global_private.h"
27    #include "../../common/Thread.h" // needed for allocAlignedMem() and freeAlignedMem()
28    
29    #if defined(__APPLE__)
30    # include <stdlib.h>
31    #else
32    # include <malloc.h>
33    #endif
34    
35    
36  namespace LinuxSampler {  namespace LinuxSampler {
37    
# Line 33  namespace LinuxSampler { Line 43  namespace LinuxSampler {
43       */       */
44      AudioChannel::AudioChannel(uint ChannelNr, uint BufferSize) {      AudioChannel::AudioChannel(uint ChannelNr, uint BufferSize) {
45          this->ChannelNr          = ChannelNr;          this->ChannelNr          = ChannelNr;
46          this->pBuffer            = (float *) memalign(16,BufferSize*sizeof(float));          this->pBuffer            = (float *) Thread::allocAlignedMem(16,BufferSize*sizeof(float));
47          this->uiBufferSize       = BufferSize;          this->uiBufferSize       = BufferSize;
48          this->pMixChannel        = NULL;          this->pMixChannel        = NULL;
49          this->UsesExternalBuffer = false;          this->UsesExternalBuffer = false;
# Line 49  namespace LinuxSampler { Line 59  namespace LinuxSampler {
59       *       *
60       * @param ChannelNr  - channel number of this new channel       * @param ChannelNr  - channel number of this new channel
61       * @param pBuffer    - external audio buffer       * @param pBuffer    - external audio buffer
62       * @param BufferSIze - size of the external buffer       * @param BufferSize - size of the external buffer
63       */       */
64      AudioChannel::AudioChannel(uint ChannelNr, float* pBuffer, uint BufferSize) {      AudioChannel::AudioChannel(uint ChannelNr, float* pBuffer, uint BufferSize) {
65          this->ChannelNr          = ChannelNr;          this->ChannelNr          = ChannelNr;
# Line 73  namespace LinuxSampler { Line 83  namespace LinuxSampler {
83       */       */
84      AudioChannel::AudioChannel(uint ChannelNr, AudioChannel* pMixChannelDestination) {      AudioChannel::AudioChannel(uint ChannelNr, AudioChannel* pMixChannelDestination) {
85          this->ChannelNr          = ChannelNr;          this->ChannelNr          = ChannelNr;
86          this->pBuffer            = pMixChannel->Buffer();          this->pBuffer            = pMixChannelDestination->Buffer();
87          this->uiBufferSize       = pMixChannel->uiBufferSize;          this->uiBufferSize       = pMixChannelDestination->uiBufferSize;
88          this->pMixChannel        = pMixChannel;          this->pMixChannel        = pMixChannelDestination;
89          this->UsesExternalBuffer = true;          this->UsesExternalBuffer = true;
90    
91          Parameters["NAME"]           = new ParameterName("Channel " + ToString(ChannelNr));          Parameters["NAME"]           = new ParameterName("Channel " + ToString(ChannelNr));
# Line 91  namespace LinuxSampler { Line 101  namespace LinuxSampler {
101      AudioChannel::~AudioChannel() {      AudioChannel::~AudioChannel() {
102          std::map<String,DeviceRuntimeParameter*>::iterator iter = Parameters.begin();          std::map<String,DeviceRuntimeParameter*>::iterator iter = Parameters.begin();
103          while (iter != Parameters.end()) { delete iter->second; iter++; }          while (iter != Parameters.end()) { delete iter->second; iter++; }
104          if (!UsesExternalBuffer) free(pBuffer);          if (!UsesExternalBuffer) Thread::freeAlignedMem(pBuffer);
105        }
106    
107        /**
108         * Copies audio data (unmodified) from this AudioChannel to the given
109         * destination AudioChannel.
110         *
111         * @e Caution: This method will overwrite the content in the destination
112         * channel buffer.
113         *
114         * @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            memcpy(pDst->Buffer(), Buffer(), Samples * sizeof(float));
119        }
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         * @e Caution: This method will overwrite the content in the destination
127         * channel buffer.
128         *
129         * @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                    #ifndef HAVE_GCC_VECTOR_EXTENSIONS
137                float* pSrcBuf = Buffer();
138                float* pDstBuf = pDst->Buffer();
139                for (int i = 0; i < Samples; i++)
140                    pDstBuf[i] = pSrcBuf[i] * fLevel;
141                    #else
142                    const v4sf vcoeff = { fLevel, fLevel, fLevel, fLevel };
143            const v4sf* src = static_cast<v4sf*>((void*)Buffer());
144            v4sf* dst       = static_cast<v4sf*>((void*)pDst->Buffer());
145            const int cells = Samples / 4;
146            for (int i = 0; i < cells; ++i)
147                dst[i] = src[i] * vcoeff;
148                    #endif
149            }
150        }
151    
152        /**
153         * Copies audio data (unmodified) from this AudioChannel and mixes it to the
154         * given destination AudioChannel.
155         *
156         * @param pDst    - destination channel
157         * @param Samples - amount of sample points to be mixed over
158         */
159        void AudioChannel::MixTo(AudioChannel* pDst, const uint Samples) {
160                    #ifndef HAVE_GCC_VECTOR_EXTENSIONS
161            float* pSrcBuf = Buffer();
162            float* pDstBuf = pDst->Buffer();
163            for (int i = 0; i < Samples; i++)
164                pDstBuf[i] += pSrcBuf[i];
165                    #else
166                    const v4sf* src = static_cast<v4sf*>((void*)Buffer());
167            v4sf* dst       = static_cast<v4sf*>((void*)pDst->Buffer());
168            const int cells = Samples / 4;
169            for (int i = 0; i < cells; ++i)
170                dst[i] += src[i];
171                    #endif
172        }
173    
174        /**
175         * Copies audio data from this AudioChannel, applies the given volume
176         * coefficient to the audio signal and mixes it to the given destination
177         * channel.
178         *
179         * @param pDst    - destination channel
180         * @param Samples - amount of sample points to be mixed over
181         * @param fLevel  - volume coefficient to be applied
182         */
183        void AudioChannel::MixTo(AudioChannel* pDst, const uint Samples, const float fLevel) {
184            if (fLevel == 1.0f) MixTo(pDst, Samples);
185            else {
186                        #ifndef HAVE_GCC_VECTOR_EXTENSIONS
187                float* pSrcBuf = Buffer();
188                float* pDstBuf = pDst->Buffer();
189                for (int i = 0; i < Samples; i++)
190                    pDstBuf[i] += pSrcBuf[i] * fLevel;
191                        #else
192                            const v4sf vcoeff = { fLevel, fLevel, fLevel, fLevel };
193                const v4sf* src = static_cast<v4sf*>((void*)Buffer());
194                v4sf* dst       = static_cast<v4sf*>((void*)pDst->Buffer());
195                const int cells = Samples / 4;
196                for (int i = 0; i < cells; ++i)
197                    dst[i] += src[i] * vcoeff;
198                            #endif
199            }
200      }      }
201    
202      std::map<String,DeviceRuntimeParameter*> AudioChannel::ChannelParameters() {      std::map<String,DeviceRuntimeParameter*> AudioChannel::ChannelParameters() {

Legend:
Removed from v.319  
changed lines
  Added in v.1913

  ViewVC Help
Powered by ViewVC