Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to check if any sound is playing
#1
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.
#2
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.
#3
Thanks for your help.

I was looking for more info and it seems that IAudioMeterInformation does the trick:

CoreAudioApi on GitHub
Programatically setting the default playback device
Our dear neighbors...
Our other neighbors...
Programmatically (or Command Line) change the default sound playback device in Windows 7
IAudioMeterInformation = {c02216f6-8c67-4b5b-9d00-d008e73e0064}

Interface Functions

Please, Gintaras, is there any chance to implement this? Unfortunately, I am not skilled enough to do it by myself.

Thanks for your support. Best regards.
#4
Function init2
Code:
Copy      Help
ref WINAPI2 "$qm$\winapi2.txt" 7 ;;http://www.quickmacros.com/forum/viewtopic.php?p=6619

Macro audio output level meter
Code:
Copy      Help
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
Code:
Copy      Help
;/
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
#5
Wow, very nice! It's just what I was looking for.

Thank you and have a nice day!
#6
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)
#7
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
#8
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.

Code:
Copy      Help
IDirectSoundBuffer8 x._create()


Forum Jump:


Users browsing this thread: 3 Guest(s)