invalid channel mask in AudioTrack

145 views
Skip to first unread message

Jason Kahler

unread,
Dec 30, 2009, 11:26:30 AM12/30/09
to android-ndk
I have some ndk code which uses AudioTrack to play music from some binary data. It works fine on sdk 1.5 but after I go to 2.0 I get an error in the Log when initializing the audio system.
The log Tag is AudioTrack and the error is "invalid channel mask" any idea what may be wrong?

momojo

unread,
Jan 4, 2010, 8:58:38 AM1/4/10
to android-ndk
Nobody has hit this before? I tried changing the number of channels
passed into the constructor but it didn't seem to have any effect.
Where can I find the source of the actual ndk class that has that
output message?

Eugene Mymrin

unread,
Jan 4, 2010, 10:21:47 AM1/4/10
to andro...@googlegroups.com
You are using SDK 2.0 to build application for Android 1.5.
You probably have to use AudioFormat.CHANNEL_CONFIGURATION_MONO and
AudioFormat.CHANNEL_CONFIGURATION_STEREO instead of
AudioFormat.CHANNEL_OUT_MONO and AudioFormat.CHANNEL_OUT_STEREO.

> --
>
> You received this message because you are subscribed to the Google Groups "android-ndk" group.
> To post to this group, send email to andro...@googlegroups.com.
> To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.
>
>
>

Jason Kahler

unread,
Jan 4, 2010, 10:31:35 AM1/4/10
to andro...@googlegroups.com
I will try that this is ndk code though not sdk. Also how can I write
it to run on both? Thanks so much for your input.

--
Sent from my mobile device

Eugene Mymrin

unread,
Jan 4, 2010, 10:36:30 AM1/4/10
to andro...@googlegroups.com
You only need to use APIs and constants for Android 1.5, also mark
application as requiring API 3 and targeted for platform 3 or 4.

Jason Kahler

unread,
Jan 4, 2010, 11:02:05 AM1/4/10
to andro...@googlegroups.com
So do I need to build multiple apks?

Eugene Mymrin

unread,
Jan 4, 2010, 2:10:32 PM1/4/10
to andro...@googlegroups.com
That would be tedious.
In my opinion you don't need to have different apks unless you don't
have "extended" version of the application which depends on some new
API which is only available in 1.6 or 2.0.

Jason Kahler

unread,
Jan 5, 2010, 8:43:30 AM1/5/10
to andro...@googlegroups.com
OK so here is my ndk code that is initializing the AudioTrack:

bool AudioPlayerImpl::init(unsigned int rate, int bits, int channels)
{
    int format = (bits == 16 ?
            AudioSystem::PCM_16_BIT : AudioSystem::PCM_8_BIT);  

    track = new AudioTrack(AudioSystem::MUSIC, rate, format, channels, 0);
    if (track->initCheck() < 0)
' {
        delete track;
        track = NULL;
        return false;
    }
    return true;

Pradeep

unread,
Jan 6, 2010, 4:14:50 AM1/6/10
to android-ndk
Hi Jason,

I wanted to play raw audio from NDK but could not find any API to do
that.

I did not find AudioTrack in any header file. Is this supported in NDK
1.6 ?

Regards,
Pradeep

Jason Kahler

unread,
Jan 6, 2010, 7:27:00 AM1/6/10
to andro...@googlegroups.com
it is in the media package.

Doug Schaefer

unread,
Jan 6, 2010, 7:49:39 AM1/6/10
to andro...@googlegroups.com
In other words, no. Audio is not accessible from the NDK APIs. There has been mention of OpenSL coming sometime but no promises when. And my bet is that it would be Android 2.1 or greater only since it would need a new system library.

Jason Kahler

unread,
Jan 6, 2010, 7:56:43 AM1/6/10
to andro...@googlegroups.com
But I am using audio now in the ndk. Do you mean its not stable?

>>> android-ndk...@googlegroups.com<android-ndk%2Bunsu...@googlegroups.com>


>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/android-ndk?hl=en.
>>>
>>>
>>>
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "android-ndk" group.
>> To post to this group, send email to andro...@googlegroups.com.
>> To unsubscribe from this group, send email to

>> android-ndk...@googlegroups.com<android-ndk%2Bunsu...@googlegroups.com>


>> .
>> For more options, visit this group at
>> http://groups.google.com/group/android-ndk?hl=en.
>>
>>
>

