I am using Basic4Android (B4A).
I created a sub that plays 2 different frequencies,
Let's call them FreqLeft and FreqRight.
Both of them is playing in one channel (Mono).
I want to play FreqLeft in the Left Channel (Left Ear Audio Speaker) and FreqRight in the Right Channel (Right Ear Audio Speaker)
And this is the code:
Public Sub GenBB (DurationMs As Double, FreqLeft As Double, FreqRight As Double)
Dim Samples As Int = 8000 * DurationMs / 1000
Dim Tone(2 * Samples) As Byte
For i = 0 To Samples - 1
Dim sample1 As Double = Sin(2 * cPI * i / (8000 / FreqLeft)) * 16383.5
Dim sample2 As Double = Sin(2 * cPI * i / (8000 / FreqRight)) * 16383.5
Tone(2 * i + 0) = Bit.And(sample1 + sample2, 0x00ff)
Tone(2 * i + 1) = Bit.UnsignedShiftRight(Bit.And(sample1 + sample2, 0xff00), 8)
Next
streamer1.Write(Tone)
End Sub
To make it easy to understand, this one only plays one frequency. How can I play it on the left audio speaker channel or the right audio speaker channel?
Public Sub GenerateTone (DurationMs As Double, Frequency As Double)
Dim Samples As Int = 8000 * DurationMs / 1000
Dim Tone(2 * Samples) As Byte
For i = 0 To Samples - 1
Dim Sample As Double = Sin(2 * cPI * i / (8000 / Frequency)) * 16383.5
Tone(2 * i + 0) = Bit.And(Sample, 0x00ff)
Tone(2 * i + 1) = Bit.UnsignedShiftRight(Bit.And(Sample, 0xff00), 8)
Next
streamer1.Write(Tone)
End Sub
Thank you in advance.
Solved! Do all these steps and it will work.
First of all, add this to Starter 'Sub Process_Globals':
In Starter 'Sub Service_Create' add this:
And this is the code, add this sub to Starter:
For playing in Main:
For playing in Starter:
For stop playing in Main:
For stop playing in Starter: