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-2008 Christian Schoenebeck * |
* Copyright (C) 2005-2009 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 * |
107 |
pSysexBuffer = new RingBuffer<uint8_t,false>(CONFIG_SYSEX_BUFFER_SIZE, 0); |
pSysexBuffer = new RingBuffer<uint8_t,false>(CONFIG_SYSEX_BUFFER_SIZE, 0); |
108 |
pEventQueue = new RingBuffer<Event,false>(CONFIG_MAX_EVENTS_PER_FRAGMENT, 0); |
pEventQueue = new RingBuffer<Event,false>(CONFIG_MAX_EVENTS_PER_FRAGMENT, 0); |
109 |
pEventPool = new Pool<Event>(CONFIG_MAX_EVENTS_PER_FRAGMENT); |
pEventPool = new Pool<Event>(CONFIG_MAX_EVENTS_PER_FRAGMENT); |
110 |
pVoicePool = new Pool<Voice>(CONFIG_MAX_VOICES); |
pVoicePool = new Pool<Voice>(GLOBAL_MAX_VOICES); |
111 |
pDimRegionPool[0] = new Pool< ::gig::DimensionRegion*>(CONFIG_MAX_VOICES); |
pDimRegionPool[0] = new Pool< ::gig::DimensionRegion*>(GLOBAL_MAX_VOICES); |
112 |
pDimRegionPool[1] = new Pool< ::gig::DimensionRegion*>(CONFIG_MAX_VOICES); |
pDimRegionPool[1] = new Pool< ::gig::DimensionRegion*>(GLOBAL_MAX_VOICES); |
113 |
pVoiceStealingQueue = new RTList<Event>(pEventPool); |
pVoiceStealingQueue = new RTList<Event>(pEventPool); |
114 |
pGlobalEvents = new RTList<Event>(pEventPool); |
pGlobalEvents = new RTList<Event>(pEventPool); |
115 |
|
iMaxDiskStreams = GLOBAL_MAX_STREAMS; |
116 |
|
|
117 |
for (RTList<Voice>::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) { |
for (RTList<Voice>::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) { |
118 |
iterVoice->SetEngine(this); |
iterVoice->SetEngine(this); |
343 |
* @param pAudioOut - audio output device to connect to |
* @param pAudioOut - audio output device to connect to |
344 |
*/ |
*/ |
345 |
void Engine::Connect(AudioOutputDevice* pAudioOut) { |
void Engine::Connect(AudioOutputDevice* pAudioOut) { |
346 |
|
// caution: don't ignore if connecting to the same device here, |
347 |
|
// because otherwise SetMaxDiskStreams() implementation won't work anymore! |
348 |
|
|
349 |
pAudioOutputDevice = pAudioOut; |
pAudioOutputDevice = pAudioOut; |
350 |
|
|
351 |
ResetInternal(); |
ResetInternal(); |
384 |
delete this->pDiskThread; |
delete this->pDiskThread; |
385 |
dmsg(1,("OK\n")); |
dmsg(1,("OK\n")); |
386 |
} |
} |
387 |
this->pDiskThread = new DiskThread(((pAudioOut->MaxSamplesPerCycle() << CONFIG_MAX_PITCH) << 1) + 6, //FIXME: assuming stereo |
this->pDiskThread = |
388 |
&instruments); |
new DiskThread( |
389 |
|
iMaxDiskStreams, |
390 |
|
((pAudioOut->MaxSamplesPerCycle() << CONFIG_MAX_PITCH) << 1) + 6, //FIXME: assuming stereo |
391 |
|
&instruments |
392 |
|
); |
393 |
|
|
394 |
if (!pDiskThread) { |
if (!pDiskThread) { |
395 |
dmsg(0,("gig::Engine new diskthread = NULL\n")); |
dmsg(0,("gig::Engine new diskthread = NULL\n")); |
396 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
416 |
exit(EXIT_FAILURE); |
exit(EXIT_FAILURE); |
417 |
} |
} |
418 |
} |
} |
419 |
|
pVoicePool->clear(); |
420 |
} |
} |
421 |
|
|
422 |
/** |
/** |
594 |
// update time of start and end of this audio fragment (as events' time stamps relate to this) |
// update time of start and end of this audio fragment (as events' time stamps relate to this) |
595 |
pEventGenerator->UpdateFragmentTime(Samples); |
pEventGenerator->UpdateFragmentTime(Samples); |
596 |
|
|
597 |
// We only allow a maximum of CONFIG_MAX_VOICES voices to be spawned |
// We only allow the given maximum number of voices to be spawned |
598 |
// in each audio fragment. All subsequent request for spawning new |
// in each audio fragment. All subsequent request for spawning new |
599 |
// voices in the same audio fragment will be ignored. |
// voices in the same audio fragment will be ignored. |
600 |
VoiceSpawnsLeft = CONFIG_MAX_VOICES; |
VoiceSpawnsLeft = MaxVoices(); |
601 |
|
|
602 |
// get all events from the engine's global input event queue which belong to the current fragment |
// get all events from the engine's global input event queue which belong to the current fragment |
603 |
// (these are usually just SysEx messages) |
// (these are usually just SysEx messages) |
1957 |
if (reader.read(&addr[0], 3) != 3) goto free_sysex_data; |
if (reader.read(&addr[0], 3) != 3) goto free_sysex_data; |
1958 |
if (addr[0] == 0x40 && addr[1] == 0x00) { // System Parameters |
if (addr[0] == 0x40 && addr[1] == 0x00) { // System Parameters |
1959 |
dmsg(3,("\tSystem Parameter\n")); |
dmsg(3,("\tSystem Parameter\n")); |
1960 |
|
if (addr[2] == 0x7f) { // GS reset |
1961 |
|
for (int i = 0; i < engineChannels.size(); ++i) { |
1962 |
|
EngineChannel* pEngineChannel = engineChannels[i]; |
1963 |
|
if (pEngineChannel->GetMidiInputPort() == itSysexEvent->pMidiInputPort) { |
1964 |
|
KillAllVoices(pEngineChannel, itSysexEvent); |
1965 |
|
pEngineChannel->ResetControllers(); |
1966 |
|
} |
1967 |
|
} |
1968 |
|
} |
1969 |
} |
} |
1970 |
else if (addr[0] == 0x40 && addr[1] == 0x01) { // Common Parameters |
else if (addr[0] == 0x40 && addr[1] == 0x01) { // Common Parameters |
1971 |
dmsg(3,("\tCommon Parameter\n")); |
dmsg(3,("\tCommon Parameter\n")); |
2130 |
return ActiveVoiceCountMax; |
return ActiveVoiceCountMax; |
2131 |
} |
} |
2132 |
|
|
2133 |
|
int Engine::MaxVoices() { |
2134 |
|
return pVoicePool->poolSize(); |
2135 |
|
} |
2136 |
|
|
2137 |
|
void Engine::SetMaxVoices(int iVoices) throw (Exception) { |
2138 |
|
if (iVoices < 1) |
2139 |
|
throw Exception("Maximum voices for an engine cannot be set lower than 1"); |
2140 |
|
|
2141 |
|
SuspendAll(); |
2142 |
|
|
2143 |
|
// NOTE: we need to clear pDimRegionsInUse before deleting pDimRegionPool, |
2144 |
|
// otherwise memory corruption will occur if there are active voices (see bug #118) |
2145 |
|
for (int iChannel = 0; iChannel < engineChannels.size(); iChannel++) { |
2146 |
|
engineChannels[iChannel]->ClearDimRegionsInUse(); |
2147 |
|
} |
2148 |
|
|
2149 |
|
if (pDimRegionPool[0]) delete pDimRegionPool[0]; |
2150 |
|
if (pDimRegionPool[1]) delete pDimRegionPool[1]; |
2151 |
|
|
2152 |
|
pDimRegionPool[0] = new Pool< ::gig::DimensionRegion*>(iVoices); |
2153 |
|
pDimRegionPool[1] = new Pool< ::gig::DimensionRegion*>(iVoices); |
2154 |
|
|
2155 |
|
for (int iChannel = 0; iChannel < engineChannels.size(); iChannel++) { |
2156 |
|
engineChannels[iChannel]->ResetDimRegionsInUse(); |
2157 |
|
} |
2158 |
|
|
2159 |
|
try { |
2160 |
|
pVoicePool->resizePool(iVoices); |
2161 |
|
} catch (...) { |
2162 |
|
throw Exception("FATAL: Could not resize voice pool!"); |
2163 |
|
} |
2164 |
|
|
2165 |
|
for (RTList<Voice>::Iterator iterVoice = pVoicePool->allocAppend(); iterVoice == pVoicePool->last(); iterVoice = pVoicePool->allocAppend()) { |
2166 |
|
iterVoice->SetEngine(this); |
2167 |
|
iterVoice->pDiskThread = this->pDiskThread; |
2168 |
|
} |
2169 |
|
pVoicePool->clear(); |
2170 |
|
|
2171 |
|
ResumeAll(); |
2172 |
|
} |
2173 |
|
|
2174 |
bool Engine::DiskStreamSupported() { |
bool Engine::DiskStreamSupported() { |
2175 |
return true; |
return true; |
2176 |
} |
} |
2183 |
return (pDiskThread) ? pDiskThread->ActiveStreamCountMax : 0; |
return (pDiskThread) ? pDiskThread->ActiveStreamCountMax : 0; |
2184 |
} |
} |
2185 |
|
|
2186 |
|
int Engine::MaxDiskStreams() { |
2187 |
|
return iMaxDiskStreams; |
2188 |
|
} |
2189 |
|
|
2190 |
|
void Engine::SetMaxDiskStreams(int iStreams) throw (Exception) { |
2191 |
|
if (iStreams < 0) |
2192 |
|
throw Exception("Maximum disk streams for an engine cannot be set lower than 0"); |
2193 |
|
|
2194 |
|
SuspendAll(); |
2195 |
|
|
2196 |
|
iMaxDiskStreams = iStreams; |
2197 |
|
|
2198 |
|
// reconnect to audio output device, because that will automatically |
2199 |
|
// recreate the disk thread with the required amount of streams |
2200 |
|
if (pAudioOutputDevice) Connect(pAudioOutputDevice); |
2201 |
|
|
2202 |
|
ResumeAll(); |
2203 |
|
} |
2204 |
|
|
2205 |
String Engine::DiskStreamBufferFillBytes() { |
String Engine::DiskStreamBufferFillBytes() { |
2206 |
return pDiskThread->GetBufferFillBytes(); |
return pDiskThread->GetBufferFillBytes(); |
2207 |
} |
} |
2219 |
} |
} |
2220 |
|
|
2221 |
String Engine::Version() { |
String Engine::Version() { |
2222 |
String s = "$Revision: 1.98 $"; |
String s = "$Revision: 1.101 $"; |
2223 |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
return s.substr(11, s.size() - 13); // cut dollar signs, spaces and CVS macro keyword |
2224 |
} |
} |
2225 |
|
|