Click here to Skip to main content
15,881,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to convert stereo wav into frequency and save them into a txt.
The idea is that i have to load the wav, reading it and finally save the frequencies in my computer as a txt.
For example
0:00 min 50HZ
0:01 min 57HZ
....
1:10 min 450HZ


I try to run and edit a lot of projects but i couldnt achive it.(Too many failed attempts with samples, bytes, fft, ...etc)
Any source code that do this?Thanks

What I have tried:

ByteArrayOutputStream out = new ByteArrayOutputStream();
                running = true;
                int n = 0;
                byte[] buffer = new byte[(int) 1024];
                try { while (running) {
                               n++;
                    if (n > 200000){break;}                  
                    int count = 0;
                    count = outDinSound.read(buffer, 0, 1024);
                        if (count > 0) {out.write(buffer, 0, count);}
                                      }
                    byte b[] = out.toByteArray();
<pre>final int totalSize = b.length;
                    int amountPossible = totalSize / 1024;
                    System.out.println("Frequencies captured: "+totalSize+"         "+amountPossible+" * 1024");
                    System.out.println("_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _");                  
                    Complex[][] results = new Complex[amountPossible][];
                    System.out.println("                    * * *   STARTING ANALYSIS   * * *");
                    for (int times = 0; times < amountPossible; times++) {
                        Complex[] complex = new Complex[1024]; 
                        for (int i = 0; i < 1024; i++)                                   {
                        complex[i] = new Complex(b[(times * 1024) + i], 0);              }
                        results[times] = FFT.fft(complex);
                                                                         }
Posted
Updated 23-Nov-17 18:32pm
Comments
Kenneth Haugland 22-Nov-17 22:15pm    
It is actually not clear to me what you actually want. What does this mean:
0:00 min 50HZ
0:01 min 57HZ
....
1:10 min 450HZ ?
In general, an FFT will give you all frequency data within a given time span and not one frequency each second.
KotsanisNakos 23-Nov-17 11:52am    
Yes you are right. The time span that i saw so far at the projects that i try to create(or modify) was different and not something stable.
At the example I'm sawing you that for each milesecond i read a frequency(actually are a lot of freq and the i find the avarage for that milesec [propably false]) from FFT and write it to a txt. My problem that i cant find a solution is that i want to read the samples, then FFT read the freq, then calcuate the freq in HZ and then write to a .txt
KotsanisNakos 23-Nov-17 12:01pm    
The idea of the way i want to do is something like that below:

|WAV FROM PATH| ->|| java -> samples->fft->freq per time span|| -> |FREQ TO TXT|

1 solution

This is quite a complex task you are setting out to do, and you have still not explained in exact detail what you want. So my advice to you is to implement an FFT algorithm that you know works, then try and implement the code you want. If you get stuck you can improve your question.

But you should know that if you want an equalizer that shows some octave band related noise level you don't need the FFT at all. You can simply get the appropriate filter and convolute that with the time signal. The same procedure can also be used, with a different filter, for A-weighted decibels which are also commonly used to give the noise level as a single digit.

But these approaches require knowledge that is not trivially implemented on a Q&A forum.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900