Announcement

Collapse
No announcement yet.

Imbed a wav file?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Imbed a wav file?

    Is is possible to imbed a WAV file in a program, (possibly in a
    HEX representation using DATA statements) and play it from
    within the program?



    ------------------
    There are no atheists in a fox hole or the morning of a math test.
    If my flag offends you, I'll help you pack.

  • #2
    resource (rc/res/pbr) files are ideal for this:

    http://www.powerbasic.com/support/pb...ead.php?t=2751

    ------------------
    email
    http://www.kgpsoftware.com
    kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

    Comment


    • #3
      Thanks for the info Kev but, you have to consider, I have been
      programming in CC for only about a year (give or take) and there's
      a bunch I'm still learning about it (this subject being one of
      them).

      Looking around, I realized that I need to run PBRES.EXE on a file
      to convert it to a "resource". Well, okay, I can do that.

      Ran it on some .WAV files and it came back and said the file has
      an "Incorrect file header. This is not a 32-bit resource file."

      Help me out there a little bit there, buddy?


      ------------------
      There are no atheists in a fox hole or the morning of a math test.
      If my flag offends you, I'll help you pack.

      Comment


      • #4
        Ok, You need to create an .RC file first - just a plain text file with this line...

        Code:
        "MYSOUND" WAVE MOVEABLE PURE "C:\\PATH\\SOUND.WAV"
        "C:\\PATH\\SOUND.WAV" is the location of your wave file (remember to use the double back-slashes). In the PB editor you can press the compile button and it will convert this .RC file into a .RES file and then finally use PBRES to create a .pbr file.

        Next you add "#RESOURCE "MYFILE.PBR" in your main source file and, finally, insert this line of code where you want the sound to be played:

        Code:
          PlaySound "MYSOUND", GetModuleHandle(ByVal 0), %SND_SYNC OR %SND_RESOURCE
        Pretty simple, huh?

        ------------------
        email
        http://www.kgpsoftware.com
        kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

        Comment


        • #5
          >I have been programming in CC for only about a year (give or take

          So enter the contest. (See Cafe forum).

          Win Fabulous prizes.
          Get comments on your code from a panel of distinguished judges.
          Compete only against others with limited experience.

          It might be a bit late to start, but...I've seen later starts for bigger jobs in my 30+ years hanging around computer geeks....


          Michael Mattias
          Tal Systems Inc. (retired)
          Racine WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Kev, thanks a LOT for your time and help. For lurkers who are
            too afraid to ask, here's what I came up with:

            Save as "sounds.rc"
            Code:
            "ding"     wave moveable pure "c:\\windows\\media\\ding.wav"
            "tada"     wave moveable pure "c:\\windows\\media\\tada.wav"
            "notify"   wave moveable pure "c:\\windows\\media\\notify.wav"
            Just compiling the above will put all three sound bytes into a
            single resource file. Then (as a test):
            Code:
            $INCLUDE "win32api.inc"
            #RESOURCE "sounds.pbr"
            
                FUNCTION PBMAIN()
            
                PlaySound "tada" , GetModuleHandle(BYVAL 0), %snd_sync
            '    waitkey$
                PlaySound "ding" , GetModuleHandle(BYVAL 0), %snd_sync
            '    waitkey$
                PlaySound "notify" , GetModuleHandle(BYVAL 0), %snd_sync
            '    WAITKEY$
                END FUNCTION
            Come to find out, the waitkey$ was not needed. The program will
            "stall" until the sound byte completes.

            This is great and exactly what I'm looking for. Thanks.


            ------------------




            [This message has been edited by Mel Bishop (edited April 29, 2005).]
            There are no atheists in a fox hole or the morning of a math test.
            If my flag offends you, I'll help you pack.

            Comment


            • #7
              You can change the %SND_SYNC to %SND_ASYNC and it will play the sound in the background and your program will continue to execute.



              ------------------
              Scott Slater
              Summit Computer Networks, Inc.
              www.summitcn.com
              Scott Slater
              Summit Computer Networks, Inc.
              www.summitcn.com

              Comment


              • #8
                I tried this using PBCC 2.0 and I can see my EXE increase in size by the size of the 2 wav files that are embedded, however, they don't play. They will play if the 2 wav files are in the directory, but that means the wav is not being gotten from the embedded copy of the wav data in the exe. I'd like to distribute this as a standalone EXE, and not have to include the wav files separately.

                Using a resource file to embed the wav files, does that only work with PBWin?

                I'm using win32api.inc dated May 2004.



                ------------------

                Comment


                • #9
                  What code are you using to play the wave files? Remember that the %SND_RESOURCE flag *must* be included to play sound from a resource.

                  ------------------
                  email
                  http://www.kgpsoftware.com
                  kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

                  Comment


                  • #10
                    kev,

                    thanks for the quick reply.
                    here's my program:

                    Code:
                    #resource "sounds.pbr"
                    $include "..\..\win32api\win32api.inc"
                    
                    function pbmain ()
                      console name "testsoun"
                      console screen 25,80
                      print "starting...": print
                    
                      print "sound1 %snd_resource or %snd_sync"
                      playsound "sound1", getmodulehandle(byval 0), (%snd_resource or %snd_sync)
                      print "sleeping for 1 second.": print
                      sleep 1000
                    
                      print "sound2 %snd_resource or %snd_sync"
                      playsound "sound2", getmodulehandle(byval 0), (%snd_resource or %snd_sync)
                      print "sleeping for 1 second.": print
                      sleep 1000
                    
                      print "sound2 %snd_resource or %snd_async"
                      playsound "sound2", getmodulehandle(byval 0), %snd_resource or %snd_async
                      print "sleeping for 1 second.": print
                      sleep 1000
                    
                      print "sound2 %snd_async"
                      playsound "sound2", getmodulehandle(byval 0), %snd_async
                      print "sleeping for 1 second.": print
                      sleep 1000
                    
                      print "sound2 %snd_sync"
                      playsound "sound2", getmodulehandle(byval 0), %snd_sync
                      print "press <any key> to exit..."
                      f$ = waitkey$
                    end function
                    the first 3 playsounds are silent, the last 2 work.
                    looks like i'm having the same problem as mel bishop at http://www.powerbasic.com/support/pb...ad.php?t=16772

                    btw, i downloaded the latest win32api.zip from pb
                    and i tried this on windows me, xp home and xp pro, all
                    with same results.

                    i experimented with case, both in the rc file
                    and the pbmain, and tried a number of options in the
                    rc file, such discardable and moveable and pure,
                    and last, but not least, to be sure it's not a lfn problem,
                    i tried with a path and without, and with all nodes in the
                    path shortened to 8 characters, and renaming the 2 sound files
                    to 8.3 format.

                    oh, i also tried a number of combinations of %snd flags.

                    all to no avail.

                    again, i'm using pbcc 2.0.
                    here's my compile log:

                    Code:
                    powerbasic console compiler
                    pb/cc   version 2.0 
                    copyright (c) 1998-99 by powerbasic inc.
                    carmel, california, usa
                    all rights reserved
                    
                    primary source:  f:\$misc\$\pbcc20\_stuff\sounds\testsoun.bas   {49724 total lines}
                    compile time:  0.3 seconds, at 9944800 lines/minute
                    
                    2128 bytes compiled code, 7265 bytes rtlibrary,
                    236 bytes string literals, and 1292 bytes dgroup.
                    executable stack size:  1048576 bytes.
                    disk image: 44032 bytes   memory image: 8793 bytes.


                    ------------------

                    Comment


                    • #11
                      Please see my masterful piece of detective work in the other thread: If you build the resource names with quotation marks, you have to call the 'play' that way.
                      Michael Mattias
                      Tal Systems Inc. (retired)
                      Racine WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment


                      • #12
                        Interesting. To add to Michael's findings it seems that the resource compiler actually includes the quote marks in resource identifiers. You can either remove the quote marks from the resource file or add them to the PlaySound call.

                        RC.EXE will treat un- #defined and unquoted indentifiers as strings if they are not numeric (a number).

                        ------------------
                        email
                        http://www.kgpsoftware.com

                        [This message has been edited by Kev Peel (edited May 10, 2005).]
                        kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

                        Comment


                        • #13
                          I had no sooner posted my reply when I saw over in the PBCC forum that Michael had supplied the answer to Mel.

                          Boy that's quick response, really appreciated.

                          Like Mel, I have met with success, but not entirely.

                          My problem now lies in that of the 2 wav files listed in my resource file, one plays via resource, the other does not!

                          I tried switching the order, both in the resource file
                          and in my calling program, and I've yet to figure out the ryhme or reason why one fails.

                          Using various combinations, I can get either of the files to play via resource, but not both.

                          As soon as I come up with a pattern, I'll post again.


                          ------------------

                          Comment


                          • #14
                            It seems as though what ever wav file is put first
                            in the resource file is the one that won't play as a resource.

                            Here's my latest code:
                            Code:
                            $INCLUDE "..\..\win32api\win32api.inc"
                            #RESOURCE "SOUNDS.PBR"
                            
                            FUNCTION PBMAIN ()
                              CONSOLE NAME "TestSoun"
                              CONSOLE SCREEN 25,80
                              PRINT "Starting...": PRINT
                            
                              PRINT "crow %SND_RESOURCE OR %SND_ASYNC"
                              PlaySound "crow", GetModuleHandle(BYVAL 0), (%SND_RESOURCE OR %SND_ASYNC)
                              PRINT "Sleeping for 1 second.": PRINT
                              SLEEP 700
                              PRINT "."
                              SLEEP 900
                            
                              PRINT "dog1 %SND_RESOURCE OR %SND_ASYNC"
                              PlaySound "dog1", GetModuleHandle(BYVAL 0), %SND_RESOURCE OR %SND_ASYNC
                              SLEEP 500
                                 
                              PRINT "crow %SND_RESOURCE OR %SND_ASYNC"
                              PlaySound "crow", GetModuleHandle(BYVAL 0), (%SND_RESOURCE OR %SND_ASYNC)
                              PRINT "Sleeping for 1 second.": PRINT
                              SLEEP 1500
                            
                              PRINT "press <any key> to exit..."
                              F$ = WAITKEY$
                            END FUNCTION
                            and here's my resource file:

                            Code:
                            dog1 wave moveable pure "F:\\$misc\\$\\PBCC20\\_stuff\\sounds\\dog1.wav"
                            crow wave moveable pure "F:\\$misc\\$\\PBCC20\\_stuff\\sounds\\crow.wav"
                            In this case, dog1 will not play as a resource.



                            ------------------

                            Comment


                            • #15
                              Try using a WAITKEY$ after the 1st file and see if both plays.

                              *** Later on ***

                              Did a little further checking Brian. %snd_resource plays the
                              file in "sync" mode meaning the program will "stall" until the
                              sound byte finishes.

                              If you play it in "async" mode, the program keeps on trucking
                              until something else happens.

                              Try changing your "async" mode to "sync" mode and see what shakes
                              loose.

                              Also, you can try the WAITKEY thing as well.



                              [This message has been edited by Mel Bishop (edited May 10, 2005).]
                              There are no atheists in a fox hole or the morning of a math test.
                              If my flag offends you, I'll help you pack.

                              Comment


                              • #16
                                When using SND_ASYNC, there must be a sufficient delay in the program to allow the sound to finish playing. The following PB/WIN 7.04 code works:

                                Code:
                                #Resource "test.pbr"
                                 
                                #Include "win32api.inc"
                                 
                                Function PBMain
                                 
                                    playsound "test1", getmodulehandle(ByVal 0), %snd_async Or %snd_resource
                                 
                                    MsgBox "play #1" 
                                 
                                    playsound "test2", getmodulehandle(ByVal 0), %snd_async Or %snd_resource
                                     
                                    MsgBox "play #2"
                                 
                                End Function
                                It is wrong to say that SND_RESOURCE plays the file in sync mode - all SND_RESOURCE does is tell Windows to play the sound from a resource. The SND_SYNC flag is included by default (it's value is &H0).

                                More here:

                                http://msdn.microsoft.com/library/de..._playsound.asp

                                ------------------
                                email
                                http://www.kgpsoftware.com
                                kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

                                Comment


                                • #17
                                  Code:
                                  $include "..\..\win32api\win32api.inc"
                                  #resource "sounds.pbr"
                                  
                                  function pbmain ()
                                    console name "testsoun"
                                    console screen 25,80
                                    print "starting...": print
                                  
                                    print "crow %snd_resource or %snd_async"
                                    playsound "crow", getmodulehandle(byval 0), %snd_resource or %snd_async
                                    f$ = waitkey$
                                    '
                                    print "intro %snd_async"
                                    playsound "intro", getmodulehandle(byval 0), %snd_resource or %snd_async
                                    for x% = 1 to 18
                                      print x%;
                                      sleep 500
                                      next
                                    print
                                    '
                                    print "intro %snd_async"
                                    playsound "intro", getmodulehandle(byval 0), %snd_resource or %snd_async
                                    for x% = 1 to 16
                                      print x%;
                                      sleep 50
                                      next
                                    print
                                    '
                                    print "dog1 %snd_resource or %snd_async"
                                    playsound "dog1", getmodulehandle(byval 0), %snd_resource or %snd_async
                                    
                                    print "press <any key> to exit..."
                                    f$ = waitkey$
                                  end function
                                  resource file...
                                  Code:
                                  dog1 wave "dog1.wav"
                                  intro wave "intro.wav"
                                  crow wave "crow.wav"
                                  in the above program, intro plays fine. it's a 7 second wave file.
                                  the for loop for the first intro lasts for 9 seconds, so the first
                                  intro plays to completion before the second intro starts.

                                  the for loop for the first intro proves that the program
                                  can be doing something else while the first intro is playing
                                  (it's displaying x across the screen).

                                  the sounds for crow and dog1 dont play.
                                  if i rearrange my rc file, putting crow as the 2nd file defined,
                                  it will play, the other two will not.

                                  at this point, i'm inclined to think it's an alignment problem in
                                  the res file,
                                  maybe something is off a double-word alignment boundary or something.

                                  one wave file embedded works fine, but i'd like more than one.
                                  note, i also tried rearranging the files according to size
                                  and also putting the playsounds in the same order as the rc file.
                                  no luck.

                                  may try this next http://www.powerbasic.com/support/pb...ad.php?t=20278


                                  ------------------


                                  [this message has been edited by brian harney (edited may 10, 2005).]

                                  Comment


                                  • #18
                                    You might want to try putting a: PlaySound BYVAL %NULL...
                                    between the end of playing one WAV and the start of playing the
                                    next WAV. BYVAL %NULL tells the API to terminate playing the
                                    current sound. It's possible that there are some collisions between
                                    the last song still playing and the next song wanting to play.


                                    ------------------
                                    clay at clayclear dot net

                                    Comment


                                    • #19
                                      It doesn't matter which order they are in the .RC file because the resource compiler sorts resources alphabetically by the identifiers, numerics first.

                                      If you have a moment, download ResHacker and open the .exe file to ensure the resources are present under WAVE...

                                      http://www.users.on.net/johnson/resourcehacker/

                                      ------------------
                                      email
                                      http://www.kgpsoftware.com
                                      kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

                                      Comment


                                      • #20
                                        This thread has helped me too. But a quick question I have with the following line:

                                        dog1 wave moveable pure "F:\\$misc\\$\\PBCC20\\_stuff\\sounds\\dog1.wav"

                                        I know "dog1" is how you reference the sound, and I obviously understand the .wav file part, but what does "wave moveable pure" mean? I see different examples of RC data using all different words. do they have meaning to the program? If so, is there a "keyword" list or something?

                                        ------------------


                                        [This message has been edited by Steve Smith (edited May 11, 2005).]

                                        Comment

                                        Working...
                                        X