--

Doug Schaefer

unread,
Jan 6, 2010, 8:03:43 AM1/6/10
to andro...@googlegroups.com
To quote the NDK page: "Important: With the exception of the libraries listed above, native system libraries in the Android platform are not stable and may change in future platform versions. Your applications should only make use of the stable native system libraries provided in this NDK."
 
If you're just playing around on one device, you have no worries. If you are going to put your work up on the market, you're rolling the dice that the hiddend platform libraries you are using will change APIs or may not even be there on some devices.
 
I really wonder why people keep skipping over that line, or just plain ignoring it...
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.

Jason Kahler

unread,
Jan 6, 2010, 8:29:19 AM1/6/10
to andro...@googlegroups.com
Thanks Doug I appreciate the info.

Olivier Guilyardi

unread,
Jan 6, 2010, 9:38:58 AM1/6/10
to andro...@googlegroups.com
Wow, just browsed through the 569 pages of the OpenSL spec.. Scary. Is it sort
of sure that this API will be chosen?

Will there be other API's available?

In regard to raw audio capture/playback, what about a simple C/C++
callback-based API similar to Portaudio, Jack or even PulseAudio?
Is this (sort of) planned?

You can do *so much* things with such "simple" API's, provided the latency is
reasonable.

On 01/06/2010 01:49 PM, Doug Schaefer wrote:
> In other words, no. Audio is not accessible from the NDK APIs. There has
> been mention of OpenSL coming sometime but no promises when. And my bet
> is that it would be Android 2.1 or greater only since it would need a
> new system library.
>
> On Wed, Jan 6, 2010 at 7:27 AM, Jason Kahler <jason....@gmail.com
> <mailto:jason....@gmail.com>> wrote:
>
> it is in the media package.
>
> On Wed, Jan 6, 2010 at 4:14 AM, Pradeep <bhatt....@gmail.com
> <mailto:bhatt....@gmail.com>> wrote:
>
> Hi Jason,
>
> I wanted to play raw audio from NDK but could not find any API to do
> that.
>
> I did not find AudioTrack in any header file. Is this supported
> in NDK
> 1.6 ?
>
> Regards,
> Pradeep
>
>
> On Dec 30 2009, 9:26 pm, Jason Kahler <jason.kah...@gmail.com

> <mailto:jason.kah...@gmail.com>> wrote:
> > I have some ndk code which uses AudioTrack to play music from
> some binary
> > data. It works fine on sdk 1.5 but after I go to 2.0 I get an
> error in the
> > Log when initializing the audio system.
> > The log Tag is AudioTrack and the error is "invalid channel
> mask" any idea
> > what may be wrong?
>
> --
> You received this message because you are subscribed to the
> Google Groups "android-ndk" group.
> To post to this group, send email to

> andro...@googlegroups.com <mailto:andro...@googlegroups.com>.


> To unsubscribe from this group, send email to
> android-ndk...@googlegroups.com

> <mailto:android-ndk%2Bunsu...@googlegroups.com>.


> For more options, visit this group at
> http://groups.google.com/group/android-ndk?hl=en.
>
>
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "android-ndk" group.
> To post to this group, send email to andro...@googlegroups.com

> <mailto:andro...@googlegroups.com>.


> To unsubscribe from this group, send email to
> android-ndk...@googlegroups.com

> <mailto:android-ndk%2Bunsu...@googlegroups.com>.


> For more options, visit this group at
> http://groups.google.com/group/android-ndk?hl=en.
>
>
>

> ------------------------------------------------------------------------

Kevin Duffey

