黑莓录音示例代码

发布于 2024-07-22 00:58:23 字数 154 浏览 14 评论 0原文

有谁知道有一个好的存储库可以获取 BlackBerry 的示例代码吗? 具体来说,可以帮助我学习录制音频的机制的示例,甚至可能对其进行采样并对其进行一些动态信号处理?

我想读取传入的音频,如果需要的话可以逐个采样,然后对其进行处理以产生所需的结果,在本例中是可视化工具。

Does anyone know of a good repository to get sample code for the BlackBerry? Specifically, samples that will help me learn the mechanics of recording audio, possibly even sampling it and doing some on the fly signal processing on it?

I'd like to read incoming audio, sample by sample if need be, then process it to produce a desired result, in this case a visualizer.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情绪失控 2024-07-29 00:58:23

RIM API 包含JSR 135 Java Mobile Media API,用于处理音频和音频 视频内容。
您纠正了 BB 知识库上的混乱情况。 唯一的办法就是浏览它,希望他们不会再更改站点地图。
这是开发人员->资源->知识库 ->Java API 和示例->音频和视频

音频录制 录制

音频基本上很简单:

  • 使用正确的音频编码创建播放器
  • 获取 RecordControl
  • 开始录制
  • 停止录制

链接:
RIM 4.6.0 API 参考:包 javax .microedition.media
如何 - 在 BlackBerry 智能手机上录制音频
操作方法 - 在应用程序中播放音频
操作方法 - 支持将音频流式传输到媒体应用程序
如何 - 指定音频路​​径路由
如何 - 从媒体应用程序获取媒体播放时间
什么是 - 支持的音频格式
什么是 - 媒体应用程序错误代码 声明

带有播放器、RecordControl 和资源的音频记录示例

线程:

final class VoiceNotesRecorderThread extends Thread{
   private Player _player;
   private RecordControl _rcontrol;
   private ByteArrayOutputStream _output;
   private byte _data[];

   VoiceNotesRecorderThread() {}

   private int getSize(){
       return (_output != null ? _output.size() : 0);
   }

   private byte[] getVoiceNote(){
      return _data;
   }
}

在 Thread.run() 上开始音频录制:

   public void run() {
      try {
          // Create a Player that captures live audio.
          _player = Manager.createPlayer("capture://audio");
          _player.realize();    
          // Get the RecordControl, set the record stream,
          _rcontrol = (RecordControl)_player.getControl("RecordControl");    
          //Create a ByteArrayOutputStream to capture the audio stream.
          _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());
            }
         });
      }
   }

在 thread.stop() 上停止录制:

   public void stop() {
      try {
           //Stop recording, capture data from the OutputStream,
           //close the OutputStream and player.
           _rcontrol.commit();
           _data = _output.toByteArray();
           _output.close();
           _player.close();    
      } catch (Exception e) {
         synchronized (UiApplication.getEventLock()) {
            Dialog.inform(e.toString());
         }
      }
   }

处理和采样音频流

在录制结束时,您将获得充满特定音频格式数据的输出流。 因此,要处理或采样它,您必须解码该音频流。

谈到即时处理,那会更加复杂。 您必须在记录期间读取输出流,而无需提交记录。 因此,将有几个问题需要解决:

  • 同步访问记录器和采样器的输出流 - 线程问题
  • 读取正确数量的音频数据 - 深入音频格式解码以找出标记规则

也可能有用:
java .net:Java ME 中的流内容实验,作者:Vikram Goyal

RIM API contains JSR 135 Java Mobile Media API for handling audio & video content.
You correct about mess on BB Knowledge Base. The only way is browse it, hoping they'll not going to change site map again.
It's Developers->Resources->Knowledge Base->Java API's&Samples->Audio&Video

Audio Recording

Basically it's simple to record audio:

  • create Player with correct audio encoding
  • get RecordControl
  • start recording
  • stop recording

Links:
RIM 4.6.0 API ref: Package javax.microedition.media
How To - Record Audio on a BlackBerry smartphone
How To - Play audio in an application
How To - Support streaming audio to the media application
How To - Specify Audio Path Routing
How To - Obtain the media playback time from a media application
What Is - Supported audio formats
What Is - Media application error codes

Audio Record Sample

Thread with Player, RecordControl and resources is declared:

final class VoiceNotesRecorderThread extends Thread{
   private Player _player;
   private RecordControl _rcontrol;
   private ByteArrayOutputStream _output;
   private byte _data[];

   VoiceNotesRecorderThread() {}

   private int getSize(){
       return (_output != null ? _output.size() : 0);
   }

   private byte[] getVoiceNote(){
      return _data;
   }
}

On Thread.run() audio recording is started:

   public void run() {
      try {
          // Create a Player that captures live audio.
          _player = Manager.createPlayer("capture://audio");
          _player.realize();    
          // Get the RecordControl, set the record stream,
          _rcontrol = (RecordControl)_player.getControl("RecordControl");    
          //Create a ByteArrayOutputStream to capture the audio stream.
          _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());
            }
         });
      }
   }

And on thread.stop() recording is stopped:

   public void stop() {
      try {
           //Stop recording, capture data from the OutputStream,
           //close the OutputStream and player.
           _rcontrol.commit();
           _data = _output.toByteArray();
           _output.close();
           _player.close();    
      } catch (Exception e) {
         synchronized (UiApplication.getEventLock()) {
            Dialog.inform(e.toString());
         }
      }
   }

Processing and sampling audio stream

In the end of recording you will have output stream filled with data in specific audio format. So to process or sample it you will have to decode this audio stream.

Talking about on the fly processing, that will be more complex. You will have to read output stream during recording without record commiting. So there will be several problems to solve:

  • synch access to output stream for Recorder and Sampler - threading issue
  • read the correct amount of audio data - go deep into audio format decode to find out markup rules

Also may be useful:
java.net: Experiments in Streaming Content in Java ME by Vikram Goyal

风向决定发型 2024-07-29 00:58:23

虽然不是特定于音频的,但这个问题确实有一些很好的“入门”参考。

编写 Blackberry 应用程序

While not audio specific, this question does have some good "getting started" references.

Writing Blackberry Applications

活雷疯 2024-07-29 00:58:23

我也花了很长时间试图弄清楚这一点。 安装 BlackBerry Component Pack(可从其网站获取)后,您可以在组件包内找到示例代码。

就我而言,将组件包安装到 Eclipse 后,我在以下位置找到了提取的示例代码:

C:\程序
文件\Eclipse\eclipse3.4\plugins\net.rim.eide.componentpack4.5.0_4.5.0.16\components\samples

不幸的是,当我导入所有示例代码时,出现了一堆编译错误。 为了解决这个问题,我删除了 20% 有编译错误的包。

我的下一个问题是启动模拟器总是启动第一个示例代码包(在我的例子中是 activetextfieldsdemo),我无法让它只运行我感兴趣的包。解决方法是删除之前按字母顺序列出的所有包我想要的那个。

其他问题:
-右键单击 Eclipse 中的项目并选择“Activate for BlackBerry”
-选择黑莓-> 构建配置...-> 编辑...并选择您的新项目以便构建。
- 确保将 BlackBerry 源代码放在 Eclipse 项目的“src”文件夹下,否则可能会遇到构建问题。

I spent ages trying to figure this out too. Once you've installed the BlackBerry Component Packs (available from their website), you can find the sample code inside the component pack.

In my case, once I had installed the Component Packs into Eclipse, I found the extracted sample code in this location:

C:\Program
Files\Eclipse\eclipse3.4\plugins\net.rim.eide.componentpack4.5.0_4.5.0.16\components\samples

Unfortunately when I imported all that sample code I had a bunch of compile errors. To workaround that I just deleted the 20% of packages with compile errors.

My next problem was that launching the Simulator always launched the first sample code package (in my case activetextfieldsdemo), I couldn't get it to run just the package I am interested in. Workaround for that was to delete all the packages listed alphabetically before the one I wanted.

Other gotchas:
-Right click on the project in Eclipse and select Activate for BlackBerry
-Choose BlackBerry -> Build Configurations... -> Edit... and select your new project so it builds.
-Make sure you put your BlackBerry source code under a "src" folder in the Eclipse project, otherwise you might hit build issues.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文