CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2008
    Posts
    108

    Send tone to sound card...

    The following function causes the small computer speaker to emit a tone for the requested duration:
    Code:
    Console.Beep(freq, duration_ms);
    Is there a generic function to call to send the tone to the sound card, or would the call have to be hardware specific dependent on the particular sound card in the computer?
    Thanks,
    Jim
    Last edited by Jim_Auricman; February 12th, 2009 at 05:05 PM. Reason: Corrected code tag.

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Send tone to sound card...

    It's a WinAPI, and you can P/Invoke it:

    Code:
    using System;
    using System.Runtime.InteropServices;
    
    public class _Main
    {
        #region Win32
        
        [DllImport("Kernel32.dll")]
        static extern bool Beep(
            uint dwFreq, uint dwDuration
        );
        
        #endregion
    
        public static void Main()
        {
            Beep(150, 150);
        }
    }
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Feb 2008
    Posts
    108

    Re: Send tone to sound card...

    Thanks, dglienna.
    I tried your test program and sound does indeed come out of the headphones.
    This enables me to do what I have planned to do.
    Jim

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured