May 11, 2024, 12:40:21 AM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


VMusic2 random play on Prop-1?

Started by wandererrob, September 27, 2008, 11:27:57 PM

Previous topic - Next topic

wandererrob

OK, I've read through a couple of threads that touch on the subject and have tried various iterations of the code, but alas I'm at an impasse.

Here's what I want to do: When the trigger is activated, I want the Vmusic2 to play one of 5 files. Randomly would be ideal, but even in order would be fine. But one track per trigger activation so that each time you get a different track to play.

I just want it so that when a second batch of TOTs walk in, they don't hear what they just heard the tail end of (i.e. it doesn't just play the same track every time). And if they pop back in on their way out they might even hear somehting different than when they came in.

I've still got a lot to learn about programming this thing I'm afraid.  :-\

Can it be done? And if so, how?

JonnyMac

Yes, it can certainly be done but does require a moderately sophisticated program (and specific connections as stated in the code).  That said, I've written code for you so all you have to do is put your file names into the Song_List section.  Do note that the file name is without the .MP3 extension and must be limited to eight characters (the VMUSIC player uses 8.3 file naming).  Also, the name should be followed by a zero -- these are already in place.

The program is setup for five files but will accommodate up to eight.  If you change the number of files in use then you need to update two symbols in the Constants section:

SYMBOL  NumMP3s         = 5
SYMBOL  ListDone        = %00011111


The first number is how many files you want to play.  The second is a bit mask for the play list that allows us to keep track of which files have played in the current cycle.  As you can see, this is a binary number.  Note that the number of 1's matches the number of files.  Let's say you want to add to more files to your program.  After putting new file names in the Song_List section you would change the symbols to this:

SYMBOL  NumMP3s         = 7
SYMBOL  ListDone        = %01111111


This should clarify the number of 1's in the ListDone symbol.

I have tested this program and find it works well (the listing shows my actual file names).  I ran two full cycles after power-up:

  Cycle 1: firefly, angel, fruity, serenity, spalding
  Cycle 2: fruity, spalding, serenity, angel, firefly

As you can see the order within each cycle is randomized and the variable called last prevents the same file from being played at the end of one cycle and the beginning of another.  I've used this kind of code in many projects, our Chuckie Chair, for example.

Have fun -- here's the code:

' =========================================================================
'
'   File...... Random_VM2.BS1
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 28 SEP 2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Random player for VMUSIC2 (up to eight files)
' -- P7 and P6 SETUP jumpers need to be in the UP position
' -- clip pins 1 and 2 from ULN2803, or pin 1 from the ULN2003
' -- trigger on P5 must be active-high; ULN acts as pull-down
'
' Note on VMUSIC2 files
' -- limit MP3 bit rate to 192; higher rates create problems for VM2


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


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

SYMBOL  RX              = 7                     ' SETUP = UP, no ULN
SYMBOL  TX              = 6                     ' SETUP = UP, no ULN
SYMBOL  Trigger         = PIN5                  ' active-high input


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

SYMBOL  Baud            = OT2400

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  NumMP3s         = 5
SYMBOL  ListDone        = %00011111


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

SYMBOL  timer           = B0                    ' debounce timer
SYMBOL  theMP3          = B1                    ' MP3 file pointer
SYMBOL  char            = B2                    ' character value
SYMBOL  eePntr          = B3                    ' EEPROM memory pointer
SYMBOL  playList        = B4                    ' played taunts/retorts
SYMBOL  mask            = B5                    ' test mask
SYMBOL  result          = B6                    ' result for play test
SYMBOL  last            = B7                    ' last file played
SYMBOL  idx             = B8                    ' loop controller

SYMBOL  lottery         = W5                    ' random value


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

Reset:
  PAUSE 2250                                    ' let VMUSIC power up
  GOSUB VM_Stop                                 ' stop if playing
  GOSUB VM_Wait_Prompt


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

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  RANDOM lottery                                ' stir random #
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' update timer
  IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

