Soundcard programming

Could somebody help me to make code which counts how many rising edges comes during 20ms ? I feed square wave to MIC plug. 20ms should be variable, so I could change it afterwards.

I am just trying to count frequency of pulses.

Square wave comes from pulse sensor or tooth gear with proximity sensor or hall-effect sensor.

All kind of help is very welcome.

Comments

  • : Could somebody help me to make code which counts how many rising edges comes during 20ms ? I feed square wave to MIC plug. 20ms should be variable, so I could change it afterwards.
    :
    : I am just trying to count frequency of pulses.
    :
    : Square wave comes from pulse sensor or tooth gear with proximity sensor or hall-effect sensor.
    :
    : All kind of help is very welcome.
    :
    :
    You can use the unit MMSystem. I'll paste some scrambled stuff of a dictation project of mine below, you can tie up the lose ends. Don't forget to visit microsofts SDK!

    ************* Open a wave device:
    with FFormat do
    begin
    wFormatTag := WAVE_FORMAT_PCM;
    nChannels := 1;
    nSamplesPerSec := SampleRate; // In your case at least 2 times the highest frequnce you want to meassure
    nAvgBytesPerSec := nSamplesPerSec * 2;
    wBitsPerSample := BitsPerSample;
    nBlockAlign := (nChannels * wBitsPerSample + 7) div 8;
    cbSize := 0;
    end;

    if waveInOpen(@FInDeviceHandle, WAVE_MAPPER, @FFormat, .Handle, Cardinal(Self), CALLBACK_WINDOW) <> MMSYSERR_NOERROR then
    raise Exception.Create('Cannot open recording device');

    ************* InitBuffers;
    var
    I: Integer;
    begin
    for I := 0 to BufferCount - 1 do
    begin
    FillChar(FInBuffers[I], SizeOf(wavehdr_tag), 0);
    with FInBuffers[I] do
    begin
    dwBufferLength := BufferSize;
    GetMem(lpData, dwBufferLength);
    dwUser := I+1;
    dwFlags := 0;
    end;
    if waveInPrepareHeader(FInDeviceHandle, @FInBuffers[I], SizeOf(wavehdr_tag)) <> MMSYSERR_NOERROR then
    raise Exception.Create('Error: waveInPrepareHeader');
    waveInAddBuffer(FInDeviceHandle, @FInBuffers[I], SizeOf(wavehdr_tag));
    end;
    end;


    if waveInStart(FInDeviceHandle) <> MMSYSERR_NOERROR then
    raise Exception.Create('Cannot start recording');

    ************* implement message method
    procedure .MMWIM_DATA(var Message: TMessage); message MM_WIM_DATA;

    var
    Data: PWaveHdr;
    begin
    Data := PWaveHdr(Message.LParam);
    if (Data.dwFlags and WHDR_DONE) = WHDR_DONE then
    begin
    //your stuff
    end



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion