Exemplo n.º 1
0
bool SignalModifier::convertToTrigger(Signal &s)
{    
    // reference counted Signal ( string command, string origin )
    Signal::SignalP midiSignal = new Signal("SEND_MIDI", "SIG_MOD");
    
    midiSignal->addStringArg("CC");
    // TODO: allow this to set the MIDI Channel
    midiSignal->addIntArg(1);
    midiSignal->addIntArg(s.getArgAsInt32(1));
    midiSignal->addIntArg(s.getArgAsInt32(2) * 127);
    
    _mCenter->handleSignal(*midiSignal); 
    
    // reference counted Signal ( string command, string origin )
    Signal::SignalP ledStateSignal = new Signal("SEND_OSC", "SIG_MOD");
    
    ledStateSignal->addStringArg("/nomestate/grid/led/set");
    // get the x position: LED bumber % 8
    ledStateSignal->addIntArg(s.getArgAsInt32(1) % 8);
    // get the y position: LED number / 8
    ledStateSignal->addIntArg(s.getArgAsInt32(1) / 8);
    // get the LED state: toggleState    
    ledStateSignal->addIntArg(s.getArgAsInt32(2));

    _mCenter->handleSignal(*ledStateSignal); 
    
    return true;
}
Exemplo n.º 2
0
bool MainWindow::loadLearningSignals(Signal& referenceSignal, Signal& distortedSignal)
{
    QString referenceFileName = QFileDialog::getOpenFileName(this, tr("Open Reference Physionet ECG File"),
                                                    "", tr("Physionet ECG File (*.dat)"));

    if(referenceFileName.isEmpty())
        return false;

    if(!referenceSignal.ReadFile(referenceFileName.toStdWString().c_str()))
    {
        QMessageBox::warning(this, "Warning", "Failed to load file " + referenceFileName);
        return false;
    }

    QString distortedFileName = QFileDialog::getOpenFileName(this, tr("Open Distorted Physionet ECG File"),
                                                    "", tr("Physionet ECG File (*.dat)"));

    if(distortedFileName.isEmpty())
        return false;

    if(!distortedSignal.ReadFile(distortedFileName.toStdWString().c_str()))
    {
        QMessageBox::warning(this, "Warning", "Failed to load file " + distortedFileName);
        return false;
    }

    return true;
}
Exemplo n.º 3
0
// profile time for emission with 4 slots, 2 in group 0 and 2 in group 1
static void benchSignalEmissionGroups()
{
	Signal<void ( void*, uint64_t )> sigIncrement;
	sigIncrement.connect( testCounterAdd2 );
	sigIncrement.connect( testCounterAdd2 );
	sigIncrement.connect( 1, testCounterAdd2 );
	sigIncrement.connect( 1, testCounterAdd2 );

	const uint64_t startCounter = TestCounter::get();
	const uint64_t benchStart = timestampBenchmark();

	uint64_t i;
	for( i = 0; i < 1000000; i++ )
		sigIncrement.emit( nullptr, 1 );

	const uint64_t benchDone = timestampBenchmark();
	const uint64_t endCounter = TestCounter::get();

	assert( endCounter - startCounter == ( i * 4 ) );

	cout << "OK" << endl;
	cout << "\tper emission: " << double( benchDone - benchStart ) / double( i ) << "ns"
	<< ", per slot: " << double( benchDone - benchStart ) / double( i * 4 ) << "ns"
	<< endl;
}
Exemplo n.º 4
0
int main( void ) {
	
	s1.setParameters( 3,2 );
	
	WRITE(2,&qfin);
	WRITE(2,&qfin);
	WRITE(2,&qfin);
	WRITE(3,&qfin2);	

	READ(3,qfout); // No data available yet
	READ(4,qfout);
	DUMP();
	READ(4,qfout);
	READ(4,qfout);
	
	cout << "Value QFOUT: " << (*qfout) << endl;
	
	READ(5,qfout);
	
	cout << "Value QFOUT: " << (*qfout) << endl;

	WRITE(7,&qfin); // READ in  9
	WRITE(8,&qfin); // READ in 10
	
	//DUMP();


	cout << "Name: \"" << s1.getName() << "\"" << endl;
	cout << "Bandwidth: " << s1.getBandwidth() << endl;
	cout << "Latency: " << s1.getLatency() << endl;

	return 0;
}
Exemplo n.º 5
0
unsigned int FlacDecoder::fetch(Signal& outleft, Signal& outright)
{
  outleft.reset();
  outright.reset();
  if (_opened)
  {
    unsigned int request_size=Signal::size;
    while (request_size > _bufferl.size() - _bufferpos)
    {
      if (!FLAC__stream_decoder_process_single(_streamdecoder) ||
          (FLAC__stream_decoder_get_state(_streamdecoder) != FLAC__STREAM_DECODER_READ_FRAME &&
           FLAC__stream_decoder_get_state(_streamdecoder) != FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC &&
           FLAC__stream_decoder_get_state(_streamdecoder) != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA &&
           FLAC__stream_decoder_get_state(_streamdecoder) != FLAC__STREAM_DECODER_READ_METADATA ))
      {
        break;
      }
    }

    const unsigned int to_read=request_size >_bufferl.size() - _bufferpos ? _bufferl.size() - _bufferpos : request_size;
    for (unsigned int i=0; i < to_read; i++)
    {
      outleft.samples[i]=_bufferl.at(_bufferpos);
      outright.samples[i]=_bufferr.at(_bufferpos++);
    }
    if (to_read == 0)
    {
      _ended=true;
    }
    return to_read;
  }
  _ended=true;
  return 0;
}
Exemplo n.º 6
0
/**
 * Message AppConfig::getMessage(QVector<QString> messageBlock)
 *
 * Takes a block of strings corresponding to one CAN message definition as
 * input and returns a Message struct with all applicable parameters set. This
 * function will throw errors if the input data is missing or malformed.
 *
 * @param messageBlock - The block of strings corresponding to one CAN message
 *     defintion
 * @returns A Message struct with all applicable parameters set, or an empty
 *     Message struct if an error occurred.
 */
