Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Monitoring audio levels
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Expand all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Mark Jacobs  
View profile  
 More options Mar 30 2004, 3:40 pm
Newsgroups: borland.public.cppbuilder.vcl.components.using
From: "Mark Jacobs" <m...@losethisbitjacobsm.com>
Date: Tue, 30 Mar 2004 21:33:08 +0100
Local: Tues, Mar 30 2004 3:33 pm
Subject: Monitoring audio levels
I need a way for a BCB app to monitor and display the current wave out audio
level on both left and right channels (or mono). The level (volume) will be
changing as system sounds are played and other music apps play stuff. Is
there a Win API method for getting its value? I have already got an MM timer
ready for its use, set at 50ms refresh. Please help.
--
Mark Jacobs

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pete Fraser  
View profile  
 More options Mar 31 2004, 3:39 am
Newsgroups: borland.public.cppbuilder.vcl.components.using
From: "Pete Fraser" <pete._no_spam_fra...@frasersoft.nospam.net>
Date: Wed, 31 Mar 2004 09:25:34 +0100
Local: Wed, Mar 31 2004 3:25 am
Subject: Re: Monitoring audio levels
Yes there is. Look in the multimedia API help files under SDK help on
Borland Start menu
HTH Pete

"Mark Jacobs" <m...@losethisbitjacobsm.com> wrote in message

news:4069d98a@newsgroups.borland.com...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pete Fraser  
View profile  
 More options Mar 31 2004, 6:09 am
