0
0

What is the best method of using FMOD on the iPhone when using multiple View Controllers?

Currently, I create a new system object as each ViewController loads, without releasing the previously created. I would guess that this is less than ideal? However, I cant see a way to create one master system object in my app delegate and then simply access it from each loaded view. (bare in mind I am a new ObjC/C++ programmer)

Cheers

  • You must to post comments
0
0

I found some of the the problems:

Firstly, you were right Mathew, I had to rename all .m files to .mm.

Secondly, ‘template’ appears to be a reserved word in Objective-C++, but not in Objective-C, hence that compilation error.

Thirdly, I had to write a get’er method in MyAppDelegate.mm as FMOD objects can’t be synthesized by Xcode.

So now it all compiles, but stops at the linker, saying that a global I’ve declared in my appDelegate.h file is a ‘duplicate symbol’.

I don’t think it has anything to do with FMOD, but if anyone knows if Objective C++ treats global variables differently to Objective C, please let me know, because this is my last stumbling block on my crusade for nirvana: FMOD players in several viewcontrollers! ….I hope… :-)

  • You must to post comments
0
0

Thanks for your response CuriousG.

Yes, I have the necessary references back to the appDelegate in my viewController’s header file. I know this because I access other appDelegate properties using the same singleton method.

I think the main issue is that I get the following compiler error in the appDelegate.h property declaration part:

[quote:2ssluu6y]"…expected specifier-qualifier-list before ‘FMOD"[/quote:2ssluu6y]
for this declaration:
[code:2ssluu6y]
FMOD::System *system;
[/code:2ssluu6y]
Exactly the same declaration works fine when in the viewController’s header file. What gives?

  • You must to post comments
0
0

Got it to work. Eventually! :-)

So now FMOD’s playing in several viewcontrollers. That was the easy part.

Cos I had to change all global variables into AppDelegate ivars and make get’er and set’er methods for them all so that I can access them from other viewcontrollers.

It was a bitch of a job that had nothing to do with FMOD except it had to be done to make it work. The alternative would have been to convert all FMOD calls to C function calls (to avoid having to compile and link everything as .mm), but that seemed even less appealing.

Anyways, thanks for all the support!

thx & brgds.

  • You must to post comments
0
0

Firstly it’s worth mentioning that on iPhone you cannot have multiple FMOD system objects that use CoreAudio, older versions permitted this with unforeseen consequences, newer versions will return an error.

To handle sharing the system between multiple view controllers perhaps you should move the FMOD code out into its own code file, possibly use a singleton to get access to the one FMOD instance.

  • You must to post comments
0
0

Hmm. I’ll take a look and see if I’ve gotten that same error and how I could reproduce it.

Another quick thought. Sometimes when you rename a file from a .m extension to .mm, it only renames it in XCode, and not in the file system. I found this out recently when I created a class with a .m extension and remembered afterwords. I noticed that when it didn’t compile that on the left it said .mm, but on the title bar when I was in the file it still said .m!

  • George
  • You must to post comments
0
0

It would be really nice to see any example of this. Personally, I put my system object in the AppDelegate and then passed references of it to my ViewControllers.

  • George
  • You must to post comments
0
0

I wasted a few hours also before working out my suffix on the Singleton class was still .m and not .mm

  • You must to post comments
0
0

Thanks Mathew, that seems clear. Cheers.

  • You must to post comments
0
0

Hi and thanks for the tip.

My appDelegate.mm file is definitely .mm so that’s hardly the issue.

In search of the problem, I’ve reduced the whole thing to ONLY doing the following in my appDelegate.h file:

[code:24h82jh7]#import "fmod.hpp"

import "fmod_errors.h"

import "fmodiphone.h"

[/code:24h82jh7]

and this in the interface section:

[code:24h82jh7]FMOD::System *system;
[/code:24h82jh7]

…and I still get the following compiler error message at above FMOD::System *system declaration:

[quote:24h82jh7]Expected specifier-qualifier-list before ‘FMOD’
[/quote:24h82jh7]

If I comment out those 4 lines (and return to appDelegate.m), everything compiles and runs smoothly, playing away in the one viewController that I’ve been using FMOD up until now.

  • You must to post comments
0
0

[quote="CuriousG":1s69sinq]Personally, I put my system object in the AppDelegate and then passed references of it to my ViewControllers.[/quote:1s69sinq]

Hi George, what method of passing references did you end up using?

  • You must to post comments
0
0

Hmm.. What about Foundation.h? Occasionally I will get crazy C-Like bug and it gets fixed if I import Foundation.h (even if it’s been imported elsewhere if you believe that).

I presume the FMOD example files work? Are you compiling for the latest Base SDK?

If you even comment out:

FMOD::System *system;

Do you still get the error?

  • George
  • You must to post comments
0
0

Basically in my appDelegate, I have lines that look like this:

