Getting Started
Introduction
Sample Programs
IDEs
History
Advice
Mini-Tutorial
Tutorials
Code Snippets

Resources
Web Sites
More Tutorials
Forums
Vendors/Tools
Books
Magazines
Newsletters
NewsGroups
User Groups
Talk Shows
Blogs

Controls
Overview
Button
Check3State
Checkbox
ComboBox
Frame
Graphic
Image
ImageX
ImgButton
ImgButtonX
Label
Line
ListBox
ListView
Option
Progress Bar
Scrollbar
StatusBar
TAB
TextBox
Toolbar
TreeView

GBIC >> PowerBASIC >> Tutorials >> Sound

PowerBASIC Information Center Tutorials
These tutorials were written to help you get a quick, but thorough, understanding of PowerBASIC - the scope of the language as well as it's specific capabilities.

Introduction       Projects       Language           Messages       Functions           Advanced
  • Overview
  • Examples
  • IDE
  • Compilation
  • Distribution
  • Project Files
  • DDT Windows
  • Controls
  • Menus
  • Dialogs  
  • Help Files
  • Resources  
  • Templates  
  • Project Shell  
  • Syntax
  • Operators
  • Data Types
  • Variables
  • Scope
  • Declarations  
  • Procedures
  • Flow Control
  • Windows
  • Messages
  • Callbacks
  • Mouse
  • Keyboard
  • Dialogs
  • Controls
  • Subclassing
  • Arithmetic
  • Trig  
  • Strings
  • Arrays
  • Date/Time
  • Printing
  • Files
  • Folders
  • Keyboard
  • Mouse
  • Sound
  • System
  • Error Traps
  • Debugging
  • Objects
  • Graphics
  • Databases
  • API
  • DLLs
  • ASM
  • Threads
  • Sound
    PowerBASIC has only one function to create a sound, the function BEEP. There are no built-in function to play standard sound files (*.wav) nor midi files (*.mid).

      • Sounds
       beep 

    API
    There are several Windows API which can be used to play sounds, including the sndPlaySound and WinBeep API.

    Both of these are included in the Win32API.inc that is distributed with PowerBASIC, so the declaration statements do not need to be put in the application as long as the #INCLUDE "Win32API.inc" compiler directive is included.

    Here is an example of using the WinBeep API.

        DECLARE FUNCTION WinBeep LIB "KERNEL32.DLL" ALIAS "Beep" _
                (BYVAL dwFreq AS DWORD, BYVAL dwDuration AS DWORD) AS LONG
        WinBeep 1000, 2000   'play 1000Hz sound for two seconds
    

    And here are several sndPlaySound API example.

        Declare Function sndPlaySound Lib "winmm.dll" 
             Alias "sndPlaySoundA" (ByVal lpszSoundName As String,
             ByVal uFlags as Long) as Long
        Dim iReturn As Long, SoundFile As String
        SoundFile = "sound.wav"  'set filename of sound to play
        iReturn = sndPlaySound(SoundFile, &H1)  'once, in background
        iReturn = sndPlaySound(SoundFile, &H0)  'once, wait until done
        iReturn = sndPlaySound(SoundFile, &H8)  'play continuously
        iReturn = sndPlaySound(vbNullString, False) 'stop playing sound
    

    Not shown here, the mciSendString API can be used to play midi files.

    Controls
    Unlike Visual Basic, PowerBASIC does not come with a built in control to play sounds. If the use of API, as discussed above, doesn't satisfy your need, you have two other choices.

    • 3rd Party COM Control
      Several vendors have created COM controls which can play sounds, either by providing a VCR-style interface for the user or by allowing the programmer to supply command strings to control the sounds generated by the control.

    • Control of Installed User Application
      If you know a user has an installed sound player, such as the built-in Windows sound recorder, you can use PowerBASIC to start the application and play the sound.

    Sound Function Reference
    Here's a quick reference of the available sound functions, in alphabetical order.

    • BEEP - plays the Windows default beep sound
          Beep      'that's it, just one line of code to get a beep
          

    Note that the default Windows sound can be changed using the control panel, or by using an API call.

    If you have any suggestions or corrections, please let me know.