November 24, 2024, 03:20:30 PM

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.


VMusic2 Subroutine help

Started by clinefx1, August 21, 2008, 11:01:10 PM

Previous topic - Next topic

clinefx1

Jon-

Hoping you can help.  I got a Vmusic2 up and running. The part I'm having trouble with is getting a subroutine to check if the Vmusic2 has finished playing.  I can get the program to wait for it but that stalls it. Including the option of stopping it on my own.  I'm guessing this involves checking for it and updating a register but I'm fuzzy on that aspect.  If it does detect a stop I would like it to go to main.

Thanks,
Chris





'{$STAMP BS2}
'{$PBASIC 2.5}
'
'   File....... MP3Boxcode1
'   Purpose.... Run VMusic2 driven by a Prop-2
'   Author.....  Chris Cline
'   E-mail..... Clinefx1@aol.com
'   Started.... 8/21/2008
'   Updated....
'
'
' =========================================================================
' -----[ Program Description ]---------------------------------------------
' Based on code from Scary Terry

' -----[ I/O Definitions ]-------------------------------------------------
EXPLAY                   PIN      12
EXSTOP                   PIN      13
EXPAUSE                  PIN      14

PLAY_LED                 PIN      8
STANDBY_LED              PIN      9
PAUSED_LED               PIN      10

' -----[ Constants ]-------------------------------------------------------
ISOFF   CON 0
ISON    CON 1

' -----[ Initialization ]--------------------------------------------------
PAUSE 5000                                'allow VMusic2 to initialize
SEROUT 0,84, ["VST",CR]                   'stop anything that's playing
' -----[ Program Code ]----------------------------------------------------

Main:
LOW PLAY_LED
LOW PAUSED_LED
HIGH STANDBY_LED

  IF (EXPLAY = ISOFF) THEN MAIN
      LOW STANDBY_LED
      HIGH PLAY_LED

PLAY_MP3:
  SEROUT 0,84,["VPF test.mp3",CR]           'Play a file named "test.mp3"
  PAUSE 2000

PLAY_ACTIVITY:
      TOGGLE PLAY_LED
      PAUSE 50
      GOSUB CHECK_PAUSE
      GOSUB CHECK_STATUS

      GOTO PLAY_ACTIVITY

PAUSE_ACTIVITY:
    TOGGLE PAUSED_LED
    PAUSE 20
    GOSUB CHECK_STOP
    GOSUB CHECK_PAUSE_2
    GOSUB CHECK_PLAY:

    GOTO PAUSE_ACTIVITY

      ' -----[ SubROUTINES ]-----------------------------------------------------
CHECK_STOP:
IF  (EXSTOP = ISOFF) THEN RETURN

STOP_PLAYBACK:
SEROUT 0,84, ["VST",CR]                   'Stop playback of "test.mp3"

GOTO MAIN
'********

CHECK_PAUSE:
  IF (EXPAUSE = ISOFF) THEN RETURN

  PAUSE_PLAYBACK:
    LOW PLAY_LED
    SEROUT 0,84,["VP",CR]                     'Pause playback of "test.mp3"
    PAUSE 500
      IF (EXPAUSE = ISOFF) THEN PAUSE_ACTIVITY

CHECK_PAUSE_2:
       IF (EXPAUSE = ISOFF)THEN RETURN
        GOTO PAUSEOFF

CHECK_PLAY:
      IF(EXPLAY = ISOFF)THEN RETURN
      GOTO PAUSEOFF

PAUSEOFF:
       LOW PAUSED_LED
       HIGH PLAY_LED
       PAUSE 30
       SEROUT 0,84,["VP",CR]                     'Resume playback of "test.mp3"
       GOTO PLAYACTIVITY

CHECK_STATUS:


RETURN

JonnyMac

Below you'll find my somewhat anal-retentive demo.  Note that I break everything into subroutines to minimize the number of SEROUTs in the program.  If I want to start a file and then wait for it to finish I use the VM_Wait_Prompt subroutine.

