🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.multimedia
1 messages
1 total messages Started by Mark Jacobs Wed, 22 Dec 2004 23:12
waveIn recording reply to sky
#267
Author: Mark Jacobs
Date: Wed, 22 Dec 2004 23:12
88 lines
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads