Google Groups Home
Help | Sign in
Message from discussion How can I change the recording volume from software?
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
 
York  
View profile  
 More options Jan 30 2007, 1:32 am
Newsgroups: microsoft.public.win32.programmer.mmedia
From: "York" <off...@onlinebg.info>
Date: Mon, 29 Jan 2007 16:32:59 +0200
Local: Tues, Jan 30 2007 1:32 am
Subject: Re: How can I change the recording volume from software?
Reading what you described it all depends on how you design your
application.

If you receive the audio streams independently and play them independently
(and simultaneously) then the Mixer API will not work for you. Because
though you can pass the waveout of which waveout created still the volume
change will affect all the streams being played.
I would probably choose this one
- if you are having separate input streams from eachone then convert each
stream to a PCM format.
- Process the PCM stream to determine the maximum/minimum levels and adjust
them accordingly.
Now that each stream is OK play them separately and simultaneously or use
some algorithm to mix them and play them.

Generally however if an input stream is too low or high then you'd better
adjust the microphone level (wavein) of the producer. Then you can filter or
do whatever processing needed.

To set the microphone volume use this

function SetMicrophoneVolume(ADeviceID: Integer; bValue: Word; AOpenFlag:
Cardinal): Boolean;
var
  hMix: HMIXER;
  mxlc: MIXERLINECONTROLS;
  mxcd: TMIXERCONTROLDETAILS;
  vol: TMIXERCONTROLDETAILS_UNSIGNED;
  mxc: MIXERCONTROL;
  mxl: TMixerLine;
  intRet: Integer;
  nMixerDevs: Integer;
  cConnections: DWord;
  j: DWORD;
begin
  // Check if Mixer is available
  Result := True;
  nMixerDevs := mixerGetNumDevs();
  if (nMixerDevs < 1) then
  begin
    Result := False;
    exit;
  end;

  // open the mixer
  intRet := mixerOpen(@hMix, ADeviceID, 0, 0, AOpenFlag);
  if intRet = MMSYSERR_NOERROR then
  begin
    mxl.dwComponentType := MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
    mxl.cbStruct := SizeOf(mxl);

    // get line info
    intRet := mixerGetLineInfo(hMix, @mxl,
MIXER_GETLINEINFOF_COMPONENTTYPE);

    if intRet = MMSYSERR_NOERROR then
    begin

      cConnections := mxl.cConnections;

      for j := 0 to cConnections - 1 do
      begin
        mxl.dwSource := j;
        mixerGetLineInfo(hMix, @mxl, MIXER_GETLINEINFOF_SOURCE);
        if (MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE = mxl.dwComponentType)
        then break;
      end;

      ZeroMemory(@mxlc, SizeOf(mxlc));
      mxlc.cbStruct := SizeOf(mxlc);
      mxlc.dwLineID := mxl.dwLineID;
      mxlc.dwControlType := MIXERCONTROL_CONTROLTYPE_VOLUME;
      mxlc.cControls := 1;
      mxlc.cbmxctrl := SizeOf(mxc);

      mxlc.pamxctrl := @mxc;
      intRet := mixerGetLineControls(hMix, @mxlc,
MIXER_GETLINECONTROLSF_ONEBYTYPE);

      if intRet = MMSYSERR_NOERROR then
      begin
        ZeroMemory(@mxcd, SizeOf(mxcd));
        mxcd.dwControlID := mxc.dwControlID;
        mxcd.cbStruct := SizeOf(mxcd);
        mxcd.cMultipleItems := 0;
        mxcd.cbDetails := SizeOf(Vol);
        mxcd.paDetails := @vol;
        mxcd.cChannels := 1;

        vol.dwValue := bValue;

        intRet := mixerSetControlDetails(hMix, @mxcd,
MIXER_SETCONTROLDETAILSF_VALUE);
        if intRet <> MMSYSERR_NOERROR then
          Result := False;
      end
      else
        Result := False;
    end
    else Result := False;
    mixerClose(hMix);
  end;
end;

Where if you have the wavein handle call the function thisway:
SetMicrophoneVolume(waveinhadle, micvolume; MIXER_OBJECTF_HWAVEIN)

If you don't have the wavein handle you could call the function this way
SetMicrophoneVolume(SoundDeviceHandle, micvolume; MIXER_OBJECTF_WAVEIN)

The function returns True if there is a Microphone level control else
returns False

Hope this helps

"Dave Stallard" <stall...@nospam.net> wrote in message

news:8Pednc1ca8CB8SDYnZ2dnUVZ_o6gnZ2d@comcast.com...
> My first post here; I think this is the right group to ask this question;
> if not, or if there are other relevant groups, please feel free to direct
> me to them.

> Background:  I have a C++ WinXP speech recognition application that takes
> spoken input from a mike.   It must interact with different people at
> different  times, and these people's voices may have very different levels
> of amplitude.  One person's speech might cause clipping, for example,
> while another's may be perfectly normal, or even too soft.  It is thus not
> possible to select a fixed recording volume that is suitable for all.

> My query: How can my application change the machine's recording volume at
> will?  For example, I'd like the app to be able to turn the volume down if
> it detects clipping.   I know there is a setWaveOutVolume API, but I have
> also learned from various searches that there is no corresponding
> setWaveInVolume API.   There *must* be a solution somehow. I'd prefer to
> have it be a simple one, if possible.  ;)

> Just to make matters worse, we also use an Andrea USB SoundPod adapter, as
> well as direct connection the standard mike jack.   Is there a solution
> that would work for both? (probably this is a dumb question)

>    thanks,
>      Dave


    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.

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