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, 2006 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 * |
23 |
|
|
24 |
#include "AudioChannel.h" |
#include "AudioChannel.h" |
25 |
|
|
26 |
|
#if defined(__APPLE__) |
27 |
|
# include <stdlib.h> |
28 |
|
#else |
29 |
|
# include <malloc.h> |
30 |
|
#endif |
31 |
|
|
32 |
|
|
33 |
namespace LinuxSampler { |
namespace LinuxSampler { |
34 |
|
|
35 |
/** |
/** |
36 |
* Create real channel. |
* Create real channel. |
37 |
* |
* |
38 |
|
* @param ChannelNr - channel number of this new channel |
39 |
* @param BufferSize - desired audio data buffer size |
* @param BufferSize - desired audio data buffer size |
|
* @param Name - arbitrary name for this channel (optional) |
|
40 |
*/ |
*/ |
41 |
AudioChannel::AudioChannel(uint BufferSize, String Name, std::map<String,DeviceRuntimeParameter*> ChannelParameters) { |
AudioChannel::AudioChannel(uint ChannelNr, uint BufferSize) { |
42 |
this->pBuffer = new float[BufferSize]; |
this->ChannelNr = ChannelNr; |
43 |
|
#if defined(__APPLE__) |
44 |
|
this->pBuffer = (float *) malloc(BufferSize*sizeof(float)); |
45 |
|
#else |
46 |
|
this->pBuffer = (float *) memalign(16,BufferSize*sizeof(float)); |
47 |
|
#endif |
48 |
this->uiBufferSize = BufferSize; |
this->uiBufferSize = BufferSize; |
49 |
this->pMixChannel = NULL; |
this->pMixChannel = NULL; |
50 |
this->UsesExternalBuffer = false; |
this->UsesExternalBuffer = false; |
51 |
|
|
52 |
if (!ChannelParameters["Name"]) ChannelParameters["Name"] = new ParameterName(Name); |
Parameters["NAME"] = new ParameterName("Channel " + ToString(ChannelNr)); |
53 |
if (!ChannelParameters["IS_MIX_CHANNEL"]) ChannelParameters["IS_MIX_CHANNEL"] = new ParameterIsMixChannel(false); |
Parameters["IS_MIX_CHANNEL"] = new ParameterIsMixChannel(false); |
|
this->mParameters = ChannelParameters; |
|
54 |
|
|
55 |
Clear(); |
Clear(); |
56 |
} |
} |
58 |
/** |
/** |
59 |
* Create channel with external (already existing) audio buffer. |
* Create channel with external (already existing) audio buffer. |
60 |
* |
* |
61 |
|
* @param ChannelNr - channel number of this new channel |
62 |
* @param pBuffer - external audio buffer |
* @param pBuffer - external audio buffer |
63 |
* @param BufferSIze - size of the external buffer |
* @param BufferSIze - size of the external buffer |
|
* @param Name - arbitrary name for this channel (optional) |
|
64 |
*/ |
*/ |
65 |
AudioChannel::AudioChannel(float* pBuffer, uint BufferSize, String Name, std::map<String,DeviceRuntimeParameter*> ChannelParameters) { |
AudioChannel::AudioChannel(uint ChannelNr, float* pBuffer, uint BufferSize) { |
66 |
|
this->ChannelNr = ChannelNr; |
67 |
this->pBuffer = pBuffer; |
this->pBuffer = pBuffer; |
68 |
this->uiBufferSize = BufferSize; |
this->uiBufferSize = BufferSize; |
69 |
this->pMixChannel = NULL; |
this->pMixChannel = NULL; |
70 |
this->UsesExternalBuffer = true; |
this->UsesExternalBuffer = true; |
71 |
|
|
72 |
if (!ChannelParameters["Name"]) ChannelParameters["Name"] = new ParameterName(Name); |
Parameters["NAME"] = new ParameterName("Channel " + ToString(ChannelNr)); |
73 |
if (!ChannelParameters["IS_MIX_CHANNEL"]) ChannelParameters["IS_MIX_CHANNEL"] = new ParameterIsMixChannel(false); |
Parameters["IS_MIX_CHANNEL"] = new ParameterIsMixChannel(false); |
74 |
|
|
75 |
Clear(); |
Clear(); |
76 |
} |
} |
78 |
/** |
/** |
79 |
* Create mix channel. |
* Create mix channel. |
80 |
* |
* |
81 |
* @param pMixChannel - the real channel this new mix channel refers to |
* @param ChannelNr - channel number of this new channel |
82 |
* @param Name - arbitrary name for this channel (optional) |
* @param pMixChannelDestination - a real audio channel this new mix |
83 |
|
* channel refers to |
84 |
*/ |
*/ |
85 |
AudioChannel::AudioChannel(AudioChannel* pMixChannel, String Name, std::map<String,DeviceRuntimeParameter*> ChannelParameters) { |
AudioChannel::AudioChannel(uint ChannelNr, AudioChannel* pMixChannelDestination) { |
86 |
this->pBuffer = pMixChannel->Buffer(); |
this->ChannelNr = ChannelNr; |
87 |
this->uiBufferSize = pMixChannel->uiBufferSize; |
this->pBuffer = pMixChannelDestination->Buffer(); |
88 |
this->pMixChannel = pMixChannel; |
this->uiBufferSize = pMixChannelDestination->uiBufferSize; |
89 |
|
this->pMixChannel = pMixChannelDestination; |
90 |
this->UsesExternalBuffer = true; |
this->UsesExternalBuffer = true; |
91 |
|
|
92 |
if (!ChannelParameters["Name"]) ChannelParameters["Name"] = new ParameterName(Name); |
Parameters["NAME"] = new ParameterName("Channel " + ToString(ChannelNr)); |
93 |
if (!ChannelParameters["IS_MIX_CHANNEL"]) ChannelParameters["IS_MIX_CHANNEL"] = new ParameterIsMixChannel(true); |
Parameters["IS_MIX_CHANNEL"] = new ParameterIsMixChannel(true); |
94 |
//TODO: if (!ChannelParameters["MIX_CHANNEL_DESTINATION"]) ChannelParameters["MIX_CHANNEL_DESTINATION"] = new ParameterMixChannelDestination(dest_chan); |
//TODO: Parameters["MIX_CHANNEL_DESTINATION"] = new ParameterMixChannelDestination(dest_chan); |
95 |
|
|
96 |
Clear(); |
Clear(); |
97 |
} |
} |
100 |
* Destructor |
* Destructor |
101 |
*/ |
*/ |
102 |
AudioChannel::~AudioChannel() { |
AudioChannel::~AudioChannel() { |
103 |
std::map<String,DeviceRuntimeParameter*>::iterator iter = mParameters.begin(); |
std::map<String,DeviceRuntimeParameter*>::iterator iter = Parameters.begin(); |
104 |
while (iter != mParameters.end()) { delete iter->second; iter++; } |
while (iter != Parameters.end()) { delete iter->second; iter++; } |
105 |
if (!UsesExternalBuffer) delete[] pBuffer; |
if (!UsesExternalBuffer) free(pBuffer); |
106 |
|
} |
107 |
|
|
108 |
|
/** |
109 |
|
* Copies audio data (unmodified) from this AudioChannel to the given |
110 |
|
* destination AudioChannel. |
111 |
|
* |
112 |
|
* @param pDst - destination channel |
113 |
|
* @param Samples - amount of sample points to be copied |
114 |
|
*/ |
115 |
|
void AudioChannel::CopyTo(AudioChannel* pDst, const uint Samples) { |
116 |
|
memcpy(pDst->Buffer(), Buffer(), Samples * sizeof(float)); |
117 |
|
} |
118 |
|
|
119 |
|
/** |
120 |
|
* Copies audio data from this AudioChannel to the given destination |
121 |
|
* AudioChannel and applies the given volume coefficient to the |
122 |
|
* destination audio signal. |
123 |
|
* |
124 |
|
* @param pDst - destination channel |
125 |
|
* @param Samples - amount of sample points to be copied |
126 |
|
* @param fLevel - volume coefficient to be applied |
127 |
|
*/ |
128 |
|
void AudioChannel::CopyTo(AudioChannel* pDst, const uint Samples, const float fLevel) { |
129 |
|
if (fLevel == 1.0f) CopyTo(pDst, Samples); |
130 |
|
else { |
131 |
|
float* pSrcBuf = Buffer(); |
132 |
|
float* pDstBuf = pDst->Buffer(); |
133 |
|
for (int i = 0; i < Samples; i++) |
134 |
|
pDstBuf[i] = pSrcBuf[i] * fLevel; |
135 |
|
} |
136 |
} |
} |
137 |
|
|
138 |
std::map<String,DeviceRuntimeParameter*> AudioChannel::ChannelParameters() { |
std::map<String,DeviceRuntimeParameter*> AudioChannel::ChannelParameters() { |
139 |
return mParameters; |
return Parameters; |
140 |
} |
} |
141 |
} |
} |