🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.multimedia
Article #695

Re: PlaySound from memory is misbehaving

#695
From: Ted Lyngmo
Date: Sat, 17 May 2003 11:32
59 lines
2961 bytes
Prof. Chuck Kelly wrote:
 > Marcelo,
 >
 > First let me say I appreciate your help.
 >
 > I do not want the program to require DirectX so that's out. I
 > want to be able to play sounds from memory. I don't want the program to
 > wait for the sound to complete before continuing execution. The code
 > which I have written works on most computers but not all.
 > Do you have any suggestions.

You could always play the sound synchronically in a thread instead. I haven't 
tested the code I've written, but you'll get the picture I think.

Kind regards,
Ted Lyngmo

#include <mmsystem.h>
#include <list>

using namespace std;

class WavePtrList : public list<char *> {
     // extend the WavePtrList class here if you need it
};

class PlaySoundThread : public TThread {
private:
     WavePtrList Waves;
public:
     __fastcall PlaySoundThread() : TThread(true) {
         // do any initialization here
     }
     __fastcall ~PlaySoundThread() {
         Terminate();
         PlaySound(NULL,NULL,SND_PURGE|SND_SYNC);
         WaitFor();
     }
     void AddWave( char *Wave ) {
         Waves.push_back(Wave);
         if( Suspended ) Resume();
     }
     void RemoveWave( char *Wave ) {
         Suspend();
         Waves.remove(Wave);
         if( Waves.size()!=0 ) Resume();
     }
     void __fastcall Execute() {
         WavePtrList::iterator wav=Waves.begin();
         while(!Terminated) {
             PlaySound( *wav, NULL, SND_SYNC | SND_NOSTOP | SND_MEMORY );
             if( ++wav == Waves.end() ) wav = Waves.begin();
         }
     }
};

-- 
Replace MY_FIRST_NAME in my email address with my first name to send a private
email to me.
Technical Details
Message-ID: <3EC61DDF.6010607@lyncon.se>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <3e823943$1@newsgroups.borland.com> <3e9c26b1@newsgroups.borland.com> <3ea70237$1@newsgroups.borland.com> <3eadeff3$1@newsgroups.borland.com> <3eaec15f$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10d0fc,e1c9dfc4b76a1dde
X-Google-Attributes: gid10d0fc,public
X-Google-ArrivalTime: 2003-05-17 04:38:44 PST
Message-ID: <3EC61DDF.6010607@lyncon.se>
Date: Sat, 17 May 2003 13:32:47 +0200
From: Ted Lyngmo <MY_FIRST_NAME@lyncon.se>
Organization: Lyncon - Computer & Music consulting
User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:0.9.4) Gecko/20011128 Netscape6/6.2.1
X-Accept-Language: sv,en
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.multimedia
Subject: Re: PlaySound from memory is misbehaving
References: <3e823943$1@newsgroups.borland.com> <3e9c26b1@newsgroups.borland.com> <3ea70237$1@newsgroups.borland.com> <3eadeff3$1@newsgroups.borland.com> <3eaec15f$1@newsgroups.borland.com>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 217.215.147.98
X-Trace: newsgroups.borland.com 1053170818 217.215.147.98 (17 May 2003 04:26:58 -0700)
Lines: 60
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail