Loading ...
Sorry, an error occurred while loading the content.

sound files

Expand Messages
  • richard.paul98
    Hi Is there any way at all that I can use sound files in my program? (I know that I can generate a tone, setting the duration and frequency.) Can I use game
    Message 1 of 10 , May 31, 2009
    View Source
    • 0 Attachment
      Hi

      Is there any way at all that I can use sound files in my program?
      (I know that I can generate a tone, setting the duration and frequency.)

      Can I use game sound files, and if so, what is the command?
      Also, what format would they need to be? (wav, mp3, ogg, etc
    • Michel Clasquin-Johnson
      ... That depends on your platform. On Mac OSX this works fine: sub Play(filename$,dothis$) dothis$= afplay + filename$ + & sys(dothis$) end sub OSX has the
      Message 2 of 10 , Jun 1, 2009
      View Source
      • 0 Attachment
        On 01 Jun 2009, at 4:58 AM, richard.paul98 wrote:

        > Hi
        >
        > Is there any way at all that I can use sound files in my program?
        > (I know that I can generate a tone, setting the duration and
        > frequency.)

        That depends on your platform. On Mac OSX this works fine:

        sub Play(filename$,dothis$)
        dothis$="afplay " + filename$ +" &"
        sys(dothis$)
        end sub

        OSX has the afplay command built in - it will play anything QuickTime
        can recognise. So all you do is make a system call to it.

        On other platforms, you'll have to scrounge around for an equivalent.

        If you want to generate speech rather than music, you could try CB's
        own "say" command.

        ---------------------
        Michel Clasquin-Johnson
        e-mail: clasqm@...
        website: http://www.reviewcentral.co.za/




        [Non-text portions of this message have been removed]
      • Richard Paul
        I am using Mac OSX This looks like exactly what I want! Does the file have to be any specific format? Thanks a lot! ... [Non-text portions of this message have
        Message 3 of 10 , Jun 3, 2009
        View Source
        • 0 Attachment
          I am using Mac OSX
          This looks like exactly what I want!
          Does the file have to be any specific format?
          Thanks a lot!


          On 2/06/2009, at 4:43 AM, Michel Clasquin-Johnson wrote:

          >
          >
          >
          > On 01 Jun 2009, at 4:58 AM, richard.paul98 wrote:
          >
          > > Hi
          > >
          > > Is there any way at all that I can use sound files in my program?
          > > (I know that I can generate a tone, setting the duration and
          > > frequency.)
          >
          > That depends on your platform. On Mac OSX this works fine:
          >
          > sub Play(filename$,dothis$)
          > dothis$="afplay " + filename$ +" &"
          > sys(dothis$)
          > end sub
          >
          > OSX has the afplay command built in - it will play anything QuickTime
          > can recognise. So all you do is make a system call to it.
          >
          > On other platforms, you'll have to scrounge around for an equivalent.
          >
          > If you want to generate speech rather than music, you could try CB's
          > own "say" command.
          >
          > ---------------------
          > Michel Clasquin-Johnson
          > e-mail: clasqm@...
          > website: http://www.reviewcentral.co.za/
          >
          > [Non-text portions of this message have been removed]
          >
          >
          >



          [Non-text portions of this message have been removed]
        • Richard Paul
          I tried this program: 10 sub play(sound$,dothis$) 20 dothis$ = afplay +sound$+ & 30 sys(dothis$) 40 end sub 50 gosub 10 This program was saved in a folder
          Message 4 of 10 , Jun 3, 2009
          View Source
          • 0 Attachment
            I tried this program:

            10 sub play(sound$,dothis$)
            20 dothis$ = "afplay "+sound$+" &"
            30 sys(dothis$)
            40 end sub
            50 gosub 10

            This program was saved in a folder which also contained two files:
            "sound"
            and
            "sound$"
            (I didn't know whether to include $ in the file name)
            Both files were mp3
            CB ran the program fine with no errors, but there was no sound output.
            Can you please show me lines of code as an extract from a program
            using sound and playing it?
            Do you have to previously define the sound file?
            What is the "&" for, anyway?
            Thanks

            On 2/06/2009, at 4:43 AM, Michel Clasquin-Johnson wrote:

            > sub Play(filename$,dothis$)
            > dothis$="afplay " + filename$ +" &"
            > sys(dothis$)
            > end sub



            [Non-text portions of this message have been removed]
          • Richard Paul
            I have it working fine now! sound file has to be decompressed type (wav, aiff, etc) Thanks for your help ... [Non-text portions of this message have been
            Message 5 of 10 , Jun 4, 2009
            View Source
            • 0 Attachment
              I have it working fine now!
              sound file has to be decompressed type (wav, aiff, etc)
              Thanks for your help


              On 2/06/2009, at 4:43 AM, Michel Clasquin-Johnson wrote:

              >
              >
              >
              > On 01 Jun 2009, at 4:58 AM, richard.paul98 wrote:
              >
              > > Hi
              > >
              > > Is there any way at all that I can use sound files in my program?
              > > (I know that I can generate a tone, setting the duration and
              > > frequency.)
              >
              > That depends on your platform. On Mac OSX this works fine:
              >
              > sub Play(filename$,dothis$)
              > dothis$="afplay " + filename$ +" &"
              > sys(dothis$)
              > end sub
              >
              > OSX has the afplay command built in - it will play anything QuickTime
              > can recognise. So all you do is make a system call to it.
              >
              > On other platforms, you'll have to scrounge around for an equivalent.
              >
              > If you want to generate speech rather than music, you could try CB's
              > own "say" command.
              >
              > ---------------------
              > Michel Clasquin-Johnson
              > e-mail: clasqm@...
              > website: http://www.reviewcentral.co.za/
              >
              > [Non-text portions of this message have been removed]
              >
              >
              >



              [Non-text portions of this message have been removed]
            • Michel Clasquin-Johnson
              OK, OK, OK first of all sound$ is here the name of a variable. Presumably the file you want to play is sound.mp3 Sorry, I don t use line numbers. CB allows
              Message 6 of 10 , Jun 4, 2009
              View Source
              • 0 Attachment
                OK, OK, OK

                first of all sound$ is here the name of a variable. Presumably the
                file you want to play is sound.mp3

                Sorry, I don't use line numbers. CB allows good structured programming
                and there is no reason not to do it.

                save this as Test.bas in a folder with an mp3 called sound.mp3. Note
                that everything is case-sensitive

                REM Main Program
                print "About to play sound.mp3"
                play("sound.mp3")
                print "Well, it should be playing. Bye now"
                quit
                REM Subroutine
                sub play(sound$, dothis$)
                dothis$ = "afplay "+sound$+" &"
                sys(dothis$)
                end sub

                Open a terminal, cd to the folder and type

                basic ./Test.bas

                and Press Enter

                So what does this do? the main program calls the subroutine play and
                feeds the filename sound.mp3 into the local variable sound$, and then
                quits

                The subroutine play starts up with two local variables, sound$ is a
                string variable that is filled with the filename sound.mp3 by the
                calling main program. dothis$, on the other hand is left blank for now.

                we then construct a valid bash statement using BASIC string
                concatenation. what we want is

                afplay sound.mp3 &

                The & at the end tells afplay to give control back immediately and not
                hog the system all to itself until it is finished playing. This works
                for almost all bash commands.

                go ahead, type that line into the terminal and see what happens
                (provided you're in the right directory)

                So, we create this string and feed it into the string variable dothis$

                Then all we need to do is make a system call and since we're not
                trying to get a value back it doesn't make much difference if we use
                sys() or sys$()

                Now all of this could be done on one line:

                sys("afplay sound.mp3 &")

                but what if you want to be able to choose from more than one sound?
                Easy.

                REM Main Program
                play("sound1.mp3")
                play("sound2.mp3")
                play("sound3.mp3")
                quit
                REM Subroutine
                sub play(sound$, dothis$)
                dothis$ = "afplay "+sound$+" &"
                sys(dothis$)
                end sub


                Or maybe you have a hundred sound files to play:

                REM Main Program
                for f = 1 to 100
                the_sound$="sound" + str$(f) = ".mp3"
                play(the_sound$)
                next f
                quit
                REM Subroutine
                sub play(sound$, dothis$)
                dothis$ = "afplay "+sound$+" &"
                sys(dothis$)
                end sub

                and this will start playing sound1.mp3 and won't stop until you reach
                sound100.mp3. Yes, I am directly feeding one variable's contents into
                another one.

                Just remember to cd to the directory before you start basic. Once you
                are in basic, finding out where the h@ll you are and changing to
                somehwere else is problematic.


                On 04 Jun 2009, at 4:35 AM, Richard Paul wrote:

                > I tried this program:
                >
                > 10 sub play(sound$,dothis$)
                > 20 dothis$ = "afplay "+sound$+" &"
                > 30 sys(dothis$)
                > 40 end sub
                > 50 gosub 10
                >
                > This program was saved in a folder which also contained two files:
                > "sound"
                > and
                > "sound$"
                > (I didn't know whether to include $ in the file name)
                > Both files were mp3
                > CB ran the program fine with no errors, but there was no sound output.
                > Can you please show me lines of code as an extract from a program
                > using sound and playing it?
                > Do you have to previously define the sound file?
                > What is the "&" for, anyway?
                > Thanks
                >
                > On 2/06/2009, at 4:43 AM, Michel Clasquin-Johnson wrote:
                >
                >> sub Play(filename$,dothis$)
                >> dothis$="afplay " + filename$ +" &"
                >> sys(dothis$)
                >> end sub
                >
                >
                >
                > [Non-text portions of this message have been removed]
                >
                >
                >
                > ------------------------------------
                >
                > Yahoo! Groups Links
                >
                >
                >

                ---------------------
                Michel Clasquin-Johnson
                e-mail: clasqm@...
                website: http://www.reviewcentral.co.za/




                [Non-text portions of this message have been removed]
              • jeffonymail
                ... Hi, Richard. I tried the following and it worked: filename$= /Users/jeff/Desktop/Allofme.MP3 gosub Play(filename$) end sub Play(filename$,dothis$)
                Message 7 of 10 , Jun 5, 2009
                View Source
                • 0 Attachment
                  --- In chipmunkbasicforum@yahoogroups.com, Richard Paul <richard.paul@...> wrote:
                  >
                  > I tried this program:
                  >
                  > 10 sub play(sound$,dothis$)
                  > 20 dothis$ = "afplay "+sound$+" &"
                  > 30 sys(dothis$)
                  > 40 end sub
                  > 50 gosub 10
                  >
                  > This program was saved in a folder which also contained two files:
                  > "sound"
                  > and
                  > "sound$"
                  > (I didn't know whether to include $ in the file name)
                  > Both files were mp3
                  > CB ran the program fine with no errors, but there
                  > was no sound output.


                  Hi, Richard.

                  I tried the following and it worked:

                  filename$="/Users/jeff/Desktop/Allofme.MP3"
                  gosub Play(filename$)
                  end

                  sub Play(filename$,dothis$)
                  sys("afplay " + filename$)
                  end sub


                  The following simplified version also worked:

                  sys("afplay /Users/jeff/Desktop/Allofme.MP3")
                  end


                  I found that I could not interrupt play in Chipmunk BASIC. To stop play before the end of file I used Activity Monitor to quit the process "afplay".

                  ....Jeff
                • jeffonymail
                  A follow-up note. I found that if I had spaces in the file path to the sound file then it no longer worked. The fix was to enclose the file path in single
                  Message 8 of 10 , Jun 5, 2009
                  View Source
                  • 0 Attachment
                    A follow-up note.

                    I found that if I had spaces in the file path to the sound file then it no longer worked. The fix was to enclose the file path in single quotes. E.g.:

                    sys("afplay '/Users/jeff/Desktop/All of me.MP3'")

                    or, in the subroutine version:

                    filename$="'/Users/jeff/Desktop/All of me.MP3'"


                    .....Jeff
                  • Michel Clasquin-Johnson
                    Correct. Or you can escape the spaces with backslashes sys( afplay /Users/jeff/Desktop/All of me.MP3 ) ... Michel Clasquin-Johnson e-mail: clasqm@gmail.com
                    Message 9 of 10 , Jun 6, 2009
                    View Source
                    • 0 Attachment
                      Correct. Or you can "escape" the spaces with backslashes

                      sys("afplay /Users/jeff/Desktop/All\ of\ me.MP3")

                      On 05 Jun 2009, at 3:56 PM, jeffonymail wrote:

                      > A follow-up note.
                      >
                      > I found that if I had spaces in the file path to the sound file then
                      > it no longer worked. The fix was to enclose the file path in single
                      > quotes. E.g.:
                      >
                      > sys("afplay '/Users/jeff/Desktop/All of me.MP3'")
                      >
                      > or, in the subroutine version:
                      >
                      > filename$="'/Users/jeff/Desktop/All of me.MP3'"
                      >
                      >
                      > .....Jeff

                      ---------------------
                      Michel Clasquin-Johnson
                      e-mail: clasqm@...
                      website: http://www.reviewcentral.co.za/




                      [Non-text portions of this message have been removed]
                    • Michel Clasquin-Johnson
                      I tested it with an mp3 and it worked OK for me, but wav is the one thing any computer out there will play. ... Michel Clasquin-Johnson e-mail:
                      Message 10 of 10 , Jun 6, 2009
                      View Source
                      • 0 Attachment
                        I tested it with an mp3 and it worked OK for me, but wav is the one
                        thing any computer out there will play.

                        On 04 Jun 2009, at 8:50 PM, Richard Paul wrote:

                        > I have it working fine now!
                        > sound file has to be decompressed type (wav, aiff, etc)
                        > Thanks for your help

                        ---------------------
                        Michel Clasquin-Johnson
                        e-mail: clasqm@...
                        website: http://www.reviewcentral.co.za/




                        [Non-text portions of this message have been removed]
                      Your message has been successfully submitted and would be delivered to recipients shortly.