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.
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
Last edited: