Thread View: borland.public.cppbuilder.multimedia
6 messages
6 total messages
Started by iim
Thu, 25 Mar 2004 00:10
microphone signal level
Author: iim
Date: Thu, 25 Mar 2004 00:10
Date: Thu, 25 Mar 2004 00:10
2 lines
938 bytes
938 bytes
I need a small program to measure the signal level from microphone via sound card. Anybody can help ?
Re: microphone signal level
Author: KL Chin
Date: Thu, 25 Mar 2004 02:03
Date: Thu, 25 Mar 2004 02:03
15 lines
1263 bytes
1263 bytes
Hi, Pls visit http://bdn.borland.com/all/0,1435,s|50038|99,00.htm look for 17610_real_time_audio_meter.zip Regards KL Chin "iim" <imamsiswanto@yahoo.com.sg> wrote in message news:40622392$1@newsgroups.borland.com... > > I need a small program to measure the signal level from microphone via sound card. Anybody can help ?
Re: microphone signal level
Author: Mark Jacobs
Date: Fri, 02 Apr 2004 20:30
Date: Fri, 02 Apr 2004 20:30
104 lines
4411 bytes
4411 bytes
In the public section of your form, add the following :-
public: // User declarations
char erst[199];
unsigned char wvbfr[99];
HWAVEIN phwo;
WAVEFORMATEX pwfx;
MMRESULT wh;
WAVEHDR wvhd;
void __fastcall ProcessInput();
then on the form's paint event put this :-
//--------------------------------------------------------------------------
-
void __fastcall TForm1::FormPaint(TObject *Sender)
{
static bool clld=false;
if (clld) return;
clld=true;
pwfx.cbSize=0;
pwfx.wFormatTag=WAVE_FORMAT_PCM;
pwfx.nChannels=2;
pwfx.nSamplesPerSec=44100;
pwfx.wBitsPerSample=16;
pwfx.nAvgBytesPerSec=44100*2*16/8;
pwfx.nBlockAlign=2*16/8;
wh=waveInOpen(&phwo,WAVE_MAPPER,&pwfx,(DWORD)WaveInProc,
(DWORD)this,CALLBACK_FUNCTION);
if (wh!=MMSYSERR_NOERROR)
{
waveOutGetErrorText(wh,erst,190); Edit3->Text="Error="+AnsiString(erst);
zcMMTimer1->Enabled=false;
}
else zcMMTimer1->Enabled=true;
}
//--------------------------------------------------------------------------
-
Somewhere in the form module declare the following callback functions :-
void CALLBACK WaveInProc(HWAVEIN waveIn,UINT uMsg,
DWORD dwInstance,
DWORD dwParam1,DWORD
dwParam2)
{
if (uMsg==MM_WIM_DATA) Form1->ProcessInput();
}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::ProcessInput()
{
short *mybf=(short *)wvbfr;
waveInStop(phwo);
wh=waveInUnprepareHeader(phwo,&wvhd,sizeof(WAVEHDR));
if (wh!=MMSYSERR_NOERROR) return;
zcDinMeter1->Value=(int)mybf[0]*100*zSlideBar1->Value/32768;
zcDinMeter2->Value=(int)mybf[1]*100*zSlideBar1->Value/32768;
zcMMTimer1->Enabled=true;
}
//--------------------------------------------------------------------------
-
Add a timer to the form. It should be set to an interval of 50ms or less to
be useful, but 100ms seems to be adequate. I use Ziegler's Multimedia Timer
so I can get good results from 20ms resolution. In the timer's OnTimer
event, put the following :-
//--------------------------------------------------------------------------
-
void __fastcall TForm1::zcMMTimer1Timer(TObject *Sender)
{
unsigned int vl; int mcierr,ii,jj;
zcMMTimer1->Enabled=false;
wvbfr[0]='\0'; wvbfr[1]='\0'; wvbfr[2]='\0'; wvbfr[3]='\0';
wvhd.lpData=wvbfr; wvhd.dwBufferLength=4;
wvhd.dwLoops=0; wvhd.dwFlags=0; waveInStop(phwo);
if (waveInPrepareHeader(phwo,&wvhd,sizeof(WAVEHDR))==MMSYSERR_NOERROR)
{
waveInAddBuffer(phwo,&wvhd,sizeof(WAVEHDR));
waveInStart(phwo);
}
}
//--------------------------------------------------------------------------
-
Hey presto, the values in ProcessInput()'s mybf buffer are :-
Left Channel = mybf[0]
Right Channel=mybf[1]
with a range of -32767 to 32767 in each case.
I verified my results on a Soundblaster Live card. I have noticed that the
Realtek AC97 Soundcard on another PC did not work properly. It could be
indicative of faulty sound drivers. I'll try other PCs and report back.
However, the code above has been arrived at painstakingly. Thankyou
Microsoft!
--
Mark Jacobs
"iim" <imamsiswanto@yahoo.com.sg> wrote in message
news:40622392$1@newsgroups.borland.com...
>
> I need a small program to measure the signal level from microphone via
sound card. Anybody can help ?
Re: microphone signal level
Author: Mark Jacobs
Date: Fri, 02 Apr 2004 20:50
Date: Fri, 02 Apr 2004 20:50
19 lines
1522 bytes
1522 bytes
I forgot to add, in the form closequery event, put this :-
if (zcMMTimer1->Enabled)
{
zcMMTimer1->Enabled=false; waveInClose(phwo);
}
--
Mark Jacobs
"Mark Jacobs" <mark@losethisbitjacobsm.com> wrote in message
news:406dcd6d@newsgroups.borland.com...
> In the public section of your form, add the following :-
> ...// Lots snipped ...
> "iim" <imamsiswanto@yahoo.com.sg> wrote in message
> news:40622392$1@newsgroups.borland.com...
> >
> > I need a small program to measure the signal level from microphone via
> sound card. Anybody can help ?
Re: microphone signal level
Author: Mark Jacobs
Date: Fri, 02 Apr 2004 21:05
Date: Fri, 02 Apr 2004 21:05
45 lines
2147 bytes
2147 bytes
Correction. It should be :-
//--------------------------------------------------------------------------
-
void __fastcall TForm1::FormCloseQuery(TObject *Sender, bool &CanClose)
{
zcMMTimer1->Enabled=false; waveInStop(phwo);
waveInUnprepareHeader(phwo,&wvhd,sizeof(WAVEHDR));
waveInClose(phwo); CanClose=true;
}
//--------------------------------------------------------------------------
-
--
Mark Jacobs
"Mark Jacobs" <mark@losethisbitjacobsm.com> wrote in message
news:406dd216$1@newsgroups.borland.com...
> I forgot to add, in the form closequery event, put this :-
>
> if (zcMMTimer1->Enabled)
> {
> zcMMTimer1->Enabled=false; waveInClose(phwo);
> }
> --
> Mark Jacobs
>
> "Mark Jacobs" <mark@losethisbitjacobsm.com> wrote in message
> news:406dcd6d@newsgroups.borland.com...
> > In the public section of your form, add the following :-
> > ...// Lots snipped ...
>
> > "iim" <imamsiswanto@yahoo.com.sg> wrote in message
> > news:40622392$1@newsgroups.borland.com...
> > >
> > > I need a small program to measure the signal level from microphone via
> > sound card. Anybody can help ?
>
>
Re: microphone signal level
Author: Mark Jacobs
Date: Sat, 03 Apr 2004 21:06
Date: Sat, 03 Apr 2004 21:06
4 lines
1269 bytes
1269 bytes
I have had problems with Ziegler's Multimedia Timer, so use a standard system timer. I can get as low as 20ms interval. -- 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