Adjust volume / mute from my Qt C++ programm - c++

Under Windows (7,8) I can mute / adjust volume as per application and per output device.
I wonder how I can set / query these values from my C++ Qt application. Basically I need to figure out / accomplish (use cases):
Is the global mute set (per device)? Set global mute from my application.
Is the application's mixer mute set? Set mixer mute.
Set mixer volume, set global volume.
Query mixer volume, set mixer volume?
Wherever possible I am looking for the Qt-ish way to accomplish things, keeping code as platform independent as possible. I can imagine to query the global mute via an OS-independent API, but using a Windows only class for the mixer.
From the C# question Get Master Sound Volume in c# I understand IAudioMeterInformation, IMMDeviceCollection, IMMDevice are the MSDN documentation entry points for Windows specific handling.
How do I tell if the master volume is muted? shows how commands can be send via WM_APPCOMMAND . Again, windows specific, also not allowing to query values but only to set them.
Is there something for Qt encapsulating these things? Is it Phonon I need to use? Checking Phonon briefly I did not see any methods for what I need, but I might have missed it.

Related

windows hard drive real time replication

I am working on a project to replicate windows write requests from one hard disk to another in real time asynchronously.
I am new to kernel mode drivers development under windows, what I have in mind is to monitor IO requests.
I searched a lot but this area is not documented as it should.
I did my search and found 4 leads (but non of them is sure the best option to start with)
IRP
IO request packets used by windows drivers to communicate between them and the OS, but will I be able to monitor the IRP used by the hard disk driver ? and what about the security?
Windows filter drivers
there is a lot of system filter drivers levels from upper to lower, which one should be used? and Will I be able to filter the IOs used by the hard disk driver?
IO hooks
this technique is used by windows antiviruses to hook the IOs and check the files. Is it reliable to use in my situation ?
kernel event tracing
Used by Microsoft Diskmon tool to monitor hard disk activity.
The problem here is that I don't know where to start and what is the best option to start with in terms of performance and security.
you at first must perfect understand windows Storage, Volumes, and File System Stacks and use Device Tree
determinate which device you need filter, and as UpperFilter or Lowfilter. you really need replicate disk, or say partition(volume) on disk or file-systems read/write ?
for attach to device you can register self in registry, say for disk filter - under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e967-e325-11ce-bfc1-08002be10318} in UpperFilters or LowerFilters
read this storage stack example
your place is at (4) (LowFilter - you will be filter IRP_MJ_SCSI for read/write) or (7) (UpperFilter - you will be filter IRP_MJ_READ/IRP_MJ_WRITE for read/write)
driver must be or direct WDM (register AddDevice in Driver) or use KMDF (shell framework)
another solution use IoRegisterPlugPlayNotification(EventCategoryDeviceInterfaceChange, &GUID_DEVINTERFACE_DISK) for attach disk FDO - here you always will be UpperFilter
and the best resource for ask this kind of question, advice - is osronline - NTFSD or NTDEV forum

Why can't I set master volume for USB/Firewire Audio interface with IAudioEndpointVolume::SetMasterVolumeLevelScalar

I am trying to fix an Audacity bug that revolves around portmixer. The output/input level is settable using the mac version of portmixer, but not always in windows. I am debugging portmixer's window code to try to make it work there.
Using IAudioEndpointVolume::SetMasterVolumeLevelScalar to set the master volume works fine for onboard sound, but using pro external USB or firewire interfaces like the RME Fireface 400, the output volume won't change, although it is reflected in Window's sound control panel for that device, and also in the system mixer.
Also, outside of our program, changing the master slider for the system mixer (in the taskbar) there is no effect - the soundcard outputs the same (full) level regardless of the level the system says it is at. The only way to change the output level is using the custom app that the hardware developers give with the card.
The IAudioEndpointVolume::QueryHardwareSupport function gives back ENDPOINT_HARDWARE_SUPPORT_VOLUME so it should be able to do this.
This behavior exists for both input and output on many devices.
Is this possibly a Window's bug?
It is possible to workaround this by emulating (scaling) the output, but this is not preferred as it is not functionally identical - better to let the audio interface do the scaling (esp. for input if it involves a preamp).
The cards you talk about -like the RME- ones simply do not support setting the master or any other level through software, and there is not much you can do about it. This is not a Windows bug. One could argue that giving back ENDPOINT_HARDWARE_SUPPORT_VOLUME is a bug though, but that likely originates from the driver level, not Windows itself.
The only solution I found so far is hooking up a debugger (or adding a dll hook) to the vendor supplied software and looking at the DeviceIOControl calls it makes (those are the ones used to talk to the hardware) while setting the volume in the vendor software. Pretty hard to do this for every single card, but probably worth doing for a couple of pro cards. Especially for Audacity, for open source audio software it's actually not that bad so I can imagine some people being really happy if the volume on their card could be set by it. (at the time we were exclusively using an RME Multiface I spent quite some time in figuring out the DeviceIOControl calls, but in the end it was definitely worth it as I could set the volume in dB for any point in the matrix)

