Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how record only loud sound in directSound?

3 views
Skip to first unread message

kazemi@discussions.microsoft.com hadi kazemi

unread,
Sep 23, 2009, 1:49:02 PM9/23/09
to
hi
i write one DirectSound Program that record mic sound to wave file. now i
want to record only when sound is loud and dont record low sound.

i use under function after lock buffer for store capture buffer to wave file :

HRESULT WaveWrite( UINT nSizeToWrite, BYTE* pbSrcData, UINT* pnSizeWrote )
{
UINT cT;
*pnSizeWrote = 0;

for( cT = 0; cT < nSizeToWrite; cT++ )
{
if( m_mmioinfoOut.pchNext == m_mmioinfoOut.pchEndWrite )
{
m_mmioinfoOut.dwFlags |= MMIO_DIRTY;
if( 0 != mmioAdvance( hFile, &m_mmioinfoOut, MMIO_WRITE ) )
MessageBox(g_hWnd, L"failed MMIOINFO",L"DirectSound Demo", MB_OK);
}

*((BYTE*)m_mmioinfoOut.pchNext) = *((BYTE*)pbSrcData+cT);
(BYTE*)m_mmioinfoOut.pchNext++;

(*pnSizeWrote)++;
}

return S_OK;
}


now how can i check sound level of buffer before store it on wave file and
if sound level be low don't store it ?

i think to use :

for( cT = 0; cT < nSizeToWrite; cT++ )
{
avg = avg + *((BYTE*)pbSrcData+cT);
}
avg = avg / nSizeToWrite;


and then use :

if (avg > 50){
for( cT = 0; cT < nSizeToWrite; cT++ )
{
....

but that's not work correctly because in silent avg is 10 - 150 !!! i think
that in silent avg must be <50 !!

now how can i check sound level ?

Alessandro Angeli

unread,
Sep 23, 2009, 3:51:37 PM9/23/09
to

From: "hadi kazemi"

> but that's not work correctly because in silent avg is 10
> - 150 !!! i think that in silent avg must be <50 !!

You can not just sum the BYTEs. You need to average the
absolute values or the squares of the actual samples and the
type of the samples depends on the wave format (16 bits =>
SHORT, 8 bits => BYTE-128). Since the mic is mono, you can
avoid taking into account the interleaving of the samples
for multiple channels.

--
// Alessandro Angeli
// MVP :: DirectShow / MediaFoundation
// mvpnews at riseoftheants dot com
// http://www.riseoftheants.com/mmx/faq.htm


hadi kazemi

unread,
Sep 24, 2009, 12:03:02 AM9/24/09
to

"Alessandro Angeli" wrote:

> tanx
i use <123 or >132 instead and its work. but dont eliminate all of silent
... if i use capture filter do better ?

Fully Half Baked

unread,
Nov 6, 2009, 9:23:52 AM11/6/09
to

you could do something like
if buffer[i] < some number
buffer[i] = 0;
zero = silence.

0 new messages