November 22, 2024, 02:10:43 PM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


random sound question

Started by Vasago, October 07, 2007, 06:06:14 AM

Previous topic - Next topic

Vasago

Hey guys,

I was looking for a code to produce random sound effect from my AP-8.  I understand that we can record multiple sounds.  Can the random sound be played in the normal sequence of evens as in this code?  I would like a completely random sound to play without repeating them.  Thanks for your help.

Peter



'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  PIR             = PIN6                  ' SETUP = DN


' -----[ Constants ]-------------------------------------------------------

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0

SYMBOL  AllOff          = %00000000


' -----[ Variables ]-------------------------------------------------------

SYMBOL   relays         = B0
SYMBOL   BlueLight      = BIT0
SYMBOL   Beacon         = BIT1
SYMBOL   Mister         = BIT2
SYMBOL   UnusedK4       = BIT3

SYMBOL  timer           = B2                    ' for PIR debouncing


' -----[ Initialization ]--------------------------------------------------

Reset:
  PINS = AllOff
  DIRS = %00000000
                               

  SEROUT Sio, OT2400, ("!!!!!!!AP8", %00, "X")  ' kill audio

  relays = AllOff
  BlueLight = IsOn
  GOSUB Update_RC4

  PAUSE 30000                                   ' quiet time
  timer = 0                                     ' clear PIR timer


' -----[ Program Code ]----------------------------------------------------

Main:
  PAUSE 10
  timer = timer + 10 * PIR                      ' update timer
  IF timer < 250 THEN Main                      ' wait for valid signal

  BlueLight = IsOff
  GOSUB Update_RC4
  PAUSE 3000

  Beacon = IsOn
  GOSUB Update_RC4
  PAUSE 3000

  SEROUT Sio, OT2400, ("!AP8", %00, "P", 0)     ' start audio
  PAUSE 10000                                    ' let audio finish

  Mister =  IsOn
  GOSUB Update_RC4
  PAUSE 5000

  Mister =  IsOff
  GOSUB Update_RC4
  PAUSE 4000

  Beacon = IsOff
  GOSUB Update_RC4
  PAUSE 3000


  relays = AllOff
  GOSUB Update_RC4
  PAUSE 3000

  GOTO Reset


' -----[ Subroutines ]-----------------------------------------------------

Update_RC4:
  SEROUT Sio, OT2400, ("!RC4", %00, "S", relays)
  RETURN


' -----[ EEPROM Data ]-----------------------------------------------------


JonnyMac

October 07, 2007, 08:24:40 AM #1 Last Edit: October 26, 2007, 09:41:31 AM by JonnyMac
Here go.

'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  PIR             = PIN6                  ' SETUP = DN


' -----[ Constants ]-------------------------------------------------------

SYMBOL  IsOn            = 1
SYMBOL  IsOff           = 0

SYMBOL  AllOff          = %00000000

SYMBOL  Yes             = 1
SYMBOL  No              = 0


' -----[ Variables ]-------------------------------------------------------

SYMBOL  relays          = B0
SYMBOL   BlueLight      = BIT0
SYMBOL   Beacon         = BIT1
SYMBOL   Mister         = BIT2
SYMBOL   UnusedK4       = BIT3

SYMBOL  status          = B8
SYMBOL   playing        = BIT15

SYMBOL  timer           = B2                    ' for PIR debouncing
SYMBOL  sfx             = B3                    ' audio segment
SYMBOL  last            = B4                    ' last played
SYMBOL  mask            = B5                    ' bit mask for selection
SYMBOL  check           = B6                    ' for testing play list
SYMBOL  playList        = B7                    ' sounds played

SYMBOL  lottery         = W5                    ' random value


' -----[ Initialization ]--------------------------------------------------

Reset:
  PINS = AllOff
  DIRS = %00000000


  SEROUT Sio, OT2400, ("!!!!!!!AP8", %00, "X")  ' kill audio

  relays = AllOff
  BlueLight = IsOn
  GOSUB Update_RC4

  PAUSE 30000                                   ' quiet time
  timer = 0                                     ' clear PIR timer


' -----[ Program Code ]----------------------------------------------------

Main:
  RANDOM lottery                                ' stir random value
  PAUSE 10
  timer = timer + 10 * PIR                      ' update timer
  IF timer < 250 THEN Main                      ' wait for valid signal

  BlueLight = IsOff
  GOSUB Update_RC4
  PAUSE 3000

  Beacon = IsOn
  GOSUB Update_RC4
  PAUSE 3000


Select_Sound:
  RANDOM lottery                                ' re-stir
  sfx = lottery // 8                            ' make 0..7
  IF sfx = last THEN Select_Sound               ' no repeats allowed
  READ sfx, mask                                ' get bit mask
  check = playList & mask                       ' check agains play list
  IF check > 0 THEN Select_Sound                ' if played, try again
    playList = playList | mask                  ' mark play list

  SEROUT Sio, OT2400, ("!AP8", %00, "P", sfx)   ' start audio

Let_Sound_Finish:
  PAUSE 100
  SEROUT Sio, OT2400, ("!AP8", %00, "G")        ' get status
  SERIN  Sio, OT2400, status
  IF playing = Yes THEN Let_Sound_Finish



  Mister =  IsOn
  GOSUB Update_RC4
  PAUSE 5000

  Mister =  IsOff
  GOSUB Update_RC4
  PAUSE 4000

  Beacon = IsOff
  GOSUB Update_RC4
  PAUSE 3000

  relays = AllOff
  GOSUB Update_RC4
  PAUSE 3000

  IF playList <> %11111111 THEN Reset           ' all played?
    playList = %00000000                        ' reset play list
    GOTO Reset



' -----[ Subroutines ]-----------------------------------------------------

Update_RC4:
  SEROUT Sio, OT2400, ("!RC4", %00, "S", relays)
  RETURN


' -----[ EEPROM Data ]-----------------------------------------------------

Bit_Mask:
  EEPROM (%00000001, %00000010, %00000100, %00001000)
  EEPROM (%00010000, %00100000, %01000000, %10000000)
Jon McPhalen
EFX-TEK Hollywood Office

Vasago

Jon,

I appreciate your support with this, and I have a follow up question.

What is the proper way to record onto ap-8?  I followed steps in the AP-8 doc, but for some reason not all sounds seems to cycle.  At least 4 out of 7 recorded segments do not play back when sequence is triggered, and some repeat as well.

Thanks again
  Peter

Vasago

Yes P6 setup jumper is set to DN.  I am not sure if I am recording this thing correctly.


JonnyMac

Have you manually tested the sounds in the AP-8?  After recording all you segments you should set the address switch manually, press the play button, and verify that the propers sound plays -- many people skip this step.  If that works, then you should write a bit of test code to play each segment.  Only after you've verified the constituent parts manually should you fold them into a full program.


Quote from: Vasago on October 08, 2007, 04:25:00 AM
Jon,

I appreciate your support with this, and I have a follow up question.

What is the proper way to record onto ap-8?  I followed steps in the AP-8 doc, but for some reason not all sounds seems to cycle.  At least 4 out of 7 recorded segments do not play back when sequence is triggered, and some repeat as well.

Thanks again
  Peter
Jon McPhalen
EFX-TEK Hollywood Office

Vasago

Jon,

I've manually checked every segment and they all worked just fine individually;  A small program starts every segment from the begginig of each segment just fine.

My problem is that the segment runs into the next segment without stopping.  Is it possible to make them stop before the next segment begins?

Thanks
Peter

JonnyMac

Are you connecting the Prop-1 to the AP-8 serial input?  I just ran your program on my system and it works exactly as you want it to.  The AP-8 "P" command only plays the segment that you select, but if the play input ("P" terminal) is used then you could get false results that cause weird tripping due to the bits in the stream, especially since the Prop-1 is polling the AP-8, waiting for it to finish (indicated by BIT7 of the status byte).
Jon McPhalen
EFX-TEK Hollywood Office