I am Farhan.
Currently, I am working on a Sound Engine using FMOD Ex API in C++ for my final grad project (a group project).
Is there anyway to create the FMOD Sound and Channel dynamically?
My idea is…
as you load a sound file with its reference name, the sound engine will go through a list of FMOD Sound and Channel and if the file/sound is not in the list yet, the sound engine will create a new FMOD Sound and Channel for that new sound and insert it in the list. The problem right now is I am not sure how to create the FMOD Sound or Channel dynamically and I don’t think I can create new FMOD Sound or new Channel.
I hope somebody can help me. Do I really need to hard code all FMOD Sound and Channel that I need? Even though this will still work but If I can do it dynamically, it would be really hopeful.
- farhanRIT asked 8 years ago
[quote="peter":3uvcqg3a]It’s not entirely clear what your intention is. If you want to dynamically load and store sounds and channels you can use a dynamic data structure such as std::list.[/quote:3uvcqg3a]
I am sorry, I am not sure how can I explain this.
The current sound manager that I have created to play 3d sounds, I only have 6 defined (in the header) FMODSound and Channels. So that I can only load 6 different sounds and play it on 6 different channels. The problem here is that if I load more than six sounds, the game / the sound manager will crash because I only have 6 FMODSound and Channels, unless if I add/defined another/more FMODSound & Channel. I would like to create a way that I am able to load any number of sounds anytime and play on a any number of channels anytime.
Can you check out my codes? It is really long.
This had been a while.
By the way, I still couldn’t figure / solve this problem.
Right now, all I did is hardcode it. I hope that someone can help me on this.
I already refer to the playsound example and I believe that it is hardcoded.
I want to focus on 3d sounds.
For example, I have 6 different 3d sounds that I want to play. So, in my .hpp/.h file, I defined 6 different FMOD Sound (like music1, music2, music3, music4, music, music6) and 6 different FMOD Channel (like channel1, channel2, channel3, channel4, channel5, channel6).
And in .cpp files I will just use the defined FMOD Sound and Channel to load sound and play sound. Basically, I will only have 6 sounds and 6 channels harcoded.
I am looking for a way to do this dynamically. First of all, I want to say that I am still new with programming. So, anyway, I know that there is no such thing as new FMODSound or new FMODChannel for FMOD compare to a regular coding style.
What I want to do is not to define all of those 6 FMOD Sound or 6 FMODChannel at all. I want it to be something like:
(This all happen in a LOAD function that I have created) As you want to load an FMODSound, I will use a list (a MAP for an example), and using a given instance (or just a unique string name as reference), I will go through the list and if it is not exist I will create new FMODSound, then load the file and keep the pointer in the MAP.
So how do I do this? I cannot use (new FMODSound) and I also have tried something like (within the LOAD function) FMOD::Sound *music; (which will be used by all sound that are loaded). load the sound and keep the pointer in a MAP, but it just doesn’t work.
I hope somebody can show me an example to do this dynamically. My main target is how can I do this without needing to define all 6 sounds and 6 channels.
[quote:jch1zzrj]FMOD::Channel *channelnew = new *FMOD::Channel;[/quote:jch1zzrj]
Theres your problem.
FMOD does not use ‘new’ for anything, none of our classes have public constructors because they are created using factory functions. To instantiate an FMOD::Sound you call System::createSound, to instantiate a channel you would call System::playSound. These function will internally allocate the object for you. To see example usage of the FMOD API check out the playsound example in the FMOD install directory.
Can you show me an example of doing that?
I am sorry I am still new with programming.
I am using C++ with Directx 11
Here is an example on how I insert a list of channels and fmod sounds into maps (hard coded) which works fine
FMOD::Sound sndMusic; //in hpp
map_AudioList.insert(map<string,FMOD::Sound>::value_type("Music",sndMusic)); // in cpp
FMOD::Channel chnlMusic; //in hpp
map_ChannelList.insert(map<string,FMOD::Channel>::value_type("Music",chnlMusic)); // in cpp
The insert them into list after I initialized the FMOD system.
I will go through the map lists when I want to load/play sounds.
So, how exactly do I create it dynamically? Just for the sake of efficiency.
I have tried to do like this…in cpp… when loading a sound
It’s not working. When I go through the list, somehow the channel/pointer is null/not exist.
I just don’t understand why this way is not working. Both ways (the hard coded example and the dynamic way example) are the same.
The only difference is that the hardcoded version, the FMOD::Channel *channelnew; is created within cpp and not hpp
I have also tried this…
FMOD::Channel *channelnew = new *FMOD::Channel; >> I don’t think this is a correct syntax
So for both FMOD sound and Channel, I did the same way (inserting them into maps harcoded) and I still couldn’t figure out how to create FMOD::Channel or FMOD::Sound dynamically as you load a sound.
So, how do you really do it?
I hope you can help me thanks.
- farhanRIT answered 8 years ago
Please login first to submit.