diff --git a/EZAudio.xcodeproj/project.pbxproj b/EZAudio.xcodeproj/project.pbxproj index 832db06e..017975cd 100644 --- a/EZAudio.xcodeproj/project.pbxproj +++ b/EZAudio.xcodeproj/project.pbxproj @@ -140,6 +140,7 @@ 469F4CF41B749F7800666A46 /* Products */, ); sourceTree = ""; + usesTabs = 0; }; 469F4CF41B749F7800666A46 /* Products */ = { isa = PBXGroup; diff --git a/EZAudio/EZAudioPlot.h b/EZAudio/EZAudioPlot.h index 92009a33..ed6db0a1 100644 --- a/EZAudio/EZAudioPlot.h +++ b/EZAudio/EZAudioPlot.h @@ -57,6 +57,11 @@ FOUNDATION_EXPORT UInt32 const EZAudioPlotDefaultHistoryBufferLength; */ FOUNDATION_EXPORT UInt32 const EZAudioPlotDefaultMaxHistoryBufferLength; +/** + The number of additional points required for the first and last point. These are required when drawing filled plots are both on the center line. + */ +FOUNDATION_EXPORT UInt32 const kEZAudioPlotAdditionalPointCount; + //------------------------------------------------------------------------------ #pragma mark - EZAudioPlotWaveformLayer //------------------------------------------------------------------------------ diff --git a/EZAudio/EZAudioPlot.m b/EZAudio/EZAudioPlot.m index 7603e26b..582af051 100644 --- a/EZAudio/EZAudioPlot.m +++ b/EZAudio/EZAudioPlot.m @@ -33,6 +33,7 @@ UInt32 const kEZAudioPlotDefaultHistoryBufferLength = 512; UInt32 const EZAudioPlotDefaultHistoryBufferLength = 512; UInt32 const EZAudioPlotDefaultMaxHistoryBufferLength = 8192; +UInt32 const kEZAudioPlotAdditionalPointCount = 2; //------------------------------------------------------------------------------ #pragma mark - EZAudioPlot (Implementation) @@ -271,7 +272,7 @@ - (CGPathRef)createPathWithPoints:(CGPoint *)points if (pointCount > 0) { path = CGPathCreateMutable(); - double xscale = (rect.size.width) / ((float)self.pointCount); + double xscale = (rect.size.width) / ((float)(self.pointCount - 1 - kEZAudioPlotAdditionalPointCount)); double halfHeight = floor(rect.size.height / 2.0); int deviceOriginFlipped = [self isDeviceOriginFlipped] ? -1 : 1; CGAffineTransform xf = CGAffineTransformIdentity; @@ -347,14 +348,22 @@ - (void)updateBuffer:(float *)buffer withBufferSize:(UInt32)bufferSize - (void)setSampleData:(float *)data length:(int)length { - CGPoint *points = self.points; - for (int i = 0; i < length; i++) - { - points[i].x = i; - points[i].y = data[i] * self.gain; - } - points[0].y = points[length - 1].y = 0.0f; - self.pointCount = length; + CGPoint *allPoints = self.points; + + CGPoint *points = &allPoints[1]; + for (int i = 0; i < length; i++) + { + points[i].x = i; + points[i].y = data[i] * self.gain; + } + + const int first = 0; + const int last = length + 1; + allPoints[first].x = 0.0f; + allPoints[last].x = length - 1; + allPoints[first].y = allPoints[last].y = 0.0f; + + self.pointCount = length + kEZAudioPlotAdditionalPointCount; } //------------------------------------------------------------------------------ diff --git a/EZAudio/EZAudioPlotGL.m b/EZAudio/EZAudioPlotGL.m index 16728505..88607ded 100644 --- a/EZAudio/EZAudioPlotGL.m +++ b/EZAudio/EZAudioPlotGL.m @@ -299,11 +299,16 @@ - (void)updateBuffer:(float *)buffer withBufferSize:(UInt32)bufferSize - (void)setSampleData:(float *)data length:(int)length { - int pointCount = self.shouldFill ? length * 2 : length; - EZAudioPlotGLPoint *points = self.info->points; + const BOOL shouldFill = self.shouldFill; + + int pointCount = (shouldFill ? length * 2 : length) + (shouldFill ? kEZAudioPlotAdditionalPointCount : 0); + + EZAudioPlotGLPoint *allPoints = self.info->points; + EZAudioPlotGLPoint *points = (shouldFill ? &allPoints[1] : allPoints); + for (int i = 0; i < length; i++) { - if (self.shouldFill) + if (shouldFill) { points[i * 2].x = points[i * 2 + 1].x = i; points[i * 2].y = data[i]; @@ -315,9 +320,18 @@ - (void)setSampleData:(float *)data length:(int)length points[i].y = data[i]; } } - points[0].y = points[pointCount - 1].y = 0.0f; + + if (shouldFill) + { + const int first = 0; + const int last = pointCount - 1; + allPoints[first].x = 0.0f; + allPoints[last].x = length - 1; + allPoints[first].y = allPoints[last].y = 0.0f; + } + self.info->pointCount = pointCount; - self.info->interpolated = self.shouldFill; + self.info->interpolated = shouldFill; #if !TARGET_OS_IPHONE [self.openGLContext lock]; glBindVertexArray(self.info->vab); @@ -485,7 +499,7 @@ - (void)redrawWithPoints:(EZAudioPlotGLPoint *)points glClear(GL_COLOR_BUFFER_BIT); GLenum mode = interpolated ? GL_TRIANGLE_STRIP : GL_LINE_STRIP; float interpolatedFactor = interpolated ? 2.0f : 1.0f; - float xscale = 2.0f / ((float)pointCount / interpolatedFactor); + float xscale = 2.0f / (((float)(pointCount) / interpolatedFactor) - 3.0f); float yscale = 1.0f * gain; GLKMatrix4 transform = GLKMatrix4MakeTranslation(-1.0f, 0.0f, 0.0f); transform = GLKMatrix4Scale(transform, xscale, yscale, 1.0f); diff --git a/EZAudioExamples/OSX/CoreGraphicsWaveform/CoreGraphicsWaveform.xcodeproj/project.pbxproj b/EZAudioExamples/OSX/CoreGraphicsWaveform/CoreGraphicsWaveform.xcodeproj/project.pbxproj index 23efb3b2..1bce64c4 100644 --- a/EZAudioExamples/OSX/CoreGraphicsWaveform/CoreGraphicsWaveform.xcodeproj/project.pbxproj +++ b/EZAudioExamples/OSX/CoreGraphicsWaveform/CoreGraphicsWaveform.xcodeproj/project.pbxproj @@ -73,6 +73,7 @@ 666062321C5421A400FB99FA /* Products */, ); sourceTree = ""; + usesTabs = 0; }; 666062321C5421A400FB99FA /* Products */ = { isa = PBXGroup; diff --git a/EZAudioExamples/OSX/FFT/FFT.xcodeproj/project.pbxproj b/EZAudioExamples/OSX/FFT/FFT.xcodeproj/project.pbxproj index b8bfa3db..96525903 100644 --- a/EZAudioExamples/OSX/FFT/FFT.xcodeproj/project.pbxproj +++ b/EZAudioExamples/OSX/FFT/FFT.xcodeproj/project.pbxproj @@ -64,6 +64,7 @@ 66374D891C544D2E000B19D0 /* Products */, ); sourceTree = ""; + usesTabs = 0; }; 66374D891C544D2E000B19D0 /* Products */ = { isa = PBXGroup; diff --git a/EZAudioExamples/OSX/OpenGLWaveform/OpenGLWaveform.xcodeproj/project.pbxproj b/EZAudioExamples/OSX/OpenGLWaveform/OpenGLWaveform.xcodeproj/project.pbxproj index 877ac1e2..e10f0b84 100644 --- a/EZAudioExamples/OSX/OpenGLWaveform/OpenGLWaveform.xcodeproj/project.pbxproj +++ b/EZAudioExamples/OSX/OpenGLWaveform/OpenGLWaveform.xcodeproj/project.pbxproj @@ -81,6 +81,7 @@ 6660627A1C5427CC00FB99FA /* Products */, ); sourceTree = ""; + usesTabs = 0; }; 6660627A1C5427CC00FB99FA /* Products */ = { isa = PBXGroup; diff --git a/EZAudioExamples/OSX/PassThrough/PassThrough.xcodeproj/project.pbxproj b/EZAudioExamples/OSX/PassThrough/PassThrough.xcodeproj/project.pbxproj index 277b3f2c..18105523 100644 --- a/EZAudioExamples/OSX/PassThrough/PassThrough.xcodeproj/project.pbxproj +++ b/EZAudioExamples/OSX/PassThrough/PassThrough.xcodeproj/project.pbxproj @@ -64,6 +64,7 @@ 66374DA91C54503E000B19D0 /* Products */, ); sourceTree = ""; + usesTabs = 0; }; 66374DA91C54503E000B19D0 /* Products */ = { isa = PBXGroup; diff --git a/EZAudioExamples/OSX/PlayFile/PlayFile.xcodeproj/project.pbxproj b/EZAudioExamples/OSX/PlayFile/PlayFile.xcodeproj/project.pbxproj index 4b7db40e..f276e53c 100644 --- a/EZAudioExamples/OSX/PlayFile/PlayFile.xcodeproj/project.pbxproj +++ b/EZAudioExamples/OSX/PlayFile/PlayFile.xcodeproj/project.pbxproj @@ -66,6 +66,7 @@ 662B6CB61C542DF500353D48 /* Products */, ); sourceTree = ""; + usesTabs = 0; }; 662B6CB61C542DF500353D48 /* Products */ = { isa = PBXGroup; diff --git a/EZAudioExamples/OSX/RecordFile/RecordFile.xcodeproj/project.pbxproj b/EZAudioExamples/OSX/RecordFile/RecordFile.xcodeproj/project.pbxproj index 04687486..20c9d4e6 100644 --- a/EZAudioExamples/OSX/RecordFile/RecordFile.xcodeproj/project.pbxproj +++ b/EZAudioExamples/OSX/RecordFile/RecordFile.xcodeproj/project.pbxproj @@ -64,6 +64,7 @@ 66374D3B1C542E18000B19D0 /* Products */, ); sourceTree = ""; + usesTabs = 0; }; 66374D3B1C542E18000B19D0 /* Products */ = { isa = PBXGroup; diff --git a/EZAudioExamples/OSX/WaveformFromFile/WaveformFromFile.xcodeproj/project.pbxproj b/EZAudioExamples/OSX/WaveformFromFile/WaveformFromFile.xcodeproj/project.pbxproj index f517d10f..d506bbdf 100644 --- a/EZAudioExamples/OSX/WaveformFromFile/WaveformFromFile.xcodeproj/project.pbxproj +++ b/EZAudioExamples/OSX/WaveformFromFile/WaveformFromFile.xcodeproj/project.pbxproj @@ -66,6 +66,7 @@ 66374D661C54456C000B19D0 /* Products */, ); sourceTree = ""; + usesTabs = 0; }; 66374D661C54456C000B19D0 /* Products */ = { isa = PBXGroup; diff --git a/EZAudioExamples/iOS/CoreGraphicsWaveform/CoreGraphicsWaveform.xcodeproj/project.pbxproj b/EZAudioExamples/iOS/CoreGraphicsWaveform/CoreGraphicsWaveform.xcodeproj/project.pbxproj index 7d9e786b..f0eaa9e5 100644 --- a/EZAudioExamples/iOS/CoreGraphicsWaveform/CoreGraphicsWaveform.xcodeproj/project.pbxproj +++ b/EZAudioExamples/iOS/CoreGraphicsWaveform/CoreGraphicsWaveform.xcodeproj/project.pbxproj @@ -96,6 +96,7 @@ 66374E181C545A8A000B19D0 /* Products */, ); sourceTree = ""; + usesTabs = 0; }; 66374E181C545A8A000B19D0 /* Products */ = { isa = PBXGroup; diff --git a/EZAudioExamples/iOS/FFT/FFT.xcodeproj/project.pbxproj b/EZAudioExamples/iOS/FFT/FFT.xcodeproj/project.pbxproj index 7bb6c048..4d84404e 100644 --- a/EZAudioExamples/iOS/FFT/FFT.xcodeproj/project.pbxproj +++ b/EZAudioExamples/iOS/FFT/FFT.xcodeproj/project.pbxproj @@ -89,6 +89,7 @@ 66374EEA1C545B18000B19D0 /* Products */, ); sourceTree = ""; + usesTabs = 0; }; 66374EEA1C545B18000B19D0 /* Products */ = { isa = PBXGroup; diff --git a/EZAudioExamples/iOS/OpenGLWaveform/OpenGLWaveform.xcodeproj/project.pbxproj b/EZAudioExamples/iOS/OpenGLWaveform/OpenGLWaveform.xcodeproj/project.pbxproj index d05e24bc..924fa182 100644 --- a/EZAudioExamples/iOS/OpenGLWaveform/OpenGLWaveform.xcodeproj/project.pbxproj +++ b/EZAudioExamples/iOS/OpenGLWaveform/OpenGLWaveform.xcodeproj/project.pbxproj @@ -89,6 +89,7 @@ 66374E3B1C545AA8000B19D0 /* Products */, ); sourceTree = ""; + usesTabs = 0; }; 66374E3B1C545AA8000B19D0 /* Products */ = { isa = PBXGroup; diff --git a/EZAudioExamples/iOS/PassThrough/PassThrough.xcodeproj/project.pbxproj b/EZAudioExamples/iOS/PassThrough/PassThrough.xcodeproj/project.pbxproj index e698ebea..5d902ffd 100644 --- a/EZAudioExamples/iOS/PassThrough/PassThrough.xcodeproj/project.pbxproj +++ b/EZAudioExamples/iOS/PassThrough/PassThrough.xcodeproj/project.pbxproj @@ -89,6 +89,7 @@ 66374EC71C545AFB000B19D0 /* Products */, ); sourceTree = ""; + usesTabs = 0; }; 66374EC71C545AFB000B19D0 /* Products */ = { isa = PBXGroup; diff --git a/EZAudioExamples/iOS/PlayFile/PlayFile.xcodeproj/project.pbxproj b/EZAudioExamples/iOS/PlayFile/PlayFile.xcodeproj/project.pbxproj index d8122e15..986f38b8 100644 --- a/EZAudioExamples/iOS/PlayFile/PlayFile.xcodeproj/project.pbxproj +++ b/EZAudioExamples/iOS/PlayFile/PlayFile.xcodeproj/project.pbxproj @@ -91,6 +91,7 @@ 66374E5E1C545AC6000B19D0 /* Products */, ); sourceTree = ""; + usesTabs = 0; }; 66374E5E1C545AC6000B19D0 /* Products */ = { isa = PBXGroup; diff --git a/EZAudioExamples/iOS/RecordFile/RecordFile.xcodeproj/project.pbxproj b/EZAudioExamples/iOS/RecordFile/RecordFile.xcodeproj/project.pbxproj index 0c1aef70..975f8a53 100644 --- a/EZAudioExamples/iOS/RecordFile/RecordFile.xcodeproj/project.pbxproj +++ b/EZAudioExamples/iOS/RecordFile/RecordFile.xcodeproj/project.pbxproj @@ -89,6 +89,7 @@ 66374E811C545AD8000B19D0 /* Products */, ); sourceTree = ""; + usesTabs = 0; }; 66374E811C545AD8000B19D0 /* Products */ = { isa = PBXGroup; diff --git a/EZAudioExamples/iOS/WaveformFromFile/WaveformFromFile.xcodeproj/project.pbxproj b/EZAudioExamples/iOS/WaveformFromFile/WaveformFromFile.xcodeproj/project.pbxproj index 6fe25e68..582149ee 100644 --- a/EZAudioExamples/iOS/WaveformFromFile/WaveformFromFile.xcodeproj/project.pbxproj +++ b/EZAudioExamples/iOS/WaveformFromFile/WaveformFromFile.xcodeproj/project.pbxproj @@ -91,6 +91,7 @@ 66374EA41C545AEA000B19D0 /* Products */, ); sourceTree = ""; + usesTabs = 0; }; 66374EA41C545AEA000B19D0 /* Products */ = { isa = PBXGroup;