Sign in to follow this  

Why does my function keep returning 0? [C++]

This topic is 3290 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I am using Fmod and for some reason, my function keeps returning 0 though pos's value is changing from the getPosition function when I debug it in VS2008. Function:
int Audio::GetMusicSecond(){
	channel->getCurrentSound(&sound); 
	unsigned int pos = 0;
	int returnV;
	result = channel->getPosition(&pos,FMOD_TIMEUNIT_MS);
	returnV = (int)pos / 1000 % 60;

		return returnV;
}

BTW, can someone tell me how I can set up a system where if 1.0 was entered it would mean 1 minute and 0 seconds in a pointer? Thanks, Ajm113.

Share this post


Link to post
Share on other sites
I'm not sure what pos is supposed to represent here but it is possible that pos / 1000 is less than 1? Maybe you want to return a float and not an int in that case.

For the minutes and seconds question - if you meant that you want an easy way to represent minutes and seconds as a floating point number, this is what I'd do:
#define GET_MINUTE_PART (x) ((int)x)
#define GET_SECOND_PART (x) ((int)(((x - (int)x) * 100) % 60)) //Assumes x is a float and for 1 second you enter 0.01 and not 0.1

class TimeData
{
int minute;
int second;
public:
TimeData(float encodedTime)
{
minute = GET_MINUTE_PART(encodedTime);
second = GET_SECOND_PART(encodedTime);
}
};

TimeData data(1.0);//Time data now stores 1 minute and 0 seconds



I really doubt this will work well with floating point precision though.

Share this post


Link to post
Share on other sites
I tried it and it's still returning as 0.

Tell you the truth idk, why pos gets wired values from the song being played from getPosition function.

The value is going up every millisecond while song is playing, but in a wired order...

Example from every time the line executes of getPosition in pos pointer:
0
55
95


float returnV;
result = channel->getPosition(&pos,FMOD_TIMEUNIT_MS);
returnV = (float)pos / 1000;
returnV = (int)returnV % 60;

return returnV;
}







F.Y.I, result pointer just returns a enum pointer saying if the line was executed properly.


Best sound API in the world? I beg too differ... Heck I mite as well make a counter from scratch and use PlaySound function if this is going to be a pain, but I need too also get pitch and bass, & etc and pause the sound..

I'll play around with the code snippet after I figure this mess out.

Share this post


Link to post
Share on other sites
Quote:
Original post by ajm113
The value is going up every millisecond while song is playing, but in a wired order...

Example from every time the line executes of getPosition in pos pointer:
0
55
95



How is 'increasing' a "weird order" ? I'm guessing 55ms passed between the 1st and second call, so I'm not sure why this seems wrong?

Share this post


Link to post
Share on other sites
The problem seems to be with the getPosition function not setting pos to anything over 1000ms. The way you have your code setup now, the result will be 0 till pos > 1000.
Does the getPosition function set the pointer to the current position in the file in milliseconds? If so then why is it hard to believe that if you call the function consecutively, it returns the same value as the audio file might not have really progressed? Maybe you need to let the file play for more than a second to see returnV > 0?

Share this post


Link to post
Share on other sites
I played around with it and I got what I want, I had too let it go for a couple of seconds so your right.

BTW on the floating point from minutes and seconds, I have a question on, what type of pointer is x? Is it supposed to be a double, how do I define it in the #define?

Share this post


Link to post
Share on other sites

This topic is 3290 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this