Android Question audiostreamer and 8 bit

canalrun

Well-Known Member
Licensed User
Longtime User
Hello,
I'm using the Walkie–Talkie demo unmodified except for the following change in the Connector service:

B4X:
Sub Service_Create
    'start listening for BT and wifi connections
    server.Initialize(port, "server")
    Try
        server.Listen
    Catch
        WifiStatus = "Error listening: " & LastException
        UpdateUI
    End Try
    admin.Initialize("admin")
    serial1.Initialize("serial1")
    If serial1.IsEnabled Then serial1.Listen2("na", uuid)
    pe.Initialize("pe")
    pe_ConnectivityChanged("", "", Null)

'    audioStream.Initialize("AudioStream", 22050, True, 16, audioStream.VOLUME_MUSIC) ' original
'    audioStream.Initialize("AudioStream", 11025, True, 16, audioStream.VOLUME_MUSIC) ' works
'    audioStream.Initialize("AudioStream", 22050, True, 8, audioStream.VOLUME_MUSIC) ' generates error
    audioStream.Initialize("AudioStream", 11025, True, 8, audioStream.VOLUME_MUSIC) ' generates error
End Sub

In an attempt to reduce the required data bandwidth I would like to use 8-bit with an 11025 sample rate. However, whenever I change the word size to 8 bit I get the following error:

B4X:
Installing file.
PackageAdded: package:b4a.example.walkietalkie
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (connector) Create **
java.lang.NegativeArraySizeException: -2
    at anywheresoftware.b4a.audio.AudioStreamer.Initialize2(AudioStreamer.java:77)
    at anywheresoftware.b4a.audio.AudioStreamer.Initialize(AudioStreamer.java:65)
    at b4a.example.walkietalkie.connector._service_create(connector.java:521)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:158)
    at b4a.example.walkietalkie.connector.onCreate(connector.java:45)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:2572)
    at android.app.ActivityThread.access$1800(ActivityThread.java:135)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5017)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
    at dalvik.system.NativeStart.main(Native Method)
java.lang.RuntimeException: Unable to create service b4a.example.walkietalkie.connector: java.lang.RuntimeException: java.lang.NegativeArraySizeException: -2
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:2582)
    at android.app.ActivityThread.access$1800(ActivityThread.java:135)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5017)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
    at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.RuntimeException: java.lang.NegativeArraySizeException: -2
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:200)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:158)
    at b4a.example.walkietalkie.connector.onCreate(connector.java:45)
    at android.app.ActivityThread.handleCreateService(ActivityThread.java:2572)
    ... 10 more
Caused by: java.lang.NegativeArraySizeException: -2
    at anywheresoftware.b4a.audio.AudioStreamer.Initialize2(AudioStreamer.java:77)
    at anywheresoftware.b4a.audio.AudioStreamer.Initialize(AudioStreamer.java:65)
    at b4a.example.walkietalkie.connector._service_create(connector.java:521)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
    ... 13 more

I am fairly certain that I have generated and played 8-bit wave data on this phone. I think the hardware supports 8-bit.

(As an aside – I see the Android audio media function getParameters(Keys), but no one seems to list what the keys are. Could I use this somehow to verify the phones audio capabilities?)

I am using version 1.62 of the Audio library. Any idea what the problem could be?

Thanks,
Barry.
 
Top