Exemple #1
0
void RecordNode::process(AudioSampleBuffer& buffer,
                         MidiBuffer& events)
{
	//update timstamp data even if we're not recording yet
	EVERY_ENGINE->updateTimestamps(&timestamps);
	EVERY_ENGINE->updateNumSamples(&numSamples);
	
	// FIRST: cycle through events -- extract the TTLs and the timestamps
    checkForEvents(events);

    if (isRecording && allFilesOpened)
    {
        // SECOND: write channel data
        if (channelPointers.size() > 0)
        {
            EVERY_ENGINE->writeData(buffer);
        }

        //  std::cout << nSamples << " " << samplesWritten << " " << blockIndex << std::endl;

        return;

    }

    // this is intended to prevent parameter changes from closing files
    // before recording stops
    if (signalFilesShouldClose)
    {
        closeAllFiles();
        signalFilesShouldClose = false;
    }

}
void RecordNode::process(AudioSampleBuffer& buffer,
                         MidiBuffer& events)
{
	
	// FIRST: cycle through events -- extract the TTLs and the timestamps
    checkForEvents(events);

    if (isRecording)
    {
        // SECOND: write channel data
		int recordChans = channelMap.size();
		for (int chan = 0; chan < recordChans; ++chan)
		{
			int realChan = channelMap[chan];
			int sourceNodeId = channelPointers[realChan]->sourceNodeId;
			int nSamples = numSamples.at(sourceNodeId);
			int timestamp = timestamps.at(sourceNodeId);
			m_dataQueue->writeChannel(buffer, chan, realChan, nSamples, timestamp);
		}

        //  std::cout << nSamples << " " << samplesWritten << " " << blockIndex << std::endl;
		if (!setFirstBlock)
		{
			m_recordThread->setFirstBlockFlag(true);
			setFirstBlock = true;
		}
        
    }


}
Exemple #3
0
void PulsePalOutput::process(AudioSampleBuffer& buffer,
                             MidiBuffer& events)
{

    checkForEvents(events);

}
void SpikeSortingDisplay::process(AudioSampleBuffer& buffer,
                                  MidiBuffer& events,
                                  int& nSamples)
{
    checkForEvents(events);

    if (redraw)
    {
        for (int i = 0; i < getNumElectrodes(); i++)
        {
            Electrode& e = electrodes.getReference(i);

            // transfer buffered spikes to spike plot
            for (int j = 0; j < e.currentSpikeIndex; j++)
            {
                //std::cout << "Transferring spikes." << std::endl;
                e.pcPlot->processSortedSpikeObject(e.mostRecentSortedSpikes[j]);
                e.currentSpikeIndex = 0;
            }

        }

        for (int i = 0; i < getNumElectrodes(); i++)
        {

            node->setParameter(1,i);
            //std::cout << node->plotRipple << " is the plotRipple" << std::endl;
            if (node->plotRipple)
            {

                Electrode& e = electrodes.getReference(i);
                e.forRasterPlot.startRipple = node->electrodes[i]->rippleStatus[1];
                e.forRasterPlot.stopRipple = node->electrodes[i]->rippleStatus[2];
                node->setParameter(0,i); //removing

                for (int j = 0; j < e.forRasterPlot.accruedRasterMarks.size(); j++)
                {
                    //cout << e.forRasterPlot.accruedRasterMarks[j].timestamp << " is the spike timestamp and " << e.forRasterPlot.startRipple << " is the ripple timestamp." <<std::endl;

                    if(e.forRasterPlot.accruedRasterMarks[j].timestamp <= e.forRasterPlot.startRipple || e.forRasterPlot.accruedRasterMarks[j].timestamp >= e.forRasterPlot.stopRipple)
                    {
                        RasterData dummy;
                        dummy.electrodeNum = -1;
                        dummy.neuronID = -1;
                        dummy.timestamp = -1;
                        e.forRasterPlot.accruedRasterMarks.setUnchecked(j,dummy);
                    }
                }

                e.pcPlot->processRasterPlot(e.forRasterPlot, i);
                e.forRasterPlot.accruedRasterMarks.clearQuick();
                //std::cout << "reached in plot ripple" << std::endl;
                node->setParameter(0,i);

            }
        }
        redraw = false;
    }
}
static void event_timer_fired(int id) {
    LuiManager_updateDeviceReadList();
    if(!LuiManager_deviceReadSuccess()) {
        ase_printf("---READ ERROR---\n");
        return;
    }
    checkForEvents();
}
Exemple #6
0
void RecordNode::process(AudioSampleBuffer& buffer,
                         MidiBuffer& events,
                         int& nSamples)
{

    //std::cout << "Record node processing block." << std::endl;
    //std::cout << "Num channels: " << buffer.getNumChannels() << std::endl;


    if (isRecording)
    {

        //timestamp = timer.getHighResolutionTicks();

        // WHY IS THIS AFFECTING THE LFP DISPLAY?
        //buffer.applyGain(0, nSamples, 5.2438f);

        // cycle through events -- extract the TTLs and the timestamps
        checkForEvents(events);

        // cycle through buffer channels

        if (channelPointers.size() > 0)
        {

            for (int i = 0; i < buffer.getNumChannels(); i++)
            {


                if (channelPointers[i]->isRecording)
                {
                    // write buffer to disk!
                    writeContinuousBuffer(buffer.getSampleData(i),
                                          nSamples,
                                          i);

                    //std::cout << "Record channel " << i << std::endl;
                }


            }
        }



        return;

    }

    // this is intended to prevent parameter changes from closing files
    // before recording stops
    if (signalFilesShouldClose)
    {
        closeAllFiles();
        signalFilesShouldClose = false;
    }

}
void update(sf::RenderWindow *mWindow, Player *player, sf::View *view)
{
	tick++;
	//std::cout << "tick: " << tick << std::endl;
	checkForEvents(mWindow);
	checkForInput(mWindow, player, view);
	player->Update();
	//world->Step(1, 8, 3);
}
Exemple #8
0
void ArduinoOutput::process(AudioSampleBuffer& buffer,
                            MidiBuffer& events)
{


    checkForEvents(events);


}
Exemple #9
0
void WiFiOutput::process(AudioSampleBuffer &buffer, 
                            MidiBuffer &events,
                            int& nSamples)
{
	

	checkForEvents(events);
	

}
Exemple #10
0
int testSensor(SaHpiSessionIdT sessionId, SaHpiResourceIdT resourceId, SaHpiRdrT *rdr)
{
        SaErrorT status;
        int retval = SAF_TEST_NOTSUPPORT;
        SaHpiSensorRecT *sensorRec;
        SaHpiBoolT sensorEventsEnabled;

        sensorRec = &rdr->RdrTypeUnion.SensorRec;

        status =
            saHpiSensorEventEnableGet(sessionId, resourceId,
                                      sensorRec->Num,
                                      &sensorEventsEnabled);
        if (status == SA_ERR_HPI_ENTITY_NOT_PRESENT) {
                retval = SAF_TEST_NOTSUPPORT;
        } else if (status != SA_OK) {
                retval = SAF_TEST_UNRESOLVED;
                e_print(saHpiSensorEnableGet, SA_OK, status);
        } else if (sensorEventsEnabled) {
                retval =
                    run_test(sessionId, resourceId, sensorRec);
        } else if (sensorRec->EventCtrl == SAHPI_SEC_PER_EVENT) {
                status =
                    saHpiSensorEventEnableSet(sessionId,
                                              resourceId,
                                              sensorRec->Num,
                                              SAHPI_TRUE);
                if (status != SA_OK) {
                        retval = SAF_TEST_UNRESOLVED;
                        e_print(saHpiSensorEventEnableSet, SA_OK, status);
                } else {
                        retval = run_test(sessionId, resourceId, sensorRec);

                        if (retval == SAF_TEST_PASS) {
                                sensorData[sensorCount-1].origEventEnable = SAHPI_FALSE;
                        } else {

                                // restore EventEnabled state
                                status = saHpiSensorEventEnableSet(sessionId,
                                                                   resourceId,
                                                                   sensorRec->Num,
                                                                   SAHPI_FALSE);
                                if (status != SA_OK) {
                                         e_print(saHpiSensorEventEnableSet, SA_OK, status);
                                }
                        }
                }
        }

        if (retval == SAF_TEST_PASS && sensorCount % POLL_COUNT == 0) {
                retval = checkForEvents(sessionId);
        }

        return retval;
}
Exemple #11
0
bool RH_TCP::available()
{
    if (_socket < 0)
	return false;
    checkForEvents();
    if (_rxBufFull)
    {
	validateRxBuf();
	_rxBufFull= false;
    }
    return _rxBufValid;
}
Exemple #12
0
void LfpDisplayNode::process(AudioSampleBuffer& buffer, MidiBuffer& events)
{
    // 1. place any new samples into the displayBuffer
    //std::cout << "Display node sample count: " << nSamples << std::endl; ///buffer.getNumSamples() << std::endl;

    initializeEventChannels();

    checkForEvents(events); // see if we got any TTL events

	ScopedLock displayLock(displayMutex);

    for (int chan = 0; chan < buffer.getNumChannels(); chan++)
    {
         int samplesLeft = displayBuffer->getNumSamples() - displayBufferIndex[chan];
         int nSamples = getNumSamples(chan);

        if (nSamples < samplesLeft)
        {

            displayBuffer->copyFrom(chan,  			// destChannel
                                    displayBufferIndex[chan], // destStartSample
                                    buffer, 			// source
                                    chan, 				// source channel
                                    0,					// source start sample
                                    nSamples); 			// numSamples
        
            displayBufferIndex.set(chan, displayBufferIndex[chan] + nSamples);
        }
        else
        {

            int extraSamples = nSamples - samplesLeft;

            displayBuffer->copyFrom(chan,  				// destChannel
                                    displayBufferIndex[chan], // destStartSample
                                        buffer, 			// source
                                        chan, 				// source channel
                                        0,					// source start sample
                                        samplesLeft); 		// numSamples

                displayBuffer->copyFrom(chan,
                                        0,
                                        buffer,
                                        chan,
                                        samplesLeft,
                                        extraSamples);

            displayBufferIndex.set(chan, extraSamples);
        }
    }

}
Exemple #13
0
void SpikeDisplayNode::process(AudioSampleBuffer& buffer, MidiBuffer& events, int& nSamples)
{

    checkForEvents(events); // automatically calls 'handleEvent

    if (signalFilesShouldClose)
    {
        for (int i = 0; i < getNumElectrodes(); i++)
        {
            closeFile(i);
        }

        signalFilesShouldClose = false;
    }

    if (redrawRequested)
    {
        // update incoming thresholds
        for (int i = 0; i < getNumElectrodes(); i++)
        {

            Electrode& e = electrodes.getReference(i);

            // update thresholds
            for (int j = 0; j < e.numChannels; j++)
            {
                e.displayThresholds.set(j, 
                e.spikePlot->getDisplayThresholdForChannel(j));

                e.spikePlot->setDetectorThresholdForChannel(j, e.detectorThresholds[j]);
            }

            // transfer buffered spikes to spike plot
            for (int j = 0; j < e.currentSpikeIndex; j++)
            {
                //std::cout << "Transferring spikes." << std::endl;
                e.spikePlot->processSpikeObject(e.mostRecentSpikes[j]);
                e.currentSpikeIndex = 0;
            }

        }

        redrawRequested = false;
    }

}
Exemple #14
0
int testSensor(SaHpiSessionIdT session, SaHpiResourceIdT resource, SaHpiRdrT *rdr)
{
        int retval = SAF_TEST_NOTSUPPORT;
        SaErrorT status;
        SaHpiSensorNumT s_num;
        SaHpiEventStateT Assertsaved, Deassertsaved;

        s_num = rdr->RdrTypeUnion.SensorRec.Num;

        status = saHpiSensorEventMasksGet(session, resource, s_num,
                                          &Assertsaved, &Deassertsaved);
        if (status != SA_OK) {
                retval = SAF_TEST_UNRESOLVED;
                e_print(saHpiSensorEventMasksGet, SA_OK, status);
        } else {
                sensorData[sensorCount].resourceId = resource;
                sensorData[sensorCount].sensorNum = s_num;
                sensorData[sensorCount].mask = rdr->RdrTypeUnion.SensorRec.Events;
                sensorData[sensorCount].asserted = Assertsaved;
                sensorData[sensorCount].deasserted = Deassertsaved;
                sensorData[sensorCount].stateIndex = 0;

                if (Assertsaved == 0) {
                        sensorData[sensorCount].state[0] = STATE_ADD;
                        sensorData[sensorCount].state[1] = STATE_REMOVE;
                        retval = change_event_masks(session, resource, s_num,
                                                    SAHPI_SENS_ADD_EVENTS_TO_MASKS);
                } else {
                        sensorData[sensorCount].state[0] = STATE_REMOVE;
                        sensorData[sensorCount].state[1] = STATE_ADD;
                        retval = change_event_masks(session, resource, s_num,
                                                    SAHPI_SENS_REMOVE_EVENTS_FROM_MASKS);
                }
                sensorCount++;
        }

        if (retval == SAF_TEST_PASS && sensorCount % POLL_COUNT == 0) {
                retval = checkForEvents(session);
        }

        return retval;
}
Exemple #15
0
/**
 * Waits for an incoming event message and copies it to user supplied
 * data buffer
 * @param waitForever indicate if the function should block forever
 * @param timeTowaitInMillisec max number of seconds to wait
 *              if waitForever is false
 * @param binaryBuffer user-supplied buffer to copy event to
 * @param binaryBufferMaxLen maximum buffer size that an event can be
 *              copied to.
 *              If an event exceeds the binaryBufferMaxLen, then the first
 *              binaryBufferMaxLen bytes of the events will be copied
 *              to user-supplied binaryBuffer, and JAVACALL_OUT_OF_MEMORY will
 *              be returned
 * @param outEventLen user-supplied pointer to variable that will hold actual
 *              event size received
 *              Platform is responsible to set this value on success to the
 *              size of the event received, or 0 on failure.
 *              If outEventLen is NULL, the event size is not returned.
 * @return <tt>JAVACALL_OK</tt> if an event successfully received,
 *         <tt>JAVACALL_FAIL</tt> or if failed or no messages are avaialable
 *         <tt>JAVACALL_OUT_OF_MEMORY</tt> If an event's size exceeds the
 *         binaryBufferMaxLen
 */
