🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #5333

Re: Playing Beep() through speakers

#5333
From: JD
Date: Fri, 02 Sep 2005 12:25
75 lines
3714 bytes
salamander1965 <salamander1@verizon.net> wrote:
>
> [...] The beeps are to provide a cue without requiring the
> user to take their eyes away from the scope.

What's wrong with using wav files? It seems to me that actual
spoken words would be more telling than tones of variouse
frequencies and durations. Look under Accessories for a sound
recorder and as long as you you have a headset with a
microphone, that's all you need.

If the wav's aren't too big, I'd add them to a resource file
so that thay're part of the exe (no disk access) and load and
play them as needed. For example:

//--- MyResource.rc -------------------------------------------
ERROR1 WAVE  SomeFile.wav
   ....
ERRORn WAVE  SomeOtherFile.wav
//-------------------------------------------------------------

Just run MyResource through the resource compiler and
include it into your application. Then to load the wave:


    DWORD  WaveSize = 0;
    LPVOID WavePtr  = NULL;
    LoadSound( "ERROR1", WaveSize, WavePtr );

//-------------------------------------------------------------
void LoadSound( AnsiString ID, DWORD &Size, LPVOID &MemoryWave )
{
    HRSRC SoundResource = ::FindResource( HInstance, ID.c_str(), "WAVE" );
    if( SoundResource )
      {
          Size = ::SizeofResource( HInstance, SoundResource );
          if( Size )
            {
                HGLOBAL SoundLoad = ::LoadResource( HInstance, SoundResource );
                if( SoundLoad )
                  {
                      LPVOID SoundPointer = ::LockResource( SoundLoad );
                      if( SoundPointer )
                        {
                            MemoryWave = ::VirtualAlloc( NULL, Size, MEM_COMMIT, PAGE_READWRITE );
                            if( MemoryWave ) ::CopyMemory( MemoryWave, SoundPointer, Size );
                        }
                  }
            }
      }
}
//-------------------------------------------------------------

To play the wave:

    ::PlaySound( (LPCSTR)WavePtr, NULL, SND_MEMORY | SND_ASYNC | SND_NODEFAULT | SND_NOWAIT );


To release the wave from memory:

    if( WavePtr ) ::VirtualFree( WavePtr, WaveSize, MEM_FREE );

I found that if you use this method of playing wave files, the
sound is played instantly. However, there is (sometimes) a
delay with the very first call to PlaySound so I have started
using a very small wav file with no sound that I load and play
at startup.

If you don't want to include the wav files in a resource file,
you can still play them from directly from disk:

    ::PlaySound( "FileName", HInstance, SND_ASYNC | SND_NODEFAULT | SND_NOWAIT );

~ JD
Technical Details
Message-ID: <431844a1$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!meganewsservers.com!feeder2.on.meganewsservers.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <43164b44$1@newsgroups.borland.com> <b20dh1ptsfm0gjr2bog6lhoc89fhf3fjmp@4ax.com> <4316d64f@newsgroups.borland.com> <43173554@newsgroups.borland.com> <43179cf9@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,1ac045379f8b141d
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "JD" <nospam@nospam.com>
Sender: "JD" <nospam@nospam.com>
Reply-To: "JD" <nospam@nospam.com>
Subject: Re: Playing Beep() through speakers
Newsgroups: borland.public.cppbuilder.nativeapi
X-User-Info: 152.163.101.6     
X-Forwarded-For: 172.157.101.111
References: <43164b44$1@newsgroups.borland.com> <b20dh1ptsfm0gjr2bog6lhoc89fhf3fjmp@4ax.com> <4316d64f@newsgroups.borland.com> <43173554@newsgroups.borland.com> <43179cf9@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.66
Message-ID: <431844a1$1@newsgroups.borland.com>
Date: 2 Sep 2005 05:25:05 -0700
X-Trace: newsgroups.borland.com 1125663905 207.105.83.66 (2 Sep 2005 05:25:05 -0700)
Lines: 76
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!meganewsservers.com!feeder2.on.meganewsservers.com!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail