/* ------------------------------------------------------------------------------ | GenMon CIN | | Author : Terry Leach | Revision: 8/21/03 Initial creation Purpose : High level module called directly from the LabView environment. This code will be embeded in the ASIO.vi */ #include #include // DebugBreak #include "misctyps.h" // Convenient data types #include "GenMonCIN.h" // CIN / LabView data types for interface #include "appGenMon2.h" // Bridges from C to C++ unsigned short _Ints[ 512 ]; // Sound buffer code makes ref to these externals, but doesn't supply unsigned short *_pctype = _Ints; int __mb_cur_max = 1; int g_AllowedOP = CW_START; // First operation must be to turn "ON" sound system ULONG g_Status; // Status CIN MgErr CINLoad( RsrcFile reserved ) { g_AllowedOP = CW_START; // All CINRun operations except sound system start are ignored until start up return noErr; } CIN MgErr CINRun( uInt32 *Control // Control bits indicating which operation to perform... see GenMonCIN.h , uInt16 *SoundSize // Size of 1/2 a double sound buffer in bytes , hWAVESDA wavesDA // New waveforms to be transmitted , uInt16 *WaveChanged // High byte indicates active A/D channels (FOR THIS CALL), low byte active D/A , uInt16 *DigitalDA // Unimplemented: values for the LAYLA's digital outputs , hWAVESAD wavesAD // Measured waveforms , uInt16 *ServiceBuf // Status bits indicating service timing , uInt32 *Status // Status bits including late buffers, and overall system status ); CIN MgErr CINRun( uInt32 *Control , uInt16 *SoundSize , hWAVESDA wavesDA , uInt16 *WaveChanged , uInt16 *DigitalDA , hWAVESAD wavesAD , uInt16 *ServiceBuf , uInt32 *Status ) { int bit; int numAD; // -------------- #ifdef _DEBUG DebugBreak(); #endif if( !(*Control & (CW_START|CW_STOP)) ) { // Must size the output arrays... find out how many A/D channels are on for( bit = 8 ,numAD = 0; bit--; ) if( *WaveChanged & (0x100 << bit) ) numAD++; if( numAD ) { NumericArrayResize( fS ,2 ,(UHandle*) &wavesAD ,(int32)*SoundSize*numAD ); (*wavesAD)-> numWaves = numAD; (*wavesAD)-> len = *SoundSize; } else { (*wavesAD)-> numWaves = 0; (*wavesAD)-> len = 0; } } // Interpret the control word, invoking the correct operation mode... multiple bits can be set // NOTE: No operations are allowed until the sound system has been started, at which point // the start operation will be prevented until a stop has be executed. for( bit = CW_START; bit < CW_LAST; bit <<= 1 ) { // Extract each control bit... multiple functions in 1 call possible switch( (*Control & bit) & g_AllowedOP ) { // Mask against allowed operations case CW_START: g_AllowedOP = ALLOW_OPS; // Start the sound driver thread, allocating sound buffers APP_load( *SoundSize ,*WaveChanged ); *ServiceBuf = APP_Query(); break; case CW_TX: APP_TX( wavesDA ,*WaveChanged ,*DigitalDA ); // Transmit new waveforms... load our 1/2 of the buffer anyway *ServiceBuf = APP_Query(); break; case CW_MEAS: APP_Measure( wavesAD ,*WaveChanged ); // Collect waveform segments for the indicated A/D channels *ServiceBuf = APP_Query(); break; case CW_QUERY: *ServiceBuf = APP_Query(); // Collect status and timing bits break; case CW_STOP: g_AllowedOP = CW_START; // Stop the sound driver thread APP_close(); break; } } *Status = APP_GetStat(); return noErr; } CIN MgErr CINUnLoad() { APP_close(); return noErr; }