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 ?
> 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
"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 ?
you could do something like
if buffer[i] < some number
buffer[i] = 0;
zero = silence.