4

Still a novice java developer, I need to build an Android app that

1 streams a single mp3 from a supplied URL and then

2 extracts volume and-or sound frequency data from the mp3 stream

3 drives a light show from the data in #2

I have a possible solution to #1 and am working on #2,

Can anyone suggest specific classes in the SDK I should be looking at?

Are there any existing Android projects on github or elsewhere that extract frequency and or volume data from streamed mp3 files I might examine and learn from?

Bachalo
  • 6,965
  • 27
  • 95
  • 189
  • For frequency of mp3, you can see this SO answer: http://stackoverflow.com/a/5189581/1739882 – Chintan Soni Dec 30 '13 at 05:55
  • The question requires a clarification on its "frequency" meaning. Did OP mean encoding bitrate or sound frequency? – Stan Dec 30 '13 at 13:37
  • I think going by the 3rd requirement they mean audio waveform frequency, but I would bet that what they actually want is an FFT analysis. –  Dec 31 '13 at 19:58
  • You can look at the below link it may help you http://stackoverflow.com/questions/4708613/graphing-the-pitch-frequency-of-a-sound – venkat530 Jan 02 '14 at 00:18
  • Hope this helps - [BeatDetectorByFrequency.java](https://github.com/OrbotixInc/HACKATHON-APPS/blob/7dedf80846b4a8bc9a7cfa6a1eeb73cd2b892bd8/Android/Spherolizer/src/com/orbotix/beatdetection/BeatDetectorByFrequency.java) – vijaykumarg Jan 27 '14 at 13:39

3 Answers3

0

Echo Nest (http://developer.echonest.com/) is a great tool for analyzing MP3s to give you volume, frequency, beat, and other data.

There's a java library that works with Android.

Darrell
  • 1,945
  • 15
  • 21
0

Here's another good resource for your project: http://therandomlab.blogspot.nl/2013/05/fft-audio-frequency-analysis-with.html

Good luck

0

You will want to expose the buffer underlying the read so you can get at derived Volume level... This may mean using some other API than 'MediaPlayer' which may NOT expose RMS level for volume.

Each time you do a buffered Read on the MP3, you can generate x-axis, y-axis data from the Volume with the following:

while (mIsPlaying) {
    double sum = 0;
    int readSize = mRecorder.read(mBuffer, 0, mBuffer.length);
    for (int i = 0; i < readSize; i++) {
        output.writeShort(mBuffer[i]);
        sum += mBuffer[i] * mBuffer[i];
    }
// PrBar needs RMS as int
//log base2 for the rms expression on the Volume from the mic
    if (readSize > 0) {
        mProgressBar.setProgress((int)Math.sqrt( sum / readSize ));
        handleRMS((Math.log(Math.sqrt( sum / readSize ))/Math.log(2))); 


    }
}

...

private void handleRMS(double rms){

    rmscnt++;
    rmssum += rms;
    if(rms > rmsmax)rmsmax=rms;
    if(rms< rmsmin)rmsmin=rms;
    double myamt=(rmsmax - rmsmin) / 10 +rmsmin;
    if (rms < myamt) decile++; 
    if(rmscnt % 5 ==0){
        if (rmssum / 5 < myamt) {                                       
        if( Long.valueOf(System.currentTimeMillis())
          - tslist.get(tslist.size()-1) - segmenttime > 0 ){
            tslist.add(Long.valueOf(System.currentTimeMillis()));
        };
    };
    rmssum = 0;
}
}
   * feature - select the TS corresponding to a 'pause' in the speech stream       *   arriving from microphone        * ''pause' in algorythm and

the normal RMS volume level on a sine-wave pattern * observe the last reading for RMS in light of the sine-wave * min & max are 'y-axis' vals on the wave * 'myamt' field is a threshold cap that is currently 10 percent of delta ( max - min ) * in practice, a pause has to have a series of adjacent RMS values with an AVG LESS than * some config-value. * Once the TS for a pause has been accepted, there is another min value of time that should * pass before looking for another pause in the speech. * Helpful hint - 5 to 10% of the RMS vals should increment 'decile'. * Otherwise, there are not enough lo-volume events on the radar to ID pauses in speech.

In order to expose the buffers, instead of 'MediaPlayer' api , you may need to use something like 'AudioTrack' to process your mp3. For samples, i think you can go to this project on git

RMS and the handler explain here

Community
  • 1
  • 1
Robert Rowntree
  • 6,230
  • 2
  • 24
  • 43