35 |
} |
} |
36 |
|
|
37 |
void Voice::Trigger(int MIDIKey, uint8_t Velocity, gig::Instrument* Instrument) { |
void Voice::Trigger(int MIDIKey, uint8_t Velocity, gig::Instrument* Instrument) { |
38 |
Active = true; |
Active = true; |
39 |
pRegion = Instrument->GetRegion(MIDIKey); |
this->MIDIKey = MIDIKey; |
40 |
PlaybackState = playback_state_ram; // we always start playback from RAM cache and switch then to disk if needed |
pRegion = Instrument->GetRegion(MIDIKey); |
41 |
Pos = 0; |
PlaybackState = playback_state_ram; // we always start playback from RAM cache and switch then to disk if needed |
42 |
|
Pos = 0; |
43 |
|
ReleaseVelocity = 127; // default release velocity value |
44 |
|
|
45 |
if (!pRegion) { |
if (!pRegion) { |
46 |
std::cerr << "Audio Thread: No Region defined for MIDI key " << MIDIKey << std::endl << std::flush; |
std::cerr << "Audio Thread: No Region defined for MIDI key " << MIDIKey << std::endl << std::flush; |
71 |
if (DiskVoice) { |
if (DiskVoice) { |
72 |
MaxRAMPos = cachedsamples - (OutputBufferSize << MAX_PITCH) / pSample->Channels; |
MaxRAMPos = cachedsamples - (OutputBufferSize << MAX_PITCH) / pSample->Channels; |
73 |
pDiskThread->OrderNewStream(&DiskStreamRef, pSample, MaxRAMPos); |
pDiskThread->OrderNewStream(&DiskStreamRef, pSample, MaxRAMPos); |
74 |
dmsg(("Disk voice launched (cached samples: %d, total Samples: %d, MaxRAMPos: %d\n", cachedsamples, pSample->SamplesTotal, MaxRAMPos)); |
dmsg(5,("Disk voice launched (cached samples: %d, total Samples: %d, MaxRAMPos: %d\n", cachedsamples, pSample->SamplesTotal, MaxRAMPos)); |
75 |
} |
} |
76 |
else { |
else { |
77 |
MaxRAMPos = cachedsamples; |
MaxRAMPos = cachedsamples; |
78 |
dmsg(("RAM only voice launched\n")); |
dmsg(5,("RAM only voice launched\n")); |
79 |
} |
} |
80 |
|
|
81 |
CurrentPitch = pow(2, (double) (MIDIKey - (int) pSample->MIDIUnityNote) / (double) 12); |
CurrentPitch = pow(2, (double) (MIDIKey - (int) pSample->MIDIUnityNote) / (double) 12); |
94 |
if (DiskVoice) { |
if (DiskVoice) { |
95 |
// check if we reached the allowed limit of the sample RAM cache |
// check if we reached the allowed limit of the sample RAM cache |
96 |
if (Pos > MaxRAMPos) { |
if (Pos > MaxRAMPos) { |
97 |
dmsg(("Voice: switching to disk playback (Pos=%f)\n", Pos)); |
dmsg(5,("Voice: switching to disk playback (Pos=%f)\n", Pos)); |
98 |
this->PlaybackState = playback_state_disk; |
this->PlaybackState = playback_state_disk; |
99 |
} |
} |
100 |
} |
} |
132 |
break; |
break; |
133 |
|
|
134 |
case playback_state_end: |
case playback_state_end: |
135 |
this->Active = false; // free voice |
Kill(); // free voice |
136 |
break; |
break; |
137 |
} |
} |
138 |
} |
} |