I am trying to find out the length (in seconds or milliseconds) of a sound that is of type FSOUND_SAMPLE*

I can get the number of samples in the sample by calling FSOUND_Sample_GetLength()

Now I need to know how to covert that into a time based figure…

Is there a way of getting the sample rate for a sample? – I am assuming that I need to calculate the number of samples per second in order to work out the length of the sample.

Thanks for any help

- bushido asked 16 years ago

- You must login to post comments

If you need a value in milliseconds, and you’re running at 44,100 Hz, here’s some code (let’s pretend lSamples is the variable holding your sample count):

float fSeconds,fMillisecs;

fSeconds = (float)lSamples / 44100;

fMillisecs = fSeconds * 1000;

It’s important that at least fSeconds be floating-point, or you will end up with an integer, which can’t represent fractions of a second. fMillisecs CAN be integer, but if it is, you need to typecast, and that’s why I made it floating-point.

- Graduate Bruce 2002 answered 16 years ago

- You must login to post comments

The thing is, I don’t want to have to restrict the sounds I am using to be 44100 or any other fixed sample rate.

In fact because of the context, some of the sounds being used are sampled at 22050

What I want is a function to tell me what the sample rate of the sample is, which I can then substitute into a formula like the one you provided.

p.s. I know C++ quite well

- bushido answered 16 years ago

- You must login to post comments

Thanks Brett that’s exactly what I was looking for

- bushido answered 16 years ago

- You must login to post comments

How would you get the length of a Module file using the FMUSIC type???

- Paranoid_Android answered 16 years ago

- You must login to post comments

**Your Answer**

Please login first to submit.