unread,
Jan 7, 2010, 1:12:47 AM1/7/10
to andro...@googlegroups.com
Olivier.. I agree with you. It would be amazing if there were some sort of simple hardware sound mixing device "required" by Android capable devices. I mean.. iPhone games and apps are high quality, low latency programs. Not that google/team planned to directly compete with apple on every aspect of the Android platform, but someone somewhere must have thought about music applications like little drum machines, sequencers and such, and also games that could use low latency high accuracy timing for smoother graphics and mixed audio and sound FX. As it stands now, from everything I've been reading, no Android device anytime in the near future will be able to support this.. and mind you it's not from the lack of hardware.. with most of the new devices having 600Mhz to 1Ghz cpus.. I can assure you that mixing 64 sounds in software while displaying 3D graphics is completely possible on such hardware. It was done years ago on lesser hardware in PCs, buck in the 90s even with less memory and so forth. Granted, the ARM cpu is not a full fledged PC cpu, but I would guess that it is quite a bit more capable than my old AMD 486 was.. and I wrote routines in Delphi back then that mixed 64 sounds at once while doing other things. Sure.. Delphi compiles to binary.. and I have no objection to using the NDK to do these things.. but we need some sort of simple access to low latency audio. I will admit I was quite surprised and disappointed that in todays heavy gaming and music world, the Android platform did not require such simplistic hardware to provide these capabilities for us developers to make use of. Until it happens, no matter how good the hardware Android runs on, games and music apps wont come close to as good as those on iPhone, or even the Nintendo DS. I really hope someone involved in the future direction of Android is paying attention to the "cries" from those of us that are feeling quite stuck on developing anything more than mostly simple games and no chance of any quick responding low latency audio applications. :(   Unless there is some hidden way to do this that not many are talking about...??

Olivier Guilyardi

unread,
Jan 8, 2010, 6:41:18 AM1/8/10
to andro...@googlegroups.com
Hi Kevin,

I agree with many things you say.

Nevertheless, I'm not "crying". From what I read, Android will feature a C/C++
audio API at some point in time in the future. And although I understand that
nothing is still certain, I would like to know what API(s) this is likely to be,
in order to anticipate.

That's what my question is about.

Olivier

> > <mailto:jason....@gmail.com <mailto:jason....@gmail.com>>>


> wrote:
> >
> > it is in the media package.
> >
> > On Wed, Jan 6, 2010 at 4:14 AM, Pradeep
> <bhatt....@gmail.com <mailto:bhatt....@gmail.com>

> > <mailto:bhatt....@gmail.com


> <mailto:bhatt....@gmail.com>>> wrote:
> >
> > Hi Jason,
> >
> > I wanted to play raw audio from NDK but could not find any
> API to do
> > that.
> >
> > I did not find AudioTrack in any header file. Is this
> supported
> > in NDK
> > 1.6 ?
> >
> > Regards,
> > Pradeep
> >
> >
> > On Dec 30 2009, 9:26 pm, Jason Kahler
> <jason.kah...@gmail.com <mailto:jason.kah...@gmail.com>

> > <mailto:jason.kah...@gmail.com


> <mailto:jason.kah...@gmail.com>>> wrote:
> > > I have some ndk code which uses AudioTrack to play music
> from
> > some binary
> > > data. It works fine on sdk 1.5 but after I go to 2.0 I
> get an
> > error in the
> > > Log when initializing the audio system.
> > > The log Tag is AudioTrack and the error is "invalid channel
> > mask" any idea
> > > what may be wrong?
> >
> > --
> > You received this message because you are subscribed to the
> > Google Groups "android-ndk" group.
> > To post to this group, send email to
> > andro...@googlegroups.com
> <mailto:andro...@googlegroups.com>

> <mailto:andro...@googlegroups.com


> <mailto:andro...@googlegroups.com>>.
> > To unsubscribe from this group, send email to
> > android-ndk...@googlegroups.com
> <mailto:android-ndk%2Bunsu...@googlegroups.com>

> > <mailto:android-ndk%2Bunsu...@googlegroups.com
> <mailto:android-ndk%252Buns...@googlegroups.com>>.


> > For more options, visit this group at
> > http://groups.google.com/group/android-ndk?hl=en.
> >
> >
> >
> >
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "android-ndk" group.
> > To post to this group, send email to
> andro...@googlegroups.com <mailto:andro...@googlegroups.com>

> > <mailto:andro...@googlegroups.com


> <mailto:andro...@googlegroups.com>>.
> > To unsubscribe from this group, send email to
> > android-ndk...@googlegroups.com
> <mailto:android-ndk%2Bunsu...@googlegroups.com>

> > <mailto:android-ndk%2Bunsu...@googlegroups.com
> <mailto:android-ndk%252Buns...@googlegroups.com>>.


> > For more options, visit this group at
> > http://groups.google.com/group/android-ndk?hl=en.
> >
> >
> >
> >
> ------------------------------------------------------------------------
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "android-ndk" group.

> > To post to this group, send email to andro...@googlegroups.com

Reply all
Reply to author
Forward
0 new messages