Now, if you wanted to be able to jump in at any time to see if a track is playing you might be able to do something like this as the VMusic player spits out tracking timing information that is prefaced with "T $"

Check_Playing:
  isPlaying = No
  SERIN RX, Baud, 1000, Check_Exit, [WAIT("T $")]
  isPlaying = Yes

Check_Exit:
  RETURN


This assumes the unit is not playing and then waits one second to see if any track timing information is returned; if SERIN times out then the program jumps to Check_Exit leaving the status a "No", otherwise it falls through setting isPlaying (a bit variable) to Yes.

Here's my demo program and the routines I use.  Another thing you MUST do is snip the ULN pins and use IOs on the Prop-2 that have pull-ups.  This has to do with the way the player deals with a low on its RX line.

' =========================================================================
'
'   File...... VMusic.BS2
'   Purpose...
'   Author.... Jon Williams, EFX-TEK (www.efx-tek.com)
'   E-mail.... jwilliams@efx-tek.com
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              see: http://creativecommons.org/licenses/by/3.0/us/
'   Started...
'   Updated... 01 MAY 2008
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'   {$PORT COM1}
'
' =========================================================================


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


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


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

Sio             PIN     15                      ' no ULN / no SETUP
Trigger         PIN     14                      ' no ULN / SETUP = DN
TX              PIN     13                      ' no ULN / SETUP = UP
RX              PIN     12                      ' no ULN / SETUP = UP


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

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

Yes             CON     1
No              CON     0

VolMax          CON     $00
VolMin          CON     $FE


T2400           CON     396
T9600           CON     84
T19K2           CON     32
T38K4           CON     6

SevenBit        CON     $2000
Inverted        CON     $4000
Open            CON     $8000
Baud            CON     Open + T9600


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

flags           VAR     Byte
rptMode        VAR     flags.BIT0
isPaused       VAR     flags.BIT1

theMP3          VAR     Byte                    ' MP3 file pointer
char            VAR     Byte                    ' character value
eePntr          VAR     Word                    ' EEPROM memory pointer

volume          VAR     Byte

panCtrl         VAR     Word
lvlLeft        VAR     panCtrl.BYTE0
lvlRight       VAR     panCtrl.BYTE1


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

Reset:
  PAUSE 2250                                    ' let VMUSIC power up

  SEROUT TX, Baud, [CR]                         ' ping (if no power-up)
  GOSUB VM_Wait_Prompt

  GOSUB VM_Stop                                 ' stop if playing
  GOSUB VM_Wait_Prompt

  volume = VolMax                               ' reset volume level
  GOSUB VM_Volume

  flags = %00000000                             ' clear flags


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

Main:
  DEBUG CLS, "Playing: Firefly theme.", CR
  theMP3 = 0
  GOSUB VM_Play
  GOSUB VM_Wait_Start
  DEBUG "-- file started", CR

  PAUSE 5000
  volume = 40
  GOSUB VM_Volume
  GOSUB VM_Wait_Prompt
  DEBUG "-- volume reduced", CR

  GOSUB VM_Wait_Prompt
  DEBUG "-- ready for new song", CR, CR


Pan_Test:
  DEBUG "Playing: Spalding.", CR
  theMP3 = 4
  GOSUB VM_Play
  GOSUB VM_Wait_Start

  lvlLeft = VolMax                              ' pan to left
  lvlRight = VolMin
  GOSUB VM_Pan
  DEBUG "-- pan left", CR

  PAUSE 3500                                    ' wait for dead spot

  lvlLeft = VolMin                              ' pan to right
  lvlRight = VolMax
  GOSUB VM_Pan
  DEBUG "-- pan right", CR, CR

  DEBUG "Good-bye"
  END


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

' Pass file # (index in DATA table) to play in "theMP3"

