Android Question Reading data from microphone

Isa Paine

Member
Licensed User
Longtime User
I have a thermometer that is providing a frequency of 600Hz, room temperature, to my Samsung Galaxy S5 through the 3.5mm. With an oscilloscope I can see that a square wave is being provided to the phone but the data read in using the AudioStreamer library does not follow the pattern of a square wave. it goes from one extreme to the next with no square wave in the data.

What could be causing this? Why doesn't the data follow the flow of a square wave?

Am I some how not reading the external 3.5mm jack input?

Please help.

Here is the pertinent parts of the code:

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Portrait")
    If FirstTime Then
        streamer.Initialize("streamer", SampleRate, True, 16, streamer.VOLUME_MUSIC)
        buffers.Initialize
        tmrTemp.Initialize("tmrTemp", 1)
        tmrTemp.Enabled = False
    End If
End Sub

Sub startRecording(duration As Int)
    buffers.Clear
    streamer.startRecording
    tmrTemp.Interval = duration * 1000
    tmrTemp.Enabled = True
End Sub

Sub stopRecording
    streamer.StopRecording
    AudioUtils.GetFrequency(buffers)
End Sub
 
Sub GetFrequency(buffers As List) As Double

    'Dim b_Array() As Byte
    Dim frequency As Double
    'Conv.LittleEndian = False
    Dim dataIndex As Int : dataIndex = 0
    Dim MyTextWriter As TextWriter
    MyTextWriter.Initialize(File.OpenOutput(File.DirRootExternal, "values.csv",False))
   
    For Each byteArray() As Byte In buffers
        Dim y_Voltage() As Short

        y_Voltage = Conv.ShortsFromBytes(byteArray)
        For index = 0 To y_Voltage.Length -1
            Dim y_VoltageString As String
            y_VoltageString = y_Voltage(index)
            MyTextWriter.WriteLine(y_VoltageString)
        Next
        dataIndex = dataIndex + 1
    Next
    MyTextWriter.Close
    Return frequency
End Sub
 

stevel05

Expert
Licensed User
Longtime User
Upvote 0
Top