Пример #1
0
//*********************************************************************************
void BeatDetectorApp::Init( uint32_t mSampleCount )
{
	mFftInit = true;
	mFft.setDataSize(mSampleCount);

	int num_bins = mFft.getBinSize();
	CSoundAnalyzer::StaticInit(num_bins, samples_per_frame);

	for(int i=0; i<5; i++)
	{
		float i_f = i/(float)5 - 0.4f;
		m_Cirlces.push_back(Circle(Color(1, 0, 0), 0, Vec2f(0, getWindowHeight() * i_f)));
	}
}
Пример #2
0
// Draw
void KissFileSampleApp::draw()
{

	// Clear screen
	gl::clear(Color(0.0f, 0.0f, 0.0f));

	// Check init flag
	if (mFftInit)
	{

		// Get data
		float * mFreqData = mFft.getAmplitude();
		float * mTimeData = mFft.getData();
		int32_t mDataSize = mFft.getBinSize();

		// Get dimensions
		float mScale = ((float)getWindowWidth() - 20.0f) / (float)mDataSize;
		float mWindowHeight = (float)getWindowHeight();

		// Use polylines to depict time and frequency domains
		PolyLine<Vec2f> mFreqLine;
		PolyLine<Vec2f> mTimeLine;

		// Iterate through data
		for (int32_t i = 0; i < mDataSize; i++) 
		{

			// Do logarithmic plotting for frequency domain
			double mLogSize = log((double)mDataSize);
			float x = (float)(log((double)i) / mLogSize) * (double)mDataSize;
			float y = math<float>::clamp(mFreqData[i] * (x / mDataSize) * log((double)(mDataSize - i)), 0.0f, 2.0f);

			// Plot points on lines
			mFreqLine.push_back(Vec2f(x * mScale + 10.0f,           -y * (mWindowHeight - 20.0f) * 1.25f + (mWindowHeight - 10.0f)));
			mTimeLine.push_back(Vec2f(i * mScale + 10.0f, mTimeData[i] * (mWindowHeight - 20.0f) * 0.3f  + (mWindowHeight * 0.15f + 10.0f)));

		}

		// Draw signals
		gl::draw(mFreqLine);
		gl::draw(mTimeLine);

	}

}