Example #1
0
bool Fbo::initMultisample( bool csaa )
{
#if defined( CINDER_GLES )
	return false;
#else
	glGenFramebuffersEXT( 1, &mObj->mResolveFramebufferId );
	glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, mObj->mResolveFramebufferId ); 
	
	// bind all of the color buffers to the resolve FB's attachment points
	vector<GLenum> drawBuffers;
	for( size_t c = 0; c < mObj->mColorTextures.size(); ++c ) {
		glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT + c, getTarget(), mObj->mColorTextures[c].getId(), 0 );
		drawBuffers.push_back( GL_COLOR_ATTACHMENT0_EXT + c );
	}

	if( ! drawBuffers.empty() )
		glDrawBuffers( drawBuffers.size(), &drawBuffers[0] );

	// see if the resolve buffer is ok
	FboExceptionInvalidSpecification ignoredException;
	if( ! checkStatus( &ignoredException ) )
		return false;

	glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, mObj->mId );

	if( mObj->mFormat.mSamples > getMaxSamples() ) {
		mObj->mFormat.mSamples = getMaxSamples();
	}

	// setup the multisampled color renderbuffers
	for( int c = 0; c < mObj->mFormat.mNumColorBuffers; ++c ) {
		mObj->mMultisampleColorRenderbuffers.push_back( Renderbuffer( mObj->mWidth, mObj->mHeight, mObj->mFormat.mColorInternalFormat, mObj->mFormat.mSamples, mObj->mFormat.mCoverageSamples ) );

		// attach the multisampled color buffer
		glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT + c, GL_RENDERBUFFER_EXT, mObj->mMultisampleColorRenderbuffers.back().getId() );
	}
	
	if( ! drawBuffers.empty() )
		glDrawBuffers( drawBuffers.size(), &drawBuffers[0] );

	if( mObj->mFormat.mDepthBuffer ) {
		// create the multisampled depth Renderbuffer
		mObj->mMultisampleDepthRenderbuffer = Renderbuffer( mObj->mWidth, mObj->mHeight, mObj->mFormat.mDepthInternalFormat, mObj->mFormat.mSamples, mObj->mFormat.mCoverageSamples );

		// attach the depth Renderbuffer
		glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, mObj->mMultisampleDepthRenderbuffer.getId() );
	}

	// see if the primary framebuffer turned out ok
	return checkStatus( &ignoredException );
#endif // ! CINDER_GLES
}
Example #2
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;
}