<commit_before>#include <iostream>
#include <string>
#include <cmath>

#include "pulseTrain.hpp"

std::ostream& operator<<(std::ostream & os, const freqPulse& pulse) {
	os << "Pulse " << pulse.myFrequency << "MHz for " << pulse.myDuration << "ns with amplitude of " << pulse.myAmplitude;
	os << " and phase " << pulse.myPhase << "*pi";
	os << (pulse.myMarkStart ? ", with " : ", without ") << "initial marker and ";
	os << (pulse.myMarkDuration ? "with " : "without ") << "duration marker.";
	return os;
}

std::string freqPulse::getMarkerChars(const unsigned int numPoints, unsigned int startMarkerPoints){
	std::string markerChars = "";
	markerChars.reserve(numPoints+1);

	if ( startMarkerPoints > numPoints ) startMarkerPoints = numPoints;

	if ( ! myMarkStart ) {
		unsigned char durationOnly = (myMarkDuration ? 0x01 : 0x00);
		for (unsigned int i = 0; i < numPoints; i++) markerChars += durationOnly;
	} else {
		unsigned char startPart	= (myMarkDuration ? 0x03 : 0x02);
		unsigned char endPart	= (myMarkDuration ? 0x01 : 0x00);
		unsigned int i;

		for (i = 0; i < startMarkerPoints; i++) markerChars += startPart;
		for (i = startMarkerPoints; i < numPoints; i++) markerChars += endPart;
	}

	return markerChars;
}

unsigned int freqPulse::getNumPoints(const double samplePeriod, const bool nearestHalfCycle) {
	if (! nearestHalfCycle) return ((unsigned int) myDuration/samplePeriod);

	double halfCycles = round(myDuration * myFrequency * 2.0 * 0.001 /*ns*MHz*/) / 2.0;
	return (unsigned int) floor(halfCycles * (1000.0/myFrequency)/samplePeriod);
}


std::string freqPulse::getWaveChars(const double samplePeriod, const unsigned int numPoints) {
	unsigned char waveBuffer[numPoints];
	const double TwoPi = 6.28318530717958647692; // NOT tau, that's just wrong
	const double phasePerSample = TwoPi * myFrequency * samplePeriod * 0.001 /* ns * MHz*/;

	for (unsigned int i = 0; i < numPoints; i++) {
		static double point;
		point = 127.0  + (127.0 * myAmplitude * sin(phasePerSample * ((double) i) + myPhase));
		waveBuffer[i] = (unsigned char) round(point);
	}

	return std::string((char *) waveBuffer, numPoints);
}

std::string pulseTrain::getMarkerChars(const double samplePeriod, const unsigned int numPoints, const bool nearestHalfCycle, const unsigned int startMarkerPoints) {
	// STUB
	return "";
}

std::string pulseTrain::getWaveChars(const double samplePeriod, const unsigned int numPoints, const bool nearestHalfCycle) {
	// STUB
	return "";
}

unsigned int pulseTrain::getNumPoints(const double samplePeriod, const bool nearestHalfCycle) {
	// STUB
	return 0;
}<commit_msg>Implement pulseTrain::getNumPoints()<commit_after>#include <iostream>
#include <string>
#include <cmath>

#include "pulseTrain.hpp"

std::ostream& operator<<(std::ostream & os, const freqPulse& pulse) {
	os << "Pulse " << pulse.myFrequency << "MHz for " << pulse.myDuration << "ns with amplitude of " << pulse.myAmplitude;
	os << " and phase " << pulse.myPhase << "*pi";
	os << (pulse.myMarkStart ? ", with " : ", without ") << "initial marker and ";
	os << (pulse.myMarkDuration ? "with " : "without ") << "duration marker.";
	return os;
}

std::string freqPulse::getMarkerChars(const unsigned int numPoints, unsigned int startMarkerPoints){
	std::string markerChars = "";
	markerChars.reserve(numPoints+1);

	if ( startMarkerPoints > numPoints ) startMarkerPoints = numPoints;

	if ( ! myMarkStart ) {
		unsigned char durationOnly = (myMarkDuration ? 0x01 : 0x00);
		for (unsigned int i = 0; i < numPoints; i++) markerChars += durationOnly;
	} else {
		unsigned char startPart	= (myMarkDuration ? 0x03 : 0x02);
		unsigned char endPart	= (myMarkDuration ? 0x01 : 0x00);
		unsigned int i;

		for (i = 0; i < startMarkerPoints; i++) markerChars += startPart;
		for (i = startMarkerPoints; i < numPoints; i++) markerChars += endPart;
	}

	return markerChars;
}

unsigned int freqPulse::getNumPoints(const double samplePeriod, const bool nearestHalfCycle) {
	if (! nearestHalfCycle) return ((unsigned int) myDuration/samplePeriod);

	double halfCycles = round(myDuration * myFrequency * 2.0 * 0.001 /*ns*MHz*/) / 2.0;
	return (unsigned int) floor(halfCycles * (1000.0/myFrequency)/samplePeriod);
}


std::string freqPulse::getWaveChars(const double samplePeriod, const unsigned int numPoints) {
	unsigned char waveBuffer[numPoints];
	const double TwoPi = 6.28318530717958647692; // NOT tau, that's just wrong
	const double phasePerSample = TwoPi * myFrequency * samplePeriod * 0.001 /* ns * MHz*/;

	for (unsigned int i = 0; i < numPoints; i++) {
		static double point;
		point = 127.0  + (127.0 * myAmplitude * sin(phasePerSample * ((double) i) + myPhase));
		waveBuffer[i] = (unsigned char) round(point);
	}

	return std::string((char *) waveBuffer, numPoints);
}

std::string pulseTrain::getMarkerChars(const double samplePeriod, const unsigned int numPoints, const bool nearestHalfCycle, const unsigned int startMarkerPoints) {
	// STUB
	return "";
}

std::string pulseTrain::getWaveChars(const double samplePeriod, const unsigned int numPoints, const bool nearestHalfCycle) {
	// STUB
	return "";
}

unsigned int pulseTrain::getNumPoints(const double samplePeriod, const bool nearestHalfCycle) {
	unsigned int totalPoints = 0;

	for (std::deque<freqPulse>::iterator thisPulse = myPulses.begin(); thisPulse != myPulses.end(); thisPulse++) {
		totalPoints += thisPulse->getNumPoints(samplePeriod, nearestHalfCycle);
	}

	return totalPoints;
}
{'fraction_non_alphanumeric': 0.13332107392423684, 'fraction_numerical': 0.025376976829716808, 'mean_word_length': 5.009944751381216, 'pattern_counts': {'":': 0, '<': 74, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2837065', 'n_tokens_mistral': 1903, 'n_tokens_neox': 1697, 'n_words': 488}