Speaker and microphone detection - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Speaker and microphone detection

iceman316iceman316 Posts: 33Member
Hi, ive been stuck on this problem for ages.....

Does anyone know how to (or indeed if its possible) to detect whether speakers or microphone have been plugged into a computers sound card??

Thanks anyone who can help me..... please....

Comments

  • injektiloinjektilo Posts: 113Member
    i think its possible, but hard
    here is some code to adjust the mic volume,

    [code]
    function SetMicrophoneVolume(bValue: Word): Boolean;
    var {0..65535}
    hMix: HMIXER;
    mxlc: MIXERLINECONTROLS;
    mxcd: TMIXERCONTROLDETAILS;
    vol: TMIXERCONTROLDETAILS_UNSIGNED;
    mxc: MIXERCONTROL;
    mxl: TMixerLine;
    intRet: Integer;
    nMixerDevs: Integer;
    begin
    // Check if Mixer is available
    nMixerDevs := mixerGetNumDevs();
    if (nMixerDevs < 1) then
    begin
    Exit;
    end;

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

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

    if intRet = MMSYSERR_NOERROR then
    begin
    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
    {
    // Microphone Name
    Label1.Caption := mxlc.pamxctrl.szName;

    // Min/Max Volume
    Label2.Caption := IntToStr(mxc.Bounds.dwMinimum) + '->' + IntToStr(mxc.Bounds.dwMaximum);
    }
    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 := mxlc.pamxctrl.Bounds.lMinimum; Set min. Volume / Minimum setzen
    // vol.dwValue := mxlc.pamxctrl.Bounds.lMaximum; Set max. Volume / Maximum setzen
    vol.dwValue := bValue;

    intRet := mixerSetControlDetails(hMix, @mxcd,
    MIXER_SETCONTROLDETAILSF_VALUE);
    if intRet <> MMSYSERR_NOERROR then
    ShowMessage('SetControlDetails Error');
    end
    else
    ShowMessage('GetLineInfo Error');
    end;
    intRet := mixerClose(hMix);
    end;
    end;
    [/code]

    look at it, i'm sure there is something in their, i cannot test it because i'm sitting infront of my laptop with build in mic


  • zibadianzibadian Posts: 6,349Member
    : Hi, ive been stuck on this problem for ages.....
    :
    : Does anyone know how to (or indeed if its possible) to detect whether speakers or microphone have been plugged into a computers sound card??
    :
    : Thanks anyone who can help me..... please....
    :
    Microphone, I'm not sure about, but speakers cannot be detected, since they don't send any information back to the computer.
  • Mike85Mike85 Posts: 61Member
    Some very new soundcards and AC'97 codecs conforming AC'97 2.3 specifications have feature called "Jack Sensing" which provides way to detect whether something is plugged to which jack. But generally this isn't possible on most of systems and this kind of API is hardware specific and often used only by driver software.
Sign In or Register to comment.