BEEPER - Stops working after a few times.

Askjerry

Member
Licensed User
Longtime User
I'm writing a metronome sort of program for a friend... using the BEEPER as the sound source... I have it as "blip" in the program.

User selects how many BPM... hits "START"... it starts it's 1,2,3,4...1,2,3,4... counting... each time making a "blip" sound...

Works great about 5 seconds... then stops producing sound. :sign0085:

Under GLOBALS I have this...
B4X:
Dim blip As Beeper         ' Noisemaker

When I first start the program I do this...
B4X:
blip.Initialize(100, 2000)          ' Initial tone on startup.
blip.beep                              ' Make wakeup sound.

Then the main sound generation loop is contained in a TIMER1 like this...
B4X:
Sub Timer1_tick
      ' First blip
      If note=1 Then
         blip.Initialize(halfbeat, 2000) ' milliseconds, hz
      End If
      ' All other blips
      If note>1 Then
         blip.Initialize(halfbeat, 1500) ' milliseconds, hz
      End If
      ' Dull Redish Brown
      LED1.Color=Colors.RGB(165,42,42)    
      LED2.Color=Colors.RGB(165,42,42)      
      LED3.Color=Colors.RGB(165,42,42)   
      LED4.Color=Colors.RGB(165,42,42)
      ' Bright Yellow
      If note=1 Then LED1.Color=Colors.RGB(255,215,0)
      If note=2 Then LED2.Color=Colors.RGB(255,215,0)
      If note=3 Then LED3.Color=Colors.RGB(255,215,0)
      If note=4 Then LED4.Color=Colors.RGB(255,215,0)
      DoEvents
      ' Make a tone depending on beat number.
      blip.Beep
      ' Increment cycle
      note=note+1
      ' If greater than higest allowed, reset to one.
      If note>4 Then note=1
End Sub

Runs well about 5 seconds... then no more sound.

Thoughts???

Thanks,
Jerry

File should be attached.
 

Attachments

  • Partally Working 1.zip
    27.6 KB · Views: 231

NJDude

Expert
Licensed User
Longtime User
Add "blip.Release" after the Timer tick:
B4X:
Sub Timer1_tick

    blip.Release

...

Also, add the following lines to Activity_Pause:
B4X:
Timer1.Enabled = False
blip.Release

However, you will have to tweak the app a little when the user moves the SeekBar while the app is beeping.
 
Last edited:
Upvote 0

Askjerry

Member
Licensed User
Longtime User
I added the blip.release in the Activity_Pause... I had meant to to that but just missed it. No change there as far as operation.

When I added the blip.release at the end of the Timer1_tick routine... it became very intermittent... not anywhere near useful.

When I tried it at the top of the Timer1_tick routine... it seems working now. :sign0060:

I see what I did in the slider section... I have beat which is the length of a period... the halfbeat is the sound duration or one half period. I was setting the Timer1 to be the halfbeat instead of the beat. That's why it jumped up so much. Timing is now functional.

I ran it for about 3 minutes without failure... should be able to continue development now. :)

Thanks for the help!
Jerry
 
Upvote 0
Top