//==============================================================================
void MPESynthesiser::noteAdded (MPENote newNote)
{
    const ScopedLock sl (voicesLock);

    if (MPESynthesiserVoice* voice = findFreeVoice (newNote, shouldStealVoices))
        startVoice (voice, newNote);
}
Example #2
0
//==============================================================================
void Synthesiser::noteOn (const int midiChannel,
                          const int midiNoteNumber,
                          const float velocity)
{
    const ScopedLock sl (lock);

    for (int i = sounds.size(); --i >= 0;)
    {
        SynthesiserSound* const sound = sounds.getUnchecked(i);

        if (sound->appliesToNote (midiNoteNumber)
             && sound->appliesToChannel (midiChannel))
        {
            // If hitting a note that's still ringing, stop it first (it could be
            // still playing because of the sustain or sostenuto pedal).
            for (int j = voices.size(); --j >= 0;)
            {
                SynthesiserVoice* const voice = voices.getUnchecked (j);

                if (voice->getCurrentlyPlayingNote() == midiNoteNumber
                     && voice->isPlayingChannel (midiChannel))
                    stopVoice (voice, true);
            }

            startVoice (findFreeVoice (sound, shouldStealNotes),
                        sound, midiChannel, midiNoteNumber, velocity);
        }
    }
}
Example #3
0
	int Soloud::play(AudioSource &aSound, float aVolume, float aPan, int aPaused, int aBus)
	{
		if (aSound.mFlags & AudioSource::SINGLE_INSTANCE)
		{
			// Only one instance allowed, stop others
			stopSound(aSound);
		}

		if (mLockMutexFunc) mLockMutexFunc(mMutex);
		int ch = findFreeVoice();
		if (ch < 0) 
		{
			if (mUnlockMutexFunc) mUnlockMutexFunc(mMutex);
			return -1;
		}
		if (!aSound.mAudioSourceID)
		{
			aSound.mAudioSourceID = mAudioSourceID;
			mAudioSourceID++;
			aSound.mSoloud = this;
		}
		mVoice[ch] = aSound.createInstance();
		mVoice[ch]->mAudioSourceID = aSound.mAudioSourceID;
		mVoice[ch]->mBusHandle = aBus;
		mVoice[ch]->init(mPlayIndex, aSound.mBaseSamplerate, aSound.mChannels, aSound.mFlags);

		mPlayIndex++;

		if (aPaused)
		{
			mVoice[ch]->mFlags |= AudioSourceInstance::PAUSED;
		}

		setVoicePan(ch, aPan);
		setVoiceVolume(ch, aVolume);
		setVoiceRelativePlaySpeed(ch, 1);

		int i;
		for (i = 0; i < FILTERS_PER_STREAM; i++)
		{
			if (aSound.mFilter[i])
			{
				mVoice[ch]->mFilter[i] = aSound.mFilter[i]->createInstance();
			}
		}

		int scratchneeded = SAMPLE_GRANULARITY * mVoice[ch]->mChannels;

		mVoice[ch]->mResampleData[0]->mBuffer = new float[scratchneeded];
		mVoice[ch]->mResampleData[1]->mBuffer = new float[scratchneeded];

		// First buffer will be overwritten anyway; the second may be referenced by resampler
		memset(mVoice[ch]->mResampleData[0]->mBuffer, 0, sizeof(float) * scratchneeded);
		memset(mVoice[ch]->mResampleData[1]->mBuffer, 0, sizeof(float) * scratchneeded);

		if (mUnlockMutexFunc) mUnlockMutexFunc(mMutex);

		int handle = getHandleFromVoice(ch);
		return handle;
	}	
Example #4
0
void musicBlock::noteOn(uint32_t channel, uint8_t key, int volume)
{
	if (volume <= 0)
	{
		noteOff(channel, key);
		return;
	}
	GenMidiInstrument *instrument;

	// Percussion channel is treated differently.
	if (channel == CHAN_PERCUSSION)
	{
		if (key < GENMIDI_FIST_PERCUSSION || key >= GENMIDI_FIST_PERCUSSION + GENMIDI_NUM_PERCUSSION)
		{
			return;
		}

		instrument = &OPLinstruments[key + (GENMIDI_NUM_INSTRS - GENMIDI_FIST_PERCUSSION)];
	}
	else
	{
		auto inst = oplchannels[channel].Instrument;
		if (inst >= GENMIDI_NUM_TOTAL) return;	// better safe than sorry.
		instrument = &OPLinstruments[inst];
	}

	bool double_voice = ((instrument->flags) & GENMIDI_FLAG_2VOICE) && !opl_singlevoice;

	int i = findFreeVoice();
	if (i < 0) i = replaceExistingVoice();

	if (i >= 0)
	{
		voiceKeyOn(i, channel, instrument, 0, key, volume);
		if (double_voice)
		{
			i = findFreeVoice();
			if (i > 0)
			{
				voiceKeyOn(i, channel, instrument, 1, key, volume);
			}
		}
	}
}
Example #5
0
void VoiceManager::onNoteOn(int noteNumber, int velocity) {
	Voice* voice = findFreeVoice();
	if (!voice) {
		return;
	}
	voice->reset();
	voice->setNoteNumber(noteNumber);
	voice->mVelocity = velocity;
	voice->isActive = true;
	voice->mVolumeEnvelope.enterStage(EnvelopeGenerator::ENVELOPE_STAGE_ATTACK);
	voice->mFilterEnvelope.enterStage(EnvelopeGenerator::ENVELOPE_STAGE_ATTACK);
}
void MPESynthesiser::reduceNumVoices (const int newNumVoices)
{
    // we can't possibly get to a negative number of voices...
    jassert (newNumVoices >= 0);

    const ScopedLock sl (voicesLock);

    while (voices.size() > newNumVoices)
    {
        if (MPESynthesiserVoice* voice = findFreeVoice (MPENote(), true))
            voices.removeObject (voice);
        else
            voices.remove (0); // if there's no voice to steal, kill the oldest voice
    }
}
Example #7
0
//==============================================================================
void Synthesiser::noteOn (const int midiChannel,
                          const int midiNoteNumber,
                          const float velocity)
{
    const ScopedLock sl (lock);

    for (auto* sound : sounds)
    {
        if (sound->appliesToNote (midiNoteNumber) && sound->appliesToChannel (midiChannel))
        {
            // If hitting a note that's still ringing, stop it first (it could be
            // still playing because of the sustain or sostenuto pedal).
            for (auto* voice : voices)
                if (voice->getCurrentlyPlayingNote() == midiNoteNumber && voice->isPlayingChannel (midiChannel))
                    stopVoice (voice, 1.0f, true);

            startVoice (findFreeVoice (sound, midiChannel, midiNoteNumber, shouldStealNotes),
                        sound, midiChannel, midiNoteNumber, velocity);
        }
    }
}
 void VoiceManager::noteOn(int note, int velocity, int channel)
 {
     for(auto& source: sourceManager->getAudioSources(note, velocity, channel))
     {
         Voice* voice = findFreeVoice();
         
         if(voice == nullptr)
         {
             voice = new Voice();
             extraVoices.emplace_back(std::move(voice));
         }
         
         auto filePlayer = new AudioFilePlayer();
         filePlayer->setFile(&sourceManager->getFileManager().getFile(source.info));
         filePlayer->setSampleRate(getSampleRate());
         
         voice->setSource(filePlayer);
         voice->playingNumber = note;
         voice->start();
         std::cout<<voices.size()<<std::endl;
         std::cout<<extraVoices.size()<<std::endl;
     }
 }