gpt4 book ai didi

blackberry - J2ME/Blackberry-获得音频信号幅度水平?

转载 作者:行者123 更新时间:2023-12-02 22:52:12 25 4
gpt4 key购买 nike

在j2me中是否可以测量JSR-135 Player制作的音频记录的信号幅度?
我知道我可以访问缓冲区,但是那又如何呢?

目标型号Bold 9000,支持格式PCM和AMR。我应该使用哪种格式?

也可以看看
Blackberry Audio Recording Sample Code
How To - Record Audio on a BlackBerry smartphone

谢谢!

最佳答案

获取原始PCM信号电平

  • 使用菜单和拨轮放大/缩小并在图形内向左/向右移动。
  • 音频格式:原始8000 Hz 16位单声道pcm。
  • 在Bold 9000 RIM OS 4.6上测试
  • Algorythm可以在支持j2me和pcm的任何移动设备上工作,当然实现可能需要更改。

  • 使用线程进行录音:
    class VoiceNotesRecorderThread extends Thread {

    private Player _player;
    private RecordControl _rcontrol;
    private ByteArrayOutputStream _output;
    private byte _data[];

    VoiceNotesRecorderThread() {
    }

    public void run() {
    try {
    _player = Manager
    .createPlayer("capture://audio?encoding=audio/basic");
    _player.realize();
    _rcontrol = (RecordControl) _player
    .getControl("RecordControl");
    _output = new ByteArrayOutputStream();
    _rcontrol.setRecordStream(_output);
    _rcontrol.startRecord();
    _player.start();
    } catch (final Exception e) {
    UiApplication.getUiApplication().invokeAndWait(new Runnable() {
    public void run() {
    Dialog.inform(e.toString());
    }
    });
    }
    }

    public void stop() {
    try {
    _rcontrol.commit();
    _data = _output.toByteArray();
    _output.close();
    _player.close();
    } catch (Exception e) {
    synchronized (UiApplication.getEventLock()) {
    Dialog.inform(e.toString());
    }
    }
    }

    byte[] getData() {
    return _data;
    }
    }

    以及使用byte []缓冲区绘制图形的方法:
    private Bitmap getGraph(byte[] buffer, int zoom, int startFrom) {
    Bitmap result = new Bitmap(Display.getWidth(), Display.getHeight());
    Graphics g = new Graphics(result);
    g.setColor(Color.BLACK);
    int xPos = 0;
    int yPos = Display.getHeight() >> 1;
    for (int i = startFrom; i < buffer.length; i += 2 * zoom) {
    byte[] b = new byte[] { buffer[i], buffer[i + 1] };
    int level = (signedShortToInt(b) * 100 / 32767);
    if (100 < level) {
    level -= 200;
    }

    g.drawPoint(xPos, yPos - level);
    xPos++;
    }
    return result;
    }

    public static final int signedShortToInt(byte[] b) {
    int result = (b[0] & 0xff) | (b[1] & 0xff) << 8;
    return result;
    }

    屏幕类别:
    class Scr extends MainScreen {
    BitmapField mGraphField = new BitmapField(new Bitmap(Display.getWidth(),
    Display.getHeight()));

    private VoiceNotesRecorderThread m_thread;

    public Scr() {
    add(mGraphField);
    add(new NullField(FOCUSABLE));
    }

    boolean mRecording = false;
    private int mZoom = 1;
    private int mStartFrom = 0;

    byte[] mAudioData = null;

    protected void makeMenu(Menu menu, int instance) {
    super.makeMenu(menu, instance);
    menu.add(mRecordStopMenuItem);

    menu.add(mPaintZoomIn);
    menu.add(mPaintZoomOut);
    menu.add(mPaintZoomToFitScreen);

    menu.add(mPaintMoveRight);
    menu.add(mPaintMoveLeft);
    menu.add(mPaintMoveToBegin);
    }

    MenuItem mRecordStopMenuItem = new MenuItem("Record", 0, 0) {
    public void run() {
    if (!mRecording) {
    m_thread = new VoiceNotesRecorderThread();
    m_thread.start();
    mRecording = true;
    this.setText("Stop");
    } else {
    m_thread.stop();
    mAudioData = m_thread.getData();
    zoomToFitScreen();
    mRecording = false;
    this.setText("Record");
    }
    }
    };

    MenuItem mPaintZoomIn = new MenuItem("Zoom In", 0, 0) {
    public void run() {
    zoomIn();
    }
    };

    MenuItem mPaintZoomOut = new MenuItem("Zoom Out", 0, 0) {
    public void run() {
    zoomOut();
    }
    };

    MenuItem mPaintZoomToFitScreen = new MenuItem("Fit Screen", 0, 0) {
    public void run() {
    zoomToFitScreen();
    }
    };

    MenuItem mPaintMoveLeft = new MenuItem("Left", 0, 0) {
    public void run() {
    moveLeft();
    }
    };

    MenuItem mPaintMoveRight = new MenuItem("Right", 0, 0) {
    public void run() {
    moveRight();
    }
    };

    MenuItem mPaintMoveToBegin = new MenuItem("To Begin", 0, 0) {
    public void run() {
    moveToBegin();
    }
    };

    private void zoomOut() {
    if (mZoom < 200)
    mZoom++;
    mGraphField.setBitmap(getGraph(mAudioData, mZoom, mStartFrom));
    }

    private void zoomIn() {
    if (mZoom > 1)
    mZoom--;
    mGraphField.setBitmap(getGraph(mAudioData, mZoom, mStartFrom));
    }

    private void zoomToFitScreen() {
    int lenght = mAudioData.length;
    mZoom = (lenght / 2) / Display.getWidth();
    mGraphField.setBitmap(getGraph(mAudioData, mZoom, mStartFrom));
    }

    private void moveRight() {
    if (mStartFrom < mAudioData.length - 30)
    mStartFrom += 30;
    mGraphField.setBitmap(getGraph(mAudioData, mZoom, mStartFrom));
    }

    private void moveLeft() {
    if (mStartFrom > 30)
    mStartFrom -= 30;
    mGraphField.setBitmap(getGraph(mAudioData, mZoom, mStartFrom));
    }

    private void moveToBegin() {
    mStartFrom = 0;
    mGraphField.setBitmap(getGraph(mAudioData, mZoom, mStartFrom));
    }

    protected boolean navigationMovement(int dx, int dy, int status,
    int time) {

    if (dx < 0) {
    moveLeft();
    } else if (dx > 0) {
    moveRight();
    }
    if (dy < 0) {
    zoomIn();
    } else if (dy > 0) {
    zoomOut();
    }
    return super.navigationMovement(dx, dy, status, time);
    }
    }

    是有帮助的:
    ADC -> integer PCM file -> signal processing
    SO - How is audio represented with numbers?
    Convert byte array to integer

    关于blackberry - J2ME/Blackberry-获得音频信号幅度水平?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1497706/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com