0

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

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • whats a significant difference to you? – 0x6C38 Apr 19 '13 at 21:22
  • Like when an advertisement comes in between videos, usually the amplitude of sound in advertisements is far more than that of videos. Secondly, suppose there is a video with a guy interviewing another guy. Here the overall loudness of sound is same for the interview unless some other advertisement abruptly comes in between. I want to measure this change. But when I find amplitude using above code. All the values are very close. Cant find a threshold to distinguish. Cant find the error as well – user2290024 Apr 19 '13 at 21:25
  • I thought taking difference between amplitudes of two sound frames would do. But that is not working. It does not help distinguishing them – user2290024 Apr 19 '13 at 21:26
  • Will finding difference using RMS(Root Mean square) work ? – user2290024 Apr 19 '13 at 21:33
  • we can only speculate, I doubt any of us has ever tried to do this before, the only way t go is testing – 0x6C38 Apr 19 '13 at 21:34
  • http://stackoverflow.com/questions/984729/how-can-i-determine-how-loud-a-wav-file-will-sound?lq=1 Just wanted to share this. Found quite interesting. Would try and implement it – user2290024 Apr 19 '13 at 21:47
  • See [this answer](http://stackoverflow.com/questions/5800649/how-to-detect-silence-when-recording-in-java/5800854#5800854) for calculating RMS. – Andrew Thompson Apr 20 '13 at 04:28
  • @AndrewThompson The link which you gave has two for loops. Taking a lot of time to calculate.Though it is quite accurate. Any technique to reduce the processing time – user2290024 Apr 20 '13 at 16:07
  • *"Taking a lot of time to calculate."* No it doesn't. You really should profile these things before making such claims. – Andrew Thompson Apr 21 '13 at 01:44
  • My program has 41633720 frames. And at a time I take 4000 frames. So for 4000 frames there are 2 for loops. So there are 8000 iterations. So total number of iterations for the whole wav file becomes 41633720 * 2 – user2290024 Apr 21 '13 at 02:47
  • Any way to calculate the same RMS using one for loop? It would be great help – user2290024 Apr 21 '13 at 02:47

1 Answers1

0

http://en.wikipedia.org/wiki/Loudness_war
The article is mostly about music but it applies to commercials too. The most interesting part is about the dynamic range reduction.

Studies have found that the human hear prefer "loud" signals instead of "weak" signals.
When you're trying to sell something, that comes in handy.

madgangmixers
  • 150
  • 1
  • 16