Exemple #1
0
SoundFile* AbcFile::createSoundFile() {
    SoundFile * soundFile = new SoundFile();
    soundFile->setBitDepth(bitRate);
    soundFile->setSampleRate(sampleRate);
    soundFile->setNumberOfChannels((int)instruments.size());
    int samplesPerCount = (int)ceil(60.0*sampleRate/tempo);
    for(int i = 0; i < instruments.size(); i++) {
        SoundFile * otherChannels = new SoundFile();
        otherChannels->setBitDepth(bitRate);
        otherChannels->setSampleRate(sampleRate);
        otherChannels->setNumberOfChannels((int)instruments.size());
        SoundGenerator::SoundBuilder builder;
        builder.setAttack(instruments[i]->getAttack()).setDecay(instruments[i]->getDecay()).setRelease(instruments[i]->getRelease()).setDuration((instruments[i]->findTotalCount() * 60 / tempo)).setSampleRate(sampleRate).setSustain(instruments[i]->getSustain());
        int numSamples = 0;
        for(int j = 0; j < instruments[i]->getScore().size(); j++) {
            SoundFile * tempFile = new SoundFile();
            tempFile->setBitDepth(bitRate);
            tempFile->setSampleRate(sampleRate);
            SoundGenerator soundGenerator = builder.setDuration((instruments[i]->getScore()[j]->getCount() * 60 / tempo)).setBitDepth(bitRate).build();
            tempFile->setNumberOfChannels((int)instruments.size());
            int waveForm = instruments[i]->getWaveform();
            if(waveForm == 1) {
                numSamples +=sineWave(instruments[i]->getScore()[j],samplesPerCount,tempFile);
            } else if(waveForm == 2) {
                numSamples +=sawtoothWave(instruments[i]->getScore()[j],samplesPerCount,tempFile);
            } else if (waveForm == 3) {
                numSamples +=triangleWave(instruments[i]->getScore()[j],samplesPerCount,tempFile);
            } else {
                numSamples +=pulseWave(instruments[i]->getScore()[j],samplesPerCount,tempFile);
            }
            soundGenerator.handleEnvelop(tempFile);
            if(i == 0) {
                *soundFile += tempFile;
            } else {
                *otherChannels += tempFile;
            }
        }
        for (int k = numSamples + 1; k < getMaxSamples(instruments); ++k) {
            SampleLine *sampleLine = new SampleLine();
            sampleLine->addNewChannel(0);
            if(i == 0) {
                soundFile->addSample(sampleLine);
            } else {
                otherChannels->addSample(sampleLine);
            }
        }
        if(std::find(mute.begin(),mute.end(),i) != mute.end()) {
            if(i == 0) {
                *soundFile * 0;
            } else {
                *otherChannels * 0;
            }
        }
        if(i != 0) {
            *soundFile | otherChannels;
        }
    }

    return soundFile;
}
Exemple #2
0
void testSineWave()
{
	std::ofstream file("../results/sine_wave.dat", std::ios::out);

	for (verve::real currentTime=0; currentTime < gMaxTime; currentTime += gDT)
	{
		verve::real input = sineWave(currentTime, gWaveAmplitude, gWaveFrequency);
		verve::real output = activateNeuron(input, gDT);
		file << currentTime << " " << input << " " << output << std::endl;
	}

	file.close();
}