Click to See Complete Forum and Search --> : sampling wave data and scaling it on 1-10 - urgent !!!


anshnen
December 4th, 2005, 09:26 PM
I have a problem here...

I am playing audio and video in synchronized manner. The whole thing is 10 secs. long and there are 100 frames in the video.

The audio is at Sampling rate of 22050 HZ , 16 bit mono of length 10 sec.

Thus total no. of samples = 220500
If i relate it to the corresponding video which has 100 frames then, i will have 2205 audio samples per video frame. I need to rate the audio on a scale of 1 to 10 on a per frame basis.

I have thought of this logic:

For every frame i add up all the 2205 audio samples which is say 'A'. Now i
A / 2205 = B and then i do a B / 65535 to get a no. C which i multiply by 10 to get a rating between 1 to 10...

I am not able to implement this.. please help..

Marc G
December 5th, 2005, 03:08 AM
I don't understand what you mean with "rate". Can you explain it a bit more?
Do you want to calculate the time between 2 successive audio samples?

anshnen
December 5th, 2005, 03:53 AM
This is what i mean:

Computing audio energy information :

The audio energy can be thought of as a simple function of the amplitude.

By adding the value of the PCM samples of audio that correspond to a
frame of video, you can get a measure of the audio energy at that frame. Convert this
number to a scale of 1-10 which then gets stored in your metadata file.

Marc G
December 5th, 2005, 05:36 AM
So, you add all the 2205 of 1 frame together and then scale the result to the range 0-10 as follows:
int sum=0;
for (int i=0; i<2205; ++i)
sum += sample[i];

// the maximum amount of energy would be 65535 * 2205 because there are 2205 samples and they are 16bit, so scale as follows:
double energy = (sum / (65535.0 * 2205.0)) * 10.0;

yiannakop
December 6th, 2005, 05:09 AM
Actually, to compute the energy value of a frame, summing all samples may not work, since the wave information is usually zero-mean, thus you should use ^2 or abs of the samples.


for (int i=0; i<2205; ++i)
sum += fabs(sample[i]);

or

for (int i=0; i<2205; ++i)
sum += pow(sample[i], 2);


Regards,
Theodore

Marc G
December 6th, 2005, 09:12 AM
Actually, to compute the energy value of a frame, summing all samples may not work, since the wave information is usually zero-mean, thus you should use ^2 or abs of the samples.
Yes, of course, I was merely answering the OPs question ;)