コード例 #1
0
ファイル: PHISynth.cpp プロジェクト: skhanker/music-tutor
    void setUsingSampledSound()
    {
        synth.clearSounds();

        WavAudioFormat wavFormat;

        AudioFormatReader* audioReader
            = wavFormat.createReaderFor (new MemoryInputStream (BinaryData::cello_wav,
                                                                BinaryData::cello_wavSize,
                                                                false),
                                         true);

        BitArray allNotes;
        allNotes.setRange (0, 128, true);

        synth.addSound (new SamplerSound (T("demo sound"),
                                          *audioReader,
                                          allNotes,
                                          74,   // root midi note
                                          0.1,  // attack time
                                          0.1,  // release time
                                          10.0  // maximum sample length
                                          ));

        delete audioReader;
    }
コード例 #2
0
ファイル: vf_Metronome.cpp プロジェクト: Izhaki/LayerEffects
  void setTickSample (void const* audioData, int dataBytes)
  {
    ScopedPointer <MemoryInputStream> mis (new MemoryInputStream (audioData, dataBytes, false));

    m_synth.clearVoices ();
    m_synth.clearSounds ();

    AudioFormatManager afm;
    afm.registerBasicFormats ();
    
    {
      ScopedPointer <AudioFormatReader> afr (afm.createReaderFor (mis));

      if (afr != nullptr)
      {
        mis.release ();

        BigInteger midiNotes;
        midiNotes.setRange (0, 127, true);

        SynthesiserSound::Ptr sound = new SamplerSound (
          "Tick",
          *afr,
          midiNotes,
          60,
          0,
          0,
          60./40.);

        m_synth.addSound (sound);
        m_synth.addVoice (new SamplerVoice);
      }
    }

  }
コード例 #3
0
    //==============================================================================
    SynthAudioSource (MidiKeyboardState& keyboardState_)
        : keyboardState (keyboardState_)
    {
        // add some voices to our synth, to play the sounds..
        for (int i = 4; --i >= 0;)
        {
            synth.addVoice (new SineWaveVoice());   // These voices will play our custom sine-wave sounds..
            synth.addVoice (new SamplerVoice());    // and these ones play the sampled sounds
        }

        // and add some sounds for them to play...
        setUsingSineWaveSound();
    }
コード例 #4
0
ファイル: PHISynth.cpp プロジェクト: skhanker/music-tutor
    void prepareToPlay (int samplesPerBlockExpected,
                        double sampleRate)
    {
        midiCollector.reset (sampleRate);

        synth.setCurrentPlaybackSampleRate (sampleRate);
    }
コード例 #5
0
ファイル: vf_Metronome.cpp プロジェクト: Izhaki/LayerEffects
  void prepareToPlay (int samplesPerBlockExpected,
                      double sampleRate)
  {
    m_sampleRate = sampleRate;

    m_synth.setCurrentPlaybackSampleRate (sampleRate);
  }
コード例 #6
0
ファイル: vf_Metronome.cpp プロジェクト: Izhaki/LayerEffects
  MetronomeImp (void const* audioData, int dataBytes)
    : m_sampleRate (44100)
    , m_tempo (120)
    , m_phase (0)
    , m_active (false)
  {
    m_synth.setNoteStealingEnabled (true);

    setTickSample (audioData, dataBytes);
  }
コード例 #7
0
ファイル: PHISynth.cpp プロジェクト: skhanker/music-tutor
    //==============================================================================
    SynthAudioSource ()
    {
        // add some voices to our synth, to play the sounds..
        for (int i = 4; --i >= 0;)
        {
            synth.addVoice (new SamplerVoice());    // and these ones play the sampled sounds
        }

        // and add some sounds for them to play...
        setUsingSampledSound();
    }
コード例 #8
0
ファイル: PHISynth.cpp プロジェクト: skhanker/music-tutor
    void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
    {
        // the synth always adds its output to the audio buffer, so we have to clear it
        // first..
        bufferToFill.clearActiveBufferRegion();

        // fill a midi buffer with incoming messages from the midi input.
        MidiBuffer incomingMidi;
        midiCollector.removeNextBlockOfMessages (incomingMidi, bufferToFill.numSamples);

        // and now get the synth to process the midi events and generate its output.
        synth.renderNextBlock (*bufferToFill.buffer, incomingMidi, 0, bufferToFill.numSamples);
    }
コード例 #9
0
    void setUsingSampledSound()
    {
        synth.clearSounds();

        WavAudioFormat wavFormat;

        ScopedPointer<AudioFormatReader> audioReader (wavFormat.createReaderFor (new MemoryInputStream (BinaryData::cello_wav,
                                                                                                        BinaryData::cello_wavSize,
                                                                                                        false),
                                                                                 true));

        BigInteger allNotes;
        allNotes.setRange (0, 128, true);

        synth.addSound (new SamplerSound ("demo sound",
                                          *audioReader,
                                          allNotes,
                                          74,   // root midi note
                                          0.1,  // attack time
                                          0.1,  // release time
                                          10.0  // maximum sample length
                                          ));
    }
コード例 #10
0
    void getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
    {
        // the synth always adds its output to the audio buffer, so we have to clear it
        // first..
        bufferToFill.clearActiveBufferRegion();

        // fill a midi buffer with incoming messages from the midi input.
        MidiBuffer incomingMidi;
        midiCollector.removeNextBlockOfMessages (incomingMidi, bufferToFill.numSamples);

        // pass these messages to the keyboard state so that it can update the component
        // to show on-screen which keys are being pressed on the physical midi keyboard.
        // This call will also add midi messages to the buffer which were generated by
        // the mouse-clicking on the on-screen keyboard.
        keyboardState.processNextMidiBuffer (incomingMidi, 0, bufferToFill.numSamples, true);

        // and now get the synth to process the midi events and generate its output.
        synth.renderNextBlock (*bufferToFill.buffer, incomingMidi, 0, bufferToFill.numSamples);
    }
コード例 #11
0
ファイル: vf_Metronome.cpp プロジェクト: Izhaki/LayerEffects
  void getNextAudioBlock (AudioSourceChannelInfo const& bufferToFill)
  {
    int const numSamples = bufferToFill.numSamples;

    // the synth always adds its output
    //bufferToFill.clearActiveBufferRegion();

    m_midi.clear ();

    if (m_active)
    {
      double const samplesPerBeat = m_sampleRate * 60 / m_tempo;

      // Adjust phase so the beat is on or after the beginning of the output
      double beat;
      if (m_phase > 0)
        beat = 1 - m_phase;
      else
        beat = 0 - m_phase;

      // Set notes in midi buffer
      for (;;beat += 1)
      {
        // Calc beat pos
        int pos = static_cast <int> (beat * samplesPerBeat);

        if (pos < numSamples)
        {
          m_midi.addEvent (MidiMessage::noteOn (1, 84, 1.f), pos);
        }
        else
        {
          break;
        }
      }
    }

    m_synth.renderNextBlock (*bufferToFill.buffer,
                            m_midi,
                            0,
                            bufferToFill.numSamples);
  }
コード例 #12
0
 void setUsingSineWaveSound()
 {
     synth.clearSounds();
     synth.addSound (new SineWaveSound());
 }