Giter Club home page Giter Club logo

scwaveformview's Introduction

SCWaveformView

A blazing fast customizable waveform view. Extract the audio section of an asset (which can be both video or audio) and display a waveform.

The SCWaveformView is optimized to do the less file read possible. When scrolling or displaying another part of the waveform, it will only read whatever it needs to render the new section. It will cache the file data to avoid having to read sections that have been already computed. Furthermore, if it does have to read the file, it will read it by bigger segment to minimize the number of read operations next time the timeRange changes.

Main features:

  • Can show a play progress.
  • Colors are changeable at runtime without reprocessing the asset.
  • Doesn't have to read the whole file if you display only a portion of your audio on screen.
  • Scrollable.
  • Can set a precision to make the drawing faster on some devices.
  • Custom LineWidth so you can have a unique waveform design.
  • Support mono and stereo (dual waveforms).

Podfile

If you are using cocoapods, you can use this project with the following Podfile

platform :ios, '7.0'
pod "SCWaveformView"

Example

// Allocating the waveformview
SCWaveformView *waveformView = [[SCWaveformView alloc] init];

// Setting the asset
AVAsset *asset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:@"blabla.mp3"]];
waveformView.asset = asset;

// Setting the waveform colors
waveformView.normalColor = [UIColor greenColor];
waveformView.progressColor = [UIColor redColor];

// Set the play progress
waveformView.progressTime = CMTimeMakeWithSeconds(5, 10000);

// Show only the first second of your asset
waveformView.timeRange = CMTimeRangeMake(kCMTimeZero, CMTimeMakeWithSeconds(1, 1));

// Use it inside a scrollView
SCScrollableWaveformView *scrollableWaveformView = [SCScrollableWaveformView new];
scrollableWaveformView.waveformView; // Access the waveformView from there

// Set the precision, 1 being the maximum
waveformView.precision = 0.25; // We are going to render one line per four pixels

// Set the lineWidth so we have some space between the lines
waveformView.lineWidthRatio = 0.5;

// Show stereo if available
waveformView.channelStartIndex = 0;
waveformView.channelEndIndex = 1;

// Show only right channel
waveformView.channelStartIndex = 1;
waveformView.channelEndIndex = 1;

// Add some padding between the channels
waveformView.channelsPadding = 10;

scwaveformview's People

Contributors

alh84001 avatar msrdjan avatar rflex avatar streeter avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

scwaveformview's Issues

Mapping Audio data from EZAudio GitHub

How can I map the data from EZAudio microphone when user is recording the data from EZMicrophone class to the SC Waveforms? Can you give me some ideas?

Bug report: UIKit

Hi,

This is just a quick note to anyone using this library. You have to include UIKit framework on the SCWaveformView class for it to work without errors like so:

In SCWaveformView.h add the following:

#import <UIKit/UIKit.h>

Processing large files locks-up UI

All the processing of reading the audio-file & generating the waveform occurs on the main thread which locks up the UI when giving the view a large file.

Everything should occur off the main thread (rendering waveform + reading assets) with occasional refreshes of updates as more of the waveform is processed.

Wave Not Working

The wave not working for file more 20 minutes.
how do I fix it?

Thanks.

generateWaveformImage: w/ Antialiasing Enabled Producing Transparent Image

When I call SCWaveformView generateWaveformImage:asset withColor:[UIColor purpleColor] andSize:CGSizeMake(640, 332) antialiasingEnabled:YES];, the entire image is output as about 75% transparent, whereas if I pass in NO for antialiasingEnabled, I miss out on the smoothing of the edges, but at least the center of the waveform is fully opaque.

Looping calls to update waveform time range can cause crash

I have a couple of crashes reported where it looks like the SCScrollableWaveformView gets into a nasty loop when the KVO observing function changes the time range and then this somehow results in the observing function triggering again to update the scroll view which then triggers the observing function to trigger and update the waveform which changes the time range again.

Here is a chunk of the stack trace that started it (which then effectively repeats many many times before crashing):

0x1002bcc28 -SCScrollableWaveformView _updateWaveform
0x1002bcf7c -SCScrollableWaveformView observeValueForKeyPath:ofObject:change:context:

4113 Foundation 0x18499bf64 NSKeyValueNotifyObserver + 304
4114 Foundation 0x18499ba8c NSKeyValueDidChange + 404
4115 Foundation 0x184a461ac -[NSObject(NSKeyValueObservingPrivate) _changeValueForKeys:count:maybeOldValuesDict:usingBlock:] + 732
4116 Foundation 0x18499afc0 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKey:key:key:usingBlock:] + 64
4117 Foundation 0x184a43b38 _NSSetPointValueAndNotify + 284

