void HiJitCube::computePoly() { // Compute sample and line coordinates in the focal plane int samp0,sampN; if (originst) { samp0=jdata.fpSamp0 + jdata.sampOffset; sampN=samp0 + npSamps[jdata.cpmmNumber] - 1; } else { samp0=jdata.fpSamp0 + jdata.sampOffset; sampN=samp0 + Samples() - 1; } int line0(jdata.fpLine0 + jdata.lineOffset), lineN(line0 + Lines() - 1); // Allocate a new coordinate sequence and define it geos::geom::CoordinateSequence *pts = new geos::geom::CoordinateArraySequence(); pts->add(geos::geom::Coordinate(samp0, lineN)); pts->add(geos::geom::Coordinate(sampN, lineN)); pts->add(geos::geom::Coordinate(sampN, line0)); pts->add(geos::geom::Coordinate(samp0, line0)); pts->add(geos::geom::Coordinate(samp0, lineN)); // Make this reentrant and delete previous one if it exists and get the // new one delete fpGeom; fpGeom = geosFactory.createPolygon(geosFactory.createLinearRing(pts), 0); return; }
void curves(void) { int i; for (i = entrysize-1; i>=0; i--) { Curve(i,entrydata[i]); } if (showSample) Samples(); }
ALuint Lecture::LoadSound(const std::string& Filename) { // Ouverture du fichier audio avec libsndfile SF_INFO FileInfos; SNDFILE* File = sf_open(Filename.c_str(), SFM_READ, &FileInfos); if (!File) { qDebug() << "Impossible d'ouvrir le fichier audio"; return 0; } // Lecture du nombre d'échantillons et du taux d'échantillonnage (nombre d'échantillons à lire par seconde) ALsizei NbSamples = static_cast<ALsizei>(FileInfos.channels * FileInfos.frames); ALsizei SampleRate = static_cast<ALsizei>(FileInfos.samplerate); // Lecture des échantillons audio au format entier 16 bits signé (le plus commun) std::vector<ALshort> Samples(NbSamples); if (sf_read_short(File, &Samples[0], NbSamples) < NbSamples) { qDebug() << "Impossible de lire les échantillons stockés dans le fichier audio"; return 0; } // Fermeture du fichier sf_close(File); // Détermination du format en fonction du nombre de canaux ALenum Format; switch (FileInfos.channels) { case 1 : Format = AL_FORMAT_MONO16; break; case 2 : Format = AL_FORMAT_STEREO16; break; default : qDebug() << "Format audio non supporté (plus de 2 canaux)"; return 0; } // Création du tampon OpenAL ALuint Buffer; alGenBuffers(1, &Buffer); // Remplissage avec les échantillons lus alBufferData(Buffer, Format, &Samples[0], NbSamples * sizeof(ALushort), SampleRate); // Vérification des erreurs if (alGetError() != AL_NO_ERROR) { qDebug() << "Impossible de remplir le tampon OpenAL avec les échantillons du fichier audio" ; return 0; } return Buffer; }
REFERENCE_TIME MediaChunk::GetDuration() { if (m_pTrack->IsAudio()) { return (m_tEnd - m_tStart); } else { return Samples() * m_pTrack->SampleDuration(); } }
void FBPPerformanceData::Update() { if (bDirty) { CachedExclusiveTime = 0.0; for (int32 Idx = 0; Idx < Samples.Num(); ++Idx) { CachedExclusiveTime += Samples(Idx); } CachedExclusiveTime /= GetSafeSampleCount(); bDirty = false; } }
int main(void) { typedef double RealType; typedef mcpack::utils::GaussPotentialEnergy<RealType> PotEngType; typedef PotEngType::RealVectorType RealVectorType; typedef PotEngType::RealMatrixType RealMatrixType; typedef RealMatrixType::Index IndexType; typedef mcpack::hamiltonian::GaussKineticEnergy<RealType> KinEngType; typedef mcpack::hamiltonian::LeapFrog<PotEngType,KinEngType> IntegratorType; typedef mcpack::utils::RandomVariateGenerator<RealType> RandVarGenType; typedef mcpack::hamiltonian::HMCProposal<IntegratorType,RandVarGenType> HMCProposalType; //typedef mcpack::hamiltonian::ClassicHMC<HMCProposalType> HMCType; typedef mcpack::hamiltonian::MPIInterChainClassicHMC<HMCProposalType> HMCType; const IndexType N=10; RealVectorType mu=RealVectorType::Zero(N); RealMatrixType SigmaInv=RealMatrixType::Identity(N,N); RealMatrixType MInv=RealMatrixType::Identity(N,N); RealVectorType q0=RealVectorType::Random(N); const RealType eps=1; const IndexType Nsteps=10; PotEngType G(mu,SigmaInv); KinEngType K(MInv); IntegratorType Lp(G,K); HMCProposalType prop(Lp,eps,Nsteps); HMCType hmc(prop,q0,12346l); const IndexType NSamples=1000; RealMatrixType Samples(NSamples,N); hmc.Generate(Samples); std::cout<<"Acceptace Rate= "<<hmc.GetAcceptanceRate()<<std::endl; return 0; }
void Run() { RealMatrixType Samples(m_RunCtrl.PacketSize(),m_RunCtrl.NumParas()); if(m_RunCtrl.Resume()) { WriteOutput2Console(std::string("Resuming from previous run"),m_RunCtrl.Silent()); if(m_RunCtrl.Continue()) { std::stringstream RandState; RandState<<m_RunCtrl.RandState(); m_Eng.SetRandState(RandState); RealVectorType ChainState= mcpack::utils::String2Vector<RealVectorType>(m_RunCtrl.ChainState(),std::string(" ")); m_Eng.SetStartPoint(ChainState); } else { WriteOutput2Console(std::string("Sampling already finished in the previous run"),m_RunCtrl.Silent()); } } else { WriteOutput2Console(std::string("Starting sampling from scratch"),m_RunCtrl.Silent()); } while(m_RunCtrl.Continue()) { std::stringstream RandState; m_Eng.Generate(Samples); m_Eng.GetRandState(RandState); RealType AccRate=m_Eng.GetAcceptanceRate(); m_RunCtrl.Save(Samples,RandState,AccRate); m_IO.Write(Samples); } }
void DataLogBlock::AddSamples(size_t num_samples, size_t dimensions, const float* data_dim_major ) { if(nextBlock) { // If next block exists, add to it instead nextBlock->AddSamples(num_samples, dimensions, data_dim_major); }else{ if(dimensions > dim) { // If dimensions is too high for this block, start a new bigger one nextBlock = new DataLogBlock(dimensions, max_samples, start_id + samples); }else{ // Try to copy samples to this block const size_t samples_to_copy = std::min(num_samples, SampleSpaceLeft()); if(dimensions == dim) { // Copy entire block all together std::copy(data_dim_major, data_dim_major + samples_to_copy*dim, sample_buffer+samples*dim); samples += samples_to_copy; data_dim_major += samples_to_copy*dim; }else{ // Copy sample at a time, filling with NaN's where needed. float* dst = sample_buffer; for(size_t i=0; i< samples_to_copy; ++i) { std::copy(data_dim_major, data_dim_major + dimensions, dst); for(size_t ii = dimensions; ii < dim; ++ii) { dst[ii] = std::numeric_limits<float>::quiet_NaN(); } dst += dimensions; data_dim_major += dimensions; } samples += samples_to_copy; } // Copy remaining data to next block (this one is full) if(samples_to_copy < num_samples) { nextBlock = new DataLogBlock(dim, max_samples, start_id + Samples()); nextBlock->AddSamples(num_samples-samples_to_copy, dimensions, data_dim_major); } } } }
ALuint AudioEngine::loadSndFile(const std::string& Filename) { auto query = buffers.find(Filename); if(query != buffers.end()) { return query->second; } // Open Audio file with libsndfile SF_INFO FileInfos; SNDFILE* File = sf_open(Filename.c_str(), SFM_READ, &FileInfos); if (!File) { return 0; } //get the number of sample and the samplerate (in samples by seconds) ALsizei NbSamples = static_cast<ALsizei>(FileInfos.channels * FileInfos.frames); ALsizei SampleRate = static_cast<ALsizei>(FileInfos.samplerate); //Read samples in 16bits signed std::vector<float> SamplesFloat(NbSamples); if (sf_read_float(File, &SamplesFloat[0], NbSamples) < NbSamples) { //return 0; } std::vector<ALshort> Samples(NbSamples); ALshort max = 0x7FFF; //biggest 16bits siged float (positive) for(size_t i(0); i < Samples.size(); i++) //This will step down a bit the amplitude of the signal to prevent saturation while using some formats Samples[i] = max*SamplesFloat[i]*0.88f; //close file sf_close(File); //Read the number of chanels. sound effects should be mono and background music should be stereo ALenum Format; switch (FileInfos.channels) { case 1 : Format = AL_FORMAT_MONO16; break; case 2 : Format = AL_FORMAT_STEREO16; break; default : return 0; } //create OpenAL buffer ALuint buffer; alGenBuffers(1, &buffer); // load buffer alBufferData(buffer, Format, &Samples[0], NbSamples * sizeof(ALshort), SampleRate); //check errors if (alGetError() != AL_NO_ERROR) { return 0; } buffers[Filename] = buffer; return buffer; }
void CRFclamped::Sample_Cutset(int size, int engine) { if (size <= 0) size = original.nSamples; else if (size > original.nSamples) original.Init_Samples(size); int *y = (int *) R_alloc(original.nNodes, sizeof(int)); int nPot = 1; for (int i = 0; i < original.nNodes; i++) { if (clamped[i] > 0) { nPot *= original.nStates[i]; clamped[i] = 1; y[i] = 0; } else { clamped[i] = 0; y[i] = -1; } } double *pot = (double *) R_alloc(nPot, sizeof(double)); double Z = 0; int n = 0; int index, n1, n2; while (1) { R_CheckUserInterrupt(); /* Reset node potentials */ Reset_NodePot(); /* Infer clamped CRF */ switch (engine) { case 0: break; case 1: Infer_Exact(); break; case 2: Infer_Chain(); break; case 3: Infer_Tree(); break; default: Infer_Tree(); break; } /* Calculate potential */ pot[n] = exp(*logZ); for (int i = 0; i < original.nNodes; i++) if (clamped[i] > 0) pot[n] *= original.NodePot(i, y[i]); for (int i = 0; i < original.nEdges; i++) { n1 = original.EdgesBegin(i); n2 = original.EdgesEnd(i); if (clamped[n1] > 0 && clamped[n2] > 0) pot[n] *= original.EdgePot(i, y[n1], y[n2]); } /* Update Z */ Z += pot[n++]; /* Next configuration */ for (index = 0; index < original.nNodes; index++) { if (clamped[index] == 0) continue; clamped[index]++; y[index]++; if (y[index] < original.nStates[index]) break; else { clamped[index] = 1; y[index] = 0; } } if (index == original.nNodes) break; } /* Sampling */ double *cutoff = (double *) R_alloc(size, sizeof(double)); GetRNGstate(); for (int k = 0; k < size; k++) cutoff[k] = unif_rand() * Z; PutRNGstate(); for (int i = 0; i < original.nNodes; i++) { if (clamped[i] > 0) { clamped[i] = 1; y[i] = 0; } else { clamped[i] = 0; y[i] = -1; } } int m, remain = size; double done = Z * 10; double cumulativePot = 0; n = 0; while (1) { R_CheckUserInterrupt(); /* Reset node potentials */ Reset_NodePot(); /* Update cumulative potential */ cumulativePot += pot[n++]; /* Count samples */ m = 0; for (int k = 0; k < size; k++) if (cumulativePot > cutoff[k]) m++; /* Generate samples */ if (m > 0) { switch (engine) { case 0: break; case 1: Sample_Exact(m); break; case 2: Sample_Chain(m); break; case 3: Sample_Tree(m); break; default: Sample_Tree(m); break; } m = 0; for (int k = 0; k < size; k++) if (cumulativePot > cutoff[k]) { for (int i = 0; i < original.nNodes; i++) { if (clamped[i] > 0) original.Samples(k, i) = clamped[i]; else original.Samples(k, i) = Samples(m, nodeMap[i] - 1); } cutoff[k] = done; remain--; m++; } } /* Next configuration */ for (index = 0; index < original.nNodes; index++) { if (clamped[index] == 0) continue; clamped[index]++; y[index]++; if (y[index] < original.nStates[index]) break; else { clamped[index] = 1; y[index] = 0; } } if (index == original.nNodes || remain <= 0) break; } }
ALuint Audio::creerBuffer(const std::string Filename) { // Ouverture du fichier audio avec libsndfile SF_INFO FileInfos; SNDFILE* File = sf_open(Filename.c_str(), SFM_READ, &FileInfos); if (!File) { std::cerr << "Impossible d'ouvrir le fichier audio : " << Filename.c_str() << std::endl; return 1; } // Lecture du nombre d'échantillons et du taux d'échantillonnage (nombre d'échantillons à lire par seconde) ALsizei NbSamples = static_cast<ALsizei> (FileInfos.channels * FileInfos.frames); ALsizei SampleRate = static_cast<ALsizei> (FileInfos.samplerate); // Lecture des échantillons audio au format entier 16 bits signé (le plus commun) std::vector<ALshort> Samples(NbSamples); if (sf_read_short(File, &Samples[0], NbSamples) < NbSamples) { std::cerr << "Impossible de lire les echantillons stockes dans le fichier audio" << std::endl; return 1; } // Fermeture du fichier int close = sf_close(File); if (close != 0) { std::cerr << "Impossible de fermer le fichier audio : " << Filename.c_str() << std::endl; return 1; } // Détermination du format en fonction du nombre de canaux ALenum Format; // bool IsMultiChannelSupported = alIsExtensionPresent("AL_EXT_MCFORMATS"); switch (FileInfos.channels) { case 1: Format = AL_FORMAT_MONO16; break; case 2: Format = AL_FORMAT_STEREO16; break; /* if (IsMultiChannelSupported == AL_TRUE) { case 4 : Format = alGetEnumValue("AL_FORMAT_QUAD16"); break; case 6 : Format = alGetEnumValue("AL_FORMAT_51CHN16"); break; case 7 : Format = alGetEnumValue("AL_FORMAT_61CHN16"); break; case 8 : Format = alGetEnumValue("AL_FORMAT_71CHN16"); break; } */ default: std::cerr << "Format audio non supporte (plus de 2 canaux)" << std::endl; return 1; } // Création du tampon OpenAL ALuint Buffer; alGenBuffers(1, &Buffer); // Remplissage avec les échantillons lus alBufferData(Buffer, Format, &Samples[0], NbSamples * sizeof(ALushort), SampleRate); // Vérification des erreurs if (alGetError() != AL_NO_ERROR) { std::cerr << "Impossible de remplir le tampon OpenAL avec les echantillons du fichier audio" << std::endl; return 1; } return Buffer; }
void HiJitCube::Init() throw (iException &) { // Get required keywords from instrument group Pvl *label(Label()); Isis::PvlGroup inst; Isis::PvlGroup idinst; jdata.filename = Filename(); Isis::PvlGroup &archive = label->FindGroup ("Archive",Isis::Pvl::Traverse); jdata.productId = (string) archive["ProductId"]; jdata.lines = Lines(); if (label->FindObject("IsisCube").HasGroup("OriginalInstrument")) { inst = label->FindGroup ("OriginalInstrument",Isis::Pvl::Traverse); originst = true; } else { inst = label->FindGroup ("Instrument",Isis::Pvl::Traverse); originst = false; } jdata.tdiMode = inst["Tdi"]; jdata.summing = inst["Summing"]; if (label->FindObject("IsisCube").HasGroup("Instrument") && originst) { idinst = label->FindGroup ("Instrument",Isis::Pvl::Traverse); jdata.pixpitch = idinst["PixelPitch"]; jdata.summing = (int) (jdata.pixpitch/.012); } if (originst && jdata.summing != 1 && !sampinit) { for (int i=0; i<14; i++) { npSamps[i] = (int) (npSamps[i]/(float)jdata.summing + 0.5); npSamp0[i] = (int) (npSamp0[i]/(float)jdata.summing + 0.5); } sampinit = true; } jdata.channelNumber = inst["ChannelNumber"]; jdata.cpmmNumber = inst["CpmmNumber"]; if (originst) { jdata.samples = npSamps[jdata.cpmmNumber]; } else { jdata.samples = Samples(); } jdata.ccdName = Instrument::CCD_NAMES[jdata.cpmmNumber]; jdata.dltCount = inst["DeltaLineTimerCount"]; jdata.UTCStartTime = (string) inst["StartTime"]; jdata.scStartTime = (string) inst["SpacecraftClockStartCount"]; try { if (originst) { jdata.fpSamp0 = npSamp0[jdata.cpmmNumber]; } else { jdata.fpSamp0 = Instrument::focal_plane_x_offset(jdata.cpmmNumber, jdata.summing); } } catch (Exception hiExc) { ostringstream msg; msg << "Summing mode (" << jdata.summing << ") is illegal (must be > 0) or CPMM number (" << jdata.cpmmNumber << ") is invalid in file " << Filename() << endl; throw iException::Message(iException::User,msg.str(),_FILEINFO_); } // It is assumed all images start at the line location in the focal plane jdata.fpLine0 = 0; // Validate channel number and adjust starting sample if ((jdata.channelNumber > 2) || (jdata.channelNumber < 0)) { ostringstream msg; msg << "Channel number (" << jdata.channelNumber << ") is invalid (must be 0, 1 or 2) in file " << Filename() << endl; throw iException::Message(iException::User,msg.str(),_FILEINFO_); } else { if (originst) { if (jdata.channelNumber == 0) jdata.fpSamp0 += npSamps[jdata.cpmmNumber]; } else { if (jdata.channelNumber == 0) jdata.fpSamp0 += Samples(); } } // Determine starting time of image and compute the binning rates computeStartTime(); // Compute the focal plane polygon for this image computePoly(); return; }