我的目标是通过分析球旋转过程中产生的声音来获得强力球的转速。在谷歌播放,几个应用程序可用于通过声音计算转速和频率,但每个应用程序都无法找到动力球的转速。我在谷歌搜索并发现“要从声音中计算频率,我们必须使用FFT Algo”。
什么是力量球? 强力球旋转并产生声音。 “Powerball®产生的阻力与使用者的努力成正比。”class RecorderThread1 extends Thread {
private static final String TAG = RecorderThread1.class.getSimpleName();
public boolean recording; // variable to start or stop recording
public int frequency; // the public variable that contains the frequency
private PlaceholderFragment placeHolder;
private Handler handler;
private long avgFrequency;
private int avg = 0;
private int sampelRateHz = 8000;
// value "heard", it is updated continually while
// the thread is running.
public RecorderThread1(PlaceholderFragment placeHolder) {
this.placeHolder = placeHolder;
}
@Override
public void run() {
AudioRecord recorder;
int numCrossing, p;
short audioData[];
int bufferSize;
bufferSize = AudioRecord.getMinBufferSize(8000,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT) * 3; // get the buffer size to
// use with this audio
// record
recorder = new AudioRecord(AudioSource.MIC, 8000,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT, bufferSize); // instantiate the
// AudioRecorder
recording = true; // variable to use start or stop recording
audioData = new short[bufferSize]; // short array that pcm data is put
// into.
while (recording) { // loop while recording is needed
if (recorder.getState() == android.media.AudioRecord.STATE_INITIALIZED) // check
// to
// see
// if
// the
// recorder
// has
// initialized
// yet.
if (recorder.getRecordingState() == android.media.AudioRecord.RECORDSTATE_STOPPED)
recorder.startRecording(); // check to see if the Recorder
// has stopped or is not
// recording, and make it
// record.
else {
recorder.read(audioData, 0, bufferSize); // read the PCM
// audio data
// into the
// audioData
// array
// Now we need to decode the PCM data using the Zero
// Crossings Method
numCrossing = 0; // initialize your number of zero crossings
// to 0
for (p = 0; p 0 && audioData[p + 1] = 0)
numCrossing++;
if (audioData[p + 1] > 0 && audioData[p + 2] = 0)
numCrossing++;
if (audioData[p + 2] > 0 && audioData[p + 3] = 0)
numCrossing++;
if (audioData[p + 3] > 0 && audioData[p + 4] = 0)
numCrossing++;
}// for p
for (p = (bufferSize / 4) * 4; p 0 && audioData[p + 1] = 0)
numCrossing++;
}
frequency = (8000 / bufferSize) * (numCrossing / 2); // Set
// the audio Frequency to half the number of zero crossings, times the number of samples our buffersize is per second.
avgFrequency = avgFrequency + frequency;
avg++;
Log.d(TAG, " frequency is " + frequency);
if (handler == null) {
handler = new Handler(Looper.getMainLooper());
handler.postDelayed(runnable, 2000);
}
// placeHolder.printFrequency((frequency * 60));
}// else recorder started
} // while recording
答案 0 :(得分:0)
过零次数不可靠,频率越高越低,噪音越大,除非声音是纯正窦或方波。
你可以在那里找到和FFT算法:FFT library in android Sdk
FFT正在计算频带中的功率(如频谱分析仪所显示的那样)。您应该尝试从强力球声音中查看曲线图像,并确定哪种是处理它的最佳方式(较低频率峰值,较高值峰值,......)。