Android Question Play Binaural Beats, Right and Left

Hedi

Member
Hello guys,

Is there is any way to play 2 difference frequencies at the same time?

One is on the Left side and the other is on the Right side.

And you can set the duration.


Thank you so much for your helps.
 
Solution
Hi @kimstudio, thank you so much for your help!

Solved! Do all these steps and it will work.

First of all, add this to Starter 'Sub Process_Globals':

B4X:
Public Streamer1 As AudioStreamer

In Starter 'Sub Service_Create' add this:

B4X:
Try

    Streamer1.Initialize("streamer1", 4000, False, 16, Streamer1.VOLUME_MUSIC)

    Streamer1.StartPlaying

Catch

    Log(LastException)

End Try

And this is the code, add this sub to Starter:

B4X:
Public Sub GenBB (DurationMs As Double, FreqLeft As Double, FreqRight As Double)

Dim Samples As Int = 4000 * 2 * DurationMs / 1000

Dim Tone(2 * Samples) As Byte



For i = 0 To Samples - 1 Step 2

   

    Dim Sample1 As Double = Sin(1 * cPI * i / (4000 / FreqLeft))

    Dim Left As Short =...

kimstudio

Active Member
Licensed User
Longtime User
Use AudioStreamer in Audio library you can generate the two signals and put in left/right channels in a stereo wave and play it.

I remeber there is a post on the forum exactly discussing about this but I forget the keyword for searching.
 
Upvote 0

Hedi

Member
Use AudioStreamer in Audio library you can generate the two signals and put in left/right channels in a stereo wave and play it.

I remeber there is a post on the forum exactly discussing about this but I forget the keyword for searching.
Dear kimstudio,

I have 2 AudioStreamer, Streamer1 and Streamer2.

In Streamer1, I want to play sounds only in the Left audio channels.
In Streamer2, I want to play sounds only in the Right audio channels.


I like using AudioStreamer, I hope if there is a solution for this.
 
Upvote 0

Hedi

Member
Hi @kimstudio, thank you so much for your help!

Solved! Do all these steps and it will work.

First of all, add this to Starter 'Sub Process_Globals':

B4X:
Public Streamer1 As AudioStreamer

In Starter 'Sub Service_Create' add this:

B4X:
Try

    Streamer1.Initialize("streamer1", 4000, False, 16, Streamer1.VOLUME_MUSIC)

    Streamer1.StartPlaying

Catch

    Log(LastException)

End Try

And this is the code, add this sub to Starter:

B4X:
Public Sub GenBB (DurationMs As Double, FreqLeft As Double, FreqRight As Double)

Dim Samples As Int = 4000 * 2 * DurationMs / 1000

Dim Tone(2 * Samples) As Byte



For i = 0 To Samples - 1 Step 2

   

    Dim Sample1 As Double = Sin(1 * cPI * i / (4000 / FreqLeft))

    Dim Left As Short = Sample1 * 32767

   

    Dim Sample2 As Double = Sin(1 * cPI * i / (4000 / FreqRight))

    Dim Right As Short = Sample2 * 32767

   

    Tone(2 * i + 1) = Bit.UnsignedShiftRight(Bit.And(Left, 0xff00), 8)

    Tone(2 * i + 3) = Bit.UnsignedShiftRight(Bit.And(Right, 0xff00), 8)

Next



    Streamer1.Write(Tone)

End Sub

For playing in Main:

B4X:
Starter.Streamer1.StartPlaying

Starter.GenBB(5000, 432, 436) 'Milliseconds, Left channel, Right channel:

For playing in Starter:

B4X:
Streamer1.StartPlaying

GenBB(5000, 432, 436) 'Milliseconds, Left channel, Right channel:

For stop playing in Main:

B4X:
Starter.Streamer1.StopPlaying

For stop playing in Starter:

B4X:
Streamer1.StopPlaying
 
Upvote 0
Solution
Top