Article View: borland.public.cppbuilder.multimedia
Article #586Re: Simultaneous Playing and Recording of WAV Audio
From: Aleksandr Shamray
Date: Sun, 12 Oct 2003 08:14
Date: Sun, 12 Oct 2003 08:14
49 lines
2787 bytes
2787 bytes
Basically you would need to spawn one thread for recording and
one for playback. Each thread will run a simple loop like this:
while (!done) {
if (WAIT_OBJECT_0 == WaitForSingleObject(event, timeout))
ProcessBuffers();
}
event is a Windows event object, which will be signaled every time
device has processed another buffer. Other methods of being notified
are also available (callbacks, messages).
ProcessBuffers() is where you copy data from buffer being recorded,
or feed playback queue with another portion of data.
To ensure you will not get cuts in recording/playback it is a good
idea to set the priority of both threads to THREAD_PRIORITY_TIME_CRITICAL.
I believe this could be done sequentially in main application thread,
using WaitForMultipleObjects() for example, but sooner or later you
will discover that managing separate threads is much easy.
Note, that VCL is not multi-thread safe, and my usual mistake was to
display some nice statistics on a form's canvas inside ProcessBuffers().
This often crashes the whole application in a very mysterious way.
--
With best wishes,
Aleksandr Shamray
Stream your audio today.
http://lakeofsoft.com/
<Isaac .> wrote in message news:3f86a0fc$1@newsgroups.borland.com...
>
> Hi,
>
> I know how to play/record wav audio, but what I'd like to try now
> is simultaneously record and play wav audio. I'm using win32
> api calls. I'm wondering if I must to do this through multi-
> threading or can it be done sequentially.
>
> I'm new at this multimedia programming, so any help will really
> be great. Thanks in advance!
>
> Isaac
Technical Details
Message-ID:
<3f890deb@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!in.100proofnews.com!in.100proofnews.com!news02.tsnz.net!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<3f86a0fc$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d0fc,a83c7f71a379761c X-Google-Attributes: gid10d0fc,public X-Google-ArrivalTime: 2003-10-12 01:28:42 PST From: "Aleksandr Shamray" <spam-lake@lakeofsoft.com> Newsgroups: borland.public.cppbuilder.multimedia References: <3f86a0fc$1@newsgroups.borland.com> Subject: Re: Simultaneous Playing and Recording of WAV Audio Date: Sun, 12 Oct 2003 11:14:29 +0300 Lines: 50 Organization: Lake of Soft, Ltd MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-2" Content-Transfer-Encoding: quoted-printable X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 NNTP-Posting-Host: 80.77.35.197 Message-ID: <3f890deb@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1065946603 80.77.35.197 (12 Oct 2003 01:16:43 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!in.100proofnews.com!in.100proofnews.com!news02.tsnz.net!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail