November 22, 2024, 10:55:47 AM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


The prop-1 and VMusic2

Started by sneeky, June 01, 2008, 10:03:03 AM

Previous topic - Next topic

sneeky

First of all, I'm a complete newbie at this and I'm excited that I got this far...  I've been lurking here for several months now and recently made the leap into Prop-1, RC-4, FC-4 and using the VMusic2 (VM2).  It's been a fun experience.  For my first prop, I wanted it to say random nice things, but occasionally say random bad things.  The VM2 random play command didn't give me the effect I was looking for.  I then discovered that the VM2 doesn't care about filename extensions.  As a result, you can name your MP3 files with numbers and randomize that way.  For me this is more simple than a long branch routine, especially when adding more files.  I'm not sure if there is a better way, but if not, the following technique may be useful if you are running out of code space and want to play certain randomize files by group.   Then again there may be a better way...

(PS - Thank you to The Garage of Evil and the Scary Terry websites, as well as this one, for posting the good stuff so I could get up and running quickly and easily with the Prop-1 and VM2).

Thank you!


' =========================================================================
'
'   File.......... VM2_Tester.bs1
'   Revision...... 1 h   Fixed VM2 file randomization routine
'   Purpose....... Learnin' the VMusic2
'   Author........ Josh
'   Hardware used. Prop-1, VM2
'   Started....... May 21, 2008
'   Updated....... May 31, 2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================
' The goal of this program is to find a way to play random tracks on the VM2
' in groups.  For example, we want to play a random EVIL sound once in a while,
' but we want to play a random nice sound most of the time. Useful for luring
' victims toward a nice prop that turns into a real jerk!
'
' MP3 Audio Tracks on VM2:
'      FileName       Description
'      0              Giggle
'      1              Yawn
'      2              Hello
'      3              Awww so cute!
'      100            Growl (Long)
'      101            Hiss (Long)
'      102            Roar (Long)
'
' Note that the above file names do not have the .mp3 file extension
' The VMusic2 doesn't seem to mind the lack of a file extension!
' By doing this, and giving file names that are numbers, we can control
' the randomization of file names.
'
' Also note that the VM2 initialization time seems to depend on the USB drive
' size and type (USB 1 vs. USB2) as well as the number of files on it.
' =========================================================================
' -----[ I/O Definitions ]-------------------------------------------------
SYMBOL VM2      = 7 'The VM2 is on P7.

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

' -----[ Variables ]-------------------------------------------------------
SYMBOL mp3      = B2
SYMBOL result   = B3
SYMBOL lottery  = W5

' -----[ Initialization ]--------------------------------------------------
PAUSE 7000                          'Allow VMusic2 to initialize.
SEROUT VM2, OT2400, ("VSV 0", 13)   'Set volume full on VMusic2

' -----[ Program Code ]----------------------------------------------------
SEROUT VM2, OT2400, ("VPF 2", 13)   'Play the mp3 file with the name 1 (not 1.mp3)
PAUSE 4000      'Pause for 4 seconds while playing sound so we know it works
                'before we start trying to hack around

Main:
  RANDOM lottery
  result = lottery // 10  'Random number from 0 to 9
  IF result > 0 THEN NICE  'Mostly Nice
  IF result < 1 THEN DARK  'A little Dark once in a while
  GOTO Main

NICE:
  mp3 = lottery // 4  'Random number from 0 to 3
  'SEROUT VM2, OT2400, ("VPF ", mp3, ".mp3", 13) Doesn't work, so just drop the .mp3 part?
  'SEROUT VM2, OT2400, ("VPF ", mp3, 13) Doesn't work either?!
  'The next line took me a long time to figure out.
  DEBUG "NICE  ", #mp3
  SEROUT VM2, OT2400, ("VPF ", #mp3, 13)   'Plays an MP3 file with the name 0 1 2 or 3
  PAUSE 3000   'Wait for 3 seconds for the nice sound to play.  Should use SERIN instead!
  GOTO Main

DARK:
  mp3 = lottery // 3 + 100 'Random number from 100 to 102
  DEBUG "DARK  ",#mp3
  SEROUT VM2, OT2400, ("VPF ", #mp3, 13)   'Plays an MP3 file with the name100, 101 or 102
  PAUSE 10000   'Wait for 10 seconds.  Use SERIN, but I haven't hooked up the right wire yet...
  GOTO Main


JonnyMac

June 01, 2008, 11:22:50 AM #1 Last Edit: June 01, 2008, 11:36:16 AM by JonnyMac
Good for you to jumping in and giving it a go.  I always say that the best way to learn to program is to start programming!

One caution... the VMUSIC firmware could change such that dropping the .mp3 extesnion from you commands no longer works.  Since the onboard decoder can handle other file times, I would be careful with this (i.e., I'd add the .mp3 extension).  You may be having touble using the # modifier with SEROUT as this pads the output string with a space -- this is why I use a subroutine in my program.

Here's a trick you can use if want variable delays per file, but don't want to connect the RX line for SERIN:  You can use LOOKUP to set a delay factor; code like this:

  mp3 = lottery // 3
  delay = LOOKUP mp3, (2000, 5000, 15000), delay
  SEROUT TX, Baud, ("VPF", #mp3, CR)
  PAUSE delay


In the dark section you would add 100 to mp3 after you used it to do the delay lookup.

One other tip: In Main you can do this and recover a little code space -- something ulitmately find yourself wanting to do as your programs get more sophisticated:

Main:
  RANDOM lottery
  result = lottery // 10
  IF result = 0 THEN Dark


This works just like your current program since a result of zero played a Dark file and anything else played Nice.

Again, congrats from jumping right in; keep it up as Halloween is not too many more months away....
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

June 01, 2008, 12:03:34 PM #2 Last Edit: June 01, 2008, 12:05:11 PM by JonnyMac
Just for grins....

If you want to send a numbered file and include the .mp3 extension you can do it with a simple subroutine:

Play_File:
  char = mp3 / 100 + "0"
  SEROUT TX, Baud, (char)
  char = mp3 // 100 / 10 + "0"
  SEROUT TX, Baud, (char)
  char = mp3 // 10 + "0"
  SEROUT TX, Baud, (char, ".mp3", 13)
  RETURN


The only thing you'll have to do is rename your files such that they have three-character filenames:

000.mp3
001.mp3
002.mp3
100.mp3
101.mp3

...etc.

I tested this by running the output through a Serial Inverter and into HyperTerminal -- it works.
Jon McPhalen
EFX-TEK Hollywood Office