[code:1b9ovbcv]controller = [[myViewController alloc] initWithSystem:&system];[/code:1b9ovbcv]

and then in my myViewController code I have:

[code:1b9ovbcv]
@interface myViewController : UIViewController
{
FMOD::System *system;
}
@end

@implementation myViewController
– (id)initWithSystem:(FMOD::System **)_system
{
system=*_system;
return self;
}
@end
[/code:1b9ovbcv]

Hope that makes sense. And feel free to let me know if there is a better way.

Thanks!

  • George
  • You must to post comments
0
0

Thanks, this may lead us somewhere.

When commenting out even the "FMOD::System *system declaration it still throws a number of compiler errors in all viewController’s in which .h file I have the following #import:

[code:2ngotuas]#import "MyappAppDelegate.h"[/code:2ngotuas]

…that I need to access other singleton appDelegate properties.

Do I need to make all viewController’s .m files into .mm if I use above #import statement in their .h (which is pretty much all of them)?

And yes, I’ve tried with and without foundation.h. Makes no difference.

  • You must to post comments
0
0

You can access your AppDelegate though the singleton application class (sharedApplication)

[code:3a94ghcp]UIApplication *app = [UIApplication sharedApplication];
MyAppDelegate *myAppDel = app.delegate;
[/code:3a94ghcp]

MyAppDelegate would have an FMOD::System* and you would access it through a getter.

this way each controller view is not strongly coupled to the system. ie no need to pass a reference
cheers
steph

  • You must to post comments
0
0

Any objective-c code file that includes an FMOD C++ header needs to be .mm.

So if you have code.m -> include code.h -> include something_else.h -> include fmod.hpp then code.m needs to be code.mm you have to follow the whole chain.

  • You must to post comments
0
0

Thanks George and Steph, that all makes sense. I will look at implementing that shortly.

  • You must to post comments
0
0

I think what Mathew is getting at is that anything that accesses your singleton class will need to be changed to .mm. I think this is also the case whether or not your other view controllers actually use FMOD.

  • You must to post comments
0
0

As an update, I did indeed follow your advice and have created an "Audio Engine" singleton that any loaded view can call and trigger audio events.

Thanks for your help.

  • You must to post comments
0
0

Yes, by indirection if anything imports the singleton header they will also get the headers included by that singleton (hence FMOD).

To make things simple you could just make all your code files .mm I don’t see any disadvantage to this. Or if it is critical your files remain as .m you can use the FMOD C interface.

  • You must to post comments
0
0

Hi,

I’ve been trying to get the Siingleton approach described herein to work, but the app won’t compile, giving me loads of error messages, beginning with "expected specifier-qualifier-list before ‘FMOD’" at this declaration in the appDelegate.h file:

[code:2jrproiv]FMOD::System *system;[/code:2jrproiv]

My app worked fine when I only played sounds in one viewController, but I need it to play sounds in several, so I decided to try the Singleton approach described in this thread.

I’ve moved the #import statements from the viewController.h file to my appDelegate.h file:

[code:2jrproiv]

import "fmod.hpp"

import "fmod_errors.h"

import "fmodiphone.h"

[/code:2jrproiv]

I’ve also moved the following compiler instruction to the top of my appDelegate.m file (that I have renamed appDelegate.mm because of FMOD’s C++ code):

[code:2jrproiv]

define PACKED __attribute((packed))

[/code:2jrproiv]

Moreover, I’ve moved the following code from the viewController’s viewDidLoad method to the appDelegate’s applicationDidFinishLaunching:

[code:2jrproiv]
FMOD_RESULT result;
unsigned int version = 0;

// Initialize FMOD system

result = FMOD::System_Create(&system);
ERRCHECK(result);

result = system->getVersion(&version);
ERRCHECK(result);

if (version < FMOD_VERSION) {
fprintf(stderr, "You are using an old version of FMOD %08x. This program requires &08x\n", version, FMOD_VERSION);
exit(-1);
}

FMOD_IPHONE_EXTRADRIVERDATA extradriverdata;

memset(&extradriverdata, 0, sizeof(FMOD_IPHONE_EXTRADRIVERDATA));
extradriverdata.sessionCategory = FMOD_IPHONE_SESSIONCATEGORY_PLAYANDRECORD;

result = system->init(kMaxChannels, FMOD_INIT_NORMAL | FMOD_INIT_ENABLE_PROFILE, &extradriverdata);
ERRCHECK(result);
[/code:2jrproiv]

In the viewController’s viewDidLoad, I simply do the following:

[code:2jrproiv]MyAppAppDelegate *mainDelegate = (MyAppAppDelegate *)[[UIApplication sharedApplication] delegate];
system = mainDelegate.system;
[/code:2jrproiv]

Any idea why this doesn’t compile, anyone?

  • You must to post comments
Showing 1 - 20 of 22 results
Your Answer

Please first to submit.