Article View: borland.public.cppbuilder.multimedia
Article #267waveIn recording reply to sky
From: Mark Jacobs
Date: Wed, 22 Dec 2004 23:12
Date: Wed, 22 Dec 2004 23:12
88 lines
4180 bytes
4180 bytes
This is its simplest form, and it is by no means the optimum programming method
that adheres strictly to whatever rules, but it works. It is the pertinent
waveIn code from my mjplayer application (at
http://www.jacobsm.com/index.htm#sft )
This code feeds the result of recording stereo waveIn to 2 VU meters on a form.
You could adapt it to write to disk, or even stream it somewhere. Good luck.
I assume the following declarations in the header :-
#define FRQ 256
#define NBFS 9
private: // private user declarations
void __fastcall SoundNext();
void __fastcall dosoundz();
bool VUEnabled;
char erst[199],wvbfr[NBFS][FRQ+5];
HWAVEIN phwo; WAVEFORMATEX pwfx; MMRESULT wh;
public: // public user declarations
WAVEHDR wvhd[NBFS]; bool clsing;
void __fastcall ProcessInput(WAVEHDR *thewvhd);
Code :-
//---------------------------------------------------------------------------
void CALLBACK WaveInProc(HWAVEIN waveIn,UINT uMsg,DWORD dwInstance,DWORD
dwParam1,DWORD dwParam2)
{
if (MainForm->clsing || dwParam1==0) return;
if (uMsg==MM_WIM_DATA) MainForm->ProcessInput((WAVEHDR *)dwParam1);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormPaint(TObject *Sender)
{
static bool clld=false;
if (clld) return;
clld=true; dosoundz();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ProcessInput(WAVEHDR *thewvhd)
{
if (clsing) return;
wh=waveInUnprepareHeader(phwo,thewvhd,sizeof(WAVEHDR));
if (wh==MMSYSERR_NOERROR)
{
int lv=(int)((unsigned char)thewvhd->lpData[0])-128,rv=(int)((unsigned
char)thewvhd->lpData[1])-128;
meter1->Position=lv*100/128; meter2->Position=rv*100/128;
thewvhd->dwFlags=0;
}
SoundNext();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::SoundNext()
{
if (clsing) return;
int ii;
for (ii=0;ii<NBFS;++ii) if (wvhd[ii].dwFlags==0) break;
if (ii==NBFS) return;
wvhd[ii].lpData=wvbfr[ii]; wvhd[ii].dwBufferLength=FRQ; wvhd[ii].dwLoops=0;
if (waveInPrepareHeader(phwo,&wvhd[ii],sizeof(WAVEHDR))!=MMSYSERR_NOERROR)
return;
else { waveInAddBuffer(phwo,&wvhd[ii],sizeof(WAVEHDR)); waveInStart(phwo);}
}
//----------------------------------------------------------------------------
void __fastcall TMainForm::dosoundz()
{
pwfx.cbSize=0; pwfx.wFormatTag=WAVE_FORMAT_PCM;
pwfx.nChannels=2; pwfx.nSamplesPerSec=11025; pwfx.wBitsPerSample=8;
pwfx.nAvgBytesPerSec=pwfx.nSamplesPerSec*pwfx.nChannels*pwfx.wBitsPerSample/8;
pwfx.nBlockAlign=pwfx.nChannels*pwfx.wBitsPerSample/8;
wh=waveInOpen(&phwo,WAVE_MAPPER,&pwfx,(DWORD)WaveInProc,(DWORD)this,CALLBACK_FUN
CTION);
if (wh==MMSYSERR_NOERROR)
{
VUEnabled=true; for (int ii=0;ii<NBFS;++ii) { memset(wvbfr[ii],'\0',FRQ);
wvhd[ii].dwFlags=0;}
SoundNext(); Application->ProcessMessages(); SoundNext();
}
}
//----------------------------------------------------------------------------
--
Mark Jacobs
Technical Details
Message-ID:
<41c9ff8a$2@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshosting.com!nx02.iad01.newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10d0fc,636e341cdb4833c1,start X-Google-Attributes: gid10d0fc,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Mark Jacobs" <http://www.jacobsm.com/mjmsg.htm?Borland%20Newsgroup> Newsgroups: borland.public.cppbuilder.multimedia Subject: waveIn recording reply to sky Date: Wed, 22 Dec 2004 23:12:36 -0000 Lines: 89 Organization: DK Computing MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 NNTP-Posting-Host: 81.86.186.94 Message-ID: <41c9ff8a$2@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1103757194 81.86.186.94 (22 Dec 2004 15:13:14 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newshosting.com!nx02.iad01.newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail