android中的拨号键盘音也是可以改变的,不过不同的是,按键音并不是存储在手机中的ogg格式的音频文件。他是通过C++代码中的频率设定来实现的。

具体的音频控制在frameworks/av/media/libmedia文件夹中的ToneGenerator.cpp中实现:

const ToneGenerator::ToneDescriptor ToneGenerator::sToneDescriptors[] = {        { segments: {{ duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1336, 941, 0 }, 0, 0},                     { duration: 0 , waveFreq: { 0 }, 0, 0}},          repeatCnt: ToneGenerator::TONEGEN_INF,          repeatSegment: 0 },                              // TONE_DTMF_0        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1209, 697, 0 }, 0, 0 },                      { duration: 0 , waveFreq: { 0 }, 0, 0}},          repeatCnt: ToneGenerator::TONEGEN_INF,          repeatSegment: 0 },                              // TONE_DTMF_1        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1336, 697, 0 }, 0, 0 },                      { duration: 0 , waveFreq: { 0 }, 0, 0}},          repeatCnt: ToneGenerator::TONEGEN_INF,          repeatSegment: 0 },                              // TONE_DTMF_2        { segments: { { duration: ToneGenerator::TONEGEN_INF, waveFreq: { 1477, 697, 0 }, 0, 0 },                      { duration: 0 , waveFreq: { 0 }, 0, 0}},          repeatCnt: ToneGenerator::TONEGEN_INF,          repeatSegment: 0 },                              // TONE_DTMF_3

我只截取了0-3号键盘的音频生成代码,其中的函数功能在ToneGenerator.h中有详细说明:

- The array waveFreq[]:
// 1 for static tone descriptors: contains the frequencies of all individual waves making the multi-tone.
// 2 for active tone descritors: contains the indexes of the WaveGenerator objects in mWaveGens
// The number of sine waves varies from 1 to TONEGEN_MAX_WAVES.
// The first null value indicates that no more waves are needed.
// - The array segments[] is used to generate the tone pulses. A segment is a period of time
// during which the tone is ON or OFF. Segments with even index (starting from 0)
// correspond to tone ON state and segments with odd index to OFF state.
// The data stored in segments[] is the duration of the corresponding period in ms.
// The first segment encountered with a 0 duration indicates that no more segment follows.
// - loopCnt - Number of times to repeat a sequence of seqments after playing this
// - loopIndx - The segment index to go back and play is loopcnt > 0
// - repeatCnt indicates the number of times the sequence described by segments[] array must be repeated.
// When the tone generator encounters the first 0 duration segment, it will compare repeatCnt to mCurCount.
// If mCurCount > repeatCnt, the tone is stopped automatically. Otherwise, tone sequence will be
// restarted from segment repeatSegment.
// - repeatSegment number of the first repeated segment when repeatCnt is not null

本来想做成钢琴音的效果,但是对于频率波神马的无能为力。。。随意改动出来的效果实在难听。。。就放弃了。

更多相关文章

  1. android 自动弹起键盘
  2. Android(安卓)startService 启动自动解锁点亮屏幕
  3. Android自定义数字键盘解析
  4. JS 解决安卓手机输入框被软键盘遮住的问题
  5. android获取短信中心号
  6. android 软件键盘
  7. Android学习之键盘事件
  8. 代码碎片
  9. android EditText不弹出软键盘的方法

随机推荐

  1. 【转】Android有效解决加载大图片时内存
  2. Android(安卓)Input设备debug技巧
  3. 【Android(安卓)开发教程】重写onKeyDown
  4. Android(安卓)Launcher 详解
  5. DirectionalViewPager支持横向和纵向的Vi
  6. Android字体00
  7. Android(安卓)stutdio2.2 启动模拟器出现
  8. GitHub上不错的Android开源项目(二)
  9. Android基础篇之AutoCompleteTextView
  10. 【OkHttp3源代码分析】(一)Request的execut