VM_Play:
  rptMode = No
  GOTO Play_MP3

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

' Pass file # (index in DATA table) to play in "theMP3"

VM_Repeat:
  rptMode = Yes
  GOTO Play_MP3

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

' Pass file # (index in DATA table) to play in "theMP3"
' -- add DATA label entries to LOOKUP as required

Play_MP3:
  LOOKUP theMP3, [SFX0, SFX1, SFX2,
                  SFX3, SFX4, SFX5], eePntr     ' get base address

Send_Play_Cmd:
  IF (rptMode = No) THEN
    SEROUT TX, Baud, ["VPF "]                   ' start play command
  ELSE
    SEROUT TX, Baud, ["VRF "]                   ' start repeat command
  ENDIF

Send_Name:                                      ' send file title
  DO
    READ eePntr, char
    eePntr = eePntr + 1
    IF (char = 0) THEN EXIT
    SEROUT TX, Baud, [char]
  LOOP

Finish_Cmd:
  SEROUT TX, Baud, [".MP3", CR]                 ' send extention + CR
  RETURN

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

VM_Stop:
  SEROUT TX, Baud, ["VST", CR]
  RETURN

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

VM_Pause:
  IF (isPaused = No) THEN
    SEROUT TX, Baud, ["VP", CR]
    isPaused = Yes
  ENDIF
  RETURN

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

VM_Resume:
  IF (isPaused = Yes) THEN
    SEROUT TX, Baud, ["VP", CR]
    isPaused = No
  ENDIF
  RETURN

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

' Pass volume (0 = loudest, 254 = muted) in "volume"

VM_Volume:
  volume = volume MAX $FE                       ' limit per spec

  ' copy to pan register for future use

  lvlLeft = volume
  lvlRight = volume

  SEROUT TX, Baud, ["VSV ", IHEX2 volume, CR]
  RETURN

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

' Pass levels (0 = loudest, 254 = muted) in "lvlLeft" and "lvlRight"
'
' NOTE: The VPF command seems to reset volume levels so you must use a
'       pan command while the file is playing for it to work.

VM_Pan:
  lvlLeft = lvlLeft MAX $FE                     ' limit per spec
  lvlRight = lvlRight MAX $FE

  SEROUT TX, Baud, ["VWR $0B", HEX4 panCtrl, CR]
  RETURN

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

VM_Wait_Prompt:
  SERIN RX, Baud, [WAIT(">")]
  RETURN

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

VM_Wait_Start:
  SERIN RX, Baud, [WAIT("T $0")]
  RETURN


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

' MP3 files are stored in root of USB memory stick
' Table below needs only name, followed by a zero
' Keep names short to conserve EE space

SFX0            DATA    "Firefly", 0
SFX1            DATA    "Serenity", 0
SFX2            DATA    "Fruity", 0
SFX3            DATA    "Angel", 0
SFX4            DATA    "Spalding", 0
SFX5            DATA    "Thunder", 0
Jon McPhalen
EFX-TEK Hollywood Office

clinefx1

August 23, 2008, 12:11:35 AM #2 Last Edit: September 02, 2008, 11:22:53 PM by clinefx1
thanks again,
Worked out great.
Chris

davisgraveyard

Hey Chris, I am curious.  What is THAT contraption you posted a picture of?

Look cool!

Jeff

clinefx1

At work I've been tasked with taking care of three industrial welding robots. Programing and maintenance, etc.  Well i thought it could be cool if they did a dance routine set to music. I started with networking the driver / computer cabinets together but i needed a way to trigger an audio track.  The picture is of my audio pack.  Its a small pelican case with a prop2, v-music, contact closer triggers and local playback speakers.  It also has RCA jacks for output to a bigger stereo system.  The barrier strip is an generic way to interface the box to different devices for trigger, pause, and stop playback.  The box is finished but I've been so slammed that I haven't had time to choreograph anything yet.

Chris