Android Question SOLVED: AudioStreamer plays with half Hertz

Midimaster

Active Member
Licensed User
I want to report a strange behavior( maybe a bug?), that happened after I updated B4A (Nov 2020) to new version. I use the AudioStreamer for playing a song (made of 20x the same piano sample with a distance of 500msec).

The Sample is loaded from Dir.Assets in a Short()-Array. The sound is a WAV-file of a piano, recorded at 24kHz and a length of 380msec. After the loading the Array-Length is correctly reported with 9134 Sample-Values.

The song is build by adding 10x the sample into a array of 240.000 elements (=10sec). The samples are added at 0, 12.000 24.000, 36000... and so on

Now I transfer every 20msec 480 samples. I copy the values into a Short-Array of 960 elements (for STEREO) in the correct sequence L1-R1-L2-R2-L3-R3-....
This is converted to a BYTE-Array by the function Converter.ShortsToBytes() with 1920 elements and sent to the AudioStreamer.

Now the AudioStreamer plays the sound but one octave too low, The length I can hear is 760msec and the given distance between the notes (500msec) changes to 1000msec. When I change the HERTZ-rate on the AudioOut.Initialize() to 48000 HZ everything would work as l expect for 24kHz.

Does anybody else observe this, too? For the first here are some relevant code snipplets from my current app. I could produce a stand-alone code that demonstrates the bug, if you need it.
AudioStreamer with half speed?:
'----------------STARTER:----------------------------'
Sub Process_Globals
    Public AudioOut As AudioStreamer
End Sub

Sub Service_Start (StartingIntent As Intent)
    Service.StopAutomaticForeground
    AudioOut.Initialize("AudioOut",24000,True,16,AudioOut.VOLUME_MUSIC)
    AudioOut.StartPlaying
End Sub

public Sub SendToAudio(Bytes() As Byte)
    AudioOut.Write(Bytes)
End Sub


'------------------ MAIN ----------------------------------'

Sub Process_Globals
    ...
    Public  HERTZ As Int=24000
    Private Converter As ByteConverter

...

Sub Every20msecSend(Chunk as Int)
    Private Stereo(Chunk*2) As Short
    For i=0 To Chunk-1
            Stereo(i*2+0) = Song(ReadPosition+i)
            Stereo(i*2+1) = Song(ReadPosition+i)
            Song(ReadPosition+i)=0
    Next
    ReadPosition=(ReadPosition + Chunk)
    Private AudioOutBytes() As Byte =Converter.ShortsToBytes(Stereo)
    CallSub2(Starter, "SendToAudio", AudioOutBytes)
End Sub
 

Attachments

  • Piano60b.zip
    15.9 KB · Views: 127
Last edited:

Midimaster

Active Member
Licensed User
It is unlikely to be related to any update.
Good to hear... So I will prepare a complete runable demo code the next days (with a related audio-file, where the effect is good to hear). would you please test it on your machine? A second people check would help me a lot . Perhaps it works on a different computer. Give me some days...because of christmas...

Are you testing it in release mode?
Yes I tested both DEBUG and RELEASE and checked it again and again and searched for a possible code bug for 4 hours before I contacted the forum. Now I can't get any further on my own.
 
Upvote 0

Midimaster

Active Member
Licensed User
Oh!!! Upps...TRUE means mono.

I'm so stupid!

Thanks Agraham and Erel for the quick help. I think this is the explanation. Will check it and report if there is still a problem.
 
Upvote 0
Top