//the entry point of our application int main(int argc, char **argv) { // generate the stereo whitenoise offset effect { // sound format parameters const int c_sampleRate = 44100; const int c_numSeconds = 4; const int c_numChannels = 2; const int c_numSamples = c_sampleRate * c_numChannels * c_numSeconds; // make space for our samples std::vector<float> samples; samples.resize(c_numSamples); // generate samples GenerateSamples(samples, c_sampleRate); // convert from float to the final format std::vector<int32> samplesInt; ConvertFloatSamples(samples, samplesInt); // write our samples to a wave file WriteWaveFile("stereonoise.wav", samplesInt, c_numChannels, c_sampleRate); } }
void CvOneWayDescriptor::Initialize(int pose_count, IplImage* frontal, const char* feature_name, int norm) { m_feature_name = std::string(feature_name); CvRect roi = cvGetImageROI(frontal); m_center = rect_center(roi); Allocate(pose_count, cvSize(roi.width, roi.height), frontal->nChannels); GenerateSamples(pose_count, frontal, norm); }
void AudioEngine::ExecuteCallback(u8 *stream, int len) { for (;;) { // Generate samples if (_samplesRemaining > 0) { int sampleCount = _samplesRemaining; if (sampleCount >= len) { sampleCount = len; GenerateSamples(stream, sampleCount); // Buffer has been filled completely. // Update samples remaining and return. _samplesRemaining -= sampleCount; return; } else { GenerateSamples(stream, sampleCount); stream += sampleCount; len -= sampleCount; _samplesRemaining = 0; } } // Process audio events from the emulator ProcessAudioEvents(); if (!_eventPending) { // Event queue is empty. // // Do a few more samples with the current channel settings or finish the buffer if it // is almost full. _samplesRemaining = WAIT_NUM_SAMPLES; if (_samplesRemaining > len) _samplesRemaining = len; } } }
void GenerateBatchSamples(const AnnotatedDatum& anno_datum, const vector<BatchSampler>& batch_samplers, vector<NormalizedBBox>* sampled_bboxes) { sampled_bboxes->clear(); vector<NormalizedBBox> object_bboxes; GroupObjectBBoxes(anno_datum, &object_bboxes); for (int i = 0; i < batch_samplers.size(); ++i) { if (batch_samplers[i].use_original_image()) { NormalizedBBox unit_bbox; unit_bbox.set_xmin(0); unit_bbox.set_ymin(0); unit_bbox.set_xmax(1); unit_bbox.set_ymax(1); GenerateSamples(unit_bbox, object_bboxes, batch_samplers[i], sampled_bboxes); } } }
//================================================================================= int main (int argc, char **argv) { // Enable Unicode UTF-16 output to console _setmode(_fileno(stdout), _O_U16TEXT); // You can test specific data samples like this: //std::vector<TRealType> sourceData = { 1, 0, 1, 0 }; //std::vector<TRealType> sourceData = { 1, -1, 1, -1 }; // Or you can generate data samples from a function like this std::vector<TRealType> sourceData = GenerateSamples( 4, [] (TRealType percent) { const TRealType c_frequency = TRealType(1.0); return cos(percent * c_twoPi * c_frequency); } ); // Show the source data wprintf(L"\nSource = [ "); for (TRealType v : sourceData) wprintf(L"%f ",v); wprintf(L"]\n\n"); // Do a dft and show the results std::vector<TComplexType> dft = DFTSamples(sourceData); wprintf(L"dft = [ "); for (TComplexType v : dft) wprintf(L"(%f, %f) ", v.real(), v.imag()); wprintf(L"]\n\n"); // Do an inverse dft of the dft data, and show the results std::vector<TRealType> idft = IDFTSamples(dft); wprintf(L"idft = [ "); for (TRealType v : idft) wprintf(L"%f ", v); wprintf(L"]\n"); return 0; }
void GenerateSamplePointSet_PointCloud_SurfaceNoise( cisstMesh &mesh, TestParameters ¶ms, unsigned int randSeed, unsigned int &randSeqPos, std::ifstream &randnStream, vctDynamicVector<vct3> &samples, vctDynamicVector<vct3> &sampleNorms, vctDynamicVector<vct3> &noisySamples, unsigned int trialNum) { // get custom params CustomTestParams_PointCloud_SurfaceNoise *pCustomParams = dynamic_cast<CustomTestParams_PointCloud_SurfaceNoise*>(params.pCustomTestParams); std::stringstream saveSamplesPath; std::stringstream saveNoisySamplesPath; std::stringstream saveNoiseCovPath; saveSamplesPath << params.outputCommonDir << "/SaveSamples_" << trialNum << ".pts"; saveNoisySamplesPath << params.outputCommonDir << "/SaveNoisySamples_" << trialNum << ".pts"; saveNoiseCovPath << params.outputCommonDir << "/SaveNoiseCov_" << trialNum << ".txt"; std::string strSaveSamplesPath = saveSamplesPath.str(); std::string strSaveNoisySamplesPath = saveNoisySamplesPath.str(); std::string strSaveNoiseCovPath = saveNoiseCovPath.str(); std::string *pSaveSamplesPath = &strSaveSamplesPath; std::string *pSaveNoisySamplesPath = &strSaveNoisySamplesPath; std::string *pSaveNoiseCovPath = &strSaveNoiseCovPath; #ifdef DISABLE_OUTPUT_FILES pSaveSamplesPath = NULL; pSaveNoisySamplesPath = NULL; pSaveNoiseCovPath = NULL; #endif vctDynamicVector<unsigned int> sampleDatums(params.nSamples); vctDynamicVector<vct3x3> sampleCov(params.nSamples, vct3x3(0.0)); vctDynamicVector<vct3x3> noiseCov(params.nSamples, vct3x3(0.0)); vctDynamicVector<vct3x3> surfaceModelCov(params.nSamples, vct3x3(0.0)); //vctDynamicVector<vct3x3> noiseInvCov(params.nSamples, vct3x3(0.0)); // Generate Samples GenerateSamples( mesh, randSeed, randSeqPos, params.nSamples, samples, sampleNorms, sampleDatums, pSaveSamplesPath); // Generate Sample Noise GenerateSampleErrors_SurfaceNoise( randSeed, randSeqPos, randnStream, pCustomParams->sampleNoise_InPlaneSD, pCustomParams->sampleNoise_PerpPlaneSD, samples, sampleNorms, noisySamples, noiseCov, //noiseInvCov, pCustomParams->percentOutliers, pCustomParams->minPosOffsetOutlier, pCustomParams->maxPosOffsetOutlier, pSaveNoisySamplesPath, pSaveNoiseCovPath); // Set Samples in Algorithm switch (params.algType) { case TestParameters::StdICP: { // configure algorithm samples cisstAlgorithmICP_StdICP *pAlg = dynamic_cast<cisstAlgorithmICP_StdICP*>(params.pAlg); pAlg->SetSamples(noisySamples); break; } case TestParameters::IMLP: { std::stringstream saveSampleCovPath; std::stringstream saveSurfaceModelCovPath; saveSampleCovPath << params.outputDataDir << "/SaveSampleCov_" << trialNum << ".txt"; saveSurfaceModelCovPath << params.outputDataDir << "/SaveSurfaceModelCov_" << trialNum << ".txt"; std::string strSaveSampleCovPath = saveSampleCovPath.str(); std::string strSaveSurfaceModelCovPath = saveSurfaceModelCovPath.str(); std::string *pSaveSampleCovPath = &strSaveSampleCovPath; std::string *pSaveSurfaceModelCovPath = &strSaveSurfaceModelCovPath; #ifdef MINIMIZE_OUTPUT_FILES pSaveSampleCovPath = NULL; pSaveSurfaceModelCovPath = NULL; #endif #ifdef DISABLE_OUTPUT_FILES pSaveSampleCovPath = NULL; pSaveSurfaceModelCovPath = NULL; #endif unsigned int nSamps = samples.size(); // Set Sample Covariances // noise covariance if (pCustomParams->bSampleCov_ApplyNoiseModel) { for (unsigned int i = 0; i < nSamps; i++) { sampleCov(i) += noiseCov(i); } } // surface model covariance if (pCustomParams->bSampleCov_ApplySurfaceModel) { // compute surface model ComputeCovariances_SurfaceModel( pCustomParams->surfaceModel_InPlaneSD, pCustomParams->surfaceModel_PerpPlaneSD, samples, sampleNorms, surfaceModelCov, pSaveSurfaceModelCovPath); // add suface model to sample covariances for (unsigned int i = 0; i < nSamps; i++) { sampleCov(i) += surfaceModelCov(i); } } // save sample covariances if (pSaveSampleCovPath) { WriteToFile_Cov(sampleCov, *pSaveSampleCovPath); } // configure algorithm samples cisstAlgorithmICP_IMLP *pAlg = dynamic_cast<cisstAlgorithmICP_IMLP*>(params.pAlg); //cisstAlgorithmICP_IMLP_PointCloud *pAlg = dynamic_cast<cisstAlgorithmICP_IMLP_PointCloud*>(params.pAlg); if (!pAlg) { std::cerr << "ERROR: algorithm class unrecognized class" << std::endl; } //pAlg->SetSamples(noisySamples); //pAlg->SetSampleCovariances(sampleCov); pAlg->SetSamples(noisySamples); pAlg->SetSampleCovariances(sampleCov, noiseCov); break; } case TestParameters::RobustICP: { // configure algorithm samples cisstAlgorithmICP_RobustICP *pAlg = dynamic_cast<cisstAlgorithmICP_RobustICP*>(params.pAlg); pAlg->SetSamples(noisySamples); break; } //case TestParameters::CPD: //{ // break; //} default: std::cout << std::endl << "=====> ERROR: Algorithm Type not Recognized by Sample Generator" << std::endl << std::endl; assert(0); break; } // switch AlgType }
void Ym3812::UpdateSoundBuffer(Dword frameNumber, SoundBufferData & soundBuffer) { Qword currentTime = timer.GetTime(); //If this is the first call to UpdateSoundBuffer, or there are no samples to update if(frameNumber == 1 || soundBuffer.numSamples == 0) { //Apply all of the register writes for(std::vector <RegisterWrite>::const_iterator i = registerWrites.begin(); i != registerWrites.end(); ++i) { ApplyRegisterWrite(i->address, i->data); } } else { //Otherwise, convert the times stored with the register writes into sample numbers for(std::vector <RegisterWrite>::iterator i = registerWrites.begin(); i != registerWrites.end(); ++i) { i->numSamples = static_cast<Dword>( ((i->time - lastUpdateTime) * soundBuffer.numSamples) / (currentTime - lastUpdateTime)); } //Allocate a temporary data buffer #ifdef USE_FMOPL std::vector <SignedWord> dataBuffer(soundBuffer.numSamples); #endif #ifdef USE_YM3812_CHANNEL std::vector <SignedDword> dataBuffer(soundBuffer.numSamples); #endif //Loop through the register writes Dword sample = 0; for(std::vector <RegisterWrite>::const_iterator i = registerWrites.begin(); i != registerWrites.end(); ++i) { //Generate samples up to the point of this write Dword samplesToGenerate = i->numSamples - sample; GenerateSamples(samplesToGenerate, &dataBuffer[sample]); sample += samplesToGenerate; //Apply the register write ApplyRegisterWrite(i->address, i->data); } //Generate the remaining samples GenerateSamples(soundBuffer.numSamples - sample, &dataBuffer[sample]); //Copy the data to the sound buffer for(Dword i = 0; i < soundBuffer.numSamples; ++i) { soundBuffer.data[i * 2 ] += dataBuffer[i]; soundBuffer.data[i * 2 + 1] += dataBuffer[i]; } } registerWrites.clear(); lastUpdateTime = currentTime; }
Hammersley::Hammersley(const int numSamples, const int numSets) : Sampler(numSamples, numSets) { GenerateSamples(); }