DevLabs > DevLabs Forums > Small Basic > Extension to play music in Small Basic
Ask a questionAsk a question
 

General DiscussionExtension to play music in Small Basic

  • Saturday, November 29, 2008 3:16 AMRushworksAnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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

All Replies

  • Saturday, November 29, 2008 9:48 PMPlayDeez Games Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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, November 30, 2008 9:16 PMRushworksAnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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, April 05, 2009 4:40 PMStendecAnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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, April 05, 2009 11:14 PMRushworksAnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

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

  • Monday, April 06, 2009 5:45 PMStendecAnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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, April 07, 2009 2:45 PMRushworksAnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    yes, there is a difference between an internal speaker connected directly to the motherboard and external speakers that use drivers and a soundcard 
  • Tuesday, June 30, 2009 11:29 PMRobson Rocha Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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, July 01, 2009 5:06 PMFremyCompanyAnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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, September 22, 2009 8:10 PMRushworksAnswererUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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.