From 3788e2f41ec044631b1cc6537e2b39ebfbdf34df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Wei=C3=9F?= Date: Tue, 16 Feb 2016 16:06:37 +0100 Subject: [PATCH 1/4] Fixing incorrect results when calculating xscale. The waveform never filled the full width before this fix. Why do we have to subtract 3 for the GL view? --- EZAudio/EZAudioPlot.m | 2 +- EZAudio/EZAudioPlotGL.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/EZAudio/EZAudioPlot.m b/EZAudio/EZAudioPlot.m index 7603e26b..85df3ac0 100644 --- a/EZAudio/EZAudioPlot.m +++ b/EZAudio/EZAudioPlot.m @@ -271,7 +271,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)); double halfHeight = floor(rect.size.height / 2.0); int deviceOriginFlipped = [self isDeviceOriginFlipped] ? -1 : 1; CGAffineTransform xf = CGAffineTransformIdentity; diff --git a/EZAudio/EZAudioPlotGL.m b/EZAudio/EZAudioPlotGL.m index 16728505..a444ed15 100644 --- a/EZAudio/EZAudioPlotGL.m +++ b/EZAudio/EZAudioPlotGL.m @@ -485,7 +485,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); From 2a733c36b0cf75dd3760ce0e4f010478409c82a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Wei=C3=9F?= Date: Tue, 16 Feb 2016 17:42:58 +0100 Subject: [PATCH 2/4] =?UTF-8?q?Adding=20local=20constant=20=E2=80=9Cshould?= =?UTF-8?q?Fill=E2=80=9D.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EZAudio/EZAudioPlotGL.m | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/EZAudio/EZAudioPlotGL.m b/EZAudio/EZAudioPlotGL.m index a444ed15..a3a71a9d 100644 --- a/EZAudio/EZAudioPlotGL.m +++ b/EZAudio/EZAudioPlotGL.m @@ -299,11 +299,13 @@ - (void)updateBuffer:(float *)buffer withBufferSize:(UInt32)bufferSize - (void)setSampleData:(float *)data length:(int)length { - int pointCount = self.shouldFill ? length * 2 : length; + const BOOL shouldFill = self.shouldFill; + int pointCount = (shouldFill ? length * 2 : length); + EZAudioPlotGLPoint *points = self.info->points; 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]; @@ -317,7 +319,7 @@ - (void)setSampleData:(float *)data length:(int)length } points[0].y = points[pointCount - 1].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); From 089031e57c24612d1fd21e3c06035631f7642dc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Wei=C3=9F?= Date: Tue, 16 Feb 2016 17:54:15 +0100 Subject: [PATCH 3/4] Fixing handling of the first and last point when plotting. --- EZAudio/EZAudioPlot.h | 5 +++++ EZAudio/EZAudioPlot.m | 27 ++++++++++++++++++--------- EZAudio/EZAudioPlotGL.m | 18 +++++++++++++++--- 3 files changed, 38 insertions(+), 12 deletions(-) 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 85df3ac0..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 - 1)); + 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 a3a71a9d..88607ded 100644 --- a/EZAudio/EZAudioPlotGL.m +++ b/EZAudio/EZAudioPlotGL.m @@ -300,9 +300,12 @@ - (void)updateBuffer:(float *)buffer withBufferSize:(UInt32)bufferSize - (void)setSampleData:(float *)data length:(int)length { const BOOL shouldFill = self.shouldFill; - int pointCount = (shouldFill ? length * 2 : length); - EZAudioPlotGLPoint *points = self.info->points; + 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 (shouldFill) @@ -317,7 +320,16 @@ - (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 = shouldFill; #if !TARGET_OS_IPHONE From 04b98a7dfd6925593edd095147c173d630bdf118 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Wei=C3=9F?= Date: Tue, 16 Feb 2016 17:47:14 +0100 Subject: [PATCH 4/4] Setting projects to default to spaces for indentation. --- EZAudio.xcodeproj/project.pbxproj | 1 + .../CoreGraphicsWaveform.xcodeproj/project.pbxproj | 1 + EZAudioExamples/OSX/FFT/FFT.xcodeproj/project.pbxproj | 1 + .../OSX/OpenGLWaveform/OpenGLWaveform.xcodeproj/project.pbxproj | 1 + .../OSX/PassThrough/PassThrough.xcodeproj/project.pbxproj | 1 + EZAudioExamples/OSX/PlayFile/PlayFile.xcodeproj/project.pbxproj | 1 + .../OSX/RecordFile/RecordFile.xcodeproj/project.pbxproj | 1 + .../WaveformFromFile/WaveformFromFile.xcodeproj/project.pbxproj | 1 + .../CoreGraphicsWaveform.xcodeproj/project.pbxproj | 1 + EZAudioExamples/iOS/FFT/FFT.xcodeproj/project.pbxproj | 1 + .../iOS/OpenGLWaveform/OpenGLWaveform.xcodeproj/project.pbxproj | 1 + .../iOS/PassThrough/PassThrough.xcodeproj/project.pbxproj | 1 + EZAudioExamples/iOS/PlayFile/PlayFile.xcodeproj/project.pbxproj | 1 + .../iOS/RecordFile/RecordFile.xcodeproj/project.pbxproj | 1 + .../WaveformFromFile/WaveformFromFile.xcodeproj/project.pbxproj | 1 + 15 files changed, 15 insertions(+) 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/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;