Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Droid native sr #4329

Merged
merged 2 commits into from

6 participants

@t-nelson

Android will resample to the "native" sampling rate regardless of what we setup the audiotrack class with. Don't bother playing the guessing game.

Trent Nelson added some commits
Trent Nelson [DROID][JNI] Add method to query HW sample rate. 34d1b05
Trent Nelson [DROID][AE] Don't guess at supported sampling rate
Android will resample to the "native" sample rate defined in firmware so
only use that rate.
9f7de7d
@t-nelson

@davilla @koying @FernetMenta @fritsch for review

jenkins build this please

@koying
Collaborator

Not sure about this one.

The AudioTrack ctor takes a sampling rate. Depending on the underlying hw, it might accept it or throw an exception.
Using "getNativeOutputSampleRate" will only get you the currently configured one, imo.

@t-nelson

@koying looking through firmware, I've never seen where android actually queries the HW for supported SR. There are several case statements with lists of "valid" SRs and other hardcoded stuff like

if (sampleRate >= 4000 && sampleRate <=48000)

I've come to my conclusion here by playing stereo audio with ae configured in fixed mode. No matter what sample rate I chose (within the valid range) the sink showed configured correctly, but the AVR never switched from 48kHz, which is what getNativeOutputSamplingRate() returns for me. Further, I've seen on some devices where 44.1 or 48k in fact do not work. So the assumptions we're currently making here are, at least, not safe.

Can you verify (at the tv/avr) a device that will actually change output SR for PCM?

@koying
Collaborator

This is about as much info I ever found regarding audio hw on android: http://source.android.com/devices/audio_implement.html
Clearly, the audio_policy.conf I have on all my devices shows various SR, which should be selectable, somehow.
I suppose it comes down to half-assed implementation, again.

Anyway, I'd suggest to postpone this to G+1. AFAIK, the current implem just works, no need to risk regressions at this point for Gotham ;)

@fritsch
Collaborator

I think this is gotham material, example:

If you open the sink with 44.1 and the real audiotrack of the system does implicit resampling, without you knowing of that, then every passthrough you send through is touched and noise ends in the AVR.

@t-nelson

Indeed it does resolve passthrough of 44.1khz DD on AML devices. 44.1khz DTS is now detected by the AVR, but plays only silence. I'm still looking into that one.

The potential for doing double resampling seems reason enough to get this in.

@koying
Collaborator

Ok, I trust the specialists ;)

@FernetMenta
Collaborator

i think you should disable passthrough if 48khz is not supported. quite a couple of receivers fail if encoded sample rate != sample rate.

@t-nelson

This got IRC signoff from @FernetMenta. The build failure is unrelated win32.

@t-nelson t-nelson merged commit 9abc85a into xbmc:master
@t-nelson t-nelson deleted the unknown repository branch
@MartijnKaijser MartijnKaijser added this to the H* 14.0-alpha1 milestone
@jmarshallnz jmarshallnz removed the Gotham label
@t-nelson t-nelson added Gotham and removed Gotham labels
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 4, 2014
  1. [DROID][JNI] Add method to query HW sample rate.

    Trent Nelson authored
  2. [DROID][AE] Don't guess at supported sampling rate

    Trent Nelson authored
    Android will resample to the "native" sample rate defined in firmware so
    only use that rate.
This page is out of date. Refresh to see the latest.
View
6 xbmc/android/jni/AudioTrack.cpp
@@ -116,3 +116,9 @@ int CJNIAudioTrack::getMinBufferSize(int sampleRateInHz, int channelConfig, int
sampleRateInHz, channelConfig, audioFormat);
}
+int CJNIAudioTrack::getNativeOutputSampleRate(int streamType)
+{
+ return call_static_method<int>( "android/media/AudioTrack", "getNativeOutputSampleRate", "(I)I",
+ streamType);
+}
+
View
1  xbmc/android/jni/AudioTrack.h
@@ -45,6 +45,7 @@ class CJNIAudioTrack : public CJNIBase
static void PopulateStaticFields();
static int getMinBufferSize(int sampleRateInHz, int channelConfig, int audioFormat);
+ static int getNativeOutputSampleRate(int streamType);
};
};
View
17 xbmc/cores/AudioEngine/Sinks/AESinkAUDIOTRACK.cpp
@@ -94,19 +94,7 @@ bool CAESinkAUDIOTRACK::Initialize(AEAudioFormat &format, std::string &device)
aml_set_audio_passthrough(m_passthrough);
#endif
- // default to 44100, all android devices support it.
- // then check if we can support the requested rate.
- unsigned int sampleRate = 44100;
- for (size_t i = 0; i < m_info.m_sampleRates.size(); i++)
- {
- if (m_format.m_sampleRate == m_info.m_sampleRates[i])
- {
- sampleRate = m_format.m_sampleRate;
- break;
- }
- }
-
- m_format.m_sampleRate = sampleRate;
+ m_format.m_sampleRate = CJNIAudioTrack::getNativeOutputSampleRate(CJNIAudioManager::STREAM_MUSIC);
m_format.m_dataFormat = AE_FMT_S16LE;
m_format.m_channelLayout = m_info.m_channels;
m_format.m_frameSize = m_format.m_channelLayout.Count() *
@@ -259,8 +247,7 @@ void CAESinkAUDIOTRACK::EnumerateDevicesEx(AEDeviceInfoList &list, bool force)
m_info.m_displayNameExtra = "audiotrack";
m_info.m_channels += AE_CH_FL;
m_info.m_channels += AE_CH_FR;
- m_info.m_sampleRates.push_back(44100);
- m_info.m_sampleRates.push_back(48000);
+ m_info.m_sampleRates.push_back(CJNIAudioTrack::getNativeOutputSampleRate(CJNIAudioManager::STREAM_MUSIC));
m_info.m_dataFormats.push_back(AE_FMT_S16LE);
#if 0 //defined(__ARM_NEON__)
if (g_cpuInfo.GetCPUFeatures() & CPU_FEATURE_NEON)
Something went wrong with that request. Please try again.