syedhali / EZAudio

An iOS and macOS audio visualization framework built upon Core Audio useful for anyone doing real-time, low-latency audio processing and visualizations.
Other
4.94k stars 821 forks source link

Enable GL_BLEND for EZAudioPlotGL #325

Open jdolan opened 8 years ago

jdolan commented 8 years ago

I've subclassed EZAudioPlotGL in my application to enable GL_BLEND with an appropriate blend function, so that when you configure the plot with colors containing alpha values, they render as expected. Here's what my subclass implementation looks like:

- (void)redrawWithPoints:(EZAudioPlotGLPoint *)points
              pointCount:(UInt32)pointCount
              baseEffect:(GLKBaseEffect *)baseEffect
      vertexBufferObject:(GLuint)vbo
       vertexArrayBuffer:(GLuint)vab
            interpolated:(BOOL)interpolated
                mirrored:(BOOL)mirrored
                    gain:(float)gain
{
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    [super redrawWithPoints:points
                 pointCount:pointCount
                 baseEffect:baseEffect
         vertexBufferObject:vbo
          vertexArrayBuffer:vab
               interpolated:interpolated
                   mirrored:mirrored
                       gain:gain];

    glDisable(GL_BLEND);
}

Resulting waveform (notice that I'm also re-rendering part of the waveform with a higher alpha value as well, to indicate current playback progress):

screen shot 2016-06-10 at 10 24 44 am

Is there any reason why this couldn't be the default behavior?