Message AppConfig::getMessage(QVector<QString> messageBlock) {
  QString msgDef = messageBlock[0];
  QStringList sections = msgDef.split(" ", QString::SkipEmptyParts);
  if (sections.size() != 5) {
    emit error("Invalid message definition.");
    return Message();
  }

  Message msg;

  bool successful = true;
  msg.id = sections[1].toUInt(&successful);
  if (!successful) {
    emit error(QString("Invalid message ID"));
    return Message();
  }

  msg.dlc = sections[3].toUInt(&successful);
  if (!successful) {
    emit error(QString("Invalid DLC for message with ID: %1").arg(QString::number(msg.id, 16)));
    return Message();
  }

  for (int i = 1; i < messageBlock.size(); i++) {
    Signal sig = getSignal(messageBlock[i]);
    if (!sig.valid()) {
      return Message();
    }
    msg.sigs.push_back(sig);
  }

  return msg;
}
Exemplo n.º 7
0
void test1()
 {
  Signal<int> signal;

  Test test1(1);

  {
   Test test2(2);

   test1.connector.connect(signal);

   signal.assert(100);

   test2.connector.connect(signal);

   signal.assert(200);

   {
    Test2 test3(3,&test2);

    test3.connector.connect(signal);

    signal.assert(2);
    signal.assert(2);
   }
  }

  signal.assert(300);
 }
Exemplo n.º 8
0
	// This method is cloned from Operator, just resetting sign and exception bits
	// (because we don't have any exception support in this toy example)
	TestCase* FPSumOf3Squares::buildRandomTestCase(int i){

		TestCase *tc;
		/* Generate test cases using random input numbers */
			tc = new TestCase(this); // TODO free all this memory when exiting TestBench
			/* Fill inputs */
			for (unsigned int j = 0; j < ioList_.size(); j++) {
				Signal* s = ioList_[j]; 
				if (s->type() == Signal::in) {
					// ****** Modification: positive normal numbers with small exponents 
					mpz_class m = getLargeRandom(wF);
					mpz_class bias = (mpz_class(1)<<(wE-1)) - 1; 
					mpz_class e = getLargeRandom(wE-2) - (mpz_class(1)<<(wE-3)) + bias; // ensure no overflow
					mpz_class a = (mpz_class(1)<<(wE+wF+1)) // 01 to denote a normal number
						+ (e<<wF) + m;
					tc->addInput(s->getName(), a);
				}
			}
			/* Get correct outputs */
			emulate(tc);

			//		cout << tc->getInputVHDL();
			//    cout << tc->getExpectedOutputVHDL();

			return tc;
	}
