MSDN > 論壇首頁 > Small Basic > Extension to play music in Small Basic
發問發問
 

一般討論Extension to play music in Small Basic

  • Saturday, 29 November, 2008 3:16Rushworks解答者使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Here's an extension to Small Basic that plays tones from your internal speaker.

    It is similar to QB's PLAY statement, but still needs a bit of work.

    There is no error checking, and no way to stop playing in the middle of a string.

    The new object is ToneGenerator

    There are two methods-
        
        PlayString(string)

            the string can be any note C, C#, D, D#, E, F, F#, G, G#, A, A#, B 
            or you can change the octave by typing the letter O followed by a number 1 - 6 ex. O3
            or you can change the length of the note by typing the letter L followed by a number 1 - 9 ex. L2
            or you can add a pause by typing the letter P followed by a number 1 - 9 ex. P7
        
            you end up with something like    ToneGenerator.PlayString("O4 L3 GAGFEF L6 G")

            I haven't tested this a lot, but it should ignore everything else.

    and 

        PlayTone(frequency, duration)

            this method will simply beep at the frequency and duration you input

    To use it, copy the ToneGen.dll and ToneGen.xml to your C:\Program Files\Microsoft\Small Basic\lib folder.

    The sample included plays Mary had a little lamb.

    http://code.msdn.microsoft.com/ExtToneGenerator

所有回覆

  • Saturday, 29 November, 2008 21:48PlayDeez Games 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Good stuff.

    However, I seem to recall that L command had longer notes for smaller values, so L1 was a whole note, L2 was a half note, L4 was a quarter note, etc.

    At least that's how it worked in GW-BASIC and QB as well.

    You going to do a Draw statement along a similar vein?
  • Sunday, 30 November, 2008 21:16Rushworks解答者使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    I don't plan on writing a DRAW extension, I think the Turtle does a similar task.  I wrote the ToneGenerator because I thought it was missing from Small Basic.

    I also wrote a simple piano program https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=ExtToneGenerator&Release

  • Sunday, 5 April, 2009 16:40Stendec解答者使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Hi Rushworks,
    I successfully downloaded the files for your tone generator and it appears in the Intellisense wheel. However. I can't get a note out of it. There is a delay while the sound should be there and then the program ends. Any ideas?
  • Sunday, 5 April, 2009 23:14Rushworks解答者使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    Sorry to hear your having trouble with the extension.  My only suggestion would be to check your internal speaker.  

  • Monday, 6 April, 2009 17:45Stendec解答者使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    I've also dowloaded litdev's speech and music extension and that works fine. Has anyone else had difficulties? My PC is set-up for the UK.

    I notice that you refer to the internal speaker. I don't have an internal speaker, I use a pair of small external speakers. I can't see that this makes any difference or am I wrong?

     

  • Tuesday, 7 April, 2009 14:45Rushworks解答者使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    yes, there is a difference between an internal speaker connected directly to the motherboard and external speakers that use drivers and a soundcard 
  • Tuesday, 30 June, 2009 23:29Robson Rocha 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Hi Rushworks!

    I was wishing to write a simple toy program for my 1 year old son, who likes to strike my keyboard to hear beeps. The tone generator you wrote seems perfect, and i was also wishing to write something simple with smallbasic.

    Well, i've downloaded Small Basic 0.5, and soon after downloaded your extension, installed it as suggested, but... It wont work. Alas, it crashes SmallBasic when it is initializing after installation. Only after removal SB works again.

    I've done something wrong?

    Thanks!

    Robson
  • Wednesday, 1 July, 2009 17:06FremyCompany解答者使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    I've done something wrong?
    No, this extension has not been updated for v0.5. It can causes problems.

    You can either recompile yourself or wait Rushworks to do it for you.
    Fremy - Developer in VB.NET, C# and JScript ... - Feel free to try my extension
  • Tuesday, 22 September, 2009 20:10Rushworks解答者使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    I created a new release of my Tone Generator.  I included a .dll for version v0.6 and a batch file that builds a new .dll file, using the command line compiler, for whatever version of Small Basic you have.

    https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=ExtToneGenerator&ReleaseId=3247

    when the next version of Small Basic is out, simply run the update file and you should be good to go.