Android Question Audio Library - Beeper - Duration

Discussion in 'Android Questions' started by Horst Leistner, Apr 22, 2017.

  1. Horst Leistner

    Horst Leistner Member Licensed User

    Hello,

    I want to create short pulses of 19kHz and with a duration shorter than 1ms.
    Currently I do that by making a wav-file, save it and play it by MP3.
    Is there a possibility to modify the Beeper function to generate pulses shorter than 1ms?
    Maybe it would be helpfull for me to get the source code of the Audio Library.

    Best regards
    Horst
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    You should use AudioStreamer for that.

    Put this code in the Starter service:
    Code:
    Sub Process_Globals
       
    Private streamer As AudioStreamer
    End Sub

    Sub Service_Create
       streamer.Initialize(
    "streamer"8000True16, streamer.VOLUME_MUSIC)
       streamer.StartPlaying
    End Sub

    Public Sub Beep (DurationMs As Double, Frequency As Int)
       
    Dim sampleRate As Int = 8000
       
    Dim numSamples As Int = sampleRate * DurationMs / 1000
       
    Dim gsnd(2 * numSamples) As Byte
       
    For i = 0 To numSamples - 1
         
    Dim d As Double = Sin(2 * cPI * i / (sampleRate / Frequency))
         
    Dim val As Short = d * 32767
         gsnd(
    2 * i) = Bit.And(val, 0x00ff)
         gsnd(
    2 * i + 1) = Bit.UnsignedShiftRight(Bit.And(val, 0xff00), 8)
       
    Next
       streamer.Write(gsnd)
    End Sub
    You can then call it with:
    Code:
    CallSub3(Starter, "Beep"1000400)
     
  3. Horst Leistner

    Horst Leistner Member Licensed User

    Thank you very much, Erel. Each time I use it I am exited with this development tool! Due to my Seagrave book I am sure to understand your piece of code within the next hours.
    Regards
    Horst.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice