Here's a way to store WAV files in EXE and play them 
Author Message
 Here's a way to store WAV files in EXE and play them

Note, I'm using this with 32bit, though I imagine can work with 16bit, but
then you're limited to smaller WAV files (I have done this successfully
with WAV files over 600,000 bytes - takes a little while to compile, but it
works).

A. Merry Christmas, Happy Chanukah (Eric and others), Happy Holidays

B. This is probably not the best way, but the only way I could think of how
to get this to work with Clarion.

C. This is a two step process. The first step is running a clarion program
that takes a .wav file as input and creates a text file from it (I call
this program WAV2ASC). This text file is formatted for doing clarion string
assignments, so non Alpha-Numeric characters are value embedded in angle
brackets (ie '<127>'). The second step is to assign this collection of data
to a clarion string variable using a little template I wrote.

1. Make the WAV2ASC program.

1A. Create dictionary WAV2ASC.DCT with the following files:

Source  FILE,DRIVER('DOS'),NAME(FileNameSource),PRE(Src),BINDABLE,THREAD
Record                   RECORD,PRE()
Buffer                      STRING(1),DIM(40)
                         END

Dest  
FILE,DRIVER('ASCII'),NAME(FileNameDest),PRE(DEST),CREATE,BINDABLE,THREAD
Record                   RECORD,PRE()
TextLine                    STRING(300)
                         END
(please note that the name attribute must be preceded with an exclamation
point (!) in the file properties for this type of code to be generated)

1B. Create a new application using WAV2ASC as a program. (don't use the
wizards)

1Bi. Create MAIN as a PROCESS procedure

1Bii. FILES: file to process is Source, other files is DEST

1Biii. EMBEDS:

1Biiia. Procedure Setup:

 IF ~GetFileNames() THEN DO ProcedureReturn.
 CREATE(Dest)

1Biiib. Activity for each Record:

DEST:TextLine=''
LOOP n#=1 TO 40
  IF INRANGE(VAL(SRC:Buffer[n#]),48,122) AND VAL(SRC:Buffer[n#])~=60 !AND
VAL(SRC:Buffer[n#])~=39
    DEST:TextLine = CLIP(DEST:TextLine) & SRC:Buffer[n#]
  ELSE
    DEST:TextLine = CLIP(DEST:TextLine) & '<60>' &VAL(SRC:Buffer[n#]) &
'<62>'
  END
END
ADD(Dest)

1Biv. Create Procedure GetFileNames

1Biva. Prototype: (),BYTE

1Bivb.  Data: RetVal BYTE, Initial Value=True (initial value found on data
attributes tab)

1Bivc.  Data: LOC:Info STRING(500), Initial value: (just cut and paste the
following)
By no means is this limited to WAVE files. This routine takes any file and
creates an output file for importing to a template to initialize variables
to hold an entire file.

1Bivd.  Return Value: RetVal (will have to close procedure and re-enter
before it is enabled after changing the prototype)

1Bive. Edit the window as text and paste in the following:
window WINDOW('Create Destination file for Importing to
Application'),AT(,,222,122),CENTER,GRAY,DOUBLE
       STRING('WAVE file:'),AT(7,11),USE(?String1),#ORIG(?String1)

BUTTON('...'),AT(194,10,12,12),USE(?LookupFile),#SEQ(3),#ORIG(?LookupFile)
       STRING('Destination:'),AT(6,28),USE(?String2),#ORIG(?String2)

       BUTTON('Create
Destination'),AT(9,45,96,21),USE(?OkButton),LEFT,ICON(ICON:Tick),DEFAULT

BUTTON('Cancel'),AT(111,45,60,21),USE(?CancelButton),LEFT,ICON(ICON:Cross)
       PANEL,AT(10,73,197,43),USE(?Panel1),BEVEL(-1,-1),#ORIG(?Panel1)

TEXT,AT(11,74,195,41),FONT(,,080000012H,),COLOR(080000014H),USE(LOC:Info),VS
CROLL,READONLY,#ORIG(LOC:Info)
     END

1Bivf. Embed Control Event Handling, After Generated Code (?OkButton):
Class Clarion: Close Current Window and Procedure

1Bivg. Embed Control Event Handling. After Generated Code(?CancelButton):
RetVal=False, then add another one: Class Clarion: Close Current Window and
Procedure

1Bv. Compile and run

When I use this program, I assign the destination filename and extension of
'.ASC' for ASCII, and that is what I assume in the following template. (ie/
when processing DING.WAV I create a DING.ASC)

2. Edit the template registry and create a new CODE template. I hope you
have your own template you would modify, if not, create one and paste this
to it:

#!---------------------------------------------------------------------
#CODE(ASCFileToVar,'ASC File Contents to Variable'),ROUTINE
#PROMPT('FileName:',OPENDIALOG('File to load into
variable','All|*.ASC')),%TheFile,REQ

#PROMPT('Variable Declaration or
Assignment:',DROP('Declaration|Assignment')),%VarDecl,REQ
#OPEN(%TheFile),READ                         #!Open it in read-only mode
#DECLARE(%FileRec)
#DECLARE(%ByteNo)
#IF(%VarDecl='Declaration')
%TheVar    STRING('' & |
#ELSE
 %TheVar ='' & |
#ENDIF
#LOOP
  #READ(%FileRec)
  #IF(%FileRec = %EOF)
      #BREAK
  #ENDIF
   '%FileRec' & |
#ENDLOOP
#IF(%VarDecl='Declaration')
 '')
#ELSE
 ''
#ENDIF
#CLOSE(%TheFile),READ
#!---------------------------------------------------------------------

3. Okay, now we have the program to create an .ASC file and a template to
import it into an application. Now to use it.

3A. In the application where you want to use sound files, in the Global
Embeds, Inside the Global Map, add the following:

MODULE('WINMM')
OMIT('***',_WIDTH32_)
 sndPlaySound(*CSTRING lpszSoundName, UNSIGNED uFlags),BOOL,PROC,Pascal,raw
 sndPlaySound(*STRING  lpszSoundName, UNSIGNED uFlags),BOOL,PROC,pascal,raw
           ***
     COMPILE('***',_WIDTH32_)
 sndPlaySound(*CSTRING lpszSoundName, UNSIGNED
uFlags),BOOL,PROC,pascal,raw,Name('SndPlaySoundA')
 sndPlaySound(*STRING  lpszSoundName, UNSIGNED
uFlags),BOOL,PROC,pascal,raw,Name('SndPlaySoundA')
     ***
end

3B. Decide if you want the sound to play from memory or from file.

3Ci. If playing from file, you need a cstring variable that will hold the
file name to be played.

3Cii. Initialize the variable and call the API function:
  cSoundFile = 'C:\WINDOWS\DING.WAV'
  n#=sndPlaySound(cSoundFile,0) !see note at end about the uFlags value

3D. If playing from memory, decide if you will be declaring the song data
or assigning it at run-time. If assigning it, you will need to declare the
clarion STRING large enough to hold the data, but if you let the template
do the declaring you don't need to worry about it.

3Di. Declaring the variable yourself.

3Dia. If you want to declare it the variable yourself, declare it as STRING
- not cString because wave files have embedded null characters and the file
will get truncated. Also be aware that the IDE will not declare a STRING
greater than 99,999 bytes (you can declare one yourself in the DATA Section
embed point up to 4GB when compiling for 32 bit). It is for this reason
that the template does not let you pick the variable name from the data
defined to the procedure.

3Dib. Somewhere in the code, ASSIGN the WAV data to the variable. Use the
ASCFileToVar template to select the file, fill in the variable name, and
then choose Assign.

3Dii. Letting the Template declare the variable and assign the data.

3Diia. In the Data Section, call the ASCFileToVar template and fill in the
file, the previously undeclared variable name, and choose declare.

3Diib. Thats all there is to it, other than calling the function.

3E. Play the sound from memory. In the code where you want the sound
played, enter the following:
  n#=sndPlaySound(MyWavData,4) !see following note about the uflags value

-------
Notes about the sndPlaySound uFlags variable.
The bits on the uFlags (second parameter to sndPlaySound) need to be set as
follows:

Bit 0:
     0 for synchronous play (play sound and then continue with app)
     1 for Asynch play (play sound while app continues on)
Bit 1:
     0 No silence when sound file not found
     1 Silence when sound not found (I couldn't find a difference with
this)
Bit 3:
     0 lpszSoundName points to file name
     1 lpszSoundName points to location of data in memory
Bit 4:
     0 sound plays once
     1 sound loops until next sound
Bit 5:
     0 interrupt and currently play sound with new sound
     1 dont stop any currently playing sound

If you BOR(uFlag,2000H) the sound will not wait to play if the device is
busy.

Like I said at the beginning, Happy Holidays.
Please send me email if this has helped you

Or a post card would be nice (4409 Cool Emerald Dr, Tallahasse, Florida
32303)



Sun, 11 Jun 2000 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. playing wav's within assembly

2. Playing WAV Files from APL*PLUS PC

3. VSW: Code for playing a WAV file

4. Playing a wav file in rb?

5. Play wav files

6. How to play wav files to internal speaker?

7. 2003 How to play .wav files??????????.

8. How to Play a WAV File

9. How to play a .WAV file in ABC

10. PLAY,REWIND,FORWARD,PAUSE ....a WAV File ????

11. Playing .wav files

12. Playing WAV files in CW

 

 
Powered by phpBB® Forum Software