Exemplo n.º 9
0
TEST(ConnectionList, MoveAssignmentOperator)
{
    Signal<void(std::string)> nameChanged;
    std::string name;

    ConnectionList connections1;
    {
        ConnectionList connections2;

        connections2 += nameChanged.Connect([&](std::string const& n) {
            name = n;
        });

        nameChanged("alice");
        EXPECT_EQ("alice", name);

        connections1 = std::move(connections2);

        nameChanged("bob");
        EXPECT_EQ("bob", name);

        connections2.Disconnect();

        nameChanged("chuck");
        EXPECT_EQ("chuck", name);
    }

    nameChanged("norris");
    EXPECT_EQ("norris", name);

    connections1.Disconnect();

    nameChanged("gates");
    EXPECT_EQ("norris", name);
}
Exemplo n.º 10
0
string  Operator::buildVHDLRegisters() {
	ostringstream o,l;

	if (isSequential()){

  if(getClkName().compare("") == 0) {
    std::cerr << "-- Can't find clock port for sequential component" << std::endl;
    return "";
  }

    std::string clk = getClkName();
    o << "-- clkname = " << clk << endl;
		o << tab << "process("<< clk <<")  begin\n"
		  << tab << tab << "if "<< clk << "'event and "<< clk <<"= '1' then\n";
		for(unsigned int i=0; i<signalList_.size(); i++) {
			Signal *s = signalList_[i];
			if(s->getLifeSpan() >0) {
				for(int j=1; j <= s->getLifeSpan(); j++)
					l << tab <<tab << tab << s->delayedName(j) << " <=  " << s->delayedName(j-1) <<";" << endl;
			}
		}
    // when there are not registers then we don't need that process stmnt
    if (l.str().compare("") == 0) return l.str();
    o << l.str();
		o << tab << tab << "end if;\n";
		o << tab << "end process;\n"; 
	}
	return o.str();
}
Exemplo n.º 11
0
void Operator::syncCycleFromSignal(string name, bool report) throw(std::string) {
	ostringstream e;
	e << "ERROR in syncCycleFromSignal, "; // just in case

	if(isSequential()) {
		Signal* s;
		try {
			s=getSignalByName(name);
		}
		catch (string e2) {
			e << endl << tab << e2;
			throw e.str();
		}

		if( s->getCycle() < 0 ) {
			ostringstream o;
			o << "signal " << name << " doesn't have (yet?) a valid cycle";
		throw o.str();
		} 
		// advance cycle if needed
		if (s->getCycle()>currentCycle_)
			currentCycle_ = s->getCycle();

		if(report)
			vhdl << tab << "----------------Synchro barrier, entering cycle " << currentCycle_ << "----------------" << endl ;
		// automatically update pipeline depth of the operator 
		if (currentCycle_ > pipelineDepth_) 
			pipelineDepth_ = currentCycle_;
	}
}
Exemplo n.º 12
0
void Operator::outputVHDLEntity(std::ostream& o) {
	unsigned int i;
  if(isSequential() && getClkName().compare("") == 0) {
    std::cerr << "-- Can't find clock port for sequential component" << std::endl;
  }
	o << "entity " << uniqueName_ << " is" << endl;
	if (ioList_.size() > 0)
	{
		o << tab << "port ( " << endl;

/*
		if(isSequential()) {
      o << getClkName() << " : in std_logic;" <<endl;
      std::string rst = getRstName();
      if (rst.compare("") != 0) {
        o << rst << " : in std_logic;" <<endl;
      }
		}
*/
		for (i=0; i<this->ioList_.size(); i++){
			Signal* s = this->ioList_[i];
//			if (i>0 || isSequential()) // align signal names 
//				o<<"          ";
			o<< tab << tab << tab << s->toVHDL();
			if(i < this->ioList_.size()-1)  o<<";" << endl;
		}
	
		o << endl << tab << ");"<<endl;
	}
	o << "end entity;" << endl << endl;
}
Exemplo n.º 13
0
bool Stream_File::DoSeek(Signal &sig, long offset, size_t offsetPrev, SeekMode seekMode)
{
	if (_hFile == INVALID_HANDLE_VALUE) return true;
	if (_map.hFileMappingObject == nullptr) {
		DWORD dwMoveMethod =
			(seekMode == SeekSet)? FILE_BEGIN :
			(seekMode == SeekCur)? FILE_CURRENT : FILE_BEGIN;
		DWORD dwPtr = ::SetFilePointer(_hFile, offset, nullptr, dwMoveMethod);
		if (dwPtr == INVALID_SET_FILE_POINTER) {
			sig.SetError(ERR_IOError, "seek error");
			return false;
		}
	} else {
		if (seekMode == SeekSet) {
			_map.offset = static_cast<size_t>(offset);
		} else if (seekMode == SeekCur) {
			if (offset < 0 && _map.offset < static_cast<size_t>(-offset)) {
				sig.SetError(ERR_IOError, "seek error");
				return false;
			}
			_map.offset = static_cast<size_t>(_map.offset + offset);
		}
		if (_map.offset > _map.bytes) {
			sig.SetError(ERR_IOError, "seek error");
			return false;
		}
	}
	return true;
}
Exemplo n.º 14
0
TEST_F(SignalTest, DeferredSynchronousSignal) {
    cout << "Instantiating signal object" << endl;

    Signal<int, int> testSignal;

    BasicTimer bt;
    cout << "Connecting signal" << endl;
    bt.start();
    testSignal.connectSlot(ExecutorScheme::DEFERRED_SYNCHRONOUS, staticSumFunction);
    bt.stop();
    cout << "Time to connect: " << bt.getElapsedMilliseconds() << "ms" << endl;

    cout << "Emitting signal" << endl;

    bt.start();
    testSignal(1, 2);
    bt.stop();
    cout << "Time to emit: " << bt.getElapsedMilliseconds() << "ms" << endl;

    ASSERT_NE(globalStaticIntX, 3);
    
    testSignal.invokeDeferred();
    
    ASSERT_EQ(globalStaticIntX, 3);

    testSignal.disconnectSlot(0);
}
Exemplo n.º 15
0
bool SignalModifier::convertToNotePressure(Signal &s)
{
    // reference counted Signal ( string command, string origin )
    Signal::SignalP midiSignal = new Signal("SEND_MIDI", "SIG_MOD");
    
    // allow this to set the MIDI Channel
    midiSignal->addStringArg("NOTE");
    midiSignal->addIntArg(1);
    midiSignal->addIntArg(s.getArgAsInt32(1));
    int pressureValue = int((s.getArgAsInt32(2)/1024.00)*127.00);
    midiSignal->addIntArg(pressureValue);
    
    _mCenter->handleSignal(*midiSignal); 
    
    // reference counted Signal ( string command, string origin )
    Signal::SignalP ledStateSignal = new Signal("SEND_OSC", "SIG_MOD");
    
    ledStateSignal->addStringArg("/nomestate/grid/led/set");
    // get the x position: LED bumber % 8
    ledStateSignal->addIntArg(s.getArgAsInt32(1) % 8);
    // get the y position: LED number / 8
    ledStateSignal->addIntArg(s.getArgAsInt32(1) / 8);
    // get the LED state: toggleState
    int state = 0;
    
    if(s.getArgAsInt32(2) > 0) 
        state = 1;
    
    ledStateSignal->addIntArg(state);
    
    _mCenter->handleSignal(*ledStateSignal); 
    
    return true;
}
Exemplo n.º 16
0
Arquivo: main.cpp Projeto: CCJY/coliru
 int main()
 {
     Signal<int> sig;
     sig.AddListener(argHandler);
     sig.AddListener(noargHandler);
     
     sig.Dispatch(22);
 }
