void drawAudioBuffer( const audio::Buffer &buffer, const Rectf &bounds, bool drawFrame, const ci::ColorA &color )
{
	gl::ScopedGlslProg glslScope( getStockShader( gl::ShaderDef().color() ) );

	gl::color( color );

	const float waveHeight = bounds.getHeight() / (float)buffer.getNumChannels();
	const float xScale = bounds.getWidth() / (float)buffer.getNumFrames();

	float yOffset = bounds.y1;
	for( size_t ch = 0; ch < buffer.getNumChannels(); ch++ ) {
		PolyLine2f waveform;
		const float *channel = buffer.getChannel( ch );
		float x = bounds.x1;
		for( size_t i = 0; i < buffer.getNumFrames(); i++ ) {
			x += xScale;
			float y = ( 1 - ( channel[i] * 0.5f + 0.5f ) ) * waveHeight + yOffset;
			waveform.push_back( vec2( x, y ) );
		}

		if( ! waveform.getPoints().empty() )
			gl::draw( waveform );

		yOffset += waveHeight;
	}

	if( drawFrame ) {
		gl::color( color.r, color.g, color.b, color.a * 0.6f );
		gl::drawStrokedRect( bounds );
	}
}
void _TBOX_PREFIX_App::update()
{
    mPcmBuffer = mMonitorNode->getBuffer();
    
    if ( !mPcmBuffer.isEmpty() )
        mXtract->update( mPcmBuffer.getData() );
}
Exemple #3
0
bool Device::add(audio::Buffer &buf)
{
# ifdef NNT_MACH
    
    int suc = 0;
    for (core::vector<AudioQueueBufferRef>::iterator each = buf.handle().begin();
         each != buf.handle().end();
         ++each)
    {
        OSStatus sta = AudioQueueEnqueueBuffer(buf.queue, *each, 0, NULL);
        if (sta)
        {
            trace_msg("failed to add audio buffer");
        }
        else
        {
            ++suc;
        }
    }
    
    // if success, the buffer will freed when dispose the queue.
    buf.need_release = suc == 0;
    
    return suc != 0;
    
# endif
    return false;
}
void _TBOX_PREFIX_App::drawPcmData()
{
    if ( mPcmBuffer.isEmpty() )
        return;
    
    // draw the first(left) channel in the PCM buffer
    // getData() returns a pointer to the first sample in the buffer
	uint32_t    bufferLength    = mPcmBuffer.getSize() / mPcmBuffer.getNumChannels();
    float       *leftBuffer     = mPcmBuffer.getData();

	int     displaySize = getWindowWidth();
	float   scale       = displaySize / (float)bufferLength;

	PolyLine<Vec2f>	leftBufferLine;

    gl::color( Color::gray( 0.4f ) );
	
	for( int i = 0; i < bufferLength; i++ )
    {
		float x = i * scale;
        float y = 50 + leftBuffer[i] * 60;
		leftBufferLine.push_back( Vec2f( x , y) );
	}

	gl::draw( leftBufferLine );
}