Select_MP3:
  RANDOM lottery                                ' re-stir
  theMP3 = lottery // NumMP3s                   ' select, 0..n
  IF theMP3 = last THEN Select_MP3              ' no repeats
  READ theMP3, mask                             ' create bit mask
  result = playList & mask                      ' test playlist
  IF result > 0 THEN Select_MP3                 ' try again if played
    playList = playList | mask                  ' update playlist
    last = theMP3                               ' save for next cycle

Play_MP3:
  GOSUB VM_Play                                 ' start the mp3
  GOSUB VM_Wait_Start                           ' verify start
  GOSUB VM_Wait_Prompt                          ' wait for end

  PAUSE 2000                                    ' min delay between plays

Check_List:
  IF playList <> ListDone THEN Main             ' keep going
    playList = %00000000                        ' all played, reset list
    GOTO Main


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

' Pass file # (0 to n) to play in "theMP3"

VM_Play:
  SEROUT TX, Baud, ("VPF ")                     ' send play command
  eePntr = theMP3 + 1 * 8                       ' point to start of name

Send_Name:
  FOR idx = 1 TO 8                              ' max is 8 characters
    READ eePntr, char                           ' read one character
    IF char = 0 THEN Finish_Cmd                 ' if 0, we're done
    SEROUT TX, Baud, (char)                     ' send it to VM2
    eePntr = eePntr + 1                         ' point to next char
  NEXT

Finish_Cmd:
  SEROUT TX, Baud, (".MP3", 13)                 ' send extention + CR
  RETURN

' -------------------------------------------------------------------------

VM_Wait_Start :
  SERIN RX, Baud, ("T $")
  RETURN

' -------------------------------------------------------------------------

VM_Stop:
  SEROUT TX, Baud, ("VST", 13)
  RETURN

' -------------------------------------------------------------------------

VM_Wait_Prompt:
  SERIN RX, Baud, (">")
  RETURN


' -----[ User Data ]-------------------------------------------------------

Bit_Mask:
  EEPROM 00, (%00000001)
  EEPROM 01, (%00000010)
  EEPROM 02, (%00000100)
  EEPROM 03, (%00001000)
  EEPROM 04, (%00010000)
  EEPROM 05, (%00100000)
  EEPROM 06, (%01000000)
  EEPROM 07, (%10000000)


' Song names (without extension) are placed in memory at eight-byte
' boundaries. Terminate name with zero -- this is required for names that
' are less than eight characters and will not hurt others.

Song_List:
  EEPROM 08, ("angel", 0)
  EEPROM 16, ("firefly", 0)
  EEPROM 24, ("fruity", 0)
  EEPROM 32, ("serenity", 0)
  EEPROM 40, ("spalding", 0)
  EEPROM 48, ("track6", 0)
  EEPROM 56, ("track7", 0)
  EEPROM 64, ("track8", 0)
Jon McPhalen
EFX-TEK Hollywood Office

wandererrob

Awesome! Thanks Jon!

I'll try it out later this afternoon and let you know how it goes.

wandererrob

OK, so far I'm not having much luck.  :-\

Here's how I'm hooked up right now, as best as I can explain it (VM2 to Prop-1):

Pin7: orange (RX) to white; red to red; green/black to black
Pin6: yellow (Tx) to white
Pin5: trigger (simple push button) on white and red  [I'd like to ultimately hook up the break beam trigger we discussed previously though which as I recall needs to go on whitew and black, not red]

I uploaded the code above verbatim (with the exception of replacing your file names with mine).

Where have I gone awry?

I humbly await the wisdom of the Great Oracle. :)

JonnyMac

P7 on the Prop-1 is RX which means it must connect to TX of the VMUSIC; the TX pin on the VMUSIC is #5 (yellow).  Likewise, P6 is the TX which means it must connect to RX of the VMUSIC, this is #4 (orange).  Give that a try.
Jon McPhalen
EFX-TEK Hollywood Office

wandererrob

We're live and working like a charm!

Thanks again Jon!

JonnyMac

Jon McPhalen
EFX-TEK Hollywood Office

wandererrob

No arguements here!

You da man!   :D

BigRez

Another method, while not as sophisticated and doesn't guarantee that a track won't be played twice in a row, is to use the VRR command for the vMusic2 as in the program below.  This does however allow for adding and removing tracks onto the thumbdrive without having to change the program and also allows for as many tracks as will fit on the drive.