javacall_result javacall_event_receive(
                            long                    timeTowaitInMillisec,
                            /*OUT*/ unsigned char*  binaryBuffer,
                            /*IN*/  int             binaryBufferMaxLen,
                            /*OUT*/ int*            outEventLen)
{
    javacall_bool ok;
    int totalRead=0;

    if (!event_initialized) {
        javacall_events_init();
    }

    ok=(binaryBuffer!=NULL) && (binaryBufferMaxLen>0);

    while (ok) {
    if (ok) {
        ok=WaitForSingleObject(events_mutex, 500)==WAIT_OBJECT_0;
    }
    if (ok) {
        totalRead=dequeueEventMessage(binaryBuffer,binaryBufferMaxLen);
        if (head==NULL) {
            ResetEvent(events_handle);
        }
        ok=ReleaseMutex(events_mutex);
    }
        if (0 == totalRead) {
            ok = checkForEvents(timeTowaitInMillisec);
        } else {
            break;
        }
    }

    ok= ok && (totalRead!=0);
    if (outEventLen!=NULL) {
        *outEventLen = ok ? totalRead : 0;
    }
	return ok?JAVACALL_OK:JAVACALL_FAIL;
}
Exemple #16
0
void RecordControl::process(AudioSampleBuffer& buffer,
                            MidiBuffer& events)
{
    checkForEvents(events);
}
Exemple #17
0
void SpikeDisplayNode::process(AudioSampleBuffer& buffer, MidiBuffer& midiMessages, int& nSamples)
{

    checkForEvents(midiMessages); // automatically calls 'handleEvent

}
Exemple #18
0
void LfpDisplayNode::process(AudioSampleBuffer &buffer, MidiBuffer &events, int& nSamples)
{
	// 1. place any new samples into the displayBuffer
	//std::cout << "Display node sample count: " << nSamples << std::endl; ///buffer.getNumSamples() << std::endl;

	totalSamples = nSamples;
	displayBufferIndexEvents = displayBufferIndex;

	initializeEventChannel();



	checkForEvents(events); // update timestamp, see if we got any TTL events

	int samplesLeft = displayBuffer->getNumSamples() - displayBufferIndex;

	if (nSamples < samplesLeft)
	{

		for (int chan = 0; chan < buffer.getNumChannels(); chan++)
		{	
			displayBuffer->copyFrom(chan,  			// destChannel
							    displayBufferIndex, // destStartSample
							    buffer, 			// source
							    chan, 				// source channel
							    0,					// source start sample
							    nSamples); 			// numSamples

		}
		displayBufferIndex += (nSamples);

	} else {

		int extraSamples = nSamples - samplesLeft;

		for (int chan = 0; chan < buffer.getNumChannels(); chan++)
		{	
			displayBuffer->copyFrom(chan,  				// destChannel
							    displayBufferIndex, // destStartSample
							    buffer, 			// source
							    chan, 				// source channel
							    0,					// source start sample
							    samplesLeft); 		// numSamples

			displayBuffer->copyFrom(chan,
								0,
								buffer,
								chan,
								samplesLeft,
								extraSamples);
		}

		displayBufferIndex = extraSamples;
	}

	//std::cout << *displayBuffer->getSampleData(displayBuffer->getNumChannels()-1, 
	//										  displayBufferIndex-1) << std::endl;


	///// failed attempt to use abstractFifo:

	// int start1, size1, start2, size2;

	// abstractFifo.prepareToWrite(nSamples, start1, size1, start2, size2);

	// if (size1 > 0)
	// {
	// 	for (int chan = 0; chan < buffer.getNumChannels(); chan++)
	// 	{	
	// 		displayBuffer->copyFrom(chan,  			// destChannel
	// 						    start1, 			// destStartSample
	// 						    buffer, 			// source
	// 						    chan, 				// source channel
	// 						    0,					// source start sample
	// 						    size1); 			// numSamples

	// 	}

	// 	displayBufferIndex += size1;
	// }

	// if (size2 > 0)
	// {
	// 	for (int chan = 0; chan < buffer.getNumChannels(); chan++)
	// 	{	
	// 		displayBuffer->copyFrom(chan,  			// destChannel
	// 						    start2, 			// destStartSample
	// 						    buffer, 			// source
	// 						    chan, 				// source channel
	// 						    size1,				// source start sample
	// 						    size2); 			// numSamples

	// 	}

	// 	displayBufferIndex = size2;
	// }

	// std::cout << displayBufferIndex << std::endl;

	// abstractFifo.finishedWrite(size1 + size2);


}
Exemple #19
0
void PhaseDetector::process(AudioSampleBuffer& buffer,
                            MidiBuffer& events,
                            int& nSamples)
{

    checkForEvents(events);

    if (selectedChannel >= 0 && selectedChannel < buffer.getNumChannels())
    {

        for (int i = 0; i < nSamples; i++)
        {

            float  sample = *buffer.getSampleData(selectedChannel, i);

            if (!triggerOnPeak)
                sample = -sample; // invert


            if (sample > lastSample && !isIncreasing)
            {

                // entering rising phase
                isIncreasing = true;
                nSamplesSinceLastPeak++;

            }
            else if (sample < lastSample && isIncreasing && nSamplesSinceLastPeak >= minSamplesToNextPeak)
            {

                numPeakIntervals++;


                //std::cout << "GOT EVENT." << std::endl;

                // entering falling phase (just reached peak or trough)
                //if (true)
                addEvent(events, TTL, i, 1, 3);


                peakIntervals[numPeakIntervals % NUM_INTERVALS] = nSamplesSinceLastPeak;

                isIncreasing = false;

                nSamplesSinceLastPeak = 0;

                estimateFrequency();

            }
            else
            {

                // either rising or falling
                nSamplesSinceLastPeak++;

                if (nSamplesSinceLastPeak == 500)
                {
                    addEvent(events, TTL, i, 0, 3);
                }

            }

            lastSample = sample;

        }
    }


}
Exemple #20
0
int TestDomain(SaHpiSessionIdT sessionId)
{
     int i;
     int retval = SAF_TEST_NOTSUPPORT;
     int response;
     SaErrorT error;
     SaHpiEntryIdT nextEntryId;
     SaHpiEntryIdT entryId;
     SaHpiRptEntryT rptEntry;
     SaHpiBoolT pass = SAHPI_FALSE;

     sensorCount = 0;
     error = saHpiSubscribe(sessionId);
     if (error != SA_OK) {
         e_print(saHpiSubscribe, SA_OK, error);
         retval = SAF_TEST_UNRESOLVED;
     } else {
         nextEntryId = SAHPI_FIRST_ENTRY;
         while (nextEntryId != SAHPI_LAST_ENTRY && retval == SAF_TEST_NOTSUPPORT) {
              entryId = nextEntryId;
              error = saHpiRptEntryGet(sessionId, entryId, &nextEntryId, &rptEntry);
              if (error == SA_ERR_HPI_NOT_PRESENT) {
                  break;
              } else if (error != SA_OK) {
                  retval = SAF_TEST_UNRESOLVED;
                  e_print(saHpiRptEntryGet, SA_OK, error);
              } else if (rptEntry.ResourceCapabilities & SAHPI_CAPABILITY_SENSOR) {
                  response = testResource(sessionId, rptEntry.ResourceId);
                  if (response == SAF_TEST_PASS) {
                      pass = SAHPI_TRUE;
                  } else {
                      retval = response;
                  }
              }
         }

         if (retval == SAF_TEST_NOTSUPPORT && pass) {
             retval = SAF_TEST_PASS;

             // Check for any remaining events that may have been generated.
             // We will pause for 5 seconds to give the last sensor time to
             // generate an event.

             for (i = 0; i < 2 && retval == SAF_TEST_PASS; i++) {
                 sleep(5);
                 retval = checkForEvents(sessionId);
             }

             if (retval == SAF_TEST_PASS) {
                 retval = verifyEvents();
             }
         }

         restoreSensors(sessionId);

         error = saHpiUnsubscribe(sessionId);
         if (error != SA_OK) {
              e_print(saHpiUnsubscribe, SA_OK, error);
         }
     }

     return retval;
}
void ArduinoOutput::process (AudioSampleBuffer& buffer)
{
    checkForEvents ();
}
Exemple #22
0
void PhaseDetector::process(AudioSampleBuffer& buffer,
                            MidiBuffer& events)
{

    checkForEvents(events);

    // loop through the modules
    for (int i = 0; i < modules.size(); i++)
    {
        DetectorModule& module = modules.getReference(i);

        // check to see if it's active and has a channel
        if (module.isActive && module.outputChan >= 0 &&
            module.inputChan >= 0 &&
            module.inputChan < buffer.getNumChannels())
        {
            for (int i = 0; i < getNumSamples(module.inputChan); i++)
            {
                const float sample = *buffer.getReadPointer(module.inputChan, i);

                if (sample < module.lastSample && sample > 0 && module.phase != FALLING_POS)
                {

                    if (module.type == PEAK)
                    {
                        addEvent(events, TTL, i, 1, module.outputChan);
                        module.samplesSinceTrigger = 0;
                        module.wasTriggered = true;
                    }

                    module.phase = FALLING_POS;

                }
                else if (sample < 0 && module.lastSample >= 0 && module.phase != FALLING_NEG)
                {

                    if (module.type == FALLING_ZERO)
                    {
                        addEvent(events, TTL, i, 1, module.outputChan);
                        module.samplesSinceTrigger = 0;
                        module.wasTriggered = true;
                    }

                    module.phase = FALLING_NEG;

                }
                else if (sample > module.lastSample && sample < 0 && module.phase != RISING_NEG)
                {

                    if (module.type == TROUGH)
                    {
                        addEvent(events, TTL, i, 1, module.outputChan);
                        module.samplesSinceTrigger = 0;
                        module.wasTriggered = true;
                    }

                    module.phase = RISING_NEG;

                }
                else if (sample > 0 && module.lastSample <= 0 && module.phase != RISING_POS)
                {

                    if (module.type == RISING_ZERO)
                    {
                        addEvent(events, TTL, i, 1, module.outputChan);
                        module.samplesSinceTrigger = 0;
                        module.wasTriggered = true;
                    }

                    module.phase = RISING_POS;

                }

                module.lastSample = sample;

                if (module.wasTriggered)
                {
                    if (module.samplesSinceTrigger > 1000)
                    {
                        addEvent(events, TTL, i, 0, module.outputChan);
                        module.wasTriggered = false;
                    }
                    else
                    {
                        module.samplesSinceTrigger++;
                    }
                }

            }


        }

    }

}
Exemple #23
0
void RecordNode::process(AudioSampleBuffer& buffer,
                         MidiBuffer& events,
                         int& nSamples)
{

    // TERMINOLOGY:
    // buffer -- incoming data stored in AudioSampleBuffer (nSamples long)
    // block -- 1024-sample sequence for disk writing (BLOCK_LENGTH long)
    // samplesWritten -- number of samples written from the current buffer
    // blockIndex -- index within the current block (used outside this function)
    // numSamplesToWrite -- number of unwritten samples from the buffer

    // CONSTRAINTS:
    // samplesWritten must equal nSamples by the end of the process() method

    if (isRecording && allFilesOpened)
    {

        // FIRST: cycle through events -- extract the TTLs and the timestamps
        checkForEvents(events);

        // SECOND: cycle through buffer channels
        int samplesWritten = 0;

        if (channelPointers.size() > 0)
        {

            while (samplesWritten < nSamples) // there are still unwritten samples in the buffer
            {

                int numSamplesToWrite = nSamples - samplesWritten; // samples remaining in the buffer

                if (blockIndex + numSamplesToWrite < BLOCK_LENGTH) // we still have space in this block
                {

                    for (int i = 0; i < buffer.getNumChannels(); i++)
                    {

                        if (channelPointers[i]->getRecordState())
                        {
                            // write buffer to disk!
                            writeContinuousBuffer(buffer.getReadPointer(i,samplesWritten),
                                                  numSamplesToWrite,
                                                  i);

                        }
                    }

                    // update our variables
                    samplesWritten += numSamplesToWrite;
                    timestamp += numSamplesToWrite;
                    blockIndex += numSamplesToWrite;

                }
                else // there's not enough space left in this block for all remaining samples
                {

                    numSamplesToWrite = BLOCK_LENGTH - blockIndex;

                    for (int i = 0; i < buffer.getNumChannels(); i++)
                    {

                        if (channelPointers[i]->getRecordState())
                        {
                            // write buffer to disk!
                            writeContinuousBuffer(buffer.getReadPointer(i,samplesWritten),
                                                  numSamplesToWrite,
                                                  i);

                            //std::cout << "Record channel " << i << std::endl;
                        }
                    }

                    // update our variables
                    samplesWritten += numSamplesToWrite;
                    timestamp += numSamplesToWrite;
                    blockIndex = 0; // back to the beginning of the block
                    
                }
            }
        }

        //  std::cout << nSamples << " " << samplesWritten << " " << blockIndex << std::endl;

        return;

    }

    // this is intended to prevent parameter changes from closing files
    // before recording stops
    if (signalFilesShouldClose)
    {
        closeAllFiles();
        signalFilesShouldClose = false;
    }

}
Exemple #24
0
static int dk_ioctl
(
 	struct inode *inode, 
	struct file *file,
	unsigned int cmd,
	unsigned long arg
)
{
		INT32 ret=-1;
		INT32 data;
		struct cfg_op co;
		INT32 cli_id;
		INT32 i;
		struct client_info ci;
		struct event_op eo;
		event_handle evt_hnd;
		p_event_struct p_event;
		p_atheros_dev p_client;

		
#ifdef DK_DEBUG
		printk("DK::dk_ioctl \n");
#endif

		cli_id = (int) ((unsigned long)file->private_data);
		p_client = get_client(cli_id);
		if (p_client == NULL) {
				printk("DK:: Invalid client \n");
				return -1;
		}
		switch (cmd) {
			case DK_IOCTL_GET_VERSION:
#ifdef DK_DEBUG
				printk("DK:: DK_IOCTL_GET_VERISION \n");
#endif
				data = (DRV_MAJOR_VERSION << 16) | (DRV_MINOR_VERSION);
				ret = put_user(data, (INT32 *)arg);
				break;
			case DK_IOCTL_GET_CLIENT_INFO:
#ifdef DK_DEBUG
				printk("DK:: DK_IOCTL_GET_CLIENT_INFO \n");
#endif
				if (get_cli_info(cli_id,&ci) < 0) {
					printk("DK:: get_cli_info failed, cli_id : %d \n", cli_id);
					ret = -1;
				} else {
					ret = copy_to_user((void *)arg,(void *)&ci,sizeof(ci));
				}
				ret = 0;
				break;
			case DK_IOCTL_CFG_READ:
#if !defined(P1020)
				if (copy_from_user((void *)&co,(void *)arg,sizeof(co))) {
						return -EFAULT;
				}
#ifdef DK_DEBUG
				printk("DK::Cfg read @ offset %x \n",co.offset);
#endif
#if defined(OWL_PB42) || defined(PYTHON_EMU)
#ifdef WASP_OSPREY
   if(cli_id!=0){ // For DBDC operation, Wasp radio's client ID is zero; 
#endif
				if (cli_cfg_read(cli_id,co.offset,co.size,&co.value) < 0) {
					ret = -1;
				} else {
					ret = copy_to_user((void *)arg,(void *)&co,sizeof(co));
				}
#ifdef WASP_OSPREY
  }
#endif
#endif
#else
                ret = -1;
#endif
				break;
                        case DK_IOCTL_RTC_REG_READ:
                                if (copy_from_user((void *)&co,(void *)arg,sizeof(co))) {
                                                return -EFAULT;
                                }
#ifdef DK_DEBUG
                                printk("DK::Rtc reg read @ offset %x \n",co.offset);
#endif
#ifndef OCTEON
                                if (rtc_reg_read(cli_id,co.offset,&co.value) < 0) {
                                        ret = -1;
                                } else {
                                        ret = copy_to_user((void *)arg,(void *)&co,sizeof(co));
                                }
#endif
                                break;

			case DK_IOCTL_GET_CHIP_ID:
				if (copy_from_user((void *)&co,(void *)arg,sizeof(co))) {
						return -EFAULT;
				}
#ifdef DK_DEBUG
				printk("DK::Reading Chio ID @ offset %x \n",co.offset);
#endif
#ifndef OCTEON
				if (get_chip_id(cli_id,co.offset,co.size,&co.value) < 0) {
					ret = -1;
				} else {
					ret = copy_to_user((void *)arg,(void *)&co,sizeof(co));
				}
				break;
#endif
			case DK_IOCTL_CFG_WRITE:
				if (copy_from_user((void *)&co,(void *)arg,sizeof(co))) {
						return -EFAULT;
				}
#ifdef DK_DEBUG
				printk("DK::Cfg write @ offset %x : %x \n",co.offset,co.value);
#endif
#if defined(OWL_PB42) || defined(PYTHON_EMU)
#ifdef WASP_OSPREY
   if(cli_id!=0){ // For DBDC operation, Wasp radio's client ID is zero; 
#endif
				if (cli_cfg_write(cli_id,co.offset,co.size,co.value) < 0) {
					ret = -1;
				} else {
					ret = 0;
				}
#ifdef WASP_OSPREY
  }
#endif
#endif
				break;
                        case DK_IOCTL_SYS_REG_WRITE_32:
                        case DK_IOCTL_FULL_ADDR_WRITE:
                                if (copy_from_user((void *)&co,(void *)arg,sizeof(co))) {
                                                return -EFAULT;
                                }
#ifdef DK_DEBUG
                                printk("DK::full addr write @ address %x : %x \n",co.offset,co.value);
#endif
#ifdef AP83
                                if (full_addr_write(cli_id,co.offset,co.value) < 0) {
                                        ret = -1;
                                } else {
                                        ret = 0;
                                }
#endif
                                break;
						case DK_IOCTL_SYS_REG_READ_32:
                        case DK_IOCTL_FULL_ADDR_READ:
                                if (copy_from_user((void *)&co,(void *)arg,sizeof(co))) {
                                                return -EFAULT;
                                }
#ifdef DK_DEBUG
                                printk("DK::Full add read @ address %x \n",co.offset);
#endif
#ifdef AP83
                                if (full_addr_read(cli_id,co.offset,&co.value) < 0) {
                                        ret = -1;
                                } else {
                                        ret = copy_to_user((void *)arg,(void *)&co,sizeof(co));
                                }
#endif
                                break;
                        case DK_IOCTL_RTC_REG_WRITE:
                                if (copy_from_user((void *)&co,(void *)arg,sizeof(co))) {
                                                return -EFAULT;
                                }
#ifdef DK_DEBUG
                                printk("DK::rtc write @ offset %x : %x \n",co.offset,co.value);
#endif
#ifdef AP83
#ifndef WASP
                                if (rtc_reg_write(cli_id,co.offset,co.value) < 0) {
                                        ret = -1;
                                } else {
                                        ret = 0;
                                }
#endif
#endif
                                break;

			case DK_IOCTL_CREATE_EVENT:
#ifdef DK_DEBUG
				printk("DK::Create event \n");
#endif
				if (copy_from_user((void *)&eo,(void *)arg,sizeof(eo))) {
						return -EFAULT;
				}
				ret = -1;
				if (eo.valid) {
			 		evt_hnd.eventID = eo.param[5] & 0xffff;
					evt_hnd.f2Handle = (eo.param[5] >> 16) & 0xffff;
					p_event = createEvent (eo.param[0], // type
					                       eo.param[1], // persistent
					                       eo.param[2], // param1
					                       eo.param[3], // param2
					                       eo.param[4], // param3
					                       evt_hnd);
					if (p_event != NULL) {
						// need to look at the event type to see which queue
						switch (p_event->type ) {
							case ISR_INTERRUPT:
								//if param1 is zero, we, by default
								// set the "ISR IMR" to pass everything
								if ( 0 == p_event->param1 ) {
									p_event->param1 = 0xffffffff;
								}
								if (pushEvent(p_event, &p_client->isr_event_q,
								               TRUE) ) {
										ret = 0;
								} else {
									printk("DK::Push Event Failed \n");
									kfree(p_event);
								} 
								break;
							default:
								printk("DK::Event Type %d not supported \n",p_event->type);
								kfree(p_event);
								break;
						}
					} 
				}
				break;
			case DK_IOCTL_GET_NEXT_EVENT:
#ifdef DK_DEBUG
				printk("DK::Get next event \n");
#endif
				ret = 0;
				eo.valid = 0;
				if (p_client->trigered_event_q.queueSize) {
					if (checkForEvents(&p_client->trigered_event_q,TRUE)){ 
						p_event = popEvent(&p_client->trigered_event_q,TRUE);
						eo.valid = 1;
						eo.param[0] = p_event->type;
						eo.param[1] = p_event->persistent;
						eo.param[2] = p_event->param1; 
						eo.param[3] = p_event->param2;
						eo.param[4] = p_event->param3;
						eo.param[5] = (p_event->eventHandle.f2Handle << 16) | 
						               p_event->eventHandle.eventID; 
						for (i=0;i<6;i++) { 
							eo.param[6+i] = p_event->result[i]; 
						} 
					#ifdef DK_DEBUG 
						printk("DK:: Pop event %x \n",(UINT32)p_event);
					#endif 
						kfree(p_event);
					} 
				}
				ret = copy_to_user((void *)arg,(void *)&eo,sizeof(eo));
				break;
            case DK_IOCTL_FLASH_READ:
                printk("DK:: Flash read is not supported any more from art driver\n");
                break;
            case DK_IOCTL_FLASH_WRITE:
                printk("DK:: Flash read is not supported any more from art driver\n");
                break; 
/*
#ifdef OWL_PB42
            case DK_IOCTL_MAC_WRITE:
#ifdef DK_DEBUG
                 printk("DK::Get DK_IOCTL_MAC_WRITE\n ");
#endif
                 if (copy_from_user((void *)&flashMac,(void *)arg,sizeof(flashMac))) {
                      printk("DK:: Copy_from_user failed 1\n");
                      return -EFAULT;
                 }
                 if (copy_from_user((void *)mac0Addr,(void *)flashMac.pAddr0, 6)){
                     printk("DK:: Copy_from_user failedi 2\n");
                     return -EFAULT;
                 }
                 if (copy_from_user((void *)mac1Addr,(void *)flashMac.pAddr1, 6)){
                     printk("DK:: Copy_from_user failed 3\n");
                     return -EFAULT;
                 }

#ifdef DK_DEBUG
                 printk("DK:: MAC Addr\n");
				 for(i=0; i<6; i++)
					printk("%x  ", mac0Addr[i]);
				 printk("\n");
				 for(i=0; i<6; i++)
					printk("%x  ", mac1Addr[i]);
				 printk("\n");
#endif

				memcpy(&hw_mac_cfg, 0xbf7f0000, 16);
				ar7100_spi_sector_erase(0x7f0000);
				// Copy mac address to ath_hw_cfg structure
				for(i=0; i<6; i++)
			        hw_mac_cfg.macAddr0[i] = mac0Addr[i];

				for(i=0; i<6; i++)
			        hw_mac_cfg.macAddr1[i] = mac1Addr[i];

				ar7100_spi_write_page(0x7f0000, &hw_mac_cfg, 256);				
				ret = 1;
                break; 
#endif
*/
			default:
				printk("DK::Unreconginzed ioctl command %d \n",cmd);
				break;
		}