Bug 17994 - Android AudioTrack constructor and static GetMinBufferSize have inconsistent channel configuration parameters
Summary: Android AudioTrack constructor and static GetMinBufferSize have inconsistent ...
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.12.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Atsushi Eno
URL:
Depends on:
Blocks:
 
Reported: 2014-02-25 12:46 UTC by Andrew Fernandes
Modified: 2014-07-07 14:31 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
SampleTest (17.82 KB, application/zip)
2014-02-27 06:29 UTC, Sadik Ali
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description Andrew Fernandes 2014-02-25 12:46:49 UTC
The AudioTrack constructor uses the ChannelConfiguration enumeration, while the AudioTrack.GetMinBufferSize static method uses the ChannelOut enumeration.

These two enumerations are inconsistent, and based on the android docs the correct one should probably be ChannelOut.

Doing so would make it consistent with the AudioRecord constructor and AudioRecord.GetMinBufferSize methods, both of which use the ChannelIn enumeration.

This is important for USB audio and android devices that are capable of multichannel audio.

Most likely this goes unnoticed by most because the underlying libmedia.so functions mostly (but not always) just count the number of set bits in the channel configurations, and auto-adjust for mono/stereo. But once you hit multichannel audio, it matters.

From the API-19 bindings:

        public static void ListChannels()
        {
            foreach (var channel in Enum.GetValues(typeof(ChannelOut)).Cast<ChannelOut>()) {
                Console.WriteLine("ChannelOut: {0} {1}", Enum.Format(typeof(ChannelOut), channel, "X"), Enum.Format(typeof(ChannelOut), channel, "F"));
            }
            foreach (var channel in Enum.GetValues(typeof(ChannelConfiguration)).Cast<ChannelConfiguration>()) {
                Console.WriteLine("ChannelConfiguration: {0} {1}", Enum.Format(typeof(ChannelConfiguration), channel, "X"), Enum.Format(typeof(ChannelConfiguration), channel, "F"));
            }
        }

ChannelOut: 00000000 None
ChannelOut: 00000001 Default
ChannelOut: 00000004 FrontLeft
ChannelOut: 00000004 FrontLeft
ChannelOut: 00000008 FrontRight
ChannelOut: 0000000C Stereo
ChannelOut: 00000010 FrontCenter
ChannelOut: 00000020 LowFrequency
ChannelOut: 00000040 BackLeft
ChannelOut: 00000080 BackRight
ChannelOut: 000000CC Quad
ChannelOut: 000000FC FivePointOne
ChannelOut: 00000100 FrontLeftOfCenter
ChannelOut: 00000200 FrontRightOfCenter
ChannelOut: 000003FC SevenPointOne
ChannelOut: 00000400 BackCenter
ChannelOut: 0000041C Surround

ChannelConfiguration: 00000000 Invalid
ChannelConfiguration: 00000001 Default
ChannelConfiguration: 00000002 Mono
ChannelConfiguration: 00000003 Stereo
Comment 1 Andrew Fernandes 2014-02-25 12:49:56 UTC
By the way, notice that ChannelOut has two "FontLeft" enumerations. That's actually what the sample code spits out for me (Mono Android 4.12.0, API 19). That might be a second buglet.
Comment 2 Andrew Fernandes 2014-02-25 12:57:14 UTC
Huh - just read the android docs more carefully; the "ChannelConfiguration" constants were deprecated in API level 5. http://developer.android.com/reference/android/media/AudioFormat.html#CHANNEL_CONFIGURATION_DEFAULT
Comment 3 Andrew Fernandes 2014-02-25 13:26:12 UTC
Sorry for the chatter - but the two "FrontLeft" enumerations are due to the fact that "Mono" is "FrontLeft", but doesn't get stringized that way. Just trying to save ya'll work.
Comment 4 Sadik Ali 2014-02-27 06:25:52 UTC
I have check this issue with help  of  bug description code and noticed that ChannelOut has two "FrontLeft" enumerations.
Refer screen shot: http://screencast.com/t/CNvqCspzv

Checked With:
All Mac
XS 4.2.2 (build 2)
Xamarin.Android 4.10.1
Comment 5 Sadik Ali 2014-02-27 06:29:20 UTC
Created attachment 6170 [details]
SampleTest
Comment 6 Andrew Fernandes 2014-02-27 08:09:59 UTC
Sadik - see "Comment 3" above; the two "FrontLeft" enumerations are correct. The ChannelOut(4) has two enumerations: "FrontLeft" and "Mono" (as opposed to Stereo). When you stringize an enumeration, only one "text" representation gets chosen.

If you use "monop -a" to see the actual definition, you'll see that the double enumeration is correct, and the string dump above shows just an artifact.

The only real problem is that the ChannelConfiguration enumeration was deprecated in API5 and should not really be used.
Comment 7 Sadik Ali 2014-02-28 04:52:19 UTC
I have checked this issue on API 15 and noticed that ChannelConfiguration enumeration has two set of values.

Refer screen cast: http://screencast.com/t/HlAo7hsPm
Please correct me if I am wrong with my understanding.

Checked With:
All Mac
XS 4.2.2 (build 2)
Xamarin.Android 4.10.1
Comment 8 Atsushi Eno 2014-03-03 03:03:24 UTC
I fixed the constructor to use ChannelOut instead. It will be in version 4.14. Thanks for the report.

[master b31978a]
Comment 9 Ram Chandra 2014-07-07 14:31:32 UTC
I have checked this issue on following builds:

Mac OS X 10.9.3
Xamarin Studio: 5.2 (build 180)
Xamarin.Android: 4.14.0 

Build Information
Release ID: 502000180
Git revision: c27cfff0160e6f3d8ad82b57be030d6adf866743
Build date: 2014-07-04 18:06:04-04
Xamarin addins: 68026ad1ccee9923e927d9cfcca408d673d5ab61

When I check the constructor of "AudioTrack" class in "assembly browser" I observed that now the constructor of "AudioTrack" class contain an "absolute" attribute which says:
 
[Obsolete("ChannelConfiguration is obsolete. Please use another overload with ChannelOut instead")]

Screencast: http://www.screencast.com/t/1uptBaXBdd

The constructor is updated as per the android d0c.Hence I am closing this issue.