(Note: The following program assumes the use of PIN0 for SEROUT and PIN1 for SERIN.)


' =========================================================================
'
'   File....... vm2_VRR_demo.bs1
'   Purpose.... Demonstrate VMusic2 VRR command for random track playing
'   Author..... Bigrez
'   Updated.... 12/14/2008
'
'   {$STAMP BS1}
'
' =========================================================================
' -----[ Revision History ]------------------------------------------------

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

' -----[ Constants ]-------------------------------------------------------
SYMBOL Baud = T2400              'The baud rate we'll be using is TRUE 2400

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

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

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

PAUSE 5000                                 'allow VMusic2 to initialize
SEROUT 0,Baud, ("VST",13)        'stop anything that's playing

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

Main:
   SEROUT 0,Baud, ("VRR",13)     'Play a random file named
   PAUSE 5000                             'necessary (maybe?) for timing purposes

Check_if_done:
   SERIN 1, T2400, (">")         'Waits for track to stop playing.
                                              'VMusic2 sends ">" character at END of file.
   PAUSE 1000
   GOTO Main

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

JonnyMac

December 30, 2008, 11:57:43 PM #9 Last Edit: December 31, 2008, 12:00:49 AM by JonnyMac
I have asserted and will again that using P0 and P1 for comms to the VMUSIC (or similar players) is a bad idea.  Why?  Because these pins are pulled low by the ULN and not easy to clip; even if you do clip them correctly there is no way to pull-them up (without adding circuitry).  Use P6 and P7.

Yeah, yeah, I know the program works, but I have more BS1 experience than anyone in these forums and am pulling rank.   ;D   Honestly, I'm making the suggestion for very good reason: the VMUSIC gets twitchy when it things there's an incoming bit and unless the RX pin into it is pulled up this can happen pretty easily.  Trust you pal, JonnyMac, he only wants the best for you!

Happy New Year.
Jon McPhalen
EFX-TEK Hollywood Office

BigRez

Thanks Jon... and of course I'll trust your expertise.

This set-up I referenced was per the instructions on Scary Terry's site:  [http://www.scary-terry.com/vm2/vm2_bs1.htm
I also used the setup instructions on the Garage of Evil's site http://www.garageofevil.com/tech/vmusic2_tutorial.php which does show using  P7 (and P6 for other serial connections) but doesn't use a SERIN operation.  How would that be connected?

(Per the GoE site, the P6 and P7 are clipped on the LN2803 to allow vmusic on one and other EXF-TEK devices (like the RC-4) on the other. )

JonnyMac

Scary Terry is a personal friend of mine -- he got me started with the VMUSIC when he asked me to help him with Prop-SX code for it.  You'll notice, though, that in his demos he also has to insert a PAUSE after a play statement.  The reason for this is that the PAUSE holds the transmit line in the idle state while the player is running; if you didn't do that and then hit and END statement the program audio would stop.  That's when I did some research and learned that the VMUSIC stops in its tracks when it sees (or thinks it sees) incoming serial -- the serial line dropping to 0 looks like a new serial.

The way around this is to use OT2400 mode with a pull-up on the lines between the Prop-1/2/SX and the VMUSIC; this means that the controller can only pull the line low while transmitting and under any other condition the line will be held high by the pull-up.  Even if the program ends while audio is playing the VMUSIC will keep right on going.

I'm not saying that the other demos you've found don't work -- what I am saying is that others have complained to me that these programs don't work under all conditions, hence my connections strategy to the VMUSIC.  I'm not a "because I said so" kind of person, when I say so I back it up with what I'd like to believe is reasonable technical logic.

If you're not using RX on the Prop-1/2/SX (which I think is a bad idea) just use P7 with the SETUP in the UP position.
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

BTW, if you're using TX and RX with the VMUSIC and want to talk to an EFX-TEK serial device (e.g., RC-4) I suggest using P5 for the EFX-TEK device.  Of course, you'll need to clip three ULN pins but that's not a problem.  There are pull-ups on the serial connection of all EFX-TEK devices so you're okay there, especially since the connections tend to be short.
Jon McPhalen
EFX-TEK Hollywood Office