Пример #1
0
//---------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------------
void BufferOverride::doTheProcess(float **inputs, float **outputs, long sampleFrames, bool replacing)
{

//-------------------------SAFETY CHECK----------------------
#if LINUX
    // no memory allocations during interrupt
#else
    // there must have not been available memory or something (like WaveLab goofing up),
    // so try to allocate buffers now
    if ( (buffer1 == NULL)
#ifdef BUFFEROVERRIDE_STEREO
            || (buffer2 == NULL)
#endif
       )
        createAudioBuffers();
#endif

    // if the creation failed, then abort audio processing
    if (buffer1 == NULL)
        return;
#ifdef BUFFEROVERRIDE_STEREO
    if (buffer2 == NULL)
        return;
#endif


//-------------------------INITIALIZATIONS----------------------
    // this is a handy value to have during LFO calculations & wasteful to recalculate at every sample
    numLFOpointsDivSR = NUM_LFO_POINTS_FLOAT / SAMPLERATE;
    divisorLFO->pickTheLFOwaveform();
    bufferLFO->pickTheLFOwaveform();

    // calculate this scaler value to minimize calculations later during processOutput()
//	float inputGain = 1.0f - fDryWetMix;
//	float outputGain = fDryWetMix;
    float inputGain = sqrtf(1.0f - fDryWetMix);
    float outputGain = sqrtf(fDryWetMix);


//-----------------------TEMPO STUFF---------------------------
    // figure out the current tempo if we're doing tempo sync
    if ( onOffTest(fBufferTempoSync) ||
            (onOffTest(divisorLFO->fTempoSync) || onOffTest(bufferLFO->fTempoSync)) )
    {
        // calculate the tempo at the current processing buffer
        if ( (fTempo > 0.0f) || (hostCanDoTempo != 1) )	// get the tempo from the user parameter
        {
            currentTempoBPS = tempoScaled(fTempo) / 60.0f;
            needResync = false;	// we don't want it true if we're not syncing to host tempo
        }
        else	// get the tempo from the host
        {
            timeInfo = getTimeInfo(kBeatSyncTimeInfoFlags);
            if (timeInfo)
            {
                if (kVstTempoValid & timeInfo->flags)
                    currentTempoBPS = (float)timeInfo->tempo / 60.0f;
                else
                    currentTempoBPS = tempoScaled(fTempo) / 60.0f;
//				currentTempoBPS = ((float)tempoAt(reportCurrentPosition())) / 600000.0f;
                // but zero & negative tempos are bad, so get the user tempo value instead if that happens
                if (currentTempoBPS <= 0.0f)
                    currentTempoBPS = tempoScaled(fTempo) / 60.0f;
                //
                // check if audio playback has just restarted & reset buffer stuff if it has (for measure sync)
                if (timeInfo->flags & kVstTransportChanged)
                {
                    needResync = true;
                    currentForcedBufferSize = 1;
                    writePos = 1;
                    minibufferSize = 1;
                    prevMinibufferSize = 0;
                    smoothcount = smoothDur = 0;
                }
            }
            else	// do the same stuff as above if the timeInfo gets a null pointer
            {
                currentTempoBPS = tempoScaled(fTempo) / 60.0f;
                needResync = false;	// we don't want it true if we're not syncing to host tempo
            }
        }
    }


//-----------------------AUDIO STUFF---------------------------
    // here we begin the audio output loop, which has two checkpoints at the beginning
    for (long samplecount = 0; (samplecount < sampleFrames); samplecount++)
    {
        // check if it's the end of this minibuffer
        if (readPos >= minibufferSize)
            updateBuffer(samplecount);

        // store the latest input samples into the buffers
        buffer1[writePos] = inputs[0][samplecount];
#ifdef BUFFEROVERRIDE_STEREO
        buffer2[writePos] = inputs[1][samplecount];
#endif

        // get the current output without any smoothing
        float out1 = buffer1[readPos];
#ifdef BUFFEROVERRIDE_STEREO
        float out2 = buffer2[readPos];
#endif

        // and if smoothing is taking place, get the smoothed audio output
        if (smoothcount > 0)
        {
            // crossfade between the current input & its corresponding overlap sample
//			out1 *= 1.0f - (smoothStep * (float)smoothcount);	// current
//			out1 += buffer1[readPos+prevMinibufferSize] * smoothStep*(float)smoothcount;	// + previous
//			float smoothfract = smoothStep * (float)smoothcount;
//			float newgain = sqrt(1.0f - smoothfract);
//			float oldgain = sqrt(smoothfract);
//			out1 = (out1 * newgain) + (buffer1[readPos+prevMinibufferSize] * oldgain);
//			out1 = (out1 * sqrtFadeIn) + (buffer1[readPos+prevMinibufferSize] * sqrtFadeOut);
            out1 = (out1 * fadeInGain) + (buffer1[readPos+prevMinibufferSize] * fadeOutGain);
#ifdef BUFFEROVERRIDE_STEREO
//			out2 *= 1.0f - (smoothStep * (float)smoothcount);	// current
//			out2 += buffer2[readPos+prevMinibufferSize] * smoothStep*(float)smoothcount;	// + previous
//			out2 = (out2 * newgain) + (buffer2[readPos+prevMinibufferSize] * oldgain);
//			out2 = (out2 * sqrtFadeIn) + (buffer2[readPos+prevMinibufferSize] * sqrtFadeOut);
            out2 = (out2 * fadeInGain) + (buffer2[readPos+prevMinibufferSize] * fadeOutGain);
#endif
            smoothcount--;
//			smoothFract += smoothStep;
//			sqrtFadeIn = 0.5f * (sqrtFadeIn + (smoothFract / sqrtFadeIn));
//			sqrtFadeOut = 0.5f * (sqrtFadeOut + ((1.0f-smoothFract) / sqrtFadeOut));
            fadeInGain = (fadeOutGain * imaginaryFadePart) + (fadeInGain * realFadePart);
            fadeOutGain = (realFadePart * fadeOutGain) - (imaginaryFadePart * fadeInGain);
        }

        // write the output samples into the output stream
        if (replacing)
        {
            outputs[0][samplecount] = (out1 * outputGain) + (inputs[0][samplecount] * inputGain);
#ifdef BUFFEROVERRIDE_STEREO
            outputs[1][samplecount] = (out2 * outputGain) + (inputs[1][samplecount] * inputGain);
#endif
        }
        else
        {
            outputs[0][samplecount] += (out1 * outputGain) + (inputs[0][samplecount] * inputGain);
#ifdef BUFFEROVERRIDE_STEREO
            outputs[1][samplecount] += (out2 * outputGain) + (inputs[1][samplecount] * inputGain);
#endif
        }

        // increment the position trackers
        readPos++;
        writePos++;
    }


//-----------------------MIDI STUFF---------------------------
    // check to see if there may be a note or pitchbend message left over that hasn't been implemented
    if (midistuff->numBlockEvents > 0)
    {
        long eventcount;
        for (eventcount = 0; eventcount < midistuff->numBlockEvents; eventcount++)
        {
            if (isNote(midistuff->blockEvents[eventcount].status))
            {
                // regardless of whether it's a note-on or note-off, we've found some note message
                oldNote = true;
                // store the note & update the notes table if it's a note-on message
                if (midistuff->blockEvents[eventcount].status == kMidiNoteOn)
                {
                    midistuff->insertNote(midistuff->blockEvents[eventcount].byte1);
                    lastNoteOn = midistuff->blockEvents[eventcount].byte1;
                    // since we're not doing the fDivisor updating yet, this needs to be falsed
                    divisorWasChangedByHand = false;
                }
                // otherwise remove the note from the notes table
                else
                    midistuff->removeNote(midistuff->blockEvents[eventcount].byte1);
            }
            else if (midistuff->blockEvents[eventcount].status == ccAllNotesOff)
            {
                oldNote = true;
                midistuff->removeAllNotes();
            }
        }
        for (eventcount = (midistuff->numBlockEvents-1); (eventcount >= 0); eventcount--)
        {
            if (midistuff->blockEvents[eventcount].status == kMidiPitchbend)
            {
                // set this pitchbend message as lastPitchbend
                lastPitchbend = midistuff->blockEvents[eventcount].byte2;
                break;	// leave this for loop
            }
        }
    }

    // always reset numBlockEvents because processEvents() may not get called before the next process()
    midistuff->numBlockEvents = 0;
}
Пример #2
0
void PaeInput::parsePlainAndEasy(std::istream &infile) {
    // buffers
    char c_clef[1024] = {0};
    char c_key[1024] = {0};
    char c_keysig[1024] = {0};
    char c_timesig[1024] = {0};
    char c_alttimesig[1024] = {0};
    char incipit[10001] = {0};
    int in_beam = 0;
    
    std::string s_key;
    MeasureObject current_measure;
    NoteObject current_note;
    Clef *staffDefClef = NULL;
    
    std::vector<MeasureObject> staff;
    
    // read values
    while (!infile.eof()) {
        infile.getline(data_line, 10000);
        if (infile.eof()) {
            LogDebug("Truncated file or ending tag missing");
            //exit(1);
        }
        getAtRecordKeyValue(data_key, data_value, data_line);
        if (strcmp(data_key,"end")==0) {   
            break;
        } else if (strcmp(data_key,"clef")==0) { 
            strcpy( c_clef, data_value );
        } else if (strcmp(data_key,"key")==0) { 
            strcpy( c_key, data_value );
        } else if (strcmp(data_key,"keysig")==0) { 
            strcpy( c_keysig, data_value );
        } else if (strcmp(data_key,"timesig")==0) { 
            strcpy( c_timesig, data_value );
        } else if (strcmp(data_key,"alttimesig")==0) { 
            strcpy( c_alttimesig, data_value );
        } else if (strcmp(data_key,"data")==0) { 
            strcpy( incipit, data_value );
        }
    }
    
    if (strlen(c_clef)) {
        Clef *c = new Clef;
        getClefInfo(c_clef, c );    // do we need to put a default clef?
        if (!staffDefClef) staffDefClef = c;
        else current_measure.clef = c;
    }

    if (strlen(c_keysig)) {
        KeySig *k = new KeySig();
        getKeyInfo( c_keysig, k);
        current_measure.key = k;
    }
    if (strlen(c_timesig)) {
        MeterSig *meter = new MeterSig;
        getTimeInfo( c_timesig, meter);
        // What about previous values? Potential memory leak? LP
        current_measure.meter = meter;
    }   
    
    // read the incipit string
    size_t length = strlen(incipit);
    int i = 0;
	while(i < length) {
        // eat the input...
        
		if (incipit[i] == ' ') {
            // just skip
            i++;
        }
        
        // octaves
        if ((incipit[i] == '\'') || (incipit[i] == ',')) {
            i += getOctave( incipit, &current_note.octave, i );
        }
        
        // rhythmic values
        else if (isdigit(incipit[i]) != 0) {
            i += getDurations( incipit, &current_measure, i );
        }
        
        //accidentals (1 = n; 2 = x; 3 = xx; 4 = b; 5 = bb)    
        else if (incipit[i] == 'n' || incipit[i] == 'x' || incipit[i] == 'b') {
            i += getAccidental( incipit, &current_note.accidental, i );
        }
        
        //
        // beaming starts
		else if (incipit[i] == '{') {
			//current_note.beam = 1;
            current_note.beam = BEAM_INITIAL;
            in_beam++;
        }
        
        // beaming ends
		else if (incipit[i] == '}' && in_beam > 0) {
            current_measure.notes[current_measure.notes.size() - 1].beam = BEAM_TERMINAL;
            current_note.beam = 0;
            in_beam--;
		}
		
        // slurs are read when adding the note
		else if (incipit[i] == '+') {
        }
        
		// beginning tuplets & fermatas
		else if (incipit[i] == '(') {
            i += getTupletFermata( incipit, &current_note, i );
		}
        
        // end of tuplets
		else if ((incipit[i] == ';') || (incipit[i] == ')')) {
            i += getTupletFermataEnd( incipit, &current_note, i );
		}
        
		// trills are read when adding the note
		else if (incipit[i] == 't') {
        }
        
		//grace notes
		else if ((incipit[i] == 'g') || (incipit[i] == 'q')) {
			i += getGraceNote( incipit, &current_note, i );
		}
		
        
        // end of appogiatura
		else if (incipit[i] == 'r') {
			current_note.appoggiatura = 0; // should not have to be done, but just in case
        }
        
        //note and rest
        // getNote also creates a new note object
        else if (((incipit[i]-'A'>=0) && (incipit[i]-'A'<7)) || (incipit[i]=='-')) {
            i += getNote( incipit, &current_note, &current_measure, i );
        }
        
  		// whole rest
		else if (incipit[i] == '=') {
            i += getWholeRest( incipit, &current_measure.wholerest, i );		
		} 
        
		// abbreviation
        else if (incipit[i] == '!') {
            i += getAbbreviation( incipit, &current_measure, i );
        }
        
        // measure repetition
        else if ((incipit[i] == 'i') && staff.size() > 0) {
            MeasureObject last_measure = staff[staff.size() - 1];
            current_measure.notes = last_measure.notes;
            current_measure.wholerest = last_measure.wholerest;
            
            // if old measure does not end with a tie
            // force the first note of the newly copied measure to be without tie
            // this is to prevent copying tie closes which are invalid
            if (last_measure.notes.size() > 0 && last_measure.notes[last_measure.notes.capacity() - 1].tie == 0)
                current_measure.notes[0].tie = 0;
        }
        
        //barLine
        else if ((incipit[i] == ':') || (incipit[i] == '/')) {
            i += getBarline(incipit, &current_measure.barLine, i);
            current_measure.abbreviation_offset = 0; // just in case...
            staff.push_back( current_measure );
            current_measure.reset();
        }
        
		//clef change
		else if ((incipit[i] == '%') && (i+1 < length)) {
            Clef *c = new Clef;
            i += getClefInfo(incipit, c, i + 1);
            //
            if (!staffDefClef) {
                staffDefClef = c;
            }          
            // If there are no notes yet in the measure
            // attach this clef change to the measure
            else if (current_measure.notes.size() == 0) {
                // If a clef was already assigned, remove it
                if (current_measure.clef)
                    delete current_measure.clef;
                
                current_measure.clef = c;
            } else {
                // as above
                if (current_note.clef)
                    delete current_note.clef;
                
                current_note.clef = c;
            }
        }
        
		//time signature change
		else if ((incipit[i] == '@') && (i+1 < length)) {
            MeterSig *meter = new MeterSig;
            i += getTimeInfo( incipit, meter, i + 1);
            if (current_measure.notes.size() == 0) {
                if (current_measure.meter) {
                    delete current_measure.meter;
                }
                // When will this be deleted? Potential memory leak? LP
                current_measure.meter = meter;
            } else {
                if (current_note.meter) {
                    delete current_note.meter;
                }
                current_note.meter = meter;
            }
        } 
        
  		//key signature change
		else if ((incipit[i] == '$') && (i+1 < length)) {
            KeySig *k = new KeySig;
            i += getKeyInfo( incipit, k, i + 1);
            if (current_measure.notes.size() == 0) {
                if (current_measure.key)
                    delete current_measure.key;
                
                current_measure.key = k;
            } else {
                if (current_note.key)
                    delete current_note.key;
                
                current_note.key = k;
            }
		}
            
        i++;
    }
    
    // we need to add the last measure if it has no barLine at the end
    if (current_measure.notes.size() != 0) {
        //current_measure.barLine = "=-";
        staff.push_back( current_measure );
        current_measure.notes.clear();
    }
    
    
    m_doc->Reset( Raw );
    Page *page = new Page();
    System *system = new System();
    
    int measure_count = 1;
    
    std::vector<MeasureObject>::iterator it;
    for ( it = staff.begin() ; it < staff.end(); it++ ) {
        
        m_staff = new Staff( 1 );
        m_measure = new Measure( true, measure_count );
        m_layer = new Layer( );
        m_layer->SetN( 1 );
        
        m_staff->AddLayer(m_layer);
        m_measure->AddStaff( m_staff );
        system->AddMeasure( m_measure );
        
        MeasureObject obj = *it;
        convertMeasure( &obj );
        measure_count++;
    }

    // add miniaml scoreDef
    StaffGrp *staffGrp = new StaffGrp();
    StaffDef *staffDef = new StaffDef();
    staffDef->SetN( 1 );
    staffDef->SetLines(5);
    if (staffDefClef) {
        staffDef->SetClefShape(staffDefClef->GetShape());
        staffDef->SetClefLine(staffDefClef->GetLine());
        staffDef->SetClefDis(staffDefClef->GetDis());
        staffDef->SetClefDisPlace(staffDefClef->GetDisPlace());
        delete staffDefClef;
    }
    staffGrp->AddStaffDef( staffDef );
    m_doc->m_scoreDef.AddStaffGrp( staffGrp );

    page->AddSystem( system );
    m_doc->AddPage( page );
}
Пример #3
0
void VSTInstrument::processReplacing(float** inputs, float** outputs, VstInt32 sampleFrames)
{
	renderMutex.Lock();

		// Before rendering, set rounding flags, and denormal flags
		ZFPUState fpuState(ZFPUState::kRoundToZero);

		// If neccesary, create or reload synth
		if (programFile.DidUpdate())
		{
			if (synth)
			{
				delete synth;
				synth = nullptr;
			}

			auto prog = invader::ZVMProgram::FromBlob(programFile.data);
			prog->Unpack();

			synth = new invader::ZSynth(prog);
		}

		eventQueueMutex.Lock();
			int32_t numSamplesToRender = ((int32_t)sampleFrames)-((int32_t)sampleBuffer.SamplesAvailable());

			// Get time info
			VstTimeInfo *timeInfo = getTimeInfo(kVstPpqPosValid | kVstTempoValid | kVstBarsValid | kVstCyclePosValid | kVstTimeSigValid | kVstTransportPlaying);

			synth->sync.bpm = (timeInfo && (timeInfo->flags & kVstTempoValid)) ? timeInfo->tempo : 120.0f;
			synth->sync.bps = synth->sync.bpm / 60.0f;

			bool shouldSync = timeInfo && (timeInfo->flags & kVstPpqPosValid) && (timeInfo->flags & kVstTransportPlaying);

			if (shouldSync)
			{
				synth->sync.pos = timeInfo->ppqPos;
				
				// Compensate for samples already generated
				synth->sync.pos += (double)sampleBuffer.SamplesAvailable() / kSampleRate * synth->sync.bps;
			}

			synth->sync.time = synth->sync.pos / synth->sync.bps;

			// Loop over blocks
			while (numSamplesToRender > 0)
			{
				// Handle relevant events
				while (!eventQueue.empty() && eventQueue.front().deltaFrames < kBlockSize)
				{
					VstMidiEvent event = eventQueue.front();
					char* midiData = event.midiData;
					zmsg("Midi Event: %02X %02X %02X\n", (unsigned char)midiData[0], (unsigned char)midiData[1], (unsigned char)midiData[2]);

					uint32_t channel = uint32_t(midiData[0]) & 0x0f;
					uint32_t status = uint32_t(midiData[0]) & 0xf0;

					if (status == 0x90 || status == 0x80) // Note on or note off
					{
						uint32_t note     = uint32_t(midiData[1]) & 0x7f;
						uint32_t velocity = uint32_t(midiData[2]) & 0x7f;

						if (status == 0x80)
							velocity = 0;	// note off by velocity 0

						if (velocity==0)
						{
							synth->NoteOff((uint32_t)channel, (uint32_t)note, (uint32_t)event.deltaFrames);
						}
						else
						{
							synth->NoteOn((uint32_t)channel, (uint32_t)note, (uint32_t)velocity, (uint32_t)event.deltaFrames);
						}
					}
					else if (status == 0xB0) // MIDI control change
					{
						uint32_t number = uint32_t(midiData[1]) & 0x7f;
						uint32_t value  = uint32_t(midiData[2]) & 0x7f;

						synth->ControlChange(channel, number, value, (uint32_t)event.deltaFrames);
					}

					eventQueue.pop_front();
				}

				// Render blocks
				synth->ProcessBlock();

				// Resample
				// Access here is a little hackish, we're relying on storage of sample block outputs to be stored continually in global storage, starting at zero
				//ZResampler2xDownsample(*downsampler, downsampleBuffer, synth->vm.globalStorage->Load<ZBlockBufferInternal>((invader::opcode_index_t)(synth->section*sizeof(ZBlockBufferInternal))));
				ZResampler2xDownsample(*downsampler, downsampleBuffer, synth->vm.stack->Pop<ZBlockBufferInternal>());

				sampleBuffer.PutBlock(downsampleBuffer);

				numSamplesToRender -= kBlockSize;

				// Decrement deltaSamples in events in queue
				for (event_queue_t::iterator it = eventQueue.begin(); it != eventQueue.end(); ++it)
					it->deltaFrames -= kBlockSize;
			}


		eventQueueMutex.Unlock();

	renderMutex.Unlock();

	// Deinterleave output into buffers
	for (int32_t i=0; i<sampleFrames; i++)
	{
		sample_t sample = sampleBuffer.GetSample();
		outputs[0][i] = (float)sample.d[0];
		outputs[1][i] = (float)sample.d[1];
	}

	/*// We must always clear the buffer, to ensure non-garbage output
	Buffer dest;
	dest.channels[0]=outputs[0];
	dest.channels[1]=outputs[1];
	dest.numChannels=2;
	dest.numSamples=sampleFrames;

	dest.Reset(); // Only do this if replacing buffer

	// Note: This is mostly useful if some operation (e.g. synth realod) takes a while
	//       We are not guarenteed that synth has not been reloaded when we get to the lock
	if (synth->shouldRender==false)
	{
		return;
	}

	synth->renderMutex.Lock();

	// Recheck
	if (synth->shouldRender==false)
	{
		synth->renderMutex.Unlock();
		return;
	}

	// Get time info
	VstTimeInfo *timeInfo = getTimeInfo(kVstPpqPosValid | kVstTempoValid | kVstBarsValid | kVstCyclePosValid | kVstTimeSigValid | kVstTransportPlaying);

	synth->timeInfo.bpm = (timeInfo && (timeInfo->flags & kVstTempoValid)) ? timeInfo->tempo : 120.0f;
	synth->timeInfo.bps = synth->timeInfo.bpm / 60.0f;

	bool shouldSync = timeInfo && (timeInfo->flags & kVstPpqPosValid) && (timeInfo->flags & kVstTransportPlaying);

	if (shouldSync)
		synth->timeInfo.pos = timeInfo->ppqPos;


	// Process, but support samplesFrames other than 256
	synth->ProcessNon256(&dest);

	synth->renderMutex.Unlock();
	*/
	return;
}
Пример #4
0
void MPHFAlgorithm<span,Abundance_t,NodeState_t>::populate ()
{
    size_t nb_iterated = 0;
    size_t n = _abundanceMap->size();

    _nb_abundances_above_precision = 0;

    /** We need a progress object. */
    tools::dp::IteratorListener* delegate = createIteratorListener(_solidCounts->getNbItems(),messages[3]);  LOCAL (delegate);
    setProgress (new ProgressCustom(delegate));

    SubjectIterator<Count>* itKmers = new SubjectIterator<Count> (_solidCounts->iterator(), _solidCounts->getNbItems()/100);
    itKmers->addObserver (_progress);
    LOCAL (itKmers);

    // TODO parallize that

	std::vector<int> & _abundanceDiscretization =  _abundanceMap->_abundanceDiscretization ;
	int max_abundance_discrete = _abundanceDiscretization[_abundanceDiscretization.size()-2];
    // set counts and at the same time, test the mphf
    for (itKmers->first(); !itKmers->isDone(); itKmers->next())
    {
        //cout << "kmer: " << itKmers->item().value.toString(21) << std::endl;
        
        /** We get the hash code of the current item. */
        typename AbundanceMap::Hash::Code h = _abundanceMap->getCode (itKmers->item().value);

        /** Little check. */
        if (h >= n) {  throw Exception ("MPHF check: value out of bounds"); }

        /** We get the abundance of the current kmer. */
        int abundance = itKmers->item().abundance;

        if (abundance > max_abundance_discrete)
        {
            _nb_abundances_above_precision++;
            abundance = max_abundance_discrete;
        }

		//get first cell strictly greater than abundance
		std::vector<int>::iterator  up = std::upper_bound(_abundanceDiscretization.begin(), _abundanceDiscretization.end(), abundance);
		up--; // get previous cell
		int idx = up- _abundanceDiscretization.begin() ;
        /** We set the abundance of the current kmer. */
        _abundanceMap->at (h) = idx;

        nb_iterated ++;
    }

    if (nb_iterated != n && n > 3)
    {
        throw Exception ("ERROR during abundance population: itKmers iterated over %d/%d kmers only", nb_iterated, n);
    }

#if 1
    // you know what? let's always test if the MPHF does not have collisions, it won't hurt.
    check ();
#endif

    /** We gather some statistics. */
    getInfo()->add (1, "stats");
    getInfo()->add (2, "nb_keys",               "%ld",  _abundanceMap->size());
    getInfo()->add (2, "data_size",             "%ld",  _dataSize);
    getInfo()->add (2, "bits_per_key",          "%.3f", (float)(_dataSize*8)/(float)_abundanceMap->size());
    getInfo()->add (2, "prec",                  "%d",   MAX_ABUNDANCE);
    getInfo()->add (2, "nb_abund_above_prec",   "%d",   _nb_abundances_above_precision);
    getInfo()->add (1, getTimeInfo().getProperties("time"));
}
Пример #5
0
void NitroSynth::setParameter(VstInt32 index, float value)
{
	int iChannel = index / 16;
	int iParameter = index % 16;
	InstrumentParameters * pParameter = & pParameters[iChannel];

 	int iValue = -1;

	if ( iParameter < InstrumentParameters::LAST )
	{
		switch ( iParameter )
		{
			case InstrumentParameters::VOLUME:
				iValue = pParameter->iVolume = (int) (value * 127.0f);
				break;

			case InstrumentParameters::PANNING:
				iValue = pParameter->iPanning = (int) (value * 128.0f);
				break;

			case InstrumentParameters::DETUNE:
				iValue = pParameter->iDetune = (int) ((value-0.5f) * 2.0f * 32.0f);
				break;

			case InstrumentParameters::ENVELOPE_ATTACK:
				if ( value <= 1.2f/127.0f )
					iValue = pParameter->Envelope.iAttack = 1;
				else
					iValue = pParameter->Envelope.iAttack = (int)(value * 127.0f);
				break;

			case InstrumentParameters::ENVELOPE_DECAY:
				if ( value <= 1.2f/127.0f )
					iValue = pParameter->Envelope.iDecay = 1;
				else
					iValue = pParameter->Envelope.iDecay = (int)(value * 127.0f);
				break;

			case InstrumentParameters::ENVELOPE_SUSTAIN:
				iValue = pParameter->Envelope.iSustain = (int)(value * 127.0f);
				break;

			case InstrumentParameters::ENVELOPE_RELEASE:
				if ( value <= 1.2f/127.0f )
					iValue = pParameter->Envelope.iRelease = 1;
				else
					iValue = pParameter->Envelope.iRelease = (int)(value * 127.0f);
				break;

			case InstrumentParameters::DUTY:
				iValue = pParameter->iDuty = (int)(value * 7.0f);
				break;

			case InstrumentParameters::PORTAMENTO_LENGTH:
				iValue = pParameter->iPortamentoLength = (int)(value * 128.0f);
				break;

			case InstrumentParameters::SWEEP_LENGTH:
				iValue = pParameter->Sweep.iLength = (int)(value * 127.0f);
				break;

			case InstrumentParameters::SWEEP_OFFSET:
				iValue = pParameter->Sweep.iOffset = (int)((value-0.5f) * 2.0f * 32.0f * 16.0f);
				break;

			case InstrumentParameters::MODULATION_AMPLITUDE:
				iValue = pParameter->Modulation.iAmplitude = (int)(value * 127.0f);
				break;

			case InstrumentParameters::MODULATION_FREQUENCY:
				iValue = pParameter->Modulation.iFrequency = (int)(value * 128.0f);
				break;

			case InstrumentParameters::TREMOLO_AMPLITUDE:
				iValue = pParameter->Tremolo.iAmplitude = (int)(value * 255.0f);
				break;

			case InstrumentParameters::TREMOLO_FREQUENCY:
				iValue = pParameter->Tremolo.iFrequency = (int)(value * 128.0f);
				break;

			case InstrumentParameters::ARPEGGIO:
				iValue = pParameter->iArpeggio = (int)(value * 32.0f);
				break;
		}
	}

	if ( bRecording && iValue != -1 )
	{
		VstTimeInfo* pTimeInfo = getTimeInfo(0);
		if ( pTimeInfo )
		{
			double iTime = pTimeInfo->samplePos / pTimeInfo->sampleRate;
			int iFrame = (int)(iTime * 1000.0 / 16.0);

			Command oCommand;
			oCommand.iChannel = iChannel;
			oCommand.iFrame = iFrame;
			oCommand.iCommand = iParameter;
			oCommand.iValue = iValue;

			oCommands.push_back(oCommand);
		}
	}
}
Пример #6
0
int main()
{
    int idCount;
    int i;
    int id;
    //int ids[MAXID];
	int *ids;
    //timeInfoNode timeInfos[MAXID];

    printf("--------------------------------------------------------\n");
    printf("             XEN Domain Monitor \n");
    printf("--------------------------------------------------------\n");

    /* NULL means connect to local Xen hypervisor */
    conn = virConnectOpenReadOnly(NULL);
    if (conn == NULL)
    {
        fprintf(stderr, "Failed to connect to hypervisor\n");
        closeConn();
        return 0;
    }

	/*char* caps;
	caps = virConnectGetCapabilities(conn);
	printf("Capabilities:\n%s\n",caps);
	free(caps);*/
	char *host;
	host = virConnectGetHostname(conn);
	fprintf(stdout, "Hostname:%s\n",host);
	free(host);
	int vcpus;
	vcpus = virConnectGetMaxVcpus(conn,NULL);
	fprintf(stdout, "Maxmum support vcpus:%d\n",vcpus);
	unsigned long long node_free_memory;
	node_free_memory = virNodeGetFreeMemory(conn);
	fprintf(stdout, "free memory:%lld\n",node_free_memory);
	virNodeInfo nodeinfo;
	virNodeGetInfo(conn,&nodeinfo);
	fprintf(stdout, "Model: %s\n", nodeinfo.model);
    fprintf(stdout, "Memory size: %lukb\n", nodeinfo.memory);
    fprintf(stdout, "Number of CPUs: %u\n", nodeinfo.cpus);
    fprintf(stdout, "MHz of CPUs: %u\n", nodeinfo.mhz);
    fprintf(stdout, "Number of NUMA nodes: %u\n", nodeinfo.nodes);
    fprintf(stdout, "Number of CPU sockets: %u\n", nodeinfo.sockets);
    fprintf(stdout, "Number of CPU cores per socket: %u\n", nodeinfo.cores);
    fprintf(stdout, "Number of CPU threads per core: %u\n", nodeinfo.threads);	
    fprintf(stdout, "Virtualization type: %s\n", virConnectGetType(conn));
	unsigned long ver;
	virConnectGetVersion(conn, &ver);
	fprintf(stdout, "Version: %lu\n", ver);
	/*unsigned long Libver;
	virConnectGetLibVersion(conn, &Libver);
	fprintf(stdout, "Libvirt Version: %lu\n", Libver);*/
	char *uri;
	uri = virConnectGetURI(conn);
	fprintf(stdout, "Canonical URI: %s\n", uri);
	free(uri);
	/* get the count of IDs and save these ID into ids[] */
    idCount = virConnectNumOfDomains(conn);
	ids = malloc(sizeof(int) *idCount);
	idCount = virConnectListDomains(conn,ids,idCount);
	//idCount = virConnectListDomains(conn, &ids[0], MAXID);
    if (idCount < 0)
    {
        fprintf(stderr, "Failed to list the domains\n");
        closeConn();
        return 0;
    }

    timeInfoNode timeInfos[idCount];
	printf("Domain Totals: %d\n", idCount);
    printf("ID\tCPU\tMEM\tMaxMEM\tVCPUs\tState\tNAME\n");

    /* loop get the CPUtime info by IDs */
    for (i = 0; i < idCount; i++)
    {
        id = ids[i];
        getTimeInfo(id, &(timeInfos[i]));
    }

    sleep(1);

    /* loop print the domain info and calculate the usage of cpus*/
    for (i = 0; i < idCount; i++)
    {
        id = ids[i];
        getDomainInfo(id, timeInfos[i]);
    }

    free(ids);
	printf("--------------------------------------------------------\n");
    closeConn();
    return 0;
}