Posts: 135
Threads: 33
Joined: Aug 2009
Hi Gintaras and QMers!
Please, I would like to know any way to check if any sound is playing on my PC.
The goal is to check every while in order to put the PC into sleep mode only if no sound is detected.
I really appreciate any help you can provide.
Posts: 12,072
Threads: 140
Joined: Dec 2002
QM can detect audio coming from microphone, but I don't know (cannot find on the internet) API to detect audio coming from a software or soundcard.
Somebody suggested to connect computer audio out with line in with a cable.
Or use a virtual audio cable software:
http://www.ntonyx.com/vac.htm
Also try Total Recorder. It can record audio output too. Its developer edition has COM interface that QM probably can use:
http://totalrecorder.com/productfr_trDEV.htm
Another idea. Open Control Panel -> Sound. On Windows 7-10 it displays sound level meters of playback devices. On XP need to find another software that shows sound level. Then we can create a macro that waits for green color in the level meter.
Posts: 135
Threads: 33
Joined: Aug 2009
Posts: 12,072
Threads: 140
Joined: Dec 2002
Function
init2
ref WINAPI2 "$qm$\winapi2.txt" 7 ;;http://www.quickmacros.com/forum/viewtopic.php?p=6619
Macro
audio output level meter
out
ref WINAPI2
double waitPeriod; int channelCount
IAudioMeterInformation meter=GetAudioMeter(waitPeriod channelCount)
rep
,FLOAT peak; meter.GetPeakValue(peak)
,out peak
,
,;ARRAY(FLOAT) af.create(channelCount)
,;meter.GetChannelsPeakValues(af.len &af[0])
,;int i
,;for(i 0 af.len) out af[i]
,
,wait waitPeriod
,1 ;;debug
Function
GetAudioMeter
;/
function'WINAPI2.IAudioMeterInformation [double&waitPeriod] [int&channelCount]
if(_winver<0x600) end "need Windows Vista+"
#opt nowarnings 1
ref WINAPI2
IMMDeviceEnumerator en._create(CLSID_MMDeviceEnumerator)
IMMDevice dev; en.GetDefaultAudioEndpoint(eRender eMultimedia &dev)
IAudioMeterInformation meter; dev.Activate(IID_IAudioMeterInformation CLSCTX_ALL 0 &meter)
if &waitPeriod
,IAudioClient ac; dev.Activate(IID_IAudioClient CLSCTX_ALL 0 &ac)
,long perDef perMin; ac.GetDevicePeriod(perDef perMin)
,waitPeriod=perDef/10000000.0 ;;10 ms
if(&channelCount) meter.GetMeteringChannelCount(channelCount)
ret meter
Posts: 135
Threads: 33
Joined: Aug 2009
Wow, very nice! It's just what I was looking for.
Thank you and have a nice day!
Posts: 133
Threads: 15
Joined: Jun 2014
Hi Gintaras,
Regarding the detection of sound in the system, I've found another method to do it
It uses the IDirectSoundBuffer8::Get_Status method.
http://stackoverflow.com/questions/39834...xp-machine
Could you give me an example how to use it in QM, since I see it declare in the winapi2.txt as:
dll C_macro IDirectSoundBuffer8_GetStatus p a ;;(p)->GetStatus(a)
Posts: 12,072
Threads: 140
Joined: Dec 2002
Are you sure that it gets system sound level and works on all Windows versions?
I have read somewhere that only of current process, but not sure. Also, that it can be used only on Windows XP, also not sure.
Interface IDirectSoundBuffer8 is defined in WINAPI2:
More Windows API declarations for QM
Posts: 133
Threads: 15
Joined: Jun 2014
You're right that topic is for the windows XP system and I'm not sure that it will work on all windows system.
By the way could you show me how to initialize this interface?
I'm stuck at this line, 'cause I don't know which params to pass in.
IDirectSoundBuffer8 x._create()