private void DrawGraph() { DrawGrid(); SynthGraphCoordMapper mapper = new SynthGraphCoordMapper( -1.0f, 1.0f, m_windowRect.height - GRAPH_MARGIN_VERTICAL, SynthGraphEditorFactory.WINDOW_HEADER_HEIGHT + GRAPH_MARGIN_VERTICAL, true ); float[] data = ProcessNode(); int sampleSkip = Mathf.FloorToInt( data.Length / ( m_windowRect.width - GRAPH_MARGIN_HORIZONTAL * 2.0f ) ); SynthGraphEditorUtils.BeginLines( Color.green ); Vector2 from, to; float val0, val1; float x = GRAPH_MARGIN_HORIZONTAL; for ( int i = sampleSkip; i < data.Length && x <= m_windowRect.width - GRAPH_MARGIN_HORIZONTAL ; i += sampleSkip ) { val0 = data[ i - sampleSkip ]; val1 = data[ i ]; from.x = x; from.y = mapper.MapFromTo( val0 ); to.x = x += 1.0f; to.y = mapper.MapFromTo( val1 ); SynthGraphEditorUtils.DrawLine( from, to ); } SynthGraphEditorUtils.EndLines(); }
private void DrawPlaybackSpectrum() { AudioSource source = m_playbackObject.Source; if ( source != null ) { float x = GRAPH_MARGIN_HORIZONTAL; float y = m_windowRect.height - GRAPH_MARGIN_VERTICAL; Vector2 from, to; SynthGraphCoordMapper mapper = new SynthGraphCoordMapper( 0.0f, 1.0f, y, GRAPH_MARGIN_VERTICAL + SynthGraphEditorFactory.WINDOW_HEADER_HEIGHT, false ); float[] samples = new float[(int)m_sampleCount]; source.GetSpectrumData( samples, 0, m_fftWindow ); SynthGraphEditorUtils.BeginLines( Color.green ); for ( int i = 0; i < samples.Length; i++ ) { from.x = x; from.y = y; to.x = x; to.y = mapper.MapFromTo( samples[ i ] ); SynthGraphEditorUtils.DrawLine( from, to ); x++; } SynthGraphEditorUtils.EndLines(); } }