Exemplo n.º 17
0
	void SegmentDescription::BuildSignal(Signal & signal) const
	{
		signal.Reset();
		for (size_t i = 0; i < cores.size(); ++i)
		{
			cores[i].AddToArray(signal.GetData(), signal.GetDesc().N);
		}
	}
Exemplo n.º 18
0
Arquivo: main.cpp Projeto: CCJY/coliru
 int main()
 {
     Signal<int, int> sig;
     sig.AddListener(twoArgHandler);
     sig.AddListener([](int a, int b) { oneArgHandler(a); });
     sig.AddListener(noArgHandler);
     
     sig.Dispatch(22, 12);
 }
Exemplo n.º 19
0
TEST(lagi_signal, basic) {
	Signal<> s;
	int x = 0;
	Connection c = s.Connect(increment(x));

	EXPECT_EQ(0, x);
	s();
	EXPECT_EQ(1, x);
}
Exemplo n.º 20
0
TEST(core_signal_test, can_add_and_execute_free_function) {
  Signal signal;

  signal.connect(&Foo);
  ASSERT_EQ(5, foo);

  signal(10);
  ASSERT_EQ(10, foo);
}
Exemplo n.º 21
0
string Operator::buildVHDLSignalDeclarations() {
	ostringstream o;
	for(unsigned int i=0; i<signalList_.size(); i++) {
		Signal *s = signalList_[i];
		o << s->toVHDLDeclaration() << endl;
	}
	
	return o.str();	
}
Exemplo n.º 22
0
//returns whether the connection was propagated successfully
bool Connection::send(Signal& S) 
{
//weigh the signal down by this connection's weight
  S.weigh(weight);
  activation = S.get();
  if(!connectionEstablished())
    return false;
  return allNeurons[to] -> receive(S);
}
Exemplo n.º 23
0
TEST(core_signal_test, can_add_and_execute_static_method) {
  Signal signal;

  signal.connect(&TestStruct::Foo);
  ASSERT_EQ(1, TestStruct::foo);

  signal(4);
  ASSERT_EQ(4, TestStruct::foo);
}
Exemplo n.º 24
0
TEST(core_signal_test, empty_slot_is_not_same_as_no_slot) {
  Signal signal;

  signal.connect();
  ASSERT_EQ(1u, signal.size());

  signal.connect(Signal::Slot());
  ASSERT_EQ(2u, signal.size());
}
Exemplo n.º 25
0
	void Polynom::AddToSignal(Signal & signal) const
	{
		const SignalDescription & d = signal.GetDesc();
		double * data = signal.GetData();
		for (int i = 0; i < d.N; ++i)
		{
			data[i] += (*this)(d.startTime + i * d.dt);
		}
	}
