mcjVU

mcjVU is a PC-Windows server compatible with the mcjWiiClient found here:

https://sites.google.com/site/mcasualsdazscripts/mcjwiikit-for-daz-studio-3-pc-version-zero-beta-not-stable-yet

this server outputs a stream of data based on the loundness of the sound from the microphone ( or other soundcard inputs )

development stopped

see https://sites.google.com/site/mcasualsdazscripts2/mcjhidkit

History

all this was developed around 10/10/2012 and 10/11/2012

Text Box

// mcjVU.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"

#include "Windows.h"

#include "MMSystem.h"

#include <stdio.h>

//************************************************************************************************************************

//************************************************************************************************************************

//************************************************************************************************************************

bool bIsRecording = false;

unsigned char wavbuffer[8000];

HWAVEIN hWaveIn = NULL;

WAVEHDR WaveHeader = {

(LPSTR)wavbuffer, // LPSTR lpData;

267, // DWORD dwBufferLength;

0, // DWORD dwBytesRecorded;

0, // DWORD dwUser;

0, // DWORD dwFlags;

0, // DWORD dwLoops;

0, // struct wavehdr_tag* lpNext;

0, // DWORD reserved;

};

WAVEFORMATEX PCMfmt = {

WAVE_FORMAT_PCM, // WORD wFormatTag;

1, // WORD nChannels;

8000, // DWORD nSamplesPerSec;

8000, // DWORD nAvgBytesPerSec;

1, // WORD nBlockAlign;

8, // WORD wBitsPerSample;

0, // WORD cbSize; Size, in bytes, of extra format information

};

BOOL CALLBACK RecordProc( HWAVEIN hwi, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2 );

double initime;

LARGE_INTEGER ticksPerSecond;

//==============================================================================

//

//==============================================================================

double gettime_ms()

{

//struct timeb t_current;

//ftime( & t_current );

//return( 1000.0 * t_current.time + t_current.millitm );

LARGE_INTEGER tick;

QueryPerformanceCounter( &tick );

return( 1000.0 * tick.QuadPart / ticksPerSecond.QuadPart );

}

//========================================================================

//

//========================================================================

BOOL RecordClose()

{

MMRESULT res;

res = waveInClose ( hWaveIn );

if( res != MMSYSERR_NOERROR ){

return FALSE;

}

else {

return TRUE;

}

}

//========================================================================

//

//========================================================================

BOOL RecordOpen()

{

if( bIsRecording ){

return FALSE;

}

RecordClose();

bIsRecording = true;


WaveHeader.dwBytesRecorded = 0;

MMRESULT res;

res = waveInOpen(

&hWaveIn,

(UINT) WAVE_MAPPER,

&PCMfmt,

(DWORD) RecordProc,

0, //instance, not used with the window callback mechanism.

CALLBACK_FUNCTION //CThe dwCallback parameter is a callback procedure address.

);

if( res != MMSYSERR_NOERROR ) {

hWaveIn = NULL;

return FALSE;

}

else{

return TRUE;

}

}

//========================================================================

//

//========================================================================

BOOL RecordStart()

{

MMRESULT res;

res = waveInPrepareHeader( hWaveIn, &WaveHeader, sizeof(WAVEHDR) );

if( res != MMSYSERR_NOERROR ) {

return FALSE;

}

res = waveInAddBuffer( hWaveIn, &WaveHeader, sizeof(WAVEHDR) );

if( res != MMSYSERR_NOERROR ) {

return FALSE;

}

res = waveInStart( hWaveIn );

if( res != MMSYSERR_NOERROR ) {

return FALSE;

}

else {

return TRUE;

}

}

//==============================================================================

//

//==============================================================================

void concat( char *ln, ... )

{

char buffer[4096];

va_list ap;

va_start( ap, ln );

vsprintf_s( buffer, ln, ap );

va_end( ap );

fprintf( stdout, "%s\t", buffer );

}

//========================================================================

//

//========================================================================

void record()

{

if( RecordOpen() ){

RecordStart();

}

}

//========================================================================

//

//========================================================================

BOOL CALLBACK RecordProc( HWAVEIN hwi, UINT uMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2 )

{

//note that a reset will also cause a wim_data

if( uMsg == WIM_DATA )

{

MMRESULT res;

res = waveInUnprepareHeader( hWaveIn, &WaveHeader, sizeof(WAVEHDR) );

if( res != MMSYSERR_NOERROR ){

return FALSE;

}

else{

bIsRecording = false;

int dclevel = 0;

for( int i = 10; i < 210; i++ )

{

dclevel += (int)wavbuffer[i];

}

dclevel /= 200;

int sum = 0;

for( int i = 10; i < 210; i++ )

{

sum += abs( wavbuffer[i] - dclevel );

}

sum /= 200;

concat( "[" ); //line start marker

concat( "DATA" ); //message type : channels values

concat( "%ld", (long)( gettime_ms() - initime ) ); //timestamp

concat( "%.3f", (double)sum / 128.0 );

fprintf( stdout, "]\n" ); //end of line marker

return TRUE;

}

}

return TRUE;

}

//========================================================================

//

//========================================================================

int _tmain(int argc, _TCHAR* argv[])

{

QueryPerformanceFrequency( &ticksPerSecond );

setvbuf( stdout, NULL,_IONBF, 0 ); //DONT BUFFER OUTPUT


concat( "[" ); //line start marker

concat( "HEADERS" ); //message type : channel names

concat( "0" ); //blank timestamp,

concat( "wm.or.roll" );

fprintf( stdout, "]\n" ); //end of line marker

initime = gettime_ms();

record();

while( 1 ){

Sleep( 1 );

if( !bIsRecording ){

record();

}

}

return 0;

}