/**
 *  Handle the correlation whether or not we have position information
 */
void ImplantSsdProcessor::Correlate(Correlator &corr, EventInfo &info, int location)
{
    if ( isnan(info.position) ) {
	corr.CorrelateAllY(info, location);
    } else {
	corr.Correlate(info, location, int(info.position));
    }
    // if we want to neglect position information using a dummy variable,
    //   uncomment this line, and comment out the above
    // corr.Correlate(info, location, 1)
    PlotType(info, location, corr.GetCondition());
}
示例#2
0
/*----------------------------------------------------------------------------------------------*/
void *Correlator_Thread(void *_arg)
{

	Correlator *aCorrelator = pCorrelator;

	while(grun)
	{
		aCorrelator->Import();
		aCorrelator->Correlate();
		aCorrelator->IncExecTic();
	}

	pthread_exit(0);

}
示例#3
0
 void reduce(r_exec::View *input)
 {
     CorrelatorOutput *output = correlator->get_output();
     output->trace();
     // TODO: exploit the output: build rgroups and inject data therein.
     //decompile(0);
     // For now, we do not retrain the Correlator on more episodes: we build another correlator instead.
     // We could also implement a method (clear()) to reset the existing correlator.
     //delete correlator;
     //correlator=new Correlator();
 }
示例#4
0
    void decompile(uint64_t time_offset)
    {
        r_comp::Image *image = r_exec::_Mem::Get()->get_objects();
        uint64_t object_count = decompiler.decompile_references(image);
        // from here on is different, by Bas
        static void* inst;
        struct OID2string {
            r_comp::Decompiler& decompiler;
            r_code::vector<r_code::SysObject*>& objects;
            uint64& object_count;
            uint64& time_offset;

            OID2string(r_comp::Decompiler& d, r_code::vector<r_code::SysObject*>& o, uint64& c, uint64& t):
                decompiler(d), objects(o), object_count(c), time_offset(t)
            {
                inst = this;
            }

            static std::string wrapper(uint64_t id)
            {
                return ((OID2string*)inst)->impl(id);
            }

            std::string impl(uint64_t id)
            {
                for (uint16_t j = 0; j < object_count; ++j)
                    if (objects[j]->oid == id) {
                        std::ostringstream decompiled_code;
                        decompiler.decompile_object(j, &decompiled_code, time_offset);
                        std::string s = decompiled_code.str();

                        for (size_t found = s.find("\n"); found != std::string::npos; found = s.find("\n")) {
                            s.replace(found, 1, " ");
                        }

                        return s;
                    }

                return "";
            }
        } closure(decompiler, image->code_segment.objects, object_count, time_offset);
        char buf[33];
        std::ofstream file((std::string("_DATA_") + itoa(rand(), buf, 10) + ".txt").c_str(), std::ios_base::trunc);

        if (file.is_open()) {
            correlator->dump(file, OID2string::wrapper);
        } else {
            std::cout << "ERROR" << std::endl;
        }

        delete image;
    }
示例#5
0
    void take_input(r_exec::View *input)
    {
        static bool once = false;

        if (once) {
            return;
        }

        // Inputs are all types of objects - salient or that have become salient depending on their view's sync member.
        // Manual filtering is needed instead of pattern-matching.
        // Here we take all inputs until we get an episode notification.
        std::string episode_end = "episode_end";

        if (input->object->code(0).asOpcode() == r_exec::Metadata.get_class(episode_end)->atom.asOpcode()) {
            //r_exec::ReductionJob<CorrelatorController> *j=new r_exec::ReductionJob<CorrelatorController>(input,this);
            //r_exec::_Mem::Get()->pushReductionJob(j);once=true;
            reduce(input);
            once = true;
        } else { //std::cout<<"input\n";
            correlator->take_input(input);
        }
    }
示例#6
0
int main(int argc, char** argv)
{
    try
    {
        //======================================================================
        // process given command line
        std::cout << SPLASH_MSG;
        parseCommandLine(argc, argv);


        //======================================================================
        // parse XDL file
        Design design;
        Device device;
        std::string devicePackageName;
        {
            // open XDL file and parse its header
            std::cout << PARSING_XDL_HEADER_MSG;
            XDLParser parser;
            std::ifstream xdlInputStream(xdlFileName.c_str());
            parser.parseHeader(xdlInputStream, design);
            devicePackageName = removeSpeed((design.deviceName()).c_str());

            // load device file of corresponding device
            std::cout << LOADING_DEVICE1_MSG << devicePackageName << LOADING_DEVICE2_MSG;
            std::string deviceFileName = dataPathName + devicePackageName + DEVICE_FILE_EXT;
            std::ifstream deviceInputStream(deviceFileName.c_str(), std::ios::binary);
            readBinary(device, deviceInputStream);

            // parse XDL
            std::cout << PARSING_XDL_MSG;
            parser.parseBody(device);
        }

        //======================================================================
        // load configuration tile map
        V5CfgTileMap cfgTileMap;
        {
            std::cout << LOADING_CFGTILEMAP_MSG;
            std::string mapFileName = dataPathName + devicePackageName + MAP_FILE_EXT;
            std::ifstream mapInputStream(mapFileName.c_str(), std::ios::binary);
            readBinary(cfgTileMap, mapInputStream);
        }

        //======================================================================
        // get configuration data from bitstream
        V5AddressLayoutRegistry addressLayoutRegistry;
        V5PacketProcessor packetProcessor(addressLayoutRegistry);
        V5Configuration& configuration = packetProcessor.configuration();
        {
            // load bitfile
            std::cout << LOADING_BITFILE_MSG;
            BitFileData bfd;
            std::ifstream bitfileStream(bitFileName.c_str(), std::ios::binary);
            readBitfile(bfd, bitfileStream);

            // construct bitstream from bitfile raw data
            std::cout << DECODING_BITSTREAM_MSG;
            Bitstream bs;
            readV5Bitstream(bs, bfd.bitstreamWords(), bfd.bitstreamWordCount());
            bfd.bitstreamWordCount(0);

            // read in available devices
            std::cout << LOADING_DEVICELIST_MSG;
            std::string deviceListFileName = dataPathName + V5DEVICES_FILENAME;
            std::ifstream lstFileStream(deviceListFileName.c_str(), std::ios::binary);
            DeviceRegistry deviceRegistry;
            readBinary(deviceRegistry, lstFileStream);

            // load address layout
            std::string deviceName = removePackageAndSpeed(devicePackageName.c_str());
            std::cout << LOADING_ADDRESSLAYOUT1_MSG << deviceName << LOADING_ADDRESSLAYOUT2_MSG;
            V5AddressLayout addressLayout;
            std::string calFileName = dataPathName + deviceName + CAL_FILE_EXT;
            std::ifstream calFileStream(calFileName.c_str(), std::ios::binary);
            readBinary(addressLayout, calFileStream);
            DeviceID::ID_t deviceID = deviceRegistry.lookup(deviceName);
            addressLayoutRegistry.insert(deviceID, addressLayout);

            // execute bitstream
            std::cout << EXECUTING_BITSTREAM_MSG;
            bs.runVisitor(packetProcessor);
        }


        //======================================================================
        // do correlation
        DeviceCfgDb cfgDatabase;
        std::cout << DOING_CORRELATION_MSG;
        {
            Correlator correlator;
            V5CfgExtractor cfgExtractor(configuration, cfgTileMap);
            correlator.run(cfgDatabase, design, device, cfgExtractor);
        }


        //======================================================================
        // save configuration mapping database
        std::cout << WRITING_DATABASE_MSG;
        std::ofstream dbFileStream(dbFileName.c_str(), std::ios::binary);
        writeBinary(cfgDatabase, dbFileStream);


        //======================================================================
        // write out stats
        std::cout << WRITING_STATS_MSG;
        {
            std::ofstream statsFileStream(statsFileName.c_str());
            DeviceCfgDbStats statsPrinter;
            statsPrinter.printStats(cfgDatabase, device, statsFileStream);
        }


        //======================================================================
        // finished
        std::cout << FINISHED_MSG;
    }
    catch (const CommandLineException& e)
    {
        std::cout << ERROR_MSG << e.what() << INFO_MSG;
        return EXIT_FAILURE;
    }
    catch (...)
    {
        std::cout << ERROR_UNKNOWN_MSG;
        return EXIT_FAILURE;
    }
    return EXIT_SUCCESS;
}
示例#7
0
void SoundPortReader::run() {
	cout << " SoundPortReader" << endl;
	while (!stoploop) {
		sound = in->read();
		//Checking if the bottle is good
		if (sound != NULL) {
//			cout << "Freq: " << sound->getFrequency() << ", Bytes: "
//					<< sound->getBytesPerSample() << ", Chan: "
//					<< sound->getChannels() << ", Samples: "
//					<< sound->getSamples() << endl;

//Fill buffer
			if (buffer.size() < BUFFER_SIZE) {
				buffer.push_back(*sound);
			} else {
				buffer.erase(buffer.begin());
				buffer.push_back(*sound);
			}

			//Create sound window
			Sound volume_buffer;
			volume_buffer.resize(buffer.size() * sound->getSamples(), 2);
			for (int i = 0; i < buffer.size(); i++) {
				Sound* tmp = &buffer[i];
				for (int j = 0; j < tmp->getSamples(); j++) {
					volume_buffer.setSafe(tmp->getSafe(j, 0),
							j + i * tmp->getSamples(), 0);
					volume_buffer.setSafe(tmp->getSafe(j, 1),
							j + i * tmp->getSamples(), 1);
				}
			}

			//Filter window
			float** signal = new float*[2];

			signal[0] = new float[volume_buffer.getSamples()];
			signal[1] = new float[volume_buffer.getSamples()];
			for (int i = 0; i < volume_buffer.getSamples(); i++) {
				signal[0][i] = pcmToFloat(volume_buffer.getSafe(i, 0));
				signal[1][i] = pcmToFloat(volume_buffer.getSafe(i, 1));
				if (signal[0][i] > 1.0 || signal[0][i] < -1.0
						|| signal[1][i] > 1.0 || signal[1][i] < -1.0) {
					cerr << "++++++Wrong transformation+++++++";
				}
			}
			float** filtered = new float*[2];
			filtered[0] = signaleProcessor->process(signal[0],
					volume_buffer.getSamples());
			filtered[1] = signaleProcessor->process(signal[1],
					volume_buffer.getSamples());
			for (int i = 0; i < volume_buffer.getSamples(); i++) {
				volume_buffer.setSafe(floatToPcm(filtered[0][i]), i, 0);
				volume_buffer.setSafe(floatToPcm(filtered[1][i]), i, 1);
			}

//			Convert
			float** samples = new float*[2];
			samples[0] = new float[volume_buffer.getSamples()];
			samples[1] = new float[volume_buffer.getSamples()];
			for (int i = 0; i < volume_buffer.getSamples(); i++) {
				samples[0][i] = pcmToFloat(volume_buffer.getSafe(i, 0));
				if (volume_buffer.getChannels() == 2) {
					samples[1][i] = pcmToFloat(volume_buffer.getSafe(i, 1));
				}
			}

			//Correlate
			Correlator correlator;
			float** envelope = new float*[2];
			float** onsets = new float*[2];
			envelope[0] = correlator.createEnvelope(samples[0],
					volume_buffer.getSamples());
			onsets[0] = correlator.createOnsets(envelope[0],
					volume_buffer.getSamples());
			if (volume_buffer.getChannels() == 2) {
				envelope[1] = correlator.createEnvelope(samples[1],
						volume_buffer.getSamples());
				onsets[1] = correlator.createOnsets(envelope[1],
						volume_buffer.getSamples());
			}
			int distance = correlator.crossCorrelate(onsets,
					volume_buffer.getSamples());
//			for (int i = 0; i < sound->getSamples(); i++)
//				cout << samples[0][i] << " -> " << envelope[0][i] << "\t->\t"
//						<< onsets[0][i] << endl;
			float angle = correlator.getAngle(distance, sound->getFrequency());
//			cout << "Distance: " << distance << " -> " << angle << endl;

			for (int i = 0; i < 2; i++) {
				delete[] envelope[i];
				delete[] onsets[i];
				delete[] samples[i];
				delete[] signal[i];
				delete[] filtered[i];
			}
			delete[] envelope;
			delete[] onsets;
			delete[] samples;
			delete[] signal;
			delete[] filtered;

//			for(int i = 0; i < check.getSamples(); i++) {
//				cout<<"Right >>>> "<<check.getSafe(i,0)<<" -> "<<signal[0][i]<<" -> "<<volume_buffer.getSafe(i,0)<<endl;
//				cout<<"Left  >>>> "<<check.getSafe(i,1)<<" -> "<<signal[1][i]<<" -> "<<volume_buffer.getSafe(i,1)<<endl;
//			}

//Check volume
			int direction = volume->getLoudestChannel(volume_buffer);
			switch (direction) {
			case -1:
				cout << "Center" << endl;
				break;
			case 0:
				cout << "---------Right :" << volume->getDistance() << endl;
				break;
			case 1:
				cout << "+++++++++Left  :" << volume->getDistance() << endl;
				break;
			default:
				cout << "Unknown" << endl;
				break;
			}

			if (direction >= 0) {
				out->prepare() = saliancyMapCreator.createMap(direction,
						volume->getVolume(volume_buffer, direction),
						volume->getDistance());
				out->write();
				saliancyMapCreator.freeMap();
			}

//			if (buffer.size() == BUFFER_SIZE) {
//				for (int i = BUFFER_SIZE / 2; i < sound->getSamples(); i++) {
//					sound->setSafe(volume_buffer.getSafe(i, 0), i, 0);
//					sound->setSafe(volume_buffer.getSafe(i, 1), i, 1);
//				}
//			}
//			//Save if specified
//			if (filename != "") {
//				if (output.getSamples() == 0) {
//					output = *sound;
//				} else {
//					int i = output.getSamples();
////					cout << i << endl;
//					Sound tmp = output;
//					output.resize(sound->getSamples() + i,
//							sound->getChannels());
//					for (int k = 0; k < i; k++) {
//						output.setSafe(tmp.getSafe(k, 0), k, 0);
//						output.setSafe(tmp.getSafe(k, 1), k, 1);
//					}
////					cout << output.getSamples() << endl;
//					int j = 0;
//					for (; i < output.getSamples(); i++) {
//						output.setSafe(sound->getSafe(j, 0), i, 0);
//						output.setSafe(sound->getSafe(j, 1), i, 1);
//						j++;
//					}
//				}
//			}
		}
	}
}