人体对声音的识别确实存在不敏感,导致现在Android系统应用层的调节停留在音量大小为主,查看系统的工程模式发现存在很多更细节的参数,如果作为一款专业的调节参数应用是不是会很好呢。有些领域的群体对音质和音效很敏感。随便看看的源码,没深入,只为脑海有个印象
1. String.xml
<string name="audio_volume_title">Volumestring>
2.AndroidMainfest.xml
".audio.AudioVolume"
android:label="@string/audio_volume_title"
android:screenOrientation="portrait" >
3.AudioVolume.java
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
switch (position) {
case 0 : {
Intent intent = new Intent(this, AudioVolumeVoice.class);
startActivity(intent);
return;
}
case 1 : {
Intent intent = new Intent(this, AudioVolumeVoIP.class);
startActivity(intent);
return;
}
case 2 : {
Intent intent = new Intent(this, AudioVolumePlayback.class);
startActivity(intent);
return;
}
case 3 : {
Intent intent = new Intent(this, AudioVolumeRecord.class);
startActivity(intent);
return;
}
default:
break;
}
}
4.AudioVolumeVoice.java
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.audio_volume_item);
mAudioMgr = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
initComponents();
}
5.布局文件 audio_volume_item.xml
1.String.xml
<string name="sound_enhancement_title">音效改善string>
<string name="music_plus_summary">针对耳机的音效改善string>
<string name="audio_profile_bes_surround_title">BesSurroundstring>
<string name="audio_profile_bes_surround_summary">音效环绕string>
<string name="audio_profile_bes_surround_mode_movie">电影模式string>
<string name="audio_profile_bes_surround_mode_music">音乐模式string>
<string name="anc_switch_title">噪音消除string>
<string name="audio_profile_bes_loudness_summary">喇叭音量助推器string>
2.调用处 audioprofile_sound_enhancement.xml
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:orderingFromXml="true"
android:persistent="false" >
<SwitchPreference
android:key="music_plus"
android:persistent="false"
android:summary="@string/music_plus_summary" 针对耳机的音效改善
android:title="@string/music_plus_title" />
<SwitchPreference
android:key="bes_loudness"
android:persistent="false"
android:summary="@string/audio_profile_bes_loudness_summary" 喇叭音量助推器
android:title="@string/audio_profile_bes_loudness_title" />
<Preference
android:key="bes_surround"
android:title="@string/audio_profile_bes_surround_title"
android:summary="@string/audio_profile_bes_surround_summary"音效环绕
android:persistent="false" />
<SwitchPreference
android:key="anc_switch"
android:persistent="false"
android:title="@string/anc_switch_title" />
PreferenceScreen>
3.SoundEnhancement.java 调用
加载布局
addPreferencesFromResource(R.xml.audioprofile_sound_enhancement);
4.喇叭音量助推器 开关
private static final String KEY_BESLOUDNESS = "bes_loudness";
mBesLoudnessPref = (SwitchPreference) findPreference(KEY_BESLOUDNESS);
if (!FeatureOption.MTK_BESLOUDNESS_SUPPORT) {
Log.d("@M_" + TAG, "feature option is off, remove BesLoudness preference");
getPreferenceScreen().removePreference(mBesLoudnessPref);
}
private static final String SET_BESLOUDNESS_ENABLED = "SetBesLoudnessStatus=1";
private static final String SET_BESLOUDNESS_DISABLED = "SetBesLoudnessStatus=0";
if (FeatureOption.MTK_BESLOUDNESS_SUPPORT) {
if (mBesLoudnessPref == preference) {
boolean enabled = ((SwitchPreference) preference).isChecked();
String cmdStr = enabled ? SET_BESLOUDNESS_ENABLED : SET_BESLOUDNESS_DISABLED;
Log.d("@M_" + TAG, " set command about besloudness: " + cmdStr);
mAudioManager.setParameters(cmdStr);
}
}
设置音量大小,是否开启音效加强器
private Context mContext;
private AudioManager mAudioManager;
public AudioUtil(Context mContext) {
this.mContext = mContext;
mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
}
public boolean isBesLoudnessEnable() {
if (MTK_BESLOUDNESS_SUPPORT) {
return GET_BESLOUDNESS_STATUS_ENABLED.equals(mAudioManager.getParameters(GET_BESLOUDNESS_STATUS));
}
return false;
}
public void startAudioPowerSave() {
if (MTK_BESLOUDNESS_SUPPORT) {
mAudioManager.setParameters(SET_BESLOUDNESS_DISABLED);
}
}
public void stopAudioPowerSave() {
if (MTK_BESLOUDNESS_SUPPORT) {
mAudioManager.setParameters(SET_BESLOUDNESS_ENABLED);
}
}
public int getMaxMediaVolume() {
return mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
}
public int getMediaVolume() {
return mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
}
public void setMediaVolume(int volume) {
mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, AudioManager.FLAG_PLAY_SOUND);
}
public void plus(View view) {
AudioManager am =(AudioManager)getSystemService(Context.AUDIO_SERVICE);
am.adjustStreamVolume (AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, 0);
Log.d("suhuazhi", "getMediaVolume = " + getMediaVolume());
}
public void sub(View view) {
AudioManager am =(AudioManager)getSystemService(Context.AUDIO_SERVICE);
am.adjustStreamVolume (AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER , 0);
Log.d("suhuazhi", "getMediaVolume = " + getMediaVolume());
}