do you still just need it for looping??
then you can use the methods i talked of before (they was suggested for samples!).
I personally use both:
-calling FSOUND_IsPlaying() every frame for all other purposes.
-looping infenetly but counting the loop-times for turn off looping on time
- for doing it by dsp-unit i ‘ve no expierience so far…
perhaps takinkg a look at the functions FSOUND_DSP_Create, FSOUND_PlaySoundEx and the DSP engine-tutorial (together with froggerproggers suggestions) can help you….
the pb is that i don’t want to just loop and count…. i’d like to know when a sound is finished, and then, use probability to play it again (delay, prob to play, count, …) and using the “isPlaying() method”, accuracy isn’t good enought.. :/ i tried it but there’s always a little part a the sound file that start to play before U can stop it!
so i tried the endcallback for stream and it work pretty fine
(i can put the code here if someone want)
is there a way to have a endcallback on a sample?? (brettttt help me…>_<)
ho that great… but in fact, is not really difficult to count on a stream, U just have to use endcallback… the problem is when using a sample :/ because i’l working on a video game and i’ve got to load several really small sound (environement, 3D, menu, …) so can’t only use stream ^^
i looking on dsp, i don’t really understand how it works but i’m working on it to understand
i don’t find a way to use DSP correctly :/
i’d like to use it to know if the sample is finished…
i create a callback for the dsp (the exemple in doc ^^). i create a DSP with DSP_Create(callback,300,0) and i active it. I load a sample and try to play it in the DSP with FSOUND_PlayEx(FSOUND_FREE, mySample, myDsp, TRUE)
in the callback i set a printf to know when the DSP is used. ’cause i think i should be able to find when sound is finished, but it doesn’t work ;_;
so i’m wrong on how to use DSP, i made a mistake??
I ‘ve the same problem….
Till now i solved it in the way that I call FSOUND_IsPlaying() for every playing- (looping) channel frequently (every frame together with FSOUND_Update()). 😕
But this, of course, can not guarantee a smooth loop playing like one long sound, which is ok for sounds like birds, bells (ringing 3 times) or so, but not if you have a contiously noise (carengine or so).
So if anyone has a better solution i would be glad to hear of it. 😉
[i:2acos132]EDIT: Ooops, actually no need of DSP here, sorry confusing you above.[/i:2acos132]
Okay, here’s a way to get a callback exactly at each loopend of a looped SAMPLE:
(1) Decompress sample-data from file into memory (to be able to load MP3, etc., too)
(2) Create a custom stream-callback with exact the same length of the sample-data (no matter, that it is a ‘stream’ – it is complete in memory like a sample)
(3) Copy the decompressed sample-data into the custom stream’s 2 buffers (to get an ‘image’ of the sample-data) Mind the Double-Buffering !
(4) Play the stream – it will call the callback-procedure every loopstart = loopend !
(5) Do anything (e.g. nothing) inside the callback each time it is called.
I made an example-EXE, ( + well-documented source in [url=http://www.purebasic.com:2acos132]PureBasic[/url:2acos132])
You’ll find it here:
http://public.2mal2mal.de (the file is located inside the directory [b:2acos132]/fmod[/b:2acos132] and is called [b:2acos132]samplelooper_0.4.zip[/b:2acos132])
It should work with a callback-procedure.
– create a dsp-callback, something like (in PB)
[code:joyj0dc9]hStream.l = FSOUND_Stream_Create(@CallbackProc(), buffer_size, wavetype, samplerate, 0) [/code:joyj0dc9]
– the Callback-procedure then looks like:
[code:joyj0dc9]Procedure.l CallbackProc(*hStream.l, *BufferPointer.l, length.l, param.l) [/code:joyj0dc9]
It reads in the samplevalues from the source-wave (e.g. from memory) and just copy the values without modifications into the buffer. If the read-in reaches the end of the allocated source-wave-memory just start from the beginning and increase the loop-counter
ok thanks mem…
i’m going to try gruebel method first, because i’m to lame, i don’t really understand how DSP work.. >_< … sorry Froggerprogger (your method is certainly better…)
i’ve got an other question, how can i create a delay between end of play and begining of next play… i though about wait() or sleep() but it’s gonna freeze the prog, isn’t it??? or maybe FMOD use thread??
hey, i have another solution, which works as smooth as the loop-flag, but it can count.
Simply check in your main loop, if the actual FSOUND_GetCurrentPosition() is lower than the last one.
If so, then there (mostly) has to be a restart of the sample.
Works very fine and easy with wav here.
Here’s the mini-test-exe (UPX-10k) and the PB-source:
(go for \fmod\loopcounter.zip with or without the fmod.dll)
btw: but perhaps it’s not worth it 😉
Froggerprogger’s solution is also one, come to me during the weekend…..
there are a few things i like to remark on it.
– you will get problems (of course) if you don’t call the check(update current position) function often enough or the other way round if the looping part of your sample is too short, (Better to say your check-interval need to be shorter than the half loop-interval) otherwise your function can miss some times looping.
-think of possible problems if the frequency is negative (the sample is played backwards.)
-don’t forget to turn off infinite-looping during the last loop (not afterwards, this could be, depending on how you count, when the loop-count is 1).
rough code example:
void loop(int times)
unsigned int old_position=position;
if (((frequency>0)&&(old_position>position))||((frequency<0)&&(old_position<position))) –loopcount;
if (loopcount==1) FSOUND_SetLoopMode([i:28nzbt3c]channel[/i:28nzbt3c],FSOUND_LOOP_OFF);
i’m back.. sorry ^^
i found a way to know when a stream is end (with the endcallback) and i can do what i want in the callback function… now i’d like to do the same with sample, but there’s no sample_endcallbakc :/
i’m sure there’s a way to do it (using DSP as Froggerprogger said before) but i didn’t find how to do.
so if some one should tell me how (in c++ if possible ^^, cause i dunno the Froggerprogger code :/ )
Please login first to submit.