I wanted to compare how much two sound frames are similar, so that I can distinguish between them.
I am doing this because, usually when we had a video playing and an advertisement comes up, usually there is either a sound drop or an increase in sound.
So I want to compare the sound frames from wav file to find the difference.
The following code finds the amplitude of sound wave per video frame
1 video frame corresponds to 2000 sound frames.
Code ---->
for (offset=waveFileHeaderOffset; ((offset < raf.length()) && (videoFrames < VideoFile.MAX_POSSIBLE_FRAMES)); offset+=2*AUDIO_PER_FRAME)
{
audioAmplitude = 0.0;
for (offset2=0; offset2 < 2*AUDIO_PER_FRAME; offset2+=2 )
{
double temp = 0.0;
raf.seek(offset+offset2);
raf.read(bytes);
temp = (double) Math.abs((double)( ( ( bytes[1] << 8 ) | ( bytes[0] & 0xff ) ) / 32768.0 ));
audioAmplitude += temp;
}
audioAmplitude /= AUDIO_PER_FRAME;//we are taking average of all frames corresponding to video frame
ArrayList<Double> tempFrameData = new ArrayList<Double>();
(VideoFile.frameHashMap.get(videoFrames).clone());
tempFrameData.add(audioAmplitude);
VideoFile.frameHashMap.put(videoFrames, tempFrameData);
videoFrames++;
}
The problem is that since the amplitude is divide by 32768 to normalize it. I cant determine a threshold to distinguish between them.
All amplitude are very close to each other. I think I am making some mistake in calculating the amplitude.
Can any one comment on how do I compare two frames using these amplitudes to find significant difference when a advertisement comes up in between a video.
Thanks