0x1002bce34 -SCScrollableWaveformView _updateScrollView
0x1002bcf7c -SCScrollableWaveformView observeValueForKeyPath:ofObject:change:context:

4120 Foundation 0x18499bf64 NSKeyValueNotifyObserver + 304
4121 Foundation 0x18499ba8c NSKeyValueDidChange + 404
4122 Foundation 0x184986624 -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 120

0x1002c01dc -SCWaveformView setTimeRange:

4124 CoreFoundation 0x1840a4a60 invoking_ + 144
4125 CoreFoundation 0x183f9c488 -[NSInvocation invoke] + 284
4126 Foundation 0x1849ad270 NSKVOForwardInvocation + 300
4127 CoreFoundation 0x1840a2a1c _forwarding_ + 408
4128 CoreFoundation 0x183fa0c5c _CF_forwarding_prep_0 + 92

0x1002bcc28 -SCScrollableWaveformView _updateWaveform
0x1002bcf7c -SCScrollableWaveformView observeValueForKeyPath:ofObject:change:context:

4131 Foundation 0x18499bf64 NSKeyValueNotifyObserver + 304
4132 Foundation 0x18499ba8c NSKeyValueDidChange + 404
4133 Foundation 0x184a461ac -[NSObject(NSKeyValueObservingPrivate) _changeValueForKeys:count:maybeOldValuesDict:usingBlock:] + 732
4134 Foundation 0x18499afc0 -[NSObject(NSKeyValueObservingPrivate) _changeValueForKey:key:key:usingBlock:] + 64
4135 Foundation 0x184a43b38 _NSSetPointValueAndNotify + 284
4136 UIKit 0x1893b8c54 -[UIScrollView _smoothScrollWithUpdateTime:] + 2400
`

Is anyone else encountering this problem?
I don't have direct steps to reproduce this problem but I have 3 reports in the last 2 days (two on iPhone 6 with iOS 9.3.4 and one on iPhone 6s with iOS 9.3.3).

Slow when loading with UITableView

There is some performance issue (lagging) when trying to reload the tableview which contains a number of cells that was added with the waveform view. I have tried to concurrently load the waveform view with GCD but it is not very stable — keep crashing.

Swift rewrite

I know Swift is in flux, but a Swift version (start with 2.0) would be nice. Bridging headers are always an option, but how about Swift? ;)

Get it working for online audio

how to get this working for online url music? it only works with saved music but i want it to work with online too, any ideas?

Cannot get SCWaveformView to Render

First off, Love this component - kudos. Can't wait to get it working!

I am building an SCWaveformView through code, and using autolayout (SnapKit, to be exact). Here is the code for doing so:

waveformView = SCWaveformView(frame: CGRectZero)
waveformView.precision = 0.25
waveformView.lineWidthRatio = 0.5
waveformView.normalColor = UIColor.lightGrayColor()
waveformView.progressColor = UIColor.mbTurquoiseColor()
waveformView.progressTime = kCMTimeZero
mainPlayerPanel.addSubview(waveformView)

waveformView.snp_makeConstraints { (make) in
     make.width.equalTo(UIScreen.mainScreen().bounds.width * 0.7)
     make.top.equalTo(artistNameFull.snp_bottom).offset(45)
     make.centerX.equalTo(mainPlayerPanel)
     make.height.equalTo(75)
}

However. I'm not adding the asset until viewDidLayoutSubviews is being called. Here is the code for that.

let asset = AVAsset(URL: NSURL(string: NSBundle.mainBundle().pathForResource("credits", ofType: "mp3")!)!)
waveformView.asset = asset
let timeRang = CMTimeRangeMake(kCMTimeZero, waveformView.actualAssetDuration)
waveformView.timeRange = timeRang

Once this is done, I would expect my waveform view to show up/be drawn. However, its not. Am I doing something incorrect that I'm not seeing?

Thanks!

Doesn't compile on 8.4.1

Throws the following errors:

SCWaveformView Group
Parse Issue Group
/Downloads/SCWaveformView-master/Sources/SCWaveformView.m:26:1: Unexpected '@' in program
/Downloads/SCWaveformView-master/Sources/SCWaveformView.m:28:1: '@EnD' must appear in an Objective-C context
Semantic Issue Group
/Downloads/SCWaveformView-master/Sources/SCWaveformView.m:30:17: Cannot find interface declaration for 'SCWaveformLayer'
/Downloads/SCWaveformView-master/Sources/SCWaveformView.m:30:17: Class 'SCWaveformLayer' defined without specifying a base class
/Downloads/SCWaveformView-master/Sources/SCWaveformView.m:35:1: Duplicate interface definition for class 'SCWaveformLayerDelegate'
/Downloads/SCWaveformView-master/Sources/SCWaveformView.m:126:19: Property 'anchorPoint' not found on object of type 'SCWaveformLayer *'
/Downloads/SCWaveformView-master/Sources/SCWaveformView.m:127:19: Property 'delegate' not found on object of type 'SCWaveformLayer *'
/Downloads/SCWaveformView-master/Sources/SCWaveformView.m:129:46: Incompatible pointer types sending 'SCWaveformLayer *' to parameter of type 'CALayer * _Nonnull'
/Downloads/SCWaveformView-master/Sources/SCWaveformView.m:238:27: Property 'backgroundColor' not found on object of type 'SCWaveformLayer *'
/Downloads/SCWaveformView-master/Sources/SCWaveformView.m:239:27: Property 'backgroundColor' not found on object of type 'SCWaveformLayer *'
/Downloads/SCWaveformView-master/Sources/SCWaveformView.m:242:23: Property 'frame' not found on object of type 'SCWaveformLayer *'
/Downloads/SCWaveformView-master/Sources/SCWaveformView.m:245:23: Property 'waveformTime' not found on object of type 'SCWaveformLayer *'
/Downloads/SCWaveformView-master/Sources/SCWaveformView.m:298:49: Property 'waveformTime' not found on object of type 'SCWaveformLayer *'
/Downloads/SCWaveformView-master/Sources/SCWaveformView.m:302:27: Property 'backgroundColor' not found on object of type 'SCWaveformLayer *'
/Downloads/SCWaveformView-master/Sources/SCWaveformView.m:303:27: Property 'backgroundColor' not found on object of type 'SCWaveformLayer *'
/Downloads/SCWaveformView-master/Sources/SCWaveformView.m:308:39: Property 'bounds' not found on object of type 'SCWaveformLayer *'
/Downloads/SCWaveformView-master/Sources/SCWaveformView.m:310:23: Property 'bounds' not found on object of type 'SCWaveformLayer *'
ARC Semantic Issue Group
/Downloads/SCWaveformView-master/Sources/SCWaveformView.m:114:24: No visible @interface for 'SCWaveformLayer' declares the selector 'removeFromSuperlayer'
/Downloads/SCWaveformView-master/Sources/SCWaveformView.m:125:55: No known class method for selector 'new'

Cannot load recorded file

Hi,

This is superb library thank you very much. How can I get it to load a file that I recorded instead of a file stored in the NS Main Bundle? I have tried the following but they don't work:


// "myURL" being a string like so:
// file:///var/mobile/Containers/Data/Application/35B72EE7-7320-4185-9B2E-55C540F738FD/Documents/23Feb2015_065229am.aif

NSURL *assetURL = [NSURL URLWithString:myURL];
AVURLAsset *asset  = [AVURLAsset URLAssetWithURL:assetURL options:nil];

I have tried so many different things and they dont work :(

getting compile error...

The file “SCWaveformViewTests-Info.plist” couldn’t be opened because there is no such file.

Xcode8 throws a warning in commonInit

Xcode 8 is throwing a warning at
_waveformSuperlayer.delegate = _waveformLayersDelegate;

This is happening because SCWaveformLayerDelegate is not explicitly declared to implement CALayerDelegate, and CALayer has delegate property now defined as
@Property(nullable, weak) id delegate;

errors and can't see a waveform

Here is my code:

UIButton *tempButton = (UIButton *) sender;
SCWaveformView *waveformView = [[SCWaveformView alloc] init];
AVAsset *asset = [AVURLAsset URLAssetWithURL:currentRecordingPath options:nil];
waveformView.asset = asset;
waveformView.normalColor = [UIColor greenColor];
[waveformView generateWaveforms];
UIImage *normalWaveformImage = waveformView.generatedNormalImage;
UIImageView *waveformimageview = [[UIImageView alloc] initWithFrame:tempButton.frame];
waveformimageview.image = normalWaveformImage;
waveformimageview.backgroundColor = [UIColor purpleColor];
[scrollView addSubview:waveformimageview];

I can see the purple background color but I never actually get a waveform.

This gets printed to the console when my app runs through your code:

: CGContextSetAllowsAntialiasing: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
: CGContextSetLineWidth: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
: CGContextSetStrokeColorWithColor: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
: CGContextSetFillColorWithColor: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

CALayerInvalidGeometry Exception

I'm seeing this error after setting the asset. Any ideas?

Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [0 nan]'

Trace leads to SCWaveformView.m's layoutSubviews.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.