Ejemplo n.º 1
0
void BeatboxVoxAudioProcessor::initialiseSynth()
{
	/** NOTE: - Quick and dirty sample drum synth for prototype
	 *  In future versions will ideally allow user to select sample to use and
	 *  also manage sample rate changes effect on loaded samples. 
	 */
	WavAudioFormat wavFormat;
	BigInteger kickNoteRange;
	BigInteger snareNoteRange;
	BigInteger hihatNoteRange;
	BigInteger osdTestSoundNoteRange;

	drumSynth.clearSounds();
	osdTestSynth.clearSounds();

	std::unique_ptr<AudioFormatReader> readerKickDrum(wavFormat.createReaderFor(new MemoryInputStream(BinaryData::bassdrum_wav,
	                                                                                                  BinaryData::bassdrum_wavSize,
	                                                                                                  false),
	                                                                            true));

	std::unique_ptr<AudioFormatReader> readerSnareDrum(wavFormat.createReaderFor(new MemoryInputStream(BinaryData::snaredrum_wav,
	                                                                                                   BinaryData::snaredrum_wavSize,
	                                                                                                   false),
	                                                                             true));

	std::unique_ptr<AudioFormatReader> readerHiHat(wavFormat.createReaderFor(new MemoryInputStream(BinaryData::hihat_wav,
	                                                                                                   BinaryData::hihat_wavSize,
	                                                                                                   false),
	                                                                             true));
	
	std::unique_ptr<AudioFormatReader> readerOSDTestSound(wavFormat.createReaderFor(new MemoryInputStream(BinaryData::osdTestOne_wav,
	                                                                                                      BinaryData::osdTestOne_wavSize,
	                                                                                                      false),
	                                                                                true));

	kickNoteRange.setBit(kickNoteNumber);
	snareNoteRange.setBit(snareNoteNumber);
	hihatNoteRange.setBit(hihatNoteNumber);
	osdTestSoundNoteRange.setBit(osdTestSoundNoteNumber);


	drumSynth.addSound(new SamplerSound("Kick Sound", *readerKickDrum, kickNoteRange, kickNoteNumber, 0.0, 0.0, 5.0));
	drumSynth.addSound(new SamplerSound("Snare Sound", *readerSnareDrum, snareNoteRange, snareNoteNumber, 0.0, 0.0, 5.0));
	drumSynth.addSound(new SamplerSound("HiHat Sound", *readerHiHat, hihatNoteRange, hihatNoteNumber, 0.0, 0.0, 5.0));

	drumSynth.addVoice(new SamplerVoice());

	drumSynth.addSound(new NoiseSound(noiseNoteNumber));
	drumSynth.addVoice(new NoiseVoice());


	osdTestSynth.addSound(new SamplerSound("OSD Test Sound", *readerOSDTestSound, osdTestSoundNoteRange, osdTestSoundNoteNumber, 0.0, 0.0, 5.0));
	osdTestSynth.addVoice(new SamplerVoice());
}
Ejemplo n.º 2
0
    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;
    }
Ejemplo n.º 3
0
SampleItem::SampleItem(const String &filename)
{
	this->filename = filename;

	File file(filename);
	if (file.exists())
	{
		shortname = file.getFileNameWithoutExtension();
		FileInputStream *stream = new FileInputStream(file);
		WavAudioFormat format;
		AudioFormatReader *reader = format.createReaderFor(stream, false);
		if (reader)
		{
			formatName = reader->getFormatName();
			sampleRate = (int)reader->sampleRate;
			size = (int)reader->lengthInSamples;
			bits = reader->bitsPerSample;
			delete reader;
		}
		else
		{
			sampleRate = 0;
			size = 0;
			bits = 0;
		}
	}

	playing = false;
}
Ejemplo n.º 4
0
void DrumMachine::setDrumSound(String soundName, File sample) {
    WavAudioFormat wavFormat;
    
    ScopedPointer<AudioFormatReader> audioReader(wavFormat.createReaderFor(new FileInputStream(sample), true));
    
    BigInteger notes;
    notes.setRange(lastNote, 1, true);
    
    synth.addSound(new SamplerSound(soundName, *audioReader, notes,
                                    lastNote,   // root midi note
                                    0.0,  // attack time
                                    0.0,  // release time
                                    10.0  // maximum sample length
                                    ));
    
    soundToNote.set(soundName, lastNote++);
}
Ejemplo n.º 5
0
void Sample::update(const String& path, WavAudioFormat& wavAudioFormat)
{
	// Don't load a subsequent sample if a new sample is already loaded (but not yet played).
	if (_readyToSwap)
		return;

	// Find audio file.
	String fileName(path);
	fileName = File::addTrailingSeparator(fileName);
	fileName += _name;
	fileName += EXT;
	File file(fileName);

	Time modification = file.getLastModificationTime();
	if (modification <= _lastModification)
		return;

	// Read audio file. We only read the left channel, mono is good enough.
	AudioFormatReader* reader = wavAudioFormat.createReaderFor(file.createInputStream(), true);
	if (reader == nullptr)
		return;
	_lastModification = modification;

	int64 start = reader->searchForLevel(0, reader->lengthInSamples, SAMPLE_START_THRESHOLD, 1.0, 0);
	if (start == -1)
		start = 0;
	int count = (int)(reader->lengthInSamples - start);

	_processor->writeTrace(String() << "Loading " << _name << " from disk (skip=" << start << ")");

	int newIndex = !_bufferIndex;
	AudioSampleBuffer* buffer = &(_buffers[newIndex]);
	buffer->setSize(1, count);

	reader->read(buffer, 0, count, start, true, false);

	delete reader;

	// Done.
	_readyToSwap = true;
}
Ejemplo n.º 6
0
    void setUsingSampledSound()
    {
        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.clearSounds();
        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
                                          ));
    }
Ejemplo n.º 7
0
void MainPanel::setAudio (int audioId)
{
  AudioSource* source = 0;

  switch (audioId)
  {
  case 1: // Amen Break
    {
      WavAudioFormat waf;
      AudioFormatReader* afr = waf.createReaderFor (
        new MemoryInputStream (binaries::amenbreakloop_wav,
          binaries::amenbreakloop_wavSize,
          false),
        true);

      source = new ResamplingReader (afr);
    }
    break;

  case 2: // sine wave
    {
      ToneGeneratorAudioSource* tgas = new ToneGeneratorAudioSource ();
      tgas->setFrequency (440);
      tgas->setAmplitude (1.f);
      source = tgas;
    }
    break;

  case 3: // White Noise
    source = new NoiseAudioSource;
    break;

  case 4: // Pink Noise
    source = new NoiseAudioSource (true);
    break;
  };

  MainApp::getInstance().getAudioOutput().setSource (source);
}