Hello, if there is an expert in sound generation with Android, can I ask a question?
I need to generate a sound (even a simple sine wave form) and i want to change its frequency and its amplitude in a continuous manner, while the sound is generated.
I tried with AudioStreamer with the code posted by Erel:
But I can change frequency before each duration.
I tried to reduce the duration of the sound and insert the frequency change in the timer whit the same duration, but the resulting sound is choppy and full of disturbs like 'click' and noise.
Is there an alternative way to generate a sound and change frequency and amplitude, in a continuos way, while the sound is generated (to obtain an effect type like 'theremin')?
Thanks a lot.
I need to generate a sound (even a simple sine wave form) and i want to change its frequency and its amplitude in a continuous manner, while the sound is generated.
I tried with AudioStreamer with the code posted by Erel:
B4X:
Sub Process_Globals
Dim streamer As AudioStreamer
Dim timer1 As Timer
Dim freq As Int = 500
End Sub
Sub Globals
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
streamer.Initialize("streamer", 11025, True, 16, streamer.VOLUME_MUSIC)
streamer.StartPlaying
timer1.Initialize("timer1", 1000)
End If
timer1.Enabled = True
End Sub
Sub Timer1_Tick
Log(freq)
Beep(1000, freq)
freq = freq + 500
End Sub
Sub Beep(Duration As Int, Frequency As Int)
Dim dur As Double = Duration / 10000
Dim sampleRate As Int = 11025
Dim numSamples As Int = sampleRate * dur
Dim snd(2 * numSamples) As Byte
For i = 0To numSamples - 1
Dim d As Double = Sin(2 * cPI * i / (sampleRate / Frequency))Dim val As Short = d * 32767
snd(i * 2) = Bit.AND(0xff, val)
snd(i * 2 + 1) = Bit.ShiftRight(Bit.AND(0xff00, val), 8)Next
streamer.Write(snd)
End Sub
Sub Activity_Pause (UserClosed As Boolean)
timer1.Enabled = False
End Sub
But I can change frequency before each duration.
I tried to reduce the duration of the sound and insert the frequency change in the timer whit the same duration, but the resulting sound is choppy and full of disturbs like 'click' and noise.
Is there an alternative way to generate a sound and change frequency and amplitude, in a continuos way, while the sound is generated (to obtain an effect type like 'theremin')?
Thanks a lot.