Android Question General Question Re Generating Sound

AlexOfOz

Active Member
Licensed User
Many, many, many years ago, the Commodore 64 allowed me to generate sound using peeks and pokes. Is there an equivalent option to generate sounds using B4* ??

Thanks,
Alex
 

emexes

Expert
Licensed User
Make yourself a PCM sample and feed it to the speaker.

The SID chip's square, saw and triangle waveforms are easy enough to generate; the white noise is a little harder.
 
Upvote 0

emexes

Expert
Licensed User
Whilst I was off finding sample audio output code, I stumbled across this nice diagram of the SID:

1668829367465.png
 
Upvote 0

emexes

Expert
Licensed User
The code in this post shows both recording from microphone to PCM samples, and playing back the recorded PCM samples:

https://www.b4x.com/android/forum/threads/noise-detector-by-microphone.143377/#post-909162

eg:

B4X:
Private Sub Play_Click
    btnStartRec.Enabled = False
    streamer.StartPlaying
    For Each b() As Byte In buffers
        streamer.Write(b)
    Next
    streamer.Write(Null) 'when this "message" will be processed, the player will stop.
End Sub

where the b() byte arrays are simply 16-bit samples in... I think little-endian format, but I'll go double-check that.

This post suggests little-endian:

https://www.b4x.com/android/forum/threads/noise-detector-by-microphone.143377/#post-909176

and that you can use ByteConverter to transform between Array of Shorts (easier for you to work with) and Array of Bytes (that the audio streamer is expecting):

B4X:
Dim bc As ByteConverter
bc.LittleEndian = True
Dim Sample16() As Short = bc.ShortsFromBytes(Buffer)
 
Upvote 0
Top