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-2009 Christian Schoenebeck * |
* Copyright (C) 2005-2008 Christian Schoenebeck * |
7 |
* Copyright (C) 2009 Grigor Iliev * |
* Copyright (C) 2009-2011 Christian Schoenebeck and Grigor Iliev * |
8 |
|
* Copyright (C) 2012-2016 Christian Schoenebeck * |
9 |
* * |
* * |
10 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
11 |
* 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 * |
36 |
D* pDiskThread; ///< Pointer to the disk thread, to be able to order a disk stream and later to delete the stream again |
D* pDiskThread; ///< Pointer to the disk thread, to be able to order a disk stream and later to delete the stream again |
37 |
int RealSampleWordsLeftToRead; ///< Number of samples left to read, not including the silence added for the interpolator |
int RealSampleWordsLeftToRead; ///< Number of samples left to read, not including the silence added for the interpolator |
38 |
|
|
39 |
VoiceBase() { |
VoiceBase(SignalUnitRack* pRack = NULL): AbstractVoice(pRack) { |
40 |
pRegion = NULL; |
pRegion = NULL; |
41 |
pDiskThread = NULL; |
pDiskThread = NULL; |
42 |
} |
} |
80 |
|
|
81 |
virtual int OrderNewStream() { |
virtual int OrderNewStream() { |
82 |
int res = pDiskThread->OrderNewStream ( |
int res = pDiskThread->OrderNewStream ( |
83 |
&DiskStreamRef, pRegion, MaxRAMPos, !RAMLoop |
&DiskStreamRef, pRegion, MaxRAMPos + GetRAMCacheOffset(), !RAMLoop |
84 |
); |
); |
85 |
|
|
86 |
if (res < 0) { |
if (res < 0) { |
91 |
|
|
92 |
return 0; |
return 0; |
93 |
} |
} |
94 |
|
|
95 |
|
/** The offset of the RAM cache from the sample start (in sample units). */ |
96 |
|
virtual int GetRAMCacheOffset() { return 0; } |
97 |
|
|
98 |
/** |
/** |
99 |
* Renders the audio data for this voice for the current audio fragment. |
* Renders the audio data for this voice for the current audio fragment. |
125 |
if (DiskVoice) { |
if (DiskVoice) { |
126 |
// check if we reached the allowed limit of the sample RAM cache |
// check if we reached the allowed limit of the sample RAM cache |
127 |
if (finalSynthesisParameters.dPos > MaxRAMPos) { |
if (finalSynthesisParameters.dPos > MaxRAMPos) { |
128 |
dmsg(5,("Voice: switching to disk playback (Pos=%f)\n", finalSynthesisParameters.dPos)); |
dmsg(5,("VoiceBase: switching to disk playback (Pos=%f)\n", finalSynthesisParameters.dPos)); |
129 |
this->PlaybackState = Voice::playback_state_disk; |
this->PlaybackState = Voice::playback_state_disk; |
130 |
} |
} |
131 |
} else if (finalSynthesisParameters.dPos >= pSample->GetCache().Size / SmplInfo.FrameSize) { |
} else if (finalSynthesisParameters.dPos >= pSample->GetCache().Size / SmplInfo.FrameSize) { |
139 |
// check if the disk thread created our ordered disk stream in the meantime |
// check if the disk thread created our ordered disk stream in the meantime |
140 |
DiskStreamRef.pStream = pDiskThread->AskForCreatedStream(DiskStreamRef.OrderID); |
DiskStreamRef.pStream = pDiskThread->AskForCreatedStream(DiskStreamRef.OrderID); |
141 |
if (!DiskStreamRef.pStream) { |
if (!DiskStreamRef.pStream) { |
142 |
std::cout << stderr << "Disk stream not available in time!" << std::endl << std::flush; |
std::cerr << "Disk stream not available in time!\n" << std::flush; |
143 |
KillImmediately(); |
KillImmediately(); |
144 |
return; |
return; |
145 |
} |
} |
146 |
DiskStreamRef.pStream->IncrementReadPos(SmplInfo.ChannelCount * (int(finalSynthesisParameters.dPos) - MaxRAMPos)); |
DiskStreamRef.pStream->IncrementReadPos(uint( |
147 |
|
SmplInfo.ChannelCount * (int(finalSynthesisParameters.dPos) - MaxRAMPos) |
148 |
|
)); |
149 |
finalSynthesisParameters.dPos -= int(finalSynthesisParameters.dPos); |
finalSynthesisParameters.dPos -= int(finalSynthesisParameters.dPos); |
150 |
RealSampleWordsLeftToRead = -1; // -1 means no silence has been added yet |
RealSampleWordsLeftToRead = -1; // -1 means no silence has been added yet |
151 |
} |
} |
181 |
break; |
break; |
182 |
|
|
183 |
case Voice::playback_state_end: |
case Voice::playback_state_end: |
184 |
std::cerr << "gig::Voice::Render(): entered with playback_state_end, this is a bug!\n" << std::flush; |
std::cerr << "VoiceBase::Render(): entered with playback_state_end, this is a bug!\n" << std::flush; |
185 |
break; |
break; |
186 |
} |
} |
187 |
|
|
191 |
itTriggerEvent = Pool<Event>::Iterator(); |
itTriggerEvent = Pool<Event>::Iterator(); |
192 |
|
|
193 |
// If sample stream or release stage finished, kill the voice |
// If sample stream or release stage finished, kill the voice |
194 |
if ( |
if (PlaybackState == Voice::playback_state_end || EG1Finished()) { |
195 |
PlaybackState == Voice::playback_state_end || |
KillImmediately(); |
196 |
EG1.getSegmentType() == gig::EGADSR::segment_end |
} |
|
) KillImmediately(); |
|
197 |
} |
} |
198 |
|
|
199 |
/** |
/** |
232 |
S* pSample; ///< Pointer to the sample to be played back |
S* pSample; ///< Pointer to the sample to be played back |
233 |
R* pRegion; ///< Pointer to the articulation information of current region of this voice |
R* pRegion; ///< Pointer to the articulation information of current region of this voice |
234 |
|
|
235 |
|
virtual MidiKeyBase* GetMidiKeyInfo(int MIDIKey) { |
236 |
|
EC* pChannel = static_cast<EC*>(pEngineChannel); |
237 |
|
return &pChannel->pMIDIKeyInfo[MIDIKey]; |
238 |
|
} |
239 |
|
|
240 |
virtual unsigned long GetNoteOnTime(int MIDIKey) { |
virtual unsigned long GetNoteOnTime(int MIDIKey) { |
241 |
EC* pChannel = static_cast<EC*>(pEngineChannel); |
EC* pChannel = static_cast<EC*>(pEngineChannel); |
242 |
return pChannel->pMIDIKeyInfo[MIDIKey].NoteOnTime; |
return pChannel->pMIDIKeyInfo[MIDIKey].NoteOnTime; |