Microsoft Developer Network > Página principal de foros > Small Basic > Extension to play music in Small Basic
Formular una preguntaFormular una pregunta
 

Debate generalExtension to play music in Small Basic

  • sábado, 29 de noviembre de 2008 3:16RushworksUsuario que respondeMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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

Todas las respuestas

  • sábado, 29 de noviembre de 2008 21:48PlayDeez Games Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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?
  • domingo, 30 de noviembre de 2008 21:16RushworksUsuario que respondeMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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

  • domingo, 05 de abril de 2009 16:40StendecUsuario que respondeMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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?
  • domingo, 05 de abril de 2009 23:14RushworksUsuario que respondeMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     

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

  • lunes, 06 de abril de 2009 17:45StendecUsuario que respondeMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     

    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?

     

  • martes, 07 de abril de 2009 14:45RushworksUsuario que respondeMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    yes, there is a difference between an internal speaker connected directly to the motherboard and external speakers that use drivers and a soundcard 
  • martes, 30 de junio de 2009 23:29Robson Rocha Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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
  • miércoles, 01 de julio de 2009 17:06FremyCompanyUsuario que respondeMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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
  • martes, 22 de septiembre de 2009 20:10RushworksUsuario que respondeMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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.