I was wondering if there is an api refererence for FMOD that uses examples anywhere? I am using Windows XP on a Pentium 4 with fmod for win32 and Microsoft Visual C++ 5.0 and is having some problems…
I wanted to sync my opengl animation with the music so I made a mod loaded and played it and it worked fine. Then I wanted stuff to happen everytime the base played so I added this line in my Initialization routine.
and myCallBack looks like this
FMUSIC_CALLBACK myCallBack(FMUSIC_MODULE *m,unsigned char p)
However as soon as instrument 2 plays my program hangs. I want to know what I am doing wrong. How is this supposed to look? Have I written something wrong somewhere? I had to have a return value or it wouldn’t compile but the documentation doesn’t state what the return value should be. Please help, thanks in advance!
- pjupju asked 14 years ago
Yes! It is a mod callback I am after. And yes I forgot (didn’t know you were supposed) to add F_CALLBACKAPI. Haven’t tried if it works with it yet but I’m sure it will. I’m off to study some more c++ before I continue, especially callbacks 😉 Thanks for all your help!
- pjupju answered 14 years ago
[i:pelavsnb](Since I have not posted in quite some time… a little C++ advice from a wise [Ed: NOT!] programmer…)[/i:pelavsnb]
Be sure to read up on C++ casts as well. While C-style casts will work, it is generally preferred to use the specialized C++ casts to promote more robust programming. I have yet to find a need to use C-style casts in a C++ program in all of my years of C++ programming, aside from laziness. (And laziness can be acceptable for personal projects…) Just to give you a little example of what I am talking about:
There are four C++ casting operators: dynamic_cast, static_cast, const_cast and reinterpret_cast. Each serves a different purpose and provides more meaning than the simple C-style cast.
The dynamic_cast operator works on polymorphic data types only, specifically pointers to objects or “void *”. It does incur a small performance penalty due the run-time validation and therefore is rarely used. For non-time-critical applications, it adds much robustness when “down-casting” pointers in class hierarchies.
class Bar : public Foo;
class Hmm : public Foo;
pfoo = &bar; // Uses an implicit "up-cast".
pbar = dynamic_cast<Bar *>(pfoo); // Works, after run-time check.
pbar = dynamic_cast<Bar *>(&hmm); // Fails, during compile.
phmm = dynamic_cast<Hmm *>(pfoo); // Fails, after run-time check.
void *ptr = &hmm; // Implicit cast to void *.
pfoo = dynamic_cast<Foo *>(ptr); // Works, after run-time check.
pbar = dynamic_cast<Bar *>(ptr); // Fails, after run-time check.
phmm = dynamic_cast<Hmm *>(ptr); // Works, after run-time check.
The static_cast operator is used for all non-polymorphic data types. There is no run-time validation and hence no performance penalty aside from any time required to convert from one type to another. The cast is validated at compile time to ensure strong type safety; as such, this operator cannot cast between pointers and non-pointer types.
int i = 1234;
float f = static_cast<float>(i); // Works.
void *v = static_cast<void *>(i); // Fails, during compile.
None of the cast operators can remove the “const” status (or “volatile” status, for that matter) except the const_cast operator. This operator will let you break type safety and introduce serious stability flaws into your programs. Use it only as a last resort.
char c = ‘x’;
const char *p = &c;
q = static_cast<char >(p); // Fails to remove constness.
q = const_cast<char *>(p); // Constness is removed.
(q) = ‘!’;
bool b = (c == ‘x’); // false?! Oops.
While the const_cast operator can be pretty evil, so can the last of the operators. The reinterpret_cast operator forces the compiler to copy the bits in memory as is, ignoring all rules of type safety. Note that this operator does not have the power to remove “const” or “volatile” status, making it only slightly less evil than the const_cast operator. This operator is the primary replacement for the C-style casts. It lets you cast pointer types to non-pointers. Like const_cast, use reinterpret_cast only as a last resort. Serious stability flaws await those who misuse this operator.
unsigned int u = 0x00001234; // Certainly not in your memory space.
short s = reinterpret_cast<short *>(u); // Works, but...
(s) = 0x1234; // ...Address Violation!! Oops.
It is true that the C++ cast operators do take up more space in the source file and take a few seconds longer to type, but you save yourself the lost time and considerable agony due to careless casting.
Please login first to submit.