[Plib-users] Changing the pitch/volume of non-looping sounds
Brought to you by:
sjbaker
From: Christos D. <dim...@id...> - 2003-11-21 13:32:37
|
I have used plib successfully to load and play 8-bit sounds. I have found that looped samples, as in the examples given at the site, have no problem handling envelopes. However, when dealing with one-shot samples, which I play using playSound(), volume/pitch changes using envelopes do not seem to work. I create a new envelope once, and I load the sample once. This is the code that I use: crashSample[i] = new slSample(filename[i], sched); crashVolEnv[i] = new slEnvelope(1, SL_SAMPLE_ONE_SHOT); Now... the question is.. where do I do AddSampleEnvelope()? I tried doing it immediately after loading the sample: sched->addSampleEnvelope(skidSample[i], 0, 0, crashVolEnv[i], SL_VOLUME_ENVELOPE); crashVolEnv[i]->setStep(0, 0.0, 0.0); Then, in order to play the sample at the appropriate volume I just do: sched->playSample(crashSample[i]); crashVolEnv[i]->setStep(0, 0.0, appropriate_volume); ... and finish with sched->update(); This did not work at all. The sound was always played at the same volume. So I thought maybe the sample envelope gets lost after the sample finishes playing. Thus I added the envelope everytime the sample was played, but to no avail: sched->playSample(crashSample[i]); sched->addSampleEnvelope(skidSample[i], 0, 0, crashVolEnv[i], SL_VOLUME_ENVELOPE); crashVolEnv[i]->setStep(0, 0.0, appropriate_volume); ... sched->update(); What am I doing wrong? Can you help? -- Christos Dimitrakakis IDIAP (http://www.idiap.ch/~dimitrak/main.html) |