void JunoLfo::lforateChanged(double data) { //printf("lfo_rate is %f\n", data); lforate = pow( data, 2.5 ); /* range is .125 HZ to 20.125 HZ */ lforate *= CPS(20); lforate += CPS(.0625); osc.set("frq", lforate); }
void MidiInput::doNoteOn( unsigned int c, unsigned int n, unsigned int v ) { /* try to avoid re-using the same note as long as possible, so that * if it has a Release envelope, it will get as much time as possible */ //debug( DEBUG_STATUS, "MidiInput::noteOn %d %d %d", c, n, v ); int start = (lastNote + 1) % nvoices; int i = start; do { if ( voices[ i ].note == -1 ) { voices[ i ].note = n; voices[ i ].pitchOutput->setData(CPS(midi_notes[n])); voices[ i ].gateOutput->setData(v / 127.0); lastNote = i; break; } i = (i + 1) % nvoices; } while (i != start); }
// return minimum value for elapsed() double Timer::elapsed_min() const { #ifdef USE_QUERY_PERFORMANCE return 1.0 / CPS(); #else return std::chrono::duration<double>::min().count(); #endif }
// return estimated maximum value for elapsed() double Timer::elapsed_max() const { #ifdef USE_QUERY_PERFORMANCE return static_cast<double>(std::numeric_limits<uint64_t>::max()) / CPS() - start_time_; #else return std::chrono::duration<double>::max().count(); #endif }
double Timer::current_time() const { #ifdef USE_QUERY_PERFORMANCE ::LARGE_INTEGER count; ::QueryPerformanceCounter(&count); return static_cast<double>(count.QuadPart) / CPS(); #else std::chrono::high_resolution_clock::time_point tp = std::chrono::high_resolution_clock::now(); return std::chrono::duration_cast<std::chrono::duration<double>>(tp.time_since_epoch()).count(); #endif }
//--------------------------------------------------------------------------- TDateTime __fastcall TFileOperationProgressType::TimeExpected() { unsigned int CurCps = CPS(); if (CurCps) { return TDateTime((double)(((double)(TransferSize - TransferedSize)) / CurCps) / SecsPerDay); } else { return 0; } }
double _CoolProp_Fluid_Props(long iOutput, long iName1, double Prop1, long iName2, double Prop2, Fluid *pFluid, bool SinglePhase) { double val = _HUGE; // This private method uses the indices directly for speed if (get_debug_level()>3){ std::cout<<__FILE__<<" _CoolProp_Fluid_Props: "<<iOutput<<","<<iName1<<","<<Prop1<<","<<iName2<<","<<Prop2<<","<<pFluid->get_name().c_str()<<std::endl; } // Generate a State instance wrapped around the Fluid instance CoolPropStateClass CPS(pFluid); // Check if it is an output that doesn't require a state input // Deal with it and return switch (iOutput) { case iMM: case iPcrit: case iTcrit: case iTtriple: case iPtriple: case iRhocrit: case iTmin: case iAccentric: case iPHASE_LIQUID: case iPHASE_GAS: case iPHASE_SUPERCRITICAL: case iPHASE_TWOPHASE: case iGWP20: case iGWP100: case iGWP500: case iODP: case iCritSplineT: case iScrit: case iHcrit: case iTreduce: case iRhoreduce: return CPS.keyed_output(iOutput); } // Update the class CPS.update(iName1,Prop1,iName2,Prop2); // Get the output val = CPS.keyed_output(iOutput); if (get_debug_level()>5){ std::cout<<__FILE__<<" _CoolProp_Fluid_Props return: "<<val<<std::endl; } // Return the value return val; }
//--------------------------------------------------------------------------- TDateTime __fastcall TFileOperationProgressType::TotalTimeLeft() { assert(TotalSizeSet); unsigned int CurCps = CPS(); // sanity check if ((CurCps > 0) && (TotalSize > TotalSkipped + TotalTransfered)) { return TDateTime((double)((double)(TotalSize - TotalSkipped - TotalTransfered) / CurCps) / SecsPerDay); } else { return 0; } }
void MidiInput::doPitchBend( unsigned int amount ) { //debug( DEBUG_STATUS, "MidiInput::pitchBend %d", amount ); double pitchBend = ( double )amount / 8192 - 1.0; #ifdef KARL_BEND for( int i = 0; i < nvoices; i++ ) { if ( voices[ i ] != -1 ) { outputs[ O_MIDI_SIG(i) ].data = CPS( midi_notes[ voices[ i ] ] ) * pitchBend; } } #else outputs[ 0 ].setData(pitchBend); #endif }
void selfie(libmaus2::util::ArgParser const & arg, std::string const & fn) { std::string const compactfn = fn + ".compact"; std::string const compactmetafn = compactfn + ".meta"; if ( ! libmaus2::util::GetFileSize::fileExists(compactfn) || libmaus2::util::GetFileSize::isOlder(compactfn,fn) ) { libmaus2::fastx::FastAToCompact4BigBandBiDir::fastaToCompact4BigBandBiDir( std::vector<std::string>(1,fn), &(std::cerr), false /* single strand */, compactfn ); } uint64_t const numthreads = arg.uniqueArgPresent("t") ? arg.getUnsignedNumericArg<uint64_t>("t") : libmaus2::suffixsort::bwtb3m::BwtMergeSortOptions::getDefaultNumThreads(); std::string const bwtfn = fn + ".bwt"; std::string const bwtmetafn = bwtfn + ".meta"; libmaus2::suffixsort::bwtb3m::BwtMergeSortResult res; if ( ! libmaus2::util::GetFileSize::fileExists(bwtmetafn) || libmaus2::util::GetFileSize::isOlder(bwtmetafn,compactfn) ) { libmaus2::suffixsort::bwtb3m::BwtMergeSortOptions options( compactfn, 16*1024ull*1024ull*1024ull, // mem // libmaus2::suffixsort::bwtb3m::BwtMergeSortOptions::getDefaultMem(), numthreads, "compactstream", false /* bwtonly */, std::string("mem:tmp_"), std::string(), // sparse bwtfn, 16 /* isa */, 16 /* sa */ ); res = libmaus2::suffixsort::bwtb3m::BwtMergeSort::computeBwt(options,&std::cerr); res.serialise(bwtmetafn); } else { res.deserialise(bwtmetafn); } //libmaus2::fastx::FastAIndex::unique_ptr_type PFAI(libmaus2::fastx::FastAIndex::load(fn+".fai")); libmaus2::fastx::DNAIndexMetaDataBigBandBiDir::unique_ptr_type Pmeta(libmaus2::fastx::DNAIndexMetaDataBigBandBiDir::load(compactmetafn)); libmaus2::rank::DNARank::unique_ptr_type Prank(res.loadDNARank(numthreads)); libmaus2::suffixsort::bwtb3m::BwtMergeSortResult::BareSimpleSampledSuffixArray BSSSA(res.loadBareSimpleSuffixArray()); uint64_t const n = Prank->size(); libmaus2::autoarray::AutoArray<char> A(n,false); libmaus2::bitio::CompactDecoderWrapper CDW(compactfn); CDW.read(A.begin(),n); assert ( CDW.gcount() == static_cast<int64_t>(n) ); uint64_t const minfreq = 2; uint64_t const minlen = 20; uint64_t const limit = 32; uint64_t const minsplitlength = 28; uint64_t const minsplitsize = 10; uint64_t const maxxdist = 1000; uint64_t const activemax = 1; uint64_t const fracmul = 95; uint64_t const fracdiv = 100; bool const selfcheck = true; uint64_t const chainminscore = arg.uniqueArgPresent("chainminscore") ? arg.getUnsignedNumericArg<uint64_t>("chainminscore") : 20; uint64_t const maxocc = 500; uint64_t const minprintlength = 1024; uint64_t const algndommul = 95; uint64_t const algndomdiv = 100; uint64_t const chaindommul = 95; uint64_t const chaindomdiv = 100; double const maxerr = arg.uniqueArgPresent("maxerr") ? arg.getParsedArg<double>("maxerr") : std::numeric_limits<double>::max(); uint64_t const cachek = arg.uniqueArgPresent("K") ? arg.getUnsignedNumericArg<uint64_t>("K") : 12; uint64_t const maxpacksize = arg.uniqueArgPresent("P") ? arg.getUnsignedNumericArg<uint64_t>("P") : 128ull*1024ull*1024ull; std::cerr << "[V] generating " << cachek << "-mer cache..."; libmaus2::rank::DNARankKmerCache::unique_ptr_type Pcache(new libmaus2::rank::DNARankKmerCache(*Prank,cachek,numthreads)); std::cerr << "done." << std::endl; std::string const deftmp = libmaus2::util::ArgInfo::getDefaultTmpFileName(arg.progname); libmaus2::util::TempFileNameGenerator tmpgen(deftmp,3); std::string const sorttmp = tmpgen.getFileName(); libmaus2::util::TempFileRemovalContainer::addTempFile(sorttmp); libmaus2::sorting::SortingBufferedOutputFile<CoordinatePair> CPS(sorttmp); libmaus2::parallel::PosixSpinLock CPSlock; uint64_t acc_s = 0; for ( uint64_t zz = 0; zz < Pmeta->S.size(); ) { uint64_t zze = zz; uint64_t pack_s = Pmeta->S[zze++].l; while ( zze < Pmeta->S.size() && pack_s + Pmeta->S[zze].l <= maxpacksize ) pack_s += Pmeta->S[zze++].l; // std::cerr << "[V] " << zz << "-" << zze << " pack_s=" << pack_s << std::endl; zz = zze; uint64_t const low = acc_s; uint64_t const high = acc_s + pack_s; std::cerr << "[V] low=" << low << " high=" << high << " acc_s=" << acc_s << " pack_s=" << pack_s << std::endl; std::string const activefn = libmaus2::rank::DNARankSMEMComputation::activeParallel(tmpgen,*Pcache,A.begin(),low,high,minfreq,minlen,numthreads,maxxdist + 2*(minlen-1)); libmaus2::gamma::GammaIntervalDecoder::unique_ptr_type Pdec(new libmaus2::gamma::GammaIntervalDecoder(std::vector<std::string>(1,activefn),0/*offset */,1 /* numthreads */)); std::string const sortinfn = tmpgen.getFileName(true); libmaus2::sorting::SerialisingSortingBufferedOutputFile<GammaInterval>::unique_ptr_type sptr( new libmaus2::sorting::SerialisingSortingBufferedOutputFile<GammaInterval>(sortinfn) ); { std::pair<uint64_t,uint64_t> P; while ( Pdec->getNext(P) ) { sptr->put( GammaInterval(P.first,P.second) ); } } libmaus2::sorting::SerialisingSortingBufferedOutputFile<GammaInterval>::merger_ptr_type Pmerger( sptr->getMerger() ); struct LockedGet { libmaus2::parallel::PosixSpinLock lock; // libmaus2::gamma::GammaIntervalDecoder& dec; libmaus2::sorting::SerialisingSortingBufferedOutputFile<GammaInterval>::merger_ptr_type & Pmerger; LockedGet(libmaus2::sorting::SerialisingSortingBufferedOutputFile<GammaInterval>::merger_ptr_type & rPmerger) : Pmerger(rPmerger) { } bool getNext(std::pair<uint64_t,uint64_t> & P) { bool ok = false; { libmaus2::parallel::ScopePosixSpinLock slock(lock); GammaInterval Q; ok = Pmerger->getNext(Q); if ( ok ) { P.first = Q.first; P.second = Q.second; } } return ok; } }; libmaus2::autoarray::AutoArray < std::pair<uint64_t,uint64_t> > VP(numthreads); LockedGet LG(Pmerger); libmaus2::fastx::CoordinateCacheBiDir cocache(*Prank,*Pmeta,16 /* blockshfit */); typedef libmaus2::suffixsort::bwtb3m::BwtMergeSortResult::BareSimpleSampledSuffixArray sa_type; typedef libmaus2::lcs::SMEMProcessor<sa_type> smem_proc_type; libmaus2::autoarray::AutoArray < smem_proc_type::unique_ptr_type > Aproc(numthreads); for ( uint64_t i = 0; i < numthreads; ++i ) { smem_proc_type::unique_ptr_type proc(new smem_proc_type( *Pmeta,cocache,*Prank,BSSSA,A.begin(),maxxdist,activemax,fracmul,fracdiv,selfcheck,chainminscore,maxocc,algndommul,algndomdiv,chaindommul,chaindomdiv, libmaus2::lcs::NNP::getDefaultMaxWindowError(),libmaus2::lcs::NNP::getDefaultMaxBack(),false /* domsameref */ ) ); Aproc[i] = UNIQUE_PTR_MOVE(proc); } stateVec.resize(numthreads); for ( uint64_t i = 0; i < numthreads; ++i ) setState(i,"idle"); #if defined(_OPENMP) #pragma omp parallel num_threads(numthreads) #endif { uint64_t const tid = #if defined(_OPENMP) omp_get_thread_num() #else 0 #endif ; std::pair<uint64_t,uint64_t> & P = VP[tid]; smem_proc_type & proc = *(Aproc[tid]); struct SelfieVerbosity : public smem_proc_type::Verbosity { uint64_t tid; std::string prefix; SelfieVerbosity(uint64_t const rtid, std::string const & rprefix) : tid(rtid), prefix(rprefix) { } void operator()(libmaus2::rank::DNARankMEM const & smem, uint64_t const z) const { std::ostringstream ostr; ostr << prefix << "\t" << z << "\t" << smem; setState(tid,ostr.str()); printState(); } }; while ( LG.getNext(P) ) { uint64_t const smemleft = std::max(static_cast<int64_t>(0),static_cast<int64_t>(P.first)-static_cast<int64_t>(minlen-1)); uint64_t const smemright = std::min(P.second+minlen,n); std::ostringstream msgstr; msgstr << "[" << smemleft << "," << smemright << ")"; setState(tid,msgstr.str()); printState(); libmaus2::rank::DNARankSMEMComputation::SMEMEnumerator<char const *> senum( *Prank,A.begin(), smemleft, smemright, minfreq, minlen, limit, minsplitlength, minsplitsize); SelfieVerbosity SV(tid,msgstr.str()); proc.process(senum,A.begin(),n,minprintlength,maxerr,SV); // proc.printAlignments(minprintlength); std::pair<libmaus2::lcs::ChainAlignment const *, libmaus2::lcs::ChainAlignment const *> const AP = proc.getAlignments(); for ( libmaus2::lcs::ChainAlignment const * it = AP.first; it != AP.second; ++it ) { libmaus2::lcs::ChainAlignment const & CA = *it; libmaus2::lcs::NNPAlignResult const & res = CA.res; std::vector<libmaus2::fastx::DNAIndexMetaDataBigBandBiDir::Coordinates> const VA = Pmeta->mapCoordinatePairToList(res.abpos,res.aepos); std::vector<libmaus2::fastx::DNAIndexMetaDataBigBandBiDir::Coordinates> const VB = Pmeta->mapCoordinatePairToList(res.bbpos,res.bepos); if ( VA.size() == 1 && VB.size() == 1 ) { CoordinatePair CP(VA[0],VB[0],res); libmaus2::parallel::ScopePosixSpinLock slock(CPSlock); CPS.put(CP); } } setState(tid,"idle"); printState(); #if 0 std::cerr << "P=[" << P.first << "," << P.second << ")" << std::endl; { std::vector<libmaus2::rank::DNARankMEM> SMEM; libmaus2::rank::DNARankSMEMComputation::smemLimitedParallel( *Prank, *Pcache, A.begin(), P.first, P.second, n, minfreq, minlen, limit, SMEM, 1 /* threads */); std::cerr << "[V] number of SMEMs is " << SMEM.size() << std::endl; // deallocate k-mer cache // Pcache.reset(); std::vector<libmaus2::rank::DNARankMEM> SMEMsplit; libmaus2::rank::DNARankSMEMComputation::smemLimitedParallelSplit(*Prank,A.begin(),P.first,P.second,minlen,limit,minsplitlength,minsplitsize,SMEM,SMEMsplit,1 /* threads */); std::cerr << "[V] number of split SMEMs is " << SMEMsplit.size() << std::endl; // insert split SMEMs into regular SMEMs std::copy(SMEMsplit.begin(),SMEMsplit.end(),std::back_insert_iterator< std::vector<libmaus2::rank::DNARankMEM> >(SMEM)); //libmaus2::sorting::InPlaceParallelSort::inplacesort2(SMEM.begin(),SMEM.end(),numthreads,libmaus2::rank::DNARankMEMPosComparator()); std::sort(SMEM.begin(),SMEM.end(),libmaus2::rank::DNARankMEMPosComparator()); SMEM.resize(std::unique(SMEM.begin(),SMEM.end())-SMEM.begin()); libmaus2::rank::DNARankSMEMComputation::SMEMEnumerator<char const *> senum( *Prank,A.begin(), std::max(static_cast<int64_t>(0),static_cast<int64_t>(P.first)-static_cast<int64_t>(minlen-1)), std::min(P.second+minlen,n), minfreq, minlen, limit, minsplitlength, minsplitsize); libmaus2::rank::DNARankMEM smem; uint64_t c = 0; while ( senum.getNext(smem) ) { // std::cerr << "ccc=" << smem << std::endl; if ( c >= SMEM.size() || smem != SMEM[c] ) { std::cerr << "mismatch " << c << " " << smem; if ( c < SMEM.size() ) std::cerr << " != " << SMEM[c]; else std::cerr << " ???"; std::cerr << std::endl; } else { std::cerr << "match " << c << " " << smem << " " << SMEM[c] << std::endl; } ++c; } std::cerr << "c=" << c << " V=" << SMEM.size() << std::endl; } #endif } } acc_s += pack_s; } libmaus2::sorting::SortingBufferedOutputFile<CoordinatePair>::merger_ptr_type Pmerger(CPS.getMerger()); CoordinatePair CP; while ( Pmerger->getNext(CP) ) { std::ostringstream ostr; CP.A.print(ostr); ostr << " "; CP.B.print(ostr); ostr << " "; ostr << CP.res.getErrorRate(); std::cout << ostr.str() << std::endl; } }
void initSynth( JunoControl* _junoControl, Settings* settings, MidiInput* midiInput, int numVoices ) { stereo = strcmp( "yes", settings->getString("devices", "stereo_output") ) == 0; int numFrags = -1; int fragSize = -1; const char *p; p = settings->getString("devices", "NumFrags"); if (strlen(p)) numFrags = atoi(p); p = settings->getString("devices", "FragSize"); if (strlen(p)) fragSize = atoi(p); dsp = new DSPOutput( settings->getString( "devices", "dsp-output" ), SAMPLE_RATE_44k, ( stereo ) ? 2 : 1, numFrags, fragSize); //FIXME: we have to hold on to the junoControl pointer... sloppy junoControl = _junoControl; lfo = new JunoLfo(junoControl,numVoices); arpeggio = new JunoArpeggio(junoControl,numVoices); pwmLfo = new Attenuator; noise = new Rand; voiceMix = new Mixer(numVoices); hpf = new HPF; PATCH(lfo, "sig", pwmLfo, "sig"); pwmLfo->set("amp", .5); pwmLfo->set("zro", .5); //FIXME: an array of voices would be nice, huh? debug(DEBUG_APPMSG1, "Creating %d voices...", numVoices); /* fall thru each case */ if (numVoices>64) { debug(DEBUG_APPMSG1, "more than 64 voices are not allowed, truncated!"); numVoices=64; } numV = numVoices; for (int i=0;i<numVoices;i++) { //debug(DEBUG_APPMSG1, "CREATING VOICE %d",i); voice[i] = new JunoVoice(junoControl,i); char *tmp = new char[6]; sprintf(tmp,"sig%d",i); //debug(DEBUG_APPMSG1, "patching voice",i); PATCH(voice[i],"sig",voiceMix,tmp); } /*switch(numVoices) { case 6: voice5 = new JunoVoice(junoControl, 5); PATCH(voice5, "sig", voiceMix, "sig5"); case 5: voice4 = new JunoVoice(junoControl, 4); PATCH(voice4, "sig", voiceMix, "sig4"); case 4: voice3 = new JunoVoice(junoControl, 3); PATCH(voice3, "sig", voiceMix, "sig3"); case 3: voice2 = new JunoVoice(junoControl, 2); PATCH(voice2, "sig", voiceMix, "sig2"); case 2: voice1 = new JunoVoice(junoControl, 1); PATCH(voice1, "sig", voiceMix, "sig1"); case 1: voice0 = new JunoVoice(junoControl, 0); PATCH(voice0, "sig", voiceMix, "sig0"); }*/ PATCH(voiceMix, "sig", hpf, "sig"); PATCH(junoControl, "hpf_frq", hpf, "frq"); //FIXME: tune the Q of the hpf hpf->set("Q", 0.0); chorus = new JunoChorus( hpf, "sig", 0 ); if ( stereo ) { chorus2 = new JunoChorus( hpf, "sig", 1 ); PATCH( junoControl, "chorus_off_switch", chorus2, "off" ); PATCH( junoControl, "chorus_I_switch", chorus2, "I" ); PATCH( junoControl, "chorus_II_switch", chorus2, "II" ); PATCH( chorus2, "sig", dsp, "sig1" ); PATCH( junoControl, "volume", dsp, "amp1"); } PATCH( junoControl, "chorus_off_switch", chorus, "off" ); PATCH( junoControl, "chorus_I_switch", chorus, "I" ); PATCH( junoControl, "chorus_II_switch", chorus, "II" ); PATCH( chorus, "sig", dsp, "sig0" ); PATCH( junoControl, "volume", dsp, "amp0"); // all cool dave, scope does nothing until you pop it up. scope = new Scope(); PATCH( chorus, "sig", scope, "sig" ); /* the Balance in the voices needs signal to calibrate, so start * the oscillators with an arbitrary frequency - they run forever */ for (int i=0;i<numV;i++) { junoControl->getOutput((String)"voice"+i+(String)"_pitch")->setData(CPS(666)); } /*junoControl->getOutput("voice1_pitch")->setData(CPS(666)); junoControl->getOutput("voice2_pitch")->setData(CPS(666)); junoControl->getOutput("voice3_pitch")->setData(CPS(666)); junoControl->getOutput("voice4_pitch")->setData(CPS(666)); junoControl->getOutput("voice5_pitch")->setData(CPS(666));*/ PATCH( junoControl, "volume", dsp, "amp0"); Scheduler::start( dsp ); }