DirectSound: how to change the input volume of a microphone?

I have some questions about Directsound and windows mixers.
My goal is to enumerate all microphones and be able to change the input volume of each one.
I think i'm not far from the solution, but I don't find what is wrong in my code.
Here is what I have done:
- I enumerate all input devices and get a GUID for each one
- I use a method found on a topic to get the mixer id corresponding to a directsound guid using this method (but I'm not sure if it works)
- Then I get the id corresponding to the control in the mixer
- Then I can modify the volume
Here is the code: a vs2008 project
To test, I have connected two microphones usb + the line-in microphone, and I visually check what sliders are moving. But unfortunately it's not the good one ...
here is a screenshot (img177.imageshack.us/img177/5189/mixers.jpg) of all my mixers opened in windows xp.
Have you an idea of what I am doing wrong? Is there an easiest solution?
bonus question: do you know if there is a way to know if a microphone is connected or not in Line-in, using Directsound? Because the Line-in is always detected as connected even if no microphone is connected.
check this questions:
How to adjust microphone gain from C# (needs to work on XP & W7)
or
http://social.msdn.microsoft.com/Forums/en/isvvba/thread/05dc2d35-1d45-4837-8e16-562ee919da85

Volume Control Number of Channels XP different than Vista

When I run this code:
MIXERLINE MixerLine;
memset( &MixerLine, 0, sizeof(MIXERLINE) );
MixerLine.cbStruct = sizeof(MIXERLINE);
MixerLine.dwComponentType = MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT;
mmResult = mixerGetLineInfo( (HMIXEROBJ)m_dwMixerHandle, &MixerLine, MIXER_GETLINEINFOF_COMPONENTTYPE );
Under XP MixerLine.cChannels comes back as the number of channels that the sound card supports. Often 2, these days often many more.
Under Vista MixerLine.cChannels comes back as one.
I have been then getting a MIXERCONTROL_CONTROLTYPE_VOLUME control and setting the volume for each channel that is supported, and setting the volumne control to different levels on different channels so as to pan music back and forth between the speakers (left to right).
Obviously under Vista this approach isn't working since there is only one channel. I can set the volume and it is for both channels at the same time.
I tried to get a MIXERCONTROL_CONTROLTYPE_PAN for this device, but that was not a valid control.
So, the question for all you MMSystem experts is this: what type of control do I need to get to adjust the left/right balance? Alternately, is there a better way? I would like a solution that works with both XP and Vista.
Computer Details: Running Vista Ultimta 32 bit SP1 and all latest patches. Audio is provided by a Creative Audigy 2 ZS card with 4 speakers attached which can all be properly addressed (controlled) through Vista's sound panel. Driver is latest on Creative's site (SBAX_PCDRV_LB_2_18_0001). The Vista sound is not set to mono, and all channels are visable and controlable from the sound panel.
Running the program in "XP Compatibility Mode" does not change the behaviour of this problem.
If you run your application in "XP compatibility" mode, the mixer APIs should work much closer to the way they did in XP.
If you're not running in XP mode, then the mixer APIs reflect the mix format - if your PC's audio solution is configured for mono, then you'll see only one channel, but if you're machine is configured for multichannel output the mixer APIs should reflect that.
You can run the speaker tuning wizard to determine the # of channels configured for your audio solution.
Long time Microsoftie Larry Osterman has a blog where he discusses issues like this because he was on the team that redid all the audio stuff in Vista.
In the comments to this blog post he seems to indicate that application controlled balance is not something they see the need for:
CN, actually we're not aware of ANY situations in which it's appropriate for an application to control its balance. Having said that, we do support individual channel volumes for applications, but it is STRONGLY recommended that apps don't use it.
He also indicates that panning the sound from one side to the other can be done, but it is dependent on whether the hardware supports it:
Joku, we're exposing the volume controls that the audio solution implements. If it can do pan, we do pan (we actually expose separate sliders for the left and right channels).
So that explains why the MIXERCONTROL_CONTROLTYPE_PAN thing failed -- the audio hardware on your system does not support it.

Volume (Balance) Control for XP/Vista

Is there a method for controlling the Balance of the Wave output that will work on both XP and Vista?
Vista has a new api for everything related to mixers and audio, per process legacy api's should still work, but to change global volume, you would have to look at the new COM interfaces added to Vista
This should get you started
have you looked at this?
waveOutSetVolume
The waveOutSetVolume function sets the
volume level of the specified
waveform-audio output device.
It uses Winmm.lib.
http://msdn.microsoft.com/en-us/library/ms713762.aspx