December 03, 2024, 10:07:54 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.


uMP3 Demo Programs (Prop-1 and Prop-2)

Started by JonnyMac, October 07, 2009, 06:54:13 PM

Previous topic - Next topic

JonnyMac

October 07, 2009, 06:54:13 PM Last Edit: July 28, 2010, 02:18:28 PM by JonnyMac
I updated my uMP3 demo to more closely match the VMUSIC demo -- this is the base code I will use whenever anyone asks for assistance.

' =========================================================================
'
'   File....... uMP3_Demo.BS1
'   Purpose....
'   Author.....
'   E-mail.....
'   Started....
'   Updated.... 07 OCT 2009
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  RX              = 7                     ' to UMP3.T; no ULN
SYMBOL  TX              = 6                     ' to UMP3.R; no ULN
SYMBOL  Sio             = 5                     ' no ULN
SYMBOL  Trigger         = PIN4                  ' keep ULN; is pull-down


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

SYMBOL  Baud            = OT2400

SYMBOL  Yes             = 1
SYMBOL  No              = 0


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

SYMBOL  timer           = B2
SYMBOL  mp3             = B3                    ' MP3 file pointer
SYMBOL  last            = B4
SYMBOL  eePntr          = B5                    ' EEPROM memory pointer
SYMBOL  char            = B6                    ' character value
SYMBOL  idx             = B7

SYMBOL  lottery         = W5                    ' random value


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

Reset:
 GOSUB UMP3_Stop                               ' stop if playing
 PAUSE 2000                                    ' let uMP3 start

Prod_uMP3:
 SEROUT TX, Baud, (13)                         ' send CR
 SERIN  RX, Baud, char                         ' get response
 IF char <> ">" THEN Prod_uMP3                 ' wait for ">"


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

Main:
 timer = 0                                     ' reset timer

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

 mp3 = lottery // 8                            ' make 0 - 7
 IF mp3 = last THEN Main
   last = mp3

 DEBUG mp3, CR
 GOSUB UMP3_Play                               ' play it

Wait_Start:
 GOSUB UMP3_Status
 IF char <> "P" THEN Wait_Start
   DEBUG "  ...playing", CR

Wait_End:
 GOSUB UMP3_Status
 IF char = "P" THEN Wait_End
   DEBUG "  ...done", CR, CR

 PAUSE 2000
 GOTO Main


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

' Put file # to play in "mp3"

UMP3_Play:
 eePntr = 8 * mp3                              ' convert to pointer

Send_Cmd:
 SEROUT TX, Baud, ("PC F /")                   ' start play command

Send_Name:                                      ' send file title
 FOR idx = 1 TO 8                              ' max is 8 characters
   READ eePntr, char                           ' get a character
   IF char = 0 THEN Finish_Cmd                 ' if 0, we're at end
   SEROUT TX, Baud, (char)
   eePntr = eePntr + 1
 NEXT

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


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

UMP3_Stop:
 SEROUT TX, Baud, ("PC S", 13)
 RETURN

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

UMP3_Status:
 SEROUT TX, Baud, ("PC Z", 13)                 ' request status
 SERIN  RX, Baud, char                         ' will be "S" or "P"
 RETURN


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

' File names are stored on 8-byte boundaries -- this is very important for
' correct program operation.  This strategy uses a little more EE space but
' is easier to update and maintain

Song_List:
 EEPROM $00, ("firefly")                       ' mp3 = 0
 EEPROM $08, ("serenity")                      ' mp3 = 1
 EEPROM $10, ("spalding")
 EEPROM $18, ("thunder1")
 EEPROM $20, ("thunder2")
 EEPROM $28, ("thunder3")
 EEPROM $30, ("explode")
 EEPROM $38, ("angel")
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

Here's a Prop-2 version that communicates with the uMP3 at 9600 baud.  Note that it expects TX and RX to be connected.

' =========================================================================
'
'   File....... uMP3_Demo.BS2
'   Purpose....
'   Author..... Jon Williams, EFX-TEK
'   E-mail..... jwilliams@efx-tek.com
'   Started....
'   Updated....
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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

' Note: SETUP jumpers for serial comms (15, 14, and 13) should be in the
'       UP position.


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


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


Sio             PIN     15                      ' for DC-16, RC-4; no ULN
TX              PIN     14                      ' to UMP3.R; no ULN
RX              PIN     13                      ' to UMP3.T; no ULN
Trigger         PIN     12                      ' setup = DN


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

#SELECT $STAMP
  #CASE BS2, BS2E, BS2PE
    T2400       CON     396
    T4800       CON     188
    T9600       CON     84
    T19K2       CON     32
    T38K4       CON     6
  #CASE BS2SX, BS2P
    T2400       CON     1021
    T4800       CON     500
    T9600       CON     240
    T19K2       CON     110
    T38K4       CON     45
#ENDSELECT

Inverted        CON     $4000
Open            CON     $8000
EfxBaud         CON     Open | T38K4            ' for DC-16, RC-4
ump3Baud        CON     T9600                   ' for uMP3 player

Yes             CON     1
No              CON     0


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

char            VAR     Byte                    ' character value
theMP3          VAR     Byte                    ' MP3 file pointer
eePntr          VAR     Word                    ' EEPROM memory pointer
pos             VAR     Word                    ' uMP3 file position
loopNum         VAR     Byte                    ' file loop # in cycle
lottery         VAR     Word                    ' random value


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

Reset:
  HIGH TX                                       ' force to idle state
  PAUSE 2000                                    ' let uMP3 start

Prod_uMP3:
  DO
    SEROUT TX, ump3Baud, [CR]                   ' send CR
    SERIN  RX, ump3Baud, [char]                 ' get response
  LOOP UNTIL (char = ">")                       ' wait for ">"


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

Main:
  RANDOM lottery
  IF (Trigger = No) THEN Main

  theMP3 = lottery // 3                         ' make 0 - 2
  GOSUB Play_MP3                                ' play it

  PAUSE 5000
  GOTO Main


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

' Put file # 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:
  SEROUT TX, ump3Baud, ["PC F /"]               ' start play command

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

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

Wait_For_Stop:                                  ' let song finish
  DO
    GOSUB Get_Status
  LOOP UNTIL (char = "S")
  RETURN

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

' Gets status from uMP3
' -- "P" = playing, "D" = paused, "S" = stopped
' -- also gets file position and loop number of play cycle

Get_Status:
  SEROUT TX, ump3Baud, ["PC Z", CR]
  SERIN  RX, ump3Baud, [char, DEC pos, DEC loopNum]
  RETURN


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

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

SFX0            DATA    "Hello", 0
SFX1            DATA    "Wolf", 0
SFX2            DATA    "Scream", 0
SFX3            DATA    "Chuckie", 0
SFX4            DATA    "Exorcist", 0
SFX5            DATA    "Lightning", 0
Jon McPhalen
EFX-TEK Hollywood Office

Ryanm0085

the baud rate looks like its set for 2400 on this demo.  the uMP3 documentation says it comes default on 9600.  Will this demo still work?  im guessing no but its a guess cause i dont know.

JonnyMac

Really?... how do you get 2400 baud from this definition?

ump3Baud        CON     T9600                   ' for uMP3 player

Don't make the "ugly JonnyMac" come forth by ignoring hard work he puts up just for you...  ;D



Yes, that's me under the make-up (by Ralis Kahn).
Jon McPhalen
EFX-TEK Hollywood Office

Ryanm0085

haha sry jonny...i dont know why but i didnt see the second program...but i do like the make-up

BigRez