Skip to content

Commit 9b65a03

Browse files
committedSep 17, 2015
Don't use envelope in sampler example
1 parent db22866 commit 9b65a03

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed
 

‎examples/sampler/src/Engine.cpp

+24-20
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static const char* samplerPlugin(bool useDisk)
8484

8585
Engine::Engine(Options inOptions)
8686
: m_engine(nullptr)
87-
, m_useDisk(Methcla::Version::isPro())
87+
, m_useDisk(true)
8888
{
8989
Methcla::EngineOptions options(inOptions.engineOptions);
9090
options.audioDriver.bufferSize = 256;
@@ -148,7 +148,7 @@ void Engine::useDisk(bool flag)
148148
}
149149
}
150150

151-
static Methcla_Time kLatency = 0.001;
151+
static Methcla_Time kLatency = 0.003;
152152

153153
static float mapRate(float value)
154154
{
@@ -174,12 +174,14 @@ void Engine::startVoice(VoiceId voice, size_t soundIndex, float amp, float rate)
174174
const Methcla::SynthId synth = request.synth(
175175
samplerPlugin(m_useDisk),
176176
m_voiceGroup,
177-
{ amp, rate },
177+
{ 1, 48000./44100. },
178178
{ Methcla::Value(sound.path())
179179
, Methcla::Value(false) }
180180
);
181181
request.mapOutput(synth, 0, bus1);
182182
request.mapOutput(synth, 1, bus2);
183+
// request.mapOutput(synth, 0, Methcla::AudioBusId(0), Methcla::kBusMappingExternal);
184+
// request.mapOutput(synth, 1, Methcla::AudioBusId(1), Methcla::kBusMappingExternal);
183185

184186
// Envelope options
185187
const std::list<Methcla::Value> envOptions =
@@ -189,12 +191,14 @@ void Engine::startVoice(VoiceId voice, size_t soundIndex, float amp, float rate)
189191
, Methcla::Value(1.5f)
190192
};
191193

192-
auto envelope1 = request.synth(METHCLA_PLUGINS_ASR_ENVELOPE_URI, m_voiceGroup, {}, envOptions);
194+
// auto envelope1 = request.synth(METHCLA_PLUGINS_ASR_ENVELOPE_URI, m_voiceGroup, {}, envOptions);
195+
auto envelope1 = request.synth(METHCLA_PLUGINS_PATCH_CABLE_URI, m_voiceGroup, {});
193196
request.mapInput(envelope1, 0, bus1);
194197
request.mapOutput(envelope1, 0, Methcla::AudioBusId(0), Methcla::kBusMappingExternal);
195198
request.whenDone(envelope1, Methcla::kNodeDoneFreeSelf|Methcla::kNodeDoneFreePreceeding);
196199

197-
auto envelope2 = request.synth(METHCLA_PLUGINS_ASR_ENVELOPE_URI, m_voiceGroup, {}, envOptions);
200+
// auto envelope2 = request.synth(METHCLA_PLUGINS_ASR_ENVELOPE_URI, m_voiceGroup, {}, envOptions);
201+
auto envelope2 = request.synth(METHCLA_PLUGINS_PATCH_CABLE_URI, m_voiceGroup, {});
198202
request.mapInput(envelope2, 0, bus2);
199203
request.mapOutput(envelope2, 0, Methcla::AudioBusId(1), Methcla::kBusMappingExternal);
200204
request.whenDone(envelope2, Methcla::kNodeDoneFreeSelf);
@@ -207,14 +211,14 @@ void Engine::startVoice(VoiceId voice, size_t soundIndex, float amp, float rate)
207211
request.closeBundle();
208212

209213
m_engine->addNotificationHandler(m_engine->freeNodeIdHandler(synth));
210-
m_engine->addNotificationHandler(m_engine->freeNodeIdHandler(envelope1));
211-
m_engine->addNotificationHandler(m_engine->freeNodeIdHandler(envelope2, [this,bus1,bus2](Methcla::NodeId){
212-
m_engine->audioBusId().free(bus1);
213-
m_engine->audioBusId().free(bus2);
214-
}));
214+
// m_engine->addNotificationHandler(m_engine->freeNodeIdHandler(envelope1));
215+
// m_engine->addNotificationHandler(m_engine->freeNodeIdHandler(envelope2, [this,bus1,bus2](Methcla::NodeId){
216+
// m_engine->audioBusId().free(bus1);
217+
// m_engine->audioBusId().free(bus2);
218+
// }));
215219

216220
request.send();
217-
// m_voices[voice] = synth;
221+
m_voices[voice] = synth;
218222
// std::cout << "Synth " << synth.id()
219223
// << sound.path()
220224
// << " duration=" << sound.duration()
@@ -238,13 +242,13 @@ void Engine::updateVoice(VoiceId voice, float amp, float rate)
238242

239243
void Engine::stopVoice(VoiceId voice)
240244
{
241-
// auto it = m_voices.find(voice);
242-
// if (it != m_voices.end()) {
243-
// Methcla::Request request(engine());
244-
// request.openBundle(engine().currentTime() + kLatency);
245-
// request.free(it->second);
246-
// request.closeBundle();
247-
//// request.send();
248-
// m_voices.erase(it);
249-
// }
245+
auto it = m_voices.find(voice);
246+
if (it != m_voices.end()) {
247+
Methcla::Request request(engine());
248+
request.openBundle(engine().currentTime() + kLatency);
249+
request.free(it->second);
250+
request.closeBundle();
251+
request.send();
252+
m_voices.erase(it);
253+
}
250254
}

0 commit comments

Comments
 (0)
Please sign in to comment.