OpenSL volume 조절 질문입니다.
글쓴이: lalupo20 / 작성시간: 토, 2018/09/01 - 1:48오후
일단 볼륨 조절 함수는 다음과 같이 만들었습니다.
SLmillibel MusicPlayer::getVolume() { SLresult result; if (uriPlayerVolume != NULL) { SLmillibel vol = 0; result = (*uriPlayerVolume)->GetVolumeLevel(uriPlayerVolume, &vol); if (result != SL_RESULT_SUCCESS) { LOGI("getVolume error"); return -1; } return vol; } return 0; } void MusicPlayer::setVolume(SLmillibel volume) { SLresult result; SLVolumeItf volumeItf = uriPlayerVolume; SLmillibel max; if (volumeItf != NULL) { (*volumeItf)->GetMaxVolumeLevel(volumeItf, &max); result = (*volumeItf)->SetVolumeLevel(volumeItf, volume); if (result != SL_RESULT_SUCCESS) { LOGI("setVolume error"); return; } } }
그리고... 엔진 초기화 할 때
// create audio player const SLInterfaceID ids[3] = { SL_IID_SEEK, SL_IID_MUTESOLO, SL_IID_VOLUME }; const SLboolean req[3] = { SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE, SL_BOOLEAN_TRUE }; result = (*engineEngine)->CreateAudioPlayer(engineEngine, &uriPlayerObject, &audioSrc, &audioSnk, 3, ids, req);
다음과 같이 구현하였습니다.
getVolume() 함수로 볼륨값 리턴 받으면 0이 나오네요.
중간에 볼륨 최대값 체크해보면 또 0이 나옵니다.
result 값은 에러 나오지 않고 SUCCESS 리턴 됩니다.
위 함수 작성한 부분에 문제가 있나요?
Forums:
참고해보세요.
- 최대값이 0 이라는 말이 보입니다.
그렇지만. 함수 설명에서는
The maximum supported level is always at least 0 mB.
지원되는 최대 레벨은 항상 최소 0 mB입니다. 라고 합니다.
- 버그가 있다는 이야기도 보입니다.
- 잘 되는 책 예제 소스를 구해야 할것 같습니다.
- 함수의 인자값. 리턴값. 오류값을 확인해보시기 바랍니다.
SetVolume()
GetVolume()
SetVolumeLevel()
GetVolumeLevel()
GetVolumeScale()
- 인자 리턴값은 NULL 이 아니어야 한다고 합니다.
pLevel [out] Pointer to a location to receive the object’s volume level in millibels. This must be non-NULL.
pLevel [out] 객체의 볼륨을 수신 할 위치의 포인터 수준 (밀리미터 단위). 이것은 NULL이 아니어야 합니다.
OpenSL/ES : maximum volume of AudioPlayer
https://groups.google.com/forum/#!topic/Android-ndk/wOJCxFg5rf8
From the document in r6 (docs/opensles/chart1.png), it looks we can get/set the volume of AudioPlayer object via VolumeItf.
The result is however, the return value of GetMaxVolumeLevel() is always 0, thus I canot set the volume anything but 0.
Am I missing something?
r6 (docs / opensles / chart1.png)에있는 문서에서 VolumeItf를 통해 AudioPlayer 객체의 볼륨을 가져 오거나 설정할 수 있습니다.
그러나 결과는 GetMaxVolumeLevel ()의 반환 값은 항상 0이므로 볼륨을 0으로 설정하지 않습니다.
내가 놓친 게 있니?
On Android the max level is 0 (unity gain). You can go below that (negative values), but you can't go above 0.
Android의 경우 최대 레벨은 0입니다 (단위 이득). 그 이하 (음수 값)로 갈 수 있지만 0 이상으로 갈 수는 없습니다.
https://www.khronos.org/registry/OpenSL-ES/specs/OpenSL_ES_Specification_1.0.1.pdf
SetVolumeLevel
SLresult (*SetVolumeLevel) (
SLVolumeItf self,
SLmillibel level
);
Description Sets the object’s volume level.
Pre-conditions None
Parameters self [in] Interface self-reference.
level [in] Volume level in millibels. The valid range is
[SL_MILLIBEL_MIN, maximum supported level],
where maximum supported level can be queried with
the method GetMaxVolumeLevel(). The maximum
supported level is always at least 0 mB.
Return value The return value can be one of the following:
SL_RESULT_SUCCESS
SL_RESULT_PARAMETER_INVALID
Comments If the object is muted, calls to SetVolumeLevel() will still change
the internal volume level, but this will have no audible effect until
the object is unmuted.
See also SetMute()
OpenSL ES 1.0.1 Specification 409
GetVolumeLevel
SLresult (*GetVolumeLevel) (
SLVolumeItf self,
SLmillibel *pLevel
);
Description Gets the object’s volume level.
Pre-conditions None
Parameters self [in] Interface self-reference.
pLevel [out] Pointer to a location to receive the object’s volume
level in millibels. This must be non-NULL.
Return value The return value can be one of the following:
SL_RESULT_SUCCESS
SL_RESULT_PARAMETER_INVALID
Comments None
See also None
Getting Started with OpenSL on Android
http://vec3.ca/getting-started-with-opensl-on-android/
OpenSLES 에서 볼륨조절하는코딩을했는데
https://www.androidpub.com/2271400
[android-ndk] OpenSL ES would cause noise when adjust volume?
https://grokbase.com/t/gg/android-ndk/165r5mahzn/opensl-es-would-cause-noise-when-adjust-volume
Android Audio & OpenSL
https://www.slideshare.net/DSPIP/android-audio-opensl
Simple streaming audio mixer for Android with OpenSL ES - part 1
http://sbcgamesdev.blogspot.com/2013/01/simple-streaming-audio-mixer-for.html
Android通?OpenSL ES播放音?套路?解
https://juejin.im/entry/5a06d7456fb9a045211e2dda
OpenSL ESその2
http://codeanalyze.blogspot.com/2012/05/opensl-es2.html
Unable to set Android audio to 0 with SoundMix
https://answers.unrealengine.com/questions/260496/unable-to-set-android-audio-to-0.html
이것은 안드로이드 오디오 구현에서 볼륨을 재생하는 방법에 불행한 안드로이드 버그가 있기 때문입니다.
이 버그는 선형 볼륨을 dB 볼륨으로 올바르게 변환하는 방법에 대한 오해에서 비롯되었습니다.
AIS가 문제의 원인이되는 현재 출시 된 Android 코드입니다 (그리고 발견 한 코드).
이 알고리즘은 선형 볼륨을 가져 와서 최소 및 최대 데시벨 (-30dB 및 0) 사이에서 조정하며 절대 수행하지 않습니다.
출력 볼륨을 크랭크로 만들면 출력 볼륨이 입력 볼륨과 같지 않을뿐만 아니라 최소 볼륨 값 (-30dB)이 계속 들립니다 (발견 한대로).
-30 dB는 0.032의 선형 볼륨 / 크기와 같습니다.
또한 클램프의 최소 볼륨을 -90dB로 변경하는 것은 올바르지 않습니다 (위에서 언급했듯이) 볼륨이 올바르지 않을 것이기 때문입니다.
예를 들어, 입력 선형 볼륨이 0.5 인 경우,
-90dB에서 0dB 사이의 스케일링은 -45dB입니다! 실제로 0.5 선형 볼륨이 실제로 -6dB이며 (우리 모두가 알고 있듯이) 완전히 들릴 수 있습니다.
필자는 최근 선형 볼륨을 dB 볼륨으로 변환하는 올바른 방법을 사용하여 선형 볼륨과 dB 볼륨 간의 올바른 변환 공식을 사용하여이를 확인했습니다.
그리고 물론, 반대 방향으로 가고, 선형 볼륨을 해결하십시오 (주어진 dB 값이 예상 된 선형 값이되는지 확인하고 싶다면) :
? 선형 = 멱 (dBVolume / 20, 10)
?
불행하게도 0.0의 선형 볼륨은 엄청난 음수 (기술적으로 음의 무한대)가되어 여전히 클램프해야합니다.
-30dB의 클램핑 대신에 나는 절대적으로 들리지 않는 -120dB로 클램프하고 있습니다 .
EnvironmentalReverb
https://developer.android.com/reference/android/media/audiofx/EnvironmentalReverb
https://www.khronos.org/files/opensl-es-1-1-quick-reference.pdf
GetVolumeScale
SLresult (*GetVolumeScale) (
SLDeviceVolumeItf self,
SLuint32 deviceID,
SLint32 *pMinValue,
SLint32 *pMaxValue,
SLboolean *pIsMillibelScale
);
Description Gets the properties of the volume scale supported by the given device.
Pre-conditions None
self [in] Interface self-reference.
deviceID [in] Audio input or output device’s identifier.
pMinValue [out] The smallest supported volume value of the
device.
pMaxValue [out] The greatest supported volume value of the
device.
Parameters
pIsMillibelScale [out] If true, the volume values used by GetVolume,
SetVolume and this method are in millibel
units; if false, the volume values are in
arbitrary volume steps.
Return value The return value can be one of the following:
SL_RESULT_SUCCESS
SL_RESULT_PARAMETER_INVALID
SL_RESULT_FEATURE_UNSUPPORTED
SL_RESULT_CONTROL_LOST
Comments This method may return SL_RESULT_FEATURE_UNSUPPORTED if the specified
device does not support changes to its volume.
The scale is always continuous and device-specific. It could be, for
example, [0, 15] if arbitrary volume steps are used or [-32768, 0] if
millibels are used.
See also SLAudioIODeviceCapabilitiesItf(), SLOutputMixItf()
SetVolume
SLresult (*SetVolume) (
SLDeviceVolumeItf self,
SLuint32 deviceID,
SLint32 volume
);
Description Sets the device’s volume level.
Pre-conditions None
self [in] Interface self-reference.
deviceID [in] Device’s identifier.
Parameters
volume [in] The new volume setting. The valid range is continuous
and its boundaries can be queried from GetVolumeScale
method.
Return value The return value can be one of the following:
SL_RESULT_SUCCESS
SL_RESULT_PARAMETER_INVALID
SL_RESULT_FEATURE_UNSUPPORTED
SL_RESULT_CONTROL_LOST
Comments The minimum and maximum supported volumes are device-dependent.
This method may fail if the specified device does not support changes to its
volume or the volume is outside the range supported by the device.
See also SLAudioIODeviceCapabilitiesItf(), SLOutputMixItf()
GetVolume
SLresult (*GetVolume) (
SLDeviceVolumeItf self,
SLuint32 deviceID,
SLint32 *pVolume
);
Description Gets the device’s volume.
Pre-conditions None
self [in] Interface self-reference.
deviceID [in] Device’s identifier.
Parameters
pVolume [out] Pointer to a location to receive the object’s volume
setting. This must be non-NULL.
Return value The return value can be one of the following:
SL_RESULT_SUCCESS
SL_RESULT_PARAMETER_INVALID
SL_RESULT_FEATURE_UNSUPPORTED
Comments SL_RESULT_FEATURE_UNSUPPORTED is returned if the specified device
does not support changes to its volume.
----------------------------------------------------------------------------
젊음'은 모든것을 가능하게 만든다.
매일 1억명이 사용하는 프로그램을 함께 만들어보고 싶습니다.
정규 근로 시간을 지키는. 야근 없는 회사와 거래합니다.
각 분야별. 좋은 책'이나 사이트' 블로그' 링크 소개 받습니다. shintx@naver.com
최대값이 100이라는 소리를 어디서 본 거 같아서 이상하게 보고 있었는데
최대값이 0이 맞네요.
값을 100정도씩 변동 주니까
소리가 조금씩 작아지는게 느껴지네요.
댓글 감사드립니다.
댓글 달기