Newsgroups: borland.public.cppbuilder.vcl.components.using
From: "Pete Fraser" <pete._no_spam_fra...@frasersoft.nospam.net>
Date: Wed, 31 Mar 2004 12:04:43 +0100
Local: Wed, Mar 31 2004 6:04 am
Subject: Re: Monitoring audio levels
You don't want the volume - that's the value of the 'volume control'
Look for MIXERCONTROL which defines xxx_CLASS_METER for different Audio
channels(Lines) and also mixerGetLineControls() which is used to get the
information.
(BTW I've never done this so I'm just searchng help)
Do look at www.torry.net as they have several controls for doing similar
things. I've seen audio metering components there - just can't remember
where :(

HTH Pete

"Mark Jacobs" <markjremovethisspuriousantispamst...@critical.co.uk> wrote in
message news:406a9fed@newsgroups.borland.com...

> I have looked, tried, tinkered and fretted. I do not know whether to open

waveIn or waveOut in order to
> monitor currently playing levels. I keep getting "An invalid flag was

passed to a system function." (code 10)

> from the following code :-

<snipped lots>

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Jacobs  
View profile  
 More options Mar 31 2004, 6:09 am
Newsgroups: borland.public.cppbuilder.vcl.components.using
From: "Mark Jacobs" <markjremovethisspuriousantispamst...@critical.co.uk>
Date: Wed, 31 Mar 2004 11:39:44 +0100
Local: Wed, Mar 31 2004 5:39 am
Subject: Re: Monitoring audio levels
I have looked, tried, tinkered and fretted. I do not know whether to open waveIn or waveOut in order to
monitor currently playing levels. I keep getting "An invalid flag was passed to a system function." (code 10)
from the following code :-
//------------------------------------------------------------------------- --
void __fastcall TForm1::zcMMTimer1Timer(TObject *Sender)
{
  char erst[199];
  unsigned long vl;
  HWAVEOUT phwo;
  MMRESULT wh;
  WAVEFORMATEX pwfx;
  zcMMTimer1->Enabled=false;
  erst[0]='\0';
  pwfx.wFormatTag=WAVE_FORMAT_PCM;
  pwfx.nChannels=2;
  pwfx.nSamplesPerSec=44100;
  pwfx.nAvgBytesPerSec=44100*2*16/8;
  pwfx.nBlockAlign=2*16/8;
  pwfx.wBitsPerSample=16;
  pwfx.cbSize=0;
  wh=waveOutOpen(&phwo,WAVE_MAPPER,&pwfx,0,0,WAVE_MAPPED);
  if (wh!=MMSYSERR_NOERROR)
  {
    waveOutGetErrorText(wh,erst,190);
    Edit3->Text="Error="+AnsiString(erst);
    return; // intentionally leaving the timer disabled
  }
  waveOutGetVolume(phwo,&vl);
  waveOutClose(phwo);
  zcDinMeter1->Value=(vl & 0xFFFF);
  zcDinMeter2->Value=((vl & 0xFFFF0000)>>16);
  Edit3->Text="L:"+mjfmtnm(vl & 0xFFFF)+"   R:"+mjfmtnm((vl & 0xFFFF0000)>>16);
  zcMMTimer1->Enabled=true;
}

//------------------------------------------------------------------------- --

If I change the waveOutOpen line to read :-
wh=waveOutOpen(&phwo,0,&pwfx,0,0,WAVE_MAPPED);
I get both channels maxed out constantly, whether there is sound or not.

The timer is firing 10 times a second. I am floundering - please help.
--
Mark Jacobs
DK Computing
http://www.dkcomputing.co.uk
ma...@criticalremovethisspuriousantispamstuff.co.uk

"Pete Fraser" <pete._no_spam_fra...@frasersoft.nospam.net> wrote in message

news:406a807d@newsgroups.borland.com...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Jacobs  
View profile  
 More options Mar 31 2004, 9:10 am
Newsgroups: borland.public.cppbuilder.vcl.components.using
From: "Mark Jacobs" <markjremovethisspuriousantispamst...@critical.co.uk>
Date: Wed, 31 Mar 2004 14:55:50 +0100
Local: Wed, Mar 31 2004 8:55 am
Subject: Re: Monitoring audio levels
I have changed my code to use mixer api, but I *cannot* set any control type except
MIXERCONTROL_CONTROLTYPE_VOLUME, and the values reflect where I am sliding the Wave volume control, when you
double-click the speaker icon in your system tray. So the code works after a fashion, but I cannot set
anything but
MIXERCONTROL_CONTROLTYPE_VOLUME. I have tried
MIXERCONTROL_CONTROLTYPE_SIGNEDMETER and
MIXERCONTROL_CONTROLTYPE_PEAKMETER and they both give error 1025 - the control specified is not valid. What is
going on? Why doesn't this work? Please help. Here is my code :-
//------------------------------------------------------------------------- --
void __fastcall TForm1::zcMMTimer1Timer(TObject *Sender)
{
  unsigned int vl,mxi; char erst[199]; int mcierr;
  zcMMTimer1->Enabled=false; erst[0]='\0';
  HMIXER hmx; MIXERCONTROLDETAILS mxd;
  MIXERCONTROLDETAILS_SIGNED chinf[2]; MIXERLINE mxl;
  MMRESULT wh; MIXERLINECONTROLS mxlcs; MIXERCONTROL mxctl;
  if (waveOutGetNumDevs()<1) return;
  Edit3->Text="Opening Mixer...";
  wh=mixerGetID(0,&mxi,MIXER_OBJECTF_WAVEOUT);
  if (wh!=MMSYSERR_NOERROR) { Edit3->Text=Edit3->Text+" - Error="+AnsiString(wh); return;}
  wh=mixerOpen(&hmx,mxi,0,0,MIXER_OBJECTF_WAVEOUT);
  if (wh!=MMSYSERR_NOERROR) { Edit3->Text=Edit3->Text+" - Error="+AnsiString(wh); return;}
  mxl.cbStruct=sizeof(MIXERLINE);
  mxl.dwComponentType=MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT;
  Edit3->Text="Getting mixer line details...";
  wh=mixerGetLineInfo(hmx,&mxl,MIXER_GETLINEINFOF_COMPONENTTYPE);
  if (wh!=MMSYSERR_NOERROR) { Edit3->Text=Edit3->Text+" - Error="+AnsiString(wh); return;}
  Edit3->Text="Getting mixer line controls...";
  mxlcs.cbStruct=sizeof(MIXERLINECONTROLS); mxlcs.dwLineID=mxl.dwLineID;
  mxlcs.dwControlType=MIXERCONTROL_CONTROLTYPE_VOLUME; mxlcs.cControls=1;
  mxlcs.cbmxctrl=sizeof(MIXERCONTROL); mxlcs.pamxctrl=&mxctl;
  wh=mixerGetLineControls(hmx,&mxlcs,MIXER_GETLINECONTROLSF_ONEBYTYPE);
  if (wh!=MMSYSERR_NOERROR) { Edit3->Text=Edit3->Text+" - Error="+AnsiString(wh); return;}
  Edit3->Text="Getting volume levels...";
  mxd.cbStruct=sizeof(MIXERCONTROLDETAILS); mxd.dwControlID=mxctl.dwControlID;
  mxd.cChannels=mxl.cChannels; mxd.hwndOwner=NULL; mxd.cMultipleItems=0;
  mxd.cbDetails=sizeof(MIXERCONTROLDETAILS_SIGNED); mxd.paDetails=chinf;
  wh=mixerGetControlDetails(hmx,&mxd,MIXER_GETCONTROLDETAILSF_VALUE);
  if (wh!=MMSYSERR_NOERROR) { Edit3->Text=Edit3->Text+" - Error="+AnsiString(wh); return;}
  Edit3->Text="L:"+mjfmtnm(chinf[0].lValue)+"   R:"+mjfmtnm(chinf[1].lValue);
  mixerClose(hmx); zcMMTimer1->Enabled=true;
}

//------------------------------------------------------------------------- --
--
Mark Jacobs
DK Computing
http://www.dkcomputing.co.uk
ma...@criticalremovethisspuriousantispamstuff.co.uk

"Pete Fraser" <pete._no_spam_fra...@frasersoft.nospam.net> wrote in message

news:406aa6a9$1@newsgroups.borland.com...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Jacobs  
View profile  
 More options Apr 1 2004, 7:09 am
Newsgroups: borland.public.cppbuilder.vcl.components.using
From: "Mark Jacobs" <markjremovethisspuriousantispamst...@critical.co.uk>
Date: Thu, 1 Apr 2004 12:51:37 +0100
Local: Thurs, Apr 1 2004 6:51 am
Subject: Re: Monitoring audio levels
Not all Soundcards have PEAKMETERS (SoundBlasters and AC97's do NOT have them, and hence, cannot display a
level meter on the standard Windows mixer control), so this rules out the methods discussed before. Is there a
way to periodically read 4 bytes from each channel on the soundcard's output? It seems an absurdly simple
thing to do, but the grief it has caused me so far is incredible!!! Surely, all I would need is the address of
the primary sound buffer in order to read from it. I have the DirectSound header file and library, but I can't
get the dang thing working for lack of documentation and examples. Has anyone got anything on DirectSound out
there that isn't MSDN and has proper examples that work, and don't use the DirectSound8 interface, but use the
one supplied with BCB5?
--
Mark Jacobs
DK Computing
http://www.dkcomputing.co.uk
ma...@criticalremovethisspuriousantispamstuff.co.uk

"Pete Fraser" <pete._no_spam_fra...@frasersoft.nospam.net> wrote in message

news:406aa6a9$1@newsgroups.borland.com...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Jacobs  
View profile  
 More options Apr 2 2004, 4:36 pm
Newsgroups: borland.public.cppbuilder.vcl.components.using
From: "Mark Jacobs" <m...@losethisbitjacobsm.com>
Date: Fri, 2 Apr 2004 22:10:00 +0100
Subject: Re: Monitoring audio levels
Here is how to do it :-

// 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);
  }
}

//------------------------------------------------------------------------- -

// In the form closequery event, put this :-

//------------------------------------------------------------------------- -
-
void __fastcall TForm1::FormCloseQuery(TObject *Sender, bool &CanClose)
{
  zcMMTimer1->Enabled=false; waveInStop(phwo);
  waveInUnprepareHeader(phwo,&wvhd,sizeof(WAVEHDR));
  waveInClose(phwo); CanClose=true;

}

//------------------------------------------------------------------------- -
-

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" <imamsiswa...@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 ?

"Mark Jacobs" <markjremovethisspuriousantispamst...@critical.co.uk> wrote in
message news:406c0244@newsgroups.borland.com...

 Not all Soundcards have PEAKMETERS (SoundBlasters and AC97's do NOT have
them, and hence, cannot display a
level meter on the standard Windows mixer control), so this rules out the
methods discussed before. Is there a
way to periodically read 4 bytes from each channel on the soundcard's
output? It seems an absurdly simple
thing to do, but the grief it has caused me so far is incredible!!! ...


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Jacobs  
View profile  
 More options Apr 3 2004, 4:09 pm
Newsgroups: borland.public.cppbuilder.vcl.components.using
From: "Mark Jacobs" <m...@losethisbitjacobsm.com>
Date: Sat, 3 Apr 2004 22:06:59 +0100
Local: Sat, Apr 3 2004 4:06 pm
Subject: Re: Monitoring audio levels
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

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google