I wanted to know, what would the coding be if I wanted to toggle mute/unmute of my microphone. I am making a program that can run in the background and pickup a keypress event and toggle mute/unmute of the mic. Any help with any of that coding would be very helpful. I am pretty new to C#, and this is just a really simple program I wanted to make. That is all it does, is it will listen for keypress of the spacebar, even when the program is in the background, then when the spacebar is pressed it will mute/unmute the mic.
Thank you for any and all help!
For Windows Vista and newer, you can no longer use the Media Control Interface, Microsoft has a new Core Audio API that you must access to interface with audio hardware in these newer operating systems.
Ray Molenkamp wrote a nice managed wrapper for interfacing with the Core Audio API here:
Vista Core Audio API Master Volume Control
Since I needed to be able to mute the microphone from XP, Vista and Windows 7 I wrote a little Windows Microphone Mute Library which uses Ray's library on the newer operating systems and parts of Gustavo Franco's MixerNative library for Windows XP and older.
You can download the source of a whole application which has muting the microphone, selecting it as a recording device, etc.
http://www.codeguru.com/csharp/csharp/cs_graphics/sound/article.php/c10931/
you can use MCI (Media Control Interface) to access mics and change their volume system wise. Check the code below it should be setting volume to 0 for all system microphones. Code is in c; check pinvoke for details on how to translate this code to c#
#include "mmsystem.h"
...
void MuteAllMics()
{
HMIXER hmx;
mixerOpen(&hmx, 0, 0, 0, 0);
// Get the line info for the wave in destination line
MIXERLINE mxl;
mxl.cbStruct = sizeof(mxl);
mxl.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
mixerGetLineInfo((HMIXEROBJ)hmx, &mxl, MIXER_GETLINEINFOF_COMPONENTTYPE);
// find the microphone source line connected to this wave in destination
DWORD cConnections = mxl.cConnections;
for (DWORD j=0; j<cConnections; j++)
{
mxl.dwSource = j;
mixerGetLineInfo((HMIXEROBJ)hmx, &mxl, MIXER_GETLINEINFOF_SOURCE);
if (MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE == mxl.dwComponentType)
{
// Find a volume control, if any, of the microphone line
LPMIXERCONTROL pmxctrl = (LPMIXERCONTROL)malloc(sizeof MIXERCONTROL);
MIXERLINECONTROLS mxlctrl =
{
sizeof mxlctrl,
mxl.dwLineID,
MIXERCONTROL_CONTROLTYPE_VOLUME,
1,
sizeof MIXERCONTROL,
pmxctrl
};
if (!mixerGetLineControls((HMIXEROBJ) hmx, &mxlctrl, MIXER_GETLINECONTROLSF_ONEBYTYPE))
{
DWORD cChannels = mxl.cChannels;
if (MIXERCONTROL_CONTROLF_UNIFORM & pmxctrl->fdwControl)
cChannels = 1;
LPMIXERCONTROLDETAILS_UNSIGNED pUnsigned = (LPMIXERCONTROLDETAILS_UNSIGNED)
malloc(cChannels * sizeof MIXERCONTROLDETAILS_UNSIGNED);
MIXERCONTROLDETAILS mxcd =
{
sizeof(mxcd),
pmxctrl->dwControlID,
cChannels,
(HWND)0,
sizeof MIXERCONTROLDETAILS_UNSIGNED,
(LPVOID) pUnsigned
};
mixerGetControlDetails((HMIXEROBJ)hmx, &mxcd, MIXER_SETCONTROLDETAILSF_VALUE);
// Set the volume to the middle (for both channels as needed)
//pUnsigned[0].dwValue = pUnsigned[cChannels - 1].dwValue = (pmxctrl->Bounds.dwMinimum+pmxctrl->Bounds.dwMaximum)/2;
// Mute
pUnsigned[0].dwValue = pUnsigned[cChannels - 1].dwValue = 0;
mixerSetControlDetails((HMIXEROBJ)hmx, &mxcd, MIXER_SETCONTROLDETAILSF_VALUE);
free(pmxctrl);
free(pUnsigned);
}
else
{
free(pmxctrl);
}
}
}
mixerClose(hmx);
}
here you can find more code on this topic
hope this helps, regards
I have several microphones in win7 and class WindowsMicrophoneMuteLibrary.CoreAudioMicMute is incorrect in this case.
so I change the code and works great because now his cup Whistle all microphones and not just in the last recognized by win7.
I am attaching the new class to put in place.
http://www.developpez.net/forums/d1145354/dotnet/langages/csharp/couper-micro-sous-win7/
Related
In my app i use Midi-dot-net to get NoteON messages and NAudio to play audio samples / notes. In NAudio i'm using ASIO implementation for lower latency and it works perfectly. But i have a problem with controlling volume.
Before i used ASIO engine i was able to controll volume this way (some part of the code):
private void...()
{
int NewVolume = ((ushort.MaxValue / 50) * trackWave.Value);
uint NewVolumeAllChannels = (((uint)NewVolume & 0x0000ffff) | ((uint)NewVolume << 16));
waveOutSetVolume(IntPtr.Zero, NewVolumeAllChannels);
volumeN.Text = trackWave.Value.ToString();
}
When i'm using ASIO implementation in NAudio it's not working, i can only mute sounds, but can't change its volume.
Do you know how can i controll volume by the use of volume slider placed in external Midi controller? Somehow it works when i was testing Steinberg or Synthogy or other audio software producers with ASIO drivers.
Thank you for any help.
with ASIO you change volume by modifying the level of the samples you send to the device. There isn't a concept of device volume. So include a VolumeSampleProvider or similar in your signal chain, and set the volume on that
Am recording the video by intel real sense camera. The video recording is done and working successfully. But audio is not coming in that video.
For that my question is...
My configuration is Lenovo Yoga 15 with internal real sense camera
I want to install audio driver for sound ? Is that are required ?
please give me some suggestion.
session = PXCMSession.CreateInstance();
senseManager = session.CreateSenseManager();
senseManager.captureManager.SetFileName("new4.rssdk", true);
senseManager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, WIDTH, HEIGHT, 30);
senseManager.Init();
for (int i = 0; i < 200; i++)
{
if (senseManager.AcquireFrame(true).IsError()) break;
PXCMCapture.Sample sample = senseManager.QuerySample();
senseManager.ReleaseFrame();
colorBitmap.Dispose();
}
I didn't understand the question well, so do you want to run audio and record the video together?
If yes, you have to create an instance of the class responsible for doing that.
take a look here Speech Recognition
I used two threads in order to do that. I have an application where I use facial recognition and audio recognition. I decided to split them and it worked very well.
VBoxManage.exe is an Oracle VirtualBox companion utility, which allows to control VMs via command line. It can do numerous operations, including start/stop and screen capturing.
I am interested, which API it uses?
How can I capture VM screen or send keyboard or mouse commands there without this heavy commandline utility? Which language is better? Is is possible to access this API with Java?
One of the advantages to using an open source project is supposed to be that you can answer such questions by looking at the source.
VBoxManage is located in the source repository under /src/VBox/Frontends/VBoxManage. The code you're looking for is in VBoxManageControlVM.cpp under the condition if (!strcmp(a->argv[1], "screenshotpng")):
ComPtr<IDisplay> pDisplay;
CHECK_ERROR_BREAK(console, COMGETTER(Display)(pDisplay.asOutParam()));
ULONG width, height, bpp;
CHECK_ERROR_BREAK(pDisplay,
GetScreenResolution(displayIdx, &width, &height, &bpp));
com::SafeArray<BYTE> saScreenshot;
CHECK_ERROR_BREAK(pDisplay, TakeScreenShotPNGToArray(displayIdx,
width, height, ComSafeArrayAsOutParam(saScreenshot)));
RTFILE pngFile = NIL_RTFILE;
vrc = RTFileOpen(&pngFile, a->argv[2], RTFILE_O_OPEN_CREATE | RTFILE_O_WRITE |
RTFILE_O_TRUNCATE | RTFILE_O_DENY_ALL);
if (RT_FAILURE(vrc))
{
RTMsgError("Failed to create file '%s'. rc=%Rrc", a->argv[2], vrc);
rc = E_FAIL;
break;
}
vrc = RTFileWrite(pngFile, saScreenshot.raw(), saScreenshot.size(), NULL);
if (RT_FAILURE(vrc))
{
RTMsgError("Failed to write screenshot to file '%s'. rc=%Rrc",
a->argv[2], vrc);
rc = E_FAIL;
}
RTFileClose(pngFile);
So it's done via a COM API, and you can look at:
Is it possible to call a COM API from Java?
Googling for TakeScreenShotPNGToArray finds the display interface:
https://www.virtualbox.org/sdkref/interface_i_display.html
From there you can find the list of all the other things like mouse and keyboard:
https://www.virtualbox.org/sdkref/annotated.html
I had an older system (XP) that allowed me to play mono encoded PCM audio out the rear channels (back right and/or back left) through DirectX using a DirectSoundBuffer and WAVEFORMATEXTENSIBLE object with the ChannelMask Set for Back Speakers.
I am trying to redo the same functionality on the old system as well and a new system with .Net and SlimDx XAudio2 but when I Call SetOutputMatrix on the old system it ignores everything I set for anything but the Front left and right Channels even though the sound card is set for 5.1 surround sound. On the new system it works fine. When I call GetDeviceDetails on the old system it reports that the channelmask is 3 (only front two speakers). I am guessing that is why it only allows me to play out the front even though the old C++ DirectSound worked. I am guessing the sound driver is in error but I can't find any updates for this.
Is there a workaround for this?
Here is a sample from the XAudio2 C++ Basic Sound Demo that has the same behavior
if( FAILED( hr = XAudio2Create( &pXAudio2, flags ) ) )
{
wprintf( L"Failed to init XAudio2 engine: %#X\n", hr );
CoUninitialize();
return 0;
}
UINT32 devCount;
hr = pXAudio2->GetDeviceCount(&devCount);
XAUDIO2_DEVICE_DETAILS devDetails;
hr = pXAudio2->GetDeviceDetails(0, &devDetails);
Here when I get the Device Details the ChannelMask is 3 (Front speakers) even though the SoundCard configuration is set for 5.1. The soundcard is an old SoundMax AC'97 card. Later on when I do the following:
float fMatrix[6] = {0};
pSourceVoice->GetOutputMatrix(pMasteringVoice, 1, 6, fMatrix);
fMatrix[0] = 0.0;
fMatrix[1] = 1.0;
fMatrix[2] = 1.0;
fMatrix[3] = 1.0;
fMatrix[4] = 1.0;
fMatrix[5] = 1.0;
hr = pSourceVoice->SetOutputMatrix(NULL,1,6, fMatrix);
pSourceVoice->GetOutputMatrix(pMasteringVoice, 1, 6, fMatrix);
After the first GetOutputMatrix the fMatrix is has [0] and [1] indexes set to 1.0. When I call SetOutputMatrix I am trying to set other channels to 1.0 but after the GetOutputMatrix the fMatrix only has [1] set to 1.0. Everything else is 0.
NOTE: When calling SetOutputMatrix and it doesn't set all the values it doesn't fail, it returns OK.
Is there a way to simulate touch events in Windows 8 (and preferably in windows 7).
I know there is a project called Multi touch vista but I feel its a bit overkill and I never got it working correctly with multiple screens.
What I want to do is very simple, I want to start an app that can send touch events to Windows no need for multiple mice or any thing like that.
Can it be done or do I need a (MMV) driver to do that?
Thanks
/Jimmy
I was looking for something similar and found this article Simulating Touch Input in Windows Developer preview using Touch Injection API and sample code (C++) may answer your question. However, this seems to work only on Windows 8 (not Windows 7).
It simulates Tap, Hold, Drag, Pinch/Pan, Rotate and Cross-Slide.
Here is the touch (Tap) code:
POINTER_TOUCH_INFO contact;
InitializeTouchInjection(1, TOUCH_FEEDBACK_DEFAULT); // Here number of contact point is declared as 1.
memset(&contact, 0, sizeof(POINTER_TOUCH_INFO));
contact.pointerInfo.pointerType = PT_TOUCH;
contact.pointerInfo.pointerId = 0; //contact 0
contact.pointerInfo.ptPixelLocation.y = 200; // Y co-ordinate of touch on screen
contact.pointerInfo.ptPixelLocation.x = 300; // X co-ordinate of touch on screen
contact.touchFlags = TOUCH_FLAG_NONE;
contact.touchMask = TOUCH_MASK_CONTACTAREA | TOUCH_MASK_ORIENTATION | TOUCH_MASK_PRESSURE;
contact.orientation = 90; // Orientation of 90 means touching perpendicular to screen.
contact.pressure = 32000;
// defining contact area (I have taken area of 4 x 4 pixel)
contact.rcContact.top = contact.pointerInfo.ptPixelLocation.y - 2;
contact.rcContact.bottom = contact.pointerInfo.ptPixelLocation.y + 2;
contact.rcContact.left = contact.pointerInfo.ptPixelLocation.x - 2;
contact.rcContact.right = contact.pointerInfo.ptPixelLocation.x + 2;
contact.pointerInfo.pointerFlags = POINTER_FLAG_DOWN | POINTER_FLAG_INRANGE | POINTER_FLAG_INCONTACT;
InjectTouchInput(1, &contact); // Injecting the touch down on screen
contact.pointerInfo.pointerFlags = POINTER_FLAG_UP;
InjectTouchInput(1, &contact); // Injecting the touch Up from screen
Another article: Getting Started with Windows Touch Gestures
I haven't had a chance to try it myself, but according to this article, the simulator included with the Windows 8 Dev Preview allows for simulating multi-touch zoom and rotation gestures using a mouse.
You can see a demonstration of this at approximately 35:40 of this BUILD conference session: Tools for building Metro style apps
Further to the solution which points to the C++ Sample code for InjectTouchInput which comes packaged in the User32.dll of Windows 8, the C# solution can be found here:
InjectTouchInput Windows 8 C# not working (returns false)
Creating a virtual Hid driver appears to be the only way.