Hello world !
I’ve started programming with the FModEx library a few days ago. It’s pretty easy and intuitive, even for me althrough I never programmed sound systems before.
But I’ve got a problem : I’m trying to write a function that looks like this :
[code:2gk2m2x5] PlayLoop(DWord Start_MS, DWord End_MS, tByte Loop_Count);[/code:2gk2m2x5]
This function should allow me to play a part of a sound file from Start to End_MS, Loop_Count times.
I wrote a little piece of code in order to see how is this possible under FMod :
result = FMOD_System_Create(&system);
result = FMOD_System_Init(system, 32, FMOD_INIT_NORMAL, NULL);
result = FMOD_System_CreateSound(system, "snd2.mp3", FMOD_SOFTWARE|FMOD_LOOP_NORMAL, 0, &sound);
result = FMOD_System_PlaySound(system, FMOD_CHANNEL_FREE, sound, 0, &channel);
//***Start at the begining of the loop
result =FMOD_Channel_SetPosition(channel, 563,FMOD_TIMEUNIT_MS );[/code:2gk2m2x5]
In this code, my loop begins at 625ms, ends at 1300 and is repeated (2+1) times.
It works fine, but my problem is that at the third time, the rest of the sound file (ie after 1300ms) is played too !!
Does anybody could tell me how to do in order to play the loop in the way I want ?
(I know it"s a lame question, but be sure that I tried many things by myself before posting. The code above is the one witch gives the closest result of the one I’m looking for.)
Thank for reading my post.
- AliceD asked 12 years ago
Thank you for your reply.
But all my program sounds are placed in a row (with 2ms betwen each) in a sigle file.
So, is there a function or a parameter to be used so it will only play the loop then stop or is there no way but storing each sound in a separate file ?
Are you loading all these sounds as one big block of sound data or something? Is that why you want to use loop points?
You should use multiple sound handles, you just create them on the same file, and use fileoffset/length members of FMOD_CREATESOUNDEXINFO if you want. I’d have to know more about how you’re trying to structure it first but I suspect thats what you’re doing.
Whew ! Thank you for your QUICK reply.
First, I’m aware that all my explainations are a bit confusing, thanks to my poor english (kids, don’t neglect learning foreign languages at school !). So I try to be now as clear as possible.
I tried to use the CREATESOUNDEXINFO structure with CreateSound, as you suggested it, but it doesn’t seems to fit to my case. Actually, my sound file (Snd.mp3) is not a pak-like file. It’s juste a MP3 file I created where I recorded in a row all the sounds I needed to play.
I choosed this way beaucause I will use about 25 different sounds and I prefered have all my sound ressources in one single file rather than having 25 MP3 files (1 for each sound).
As an example, here is how the Snd.mp3 files looks like :
[code:2d49n8ox]OffSet (in ms)
[0;1000] – "CRASH"
[1002;2100] – "ZAP"
[2102;3000] – "BANG"
In my program, if an event occurs (eg a lazer-gun shot), I’d like to have a function I could call that way :
[code:2d49n8ox]//**Play "ZAP" sound
So far, I know how to start playing at a given offset in ms (here : 1002ms) with Channel::SetPosition, But I don’t kwon how to tell the library to stop playing after 2100 ms. The only result I’ve got so far is not a nice "ZAP" sound but a damned "ZAP-BANG" !
I have not started to write my sound engine, so I’m open to any methods or techniques but the piece of code in my first post is the best illustration of how I would like the tings to be structured.
I finally stop trying to play loops from a single MP3.
I did what you recommanded : I coded a little tool that compile into a big one DAT file all the small single sound mp3 files. Then I load each ‘sub-file’ with the function CreatSound and the option FromMemory.
I works great and allows me to assign differents effects for eatch sounds.
Thank you for your help !!!
Please login first to submit.