Exemplo n.º 26
0
Handle<Value> Signal_IsDisconnected(Local<String> property, const AccessorInfo &info)
{
    HandleScope handle_scope;

    Signal* self = GetPtr(info.This());
    assert(self);

    return handle_scope.Close(Boolean::New(self->isDisconnected()));
}
Exemplo n.º 27
0
TEST(lagi_signal, basic) {
	Signal<> s;
	int x = 0;
	Connection c = s.Connect([&] { ++x; });

	EXPECT_EQ(0, x);
	s();
	EXPECT_EQ(1, x);
}
Exemplo n.º 28
0
 virtual void onReadValue(const Signal &signal)
 {
     cout << "digital probe [" << mName << "]: ";
     if(signal.isHigh()) cout << "HIGH";
     else if(signal.isUndefined()) cout << "UNDEFINED";
     else if(signal.isLow()) cout << "LOW";
     else cout << "ERROR";
     cout << endl;
 }
void Convolve::start(Signal &signal, Kernel &kernel) {

  write(signal.getUnpaddedSize(),RA_SIZE);
  write(0,RA_IN_START_ADDR);
  write(0,RA_OUT_START_ADDR);

  write(signal.getSignal(), signal.getSize(), 0, MEM_SRAM_0);
  write(kernel.getKernel(), kernel.getSize(), RA_KERNEL);
  write(1,RA_GO); 
}
Exemplo n.º 30
0
TEST(core_signal_test, can_add_and_execute_method) {
  Signal signal;
  TestStruct testStruct;

  signal.connect(&TestStruct::Boo, &testStruct, std::placeholders::_1);
  ASSERT_EQ(2, testStruct.boo);

  signal(9);
  ASSERT_EQ(9, testStruct.boo);
}