« 自作ガイガーカウンタ2号機タイプ1(Rev.1)の製作 | トップページ | 自作ガイガーカウンタ測定値のWEB公開システムプロト(2) »

2011.06.11

自作ガイガーカウンタ測定値のWEB公開システムプロト(1)

現在、まだ、自作ガイガーカウンタは、動作確認中だが、自作ガイガーカウンタの出力パルス計測とWEB公開システムを、暫定で組んでみた(右下図)。


11061101 11060801

 

 

作成したプログラムのソースコード(MS VC/C++)は以下。でも、ハード構成に依って、修正が必要である事を、注意しておく。

[ソースコード置場] https://github.com/digiponta/GeigerCounterFromMic


// gm_cnt_01.cpp : コンソール アプリケーション用のエントリ ポイントの定義
//

#include "stdafx.h"
#include <windows.h>
#include <mmsystem.h>

#include "gm_cnt_01.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// 唯一のアプリケーション オブジェクト

// WinApp theApp;
using namespace std;

WAVEFORMATEX wfe;
WAVEHDR whdr;
short *bWave;
HWAVEOUT hWaveOut;
HWAVEIN hWaveIn;

UINT numDevs;


int MyMain(int argc, TCHAR* argv[], TCHAR* envp[]);


void MyWaveInProc ( HWAVEIN hwi, UINT uMSG, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2 ) {
int ret;
if ( uMSG != 958 ) fprintf( stderr , "CALLBACKE! (%d) @ %d\n", uMSG, __LINE__ );

if ( uMSG == WIM_OPEN ) {
// fprintf( stderr, "WIM_OPEN(%d)\n", __LINE__ );
}

if ( uMSG == WIM_DATA ) {
ret = waveInStop( hWaveIn );
if ( ret != MMSYSERR_NOERROR ) {
fprintf( stderr, "ERROR(%d)\n", __LINE__ );
return ;
}
ret = waveInClose( hWaveIn );
if ( ret != MMSYSERR_NOERROR ) {
fprintf( stderr, "ERROR(%d)\n", __LINE__ );
return ;
}
// (long)hWaveIn = -1;
fprintf( stderr, "WIM_DATA(%d)\n", __LINE__ );
}

}

#define MAX_NUM_DEVS 10
HMIXER hMixer[MAX_NUM_DEVS];
int isOpenedMixer[MAX_NUM_DEVS];
MIXERLINE mixerLine[MAX_NUM_DEVS];
UINT idMic;


int MyMain(int argc, TCHAR* argv[], TCHAR* envp[] )
{
int ret = 0;
int i;

{
int j;
numDevs = mixerGetNumDevs();
if ( numDevs == 0 ) {
fprintf( stderr, "ERROR(%d)\n", __LINE__ );
return -1;
}
fprintf( stderr, "numDevs = %d\n", numDevs );
if ( numDevs > MAX_NUM_DEVS ) numDevs = MAX_NUM_DEVS;

for (i=0, j=0; i<numDevs; i++ ){
ret = mixerOpen( &(hMixer[i]), (UINT)i, 0, 0, MIXER_OBJECTF_MIXER );
if ( ret != MMSYSERR_NOERROR ) {
fprintf( stderr, "ERROR(%d) can't open mixar[%d]\n", __LINE__,
i);
isOpenedMixer[i] = 0;
} else {
j++;
isOpenedMixer[i] = 1;
}
}
if ( j < 1 ) {
fprintf( stderr, "ERROR(%d) cna't open all mixers\n", __LINE__ );
return -1;
} else {
fprintf( stderr, "%d opendMixars\n", j );
}


for (i=0, idMic = -1; i < numDevs; i++ ){
mixerLine[i].cbStruct = sizeof( mixerLine );
mixerLine[i].dwComponentType = MIXERLINE_COMPONENTTYPE_DST_WAVEIN;
ret = mixerGetLineInfo( (HMIXEROBJ)hMixer[i], &(mixerLine[i]),
MIXER_OBJECTF_HMIXER | MIXER_GETLINEINFOF_COMPONENTTYPE );
if ( ret == MMSYSERR_NOERROR ) {
// fprintf( stderr, "found Mic[%d]\n", i );
// fprintf( stderr,
// "Name: %s, %s, %x\n",
// mixerLine[i].szName,
// mixerLine[i].szShortName
// );
if ( (mixerLine[i].szName)[0] != (char)'R' ){
idMic = i;
}
}
}
fprintf( stderr, "Mic ID = %d\n", idMic );

MIXERCONTROL mixerCtrl;
MIXERLINECONTROLS mixerLineCtrls;

mixerLineCtrls.cbStruct = sizeof ( mixerLineCtrls );
mixerLineCtrls.dwLineID = mixerLine[idMic].dwLineID;
mixerLineCtrls.dwControlType = MIXERCONTROL_CONTROLTYPE_VOLUME;
mixerLineCtrls.cControls = 1;
mixerLineCtrls.cbmxctrl = sizeof ( mixerCtrl );
mixerLineCtrls.pamxctrl = &mixerCtrl;
ret = mixerGetLineControls(
(HMIXEROBJ)hMixer[idMic], &mixerLineCtrls,
MIXER_OBJECTF_HMIXER | MIXER_GETLINECONTROLSF_ONEBYTYPE );
if ( ret != MMSYSERR_NOERROR ) {
fprintf( stderr, "ERROR(%d)\n", __LINE__ );
}
{
MIXERCONTROLDETAILS_UNSIGNED micVolume;
MIXERCONTROLDETAILS mixerDts;

mixerDts.cbStruct = sizeof( mixerDts );
mixerDts.dwControlID = mixerCtrl.dwControlID;
mixerDts.cChannels = 1;
mixerDts.cMultipleItems = 0;
mixerDts.cbDetails = sizeof ( MIXERCONTROLDETAILS_UNSIGNED );
mixerDts.paDetails = &micVolume;

ret = mixerGetControlDetails( (HMIXEROBJ)hMixer[idMic],
&mixerDts,
MIXER_GETCONTROLDETAILSF_VALUE );
if (ret != MMSYSERR_NOERROR ){
fprintf( stderr, "ERROR(%d)\n", __LINE__ );
return -1;
}
fprintf( stderr, "Vol: %d, Max: %d\n", micVolume.dwValue,
mixerCtrl.Bounds.dwMaximum );

// micVolume.dwValue = 24348; // needed value for GM counter
micVolume.dwValue = 22000; // needed value for GM counter

mixerDts.cbStruct = sizeof( mixerDts );
mixerDts.dwControlID = mixerCtrl.dwControlID;
mixerDts.cChannels = 1;
mixerDts.cMultipleItems = 0;
mixerDts.cbDetails = sizeof ( MIXERCONTROLDETAILS_UNSIGNED );
mixerDts.paDetails = &micVolume;

ret = mixerSetControlDetails( (HMIXEROBJ)hMixer[idMic],
&mixerDts,
MIXER_SETCONTROLDETAILSF_VALUE );
if (ret != MMSYSERR_NOERROR ){
fprintf( stderr, "ERROR(%d)\n", __LINE__ );
return -1;
}
fprintf( stderr, "Changed to Vol: %d, Max: %d\n", micVolume.dwValue,
mixerCtrl.Bounds.dwMaximum );

}


for (i=0; i<numDevs; i++ ){
ret = mixerClose( hMixer[i] );
}

}
// return 0;

wfe.wFormatTag = WAVE_FORMAT_PCM;
wfe.nChannels = 1;
wfe.nSamplesPerSec = 32 * 1000 ;
wfe.nAvgBytesPerSec = wfe.nSamplesPerSec * 2 ;
wfe.wBitsPerSample = 16 ;
wfe.nBlockAlign = wfe.nChannels * wfe.wBitsPerSample / 16;

whdr.dwBufferLength = wfe.nAvgBytesPerSec * 60 ; // 60 sec

bWave = (short *)malloc( whdr.dwBufferLength );
if ( bWave == NULL ) {
fprintf( stderr, "ERROR(%d)\n", __LINE__ );
return -1 ;
}
whdr.lpData = (char *)bWave;

whdr.dwLoops = 0; // 1;
whdr.dwBytesRecorded = 0;
whdr.dwFlags = 0;
whdr.lpNext = NULL;
whdr.dwUser = 0;
whdr.reserved = 0;

ret = waveInOpen( &hWaveIn, WAVE_MAPPER, &wfe, (unsigned long)MyWaveInProc, 0, CALLBACK_NULL );
if ( ret != MMSYSERR_NOERROR ) {
fprintf( stderr, "ERROR(%d)\n", __LINE__ );
return -1;
}

ret = waveInPrepareHeader( hWaveIn, &whdr, sizeof(WAVEHDR) );
if ( ret != MMSYSERR_NOERROR ) {
fprintf( stderr, "ERROR(%d)\n", __LINE__ );
return -1;
}

ret = waveInAddBuffer( hWaveIn, &whdr, sizeof(WAVEHDR) );
if ( ret != MMSYSERR_NOERROR ) {
fprintf( stderr, "ERROR(%d)\n", __LINE__ );
return -1;
}
ret = waveInStart( hWaveIn );
if ( ret != MMSYSERR_NOERROR ) {
fprintf( stderr, "ERROR(%d)\n", __LINE__ );
return -1;
}


Sleep( 70 * 1000  ); // wait 60 sec

// if ( hWaveIn != -1 )
{
ret = waveInStop( hWaveIn );
if ( ret != MMSYSERR_NOERROR ) {
fprintf( stderr, "ERROR(%d)\n", __LINE__ );
return -1;
}
ret = waveInClose( hWaveIn );
if ( ret != MMSYSERR_NOERROR ) {
fprintf( stderr, "ERROR(%d)\n", __LINE__ );
return -1;
}
}

short max, min, cur, prv, thr;
int cnt;

max = min = 0;
prv = cur = 0;
thr = 27000;
cnt = 0;

SYSTEMTIME mytm;


GetLocalTime( &mytm );

for (i=0; i<whdr.dwBufferLength/2; i++ ){
// fprintf( stdout, "%d,\n", (short)bWave[i] );
cur = bWave[i];
// if ( cur  == 0xffffcdcd ) break;
if ( max < cur ) max = cur;
if ( min > cur ) min = cur;

if ( prv < thr ) {
if ( cur >= thr ) cnt++;
}

prv = cur;
}


fprintf( stdout, "%04d/%02d/%02d %02d:%02d:%02d, %d, psV/h,  %d, %d, %d\n",
mytm.wYear, mytm.wMonth, mytm.wDay, mytm.wHour, mytm.wMinute, mytm.wSecond,
(cnt * 1000) / (3100) , cnt , max, min );



free( bWave );
return ret;

}
<numdevs; cur="bWave[i];" cnt="0;" thr="27000;" prv="cur" max="min" whdr.reserved="0;" whdr.dwuser="0;" whdr.lpnext="NULL;" whdr.dwflags="0;" whdr.dwbytesrecorded="0;" whdr.dwloops="0;" whdr.lpdata="(char" bwave="(short" whdr.dwbufferlength="wfe.nAvgBytesPerSec" wfe.nblockalign="wfe.nChannels" wfe.wbitspersample="16" wfe.navgbytespersec="wfe.nSamplesPerSec" wfe.nsamplespersec="32" wfe.nchannels="1;" wfe.wformattag="WAVE_FORMAT_PCM;" micvolume.dwvalue="24348;" mixerdts.padetails="&micVolume;" mixerdts.cbdetails="sizeof" mixerdts.cmultipleitems="0;" mixerdts.cchannels="1;" mixerdts.dwcontrolid="mixerCtrl.dwControlID;" mixerdts.cbstruct="sizeof(" mixerlinectrls.pamxctrl="&mixerCtrl;" mixerlinectrls.cbmxctrl="sizeof" mixerlinectrls.ccontrols="1;" mixerlinectrls.dwcontroltype="MIXERCONTROL_CONTROLTYPE_VOLUME;" mixerlinectrls.dwlineid="mixerLine[idMic].dwLineID;" mixerlinectrls.cbstruct="sizeof" id="%d\n"," mixerline[i].dwcomponenttype="MIXERLINE_COMPONENTTYPE_DST_WAVEIN;" mixerline[i].cbstruct="sizeof(" idmic="-1;" (i="0," isopenedmixer[i]="0;" !="MMSYSERR_NOERROR" ret="mixerOpen("></numdevs;>

このプログラムは、マイク入力の音量を既定値へ設定し、1分間、32kbpsでサンプリング。サンプリンフしたデータからパルスを計数するもの。

|

« 自作ガイガーカウンタ2号機タイプ1(Rev.1)の製作 | トップページ | 自作ガイガーカウンタ測定値のWEB公開システムプロト(2) »

趣味」カテゴリの記事

自作ーガイガーカウンタ」カテゴリの記事

コメント

この記事へのコメントは終了しました。

トラックバック


この記事へのトラックバック一覧です: 自作ガイガーカウンタ測定値のWEB公開システムプロト(1):

« 自作ガイガーカウンタ2号機タイプ1(Rev.1)の製作 | トップページ | 自作ガイガーカウンタ測定値のWEB公開システムプロト(2) »