从MIC读取android AudioRecord幅度 [英] android AudioRecord amplitude reading from MIC

查看:311
本文介绍了从MIC读取android AudioRecord幅度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试记录MIC的声音并绘制实时图表.我能够记录并绘制图形.问题是使用下面的代码记录的值不准确,例如...下面的图像是当我完全没有声音时得到的图像.我已经看到了使用fft的示例,但我不确定这对我的情况是否有帮助,因为我正在尝试绘制时域图,并且我认为无意将其转换为频域.其他人正在使用平均功率,这可能会有所帮助,但我不确定.

I am trying to record the sound from the MIC and draw a live graph. I am able to record and draw the graph. The problem is the values that are recorded using the code below are not accurate for example ... the image below is what i get when there is no sound at all present. I have seen examples using the fft but I am noot sure if that will be of any help in my case as I am trying to draw a time domain graph and I see no purpose to convert it to frequency domain (for now). Others are using average power, this might be helpful but I am not sure.

感谢您的帮助.

bufferSize = AudioRecord.getMinBufferSize(RECORDER_SAMPLERATE,RECORDER_CHANNELS,RECORDER_AUDIO_ENCODING);

    recorder = new AudioRecord(MediaRecorder.AudioSource.MIC,
            RECORDER_SAMPLERATE, RECORDER_CHANNELS,RECORDER_AUDIO_ENCODING, bufferSize);

    short data [] = new short[bufferSize];

    while (!Thread.interrupted()) {

        recorder.startRecording();

        recorder.read(data, 0, bufferSize);

        recorder.stop();

        for (short s : data)
        {
            try {
                Thread.sleep((long) 300.00);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            postUI (Math.abs(s));
        }
    }

    recorder.release();

推荐答案

对于其他寻求方法的人,请查看

For anyone else looking for a way to do this, check out Samsung's fantastic example complete with source code

这篇关于从MIC读取android AudioRecord幅度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