FDWaveformView is an easy way to display an audio waveform in your app

Overview

FDWaveformView

Build Status Version License Platform Carthage compatible

FDWaveformView is an easy way to display an audio waveform in your app. It is a nice visualization to show a playing audio file or to select a position in a file.

🐣 Virtual tip jar: https://amazon.com/hz/wishlist/ls/EE78A23EEGQB

Usage

To use it, add an FDWaveformView using Interface Builder or programmatically and then just load your audio as per this example. Note: if your audio file does not have file extension, see this SO question.

let thisBundle = Bundle(for: type(of: self))
let url = thisBundle.url(forResource: "Submarine", withExtension: "aiff")
self.waveform.audioURL = url

Features

Set play progress to highlight part of the waveform:

self.waveform.progressSamples = self.waveform.totalSamples / 2

Zoom in to show only part of the waveform, of course, zooming in will smoothly re-render to show progressively more detail:

self.waveform.zoomStartSamples = 0
self.waveform.zoomEndSamples = self.waveform.totalSamples / 4

Enable gestures for zooming in, panning around or scrubbing:

self.waveform.doesAllowScrubbing = true
self.waveform.doesAllowStretch = true
self.waveform.doesAllowScroll = true

Supports animation for changing properties:

UIView.animate(withDuration: 0.3) {
    let randomNumber = arc4random() % self.waveform.totalSamples
    self.waveform.progressSamples = randomNumber
}

Creates antialiased waveforms by drawing more pixels than are seen on screen. Also, if you resize me (autolayout) I will render more detail if necessary to avoid pixelation.

Supports iOS8+ and Swift 3.

Includes unit tests which run successfully using Travis CI.

Installation

Add this to your project using Swift Package Manager. In Xcode that is simply: File > Swift Packages > Add Package Dependency... and you're done. Alternative installations options are shown below for legacy projects.

Contributing

This project's layout is based on https://github.com/fulldecent/swift4-module-template If you would like to change the layout, please change that project FIRST. Also you may appreciate that project has "recipes" -- you don't just change code, you also explain why you are doing things. As a maintainer this makes my job MUCH simpler. In a similar respect, if you are introducing non-minor changes, it will be VERY helpful if you could please reference to another project (like AlamoFire) that has seen and discussed the types of design challenges you are touching.) Thanks again and we all really do appreciate your contributions.

Comments
  • Zoom

    Zoom

    Allowing zooming, or displaying only part of the song.

    Some notes on seeking an AVAssetReader are at http://stackoverflow.com/questions/13210684/reading-samples-with-avassetreader-and-timerange-in-real-time

    enhancement 
    opened by fulldecent 12
  • Add arbitrary selection and play only that selection

    Add arbitrary selection and play only that selection

    Hi, Amazing thanks! Had a question. R u planning to add selection? For example I want to select a specific section of the file (using Pan gesture -- UIGestureRecognizerStateBegin and End in handlePanGesture()). So the user can select a section of the file with his finger (pan/touch); of course color the selection differently. thank you very much

    enhancement 
    opened by vittalk 11
  • UIGraphicsGetCurrentContext() returns nil - what now?

    UIGraphicsGetCurrentContext() returns nil - what now?

    Hi!

    I've successfully integrated your library into one of my projects. It works very nice, but sometimes the waveform is not rendered and I get the "FDWaveformView failed to get graphics context".

    Do You know what to do then or the circumstances why it can happen?

    BR Joern

    needtestcase 
    opened by jboegeholz 10
  • M4A format compatibility

    M4A format compatibility

    I'm no audio expert by any means, so this might be a silly question: is FDWaveformView supposed to be compatible with M4A files?

    When I try to set the audioURL to my M4A file (local file, not streamed) the code crashes as the "tracks" property is an empty array.

    --Joao

    opened by jpm 10
  • progressSamples incorrect when doesAllowStretch = true and zoomed in

    progressSamples incorrect when doesAllowStretch = true and zoomed in

    When you enable doesAllowStretch and zoom in, the progressSamples value is incorrect in relation to where you click on the wave form. It seems to always calculate progress samples based on the zoomed out waveform. Let me know if you need more information and I will try to provide it.

    bug 
    opened by nickcastel50 8
  • Not drawing

    Not drawing

    Version 1.0.1 is not visualizing when trying to play a sound shorter than 2 secs, obviously there is something with the frame calculation since the image frame printed by the console is minus one pixel of width:

    (9.0, 6.0, 84.0, 30.0) -- (-0.00151425, 0.0, 0.00151425, 30.0)

    Weird thing is that is the same value of the x position.

    With 0.3.1 version it works fine.

    opened by JuanPabloBoero 8
  • Crash -[AVAssetReader setTimeRange:] cannot be called after reading has started'

    Crash -[AVAssetReader setTimeRange:] cannot be called after reading has started'

    It happens after fixing that issue i think https://github.com/fulldecent/FDWaveformView/issues/76

    That crash occurs in case with tableView with audio cells (7-8 cells with short audio)

    func sliceAsset(withRange slice: Range, andDownsampleTo targetSamples: Int, done: (_ samples: [CGFloat], _ sampleMax: CGFloat) -> Void) { guard slice.count > 0 else { return } guard let asset = asset else { return } guard let assetTrack = assetTrack else { return } guard let assetReader = assetReader else { return }

        assetReader.timeRange = CMTimeRange(start: CMTime(value: Int64(slice.lowerBound), timescale: asset.duration.timescale), duration: CMTime(value: Int64(slice.count), timescale: asset.duration.timescale)) <<------ here is crash
    

    here is screenshot http://joxi.ru/RmzYddWcoLzkrO

    opened by PavelKandziuba 7
  • Add support for rendering waveform images outside of the view

    Add support for rendering waveform images outside of the view

    I needed support for rending the waveform image outside of the view so I could cache it as well as support for showing a linear scaled waveform. This PR includes those features as well as several bugs that were fixed along side the massive refactor:

    Features Added:

    • Added support for rendering waveform images outside of a view (See FDWaveformRenderOperation).
    • Added support for rendering linear waveforms.
    • Added support for changing wavesColor and progressColor after waveform was rendered.
    • Added support for updating waveform type and color to iOS Example app.

    Bugs Fixed:

    • Fixed bug which could prevent waveform from fitting new view size if rendering was in progress during a view resize.
    • Fixed bug which caused waveformViewDidLoad() to not be called after the audio file was loaded.
    • Fixed bug which caused subsequent waveform renderings for new audioURLs to never complete if there was an error with a previous render.
    • Fixed bug which could cause a crash (divide by zero error) if the view's width was 0.

    Tested performance using iOS Example's performance testing and confirmed there were no regressions. Tested linear/log and color changing support in added features in iOS Example app.

    Note that this also includes the changes made in my previous PR https://github.com/fulldecent/FDWaveformView/pull/79.

    opened by ospr 7
  • Exception

    Exception

    *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '*** -[AVAssetReader addOutput:] cannot add an output that has already been added to another AVAssetReader'

    I use the pod for a sampler app, where you shot many sounds quickly and update the wave form analyzer, from time to time i got that exception, let me paste where it did happen:

            let readerOutput = AVAssetReaderTrackOutput(track: assetTrack, outputSettings: outputSettingsDict)
            readerOutput.alwaysCopiesSampleData = false
            reader.add(readerOutput)  <<<--- HERE
    
    opened by JuanPabloBoero 7
  • Can I use it with NSData instead URL?

    Can I use it with NSData instead URL?

    I have a audio saved on a Realm Database as NSData. With AVAudioPlayer I can success load the data and play the audio. I'm willing to use FDWaveformView to display the sound waves, but I couldn't found a way to make it work with NSData instead URL...

    opened by Cleversou1983 6
  • Crash

    Crash

    When trying to render this file, it crashes at line 266 , when doing downsample and average. The weird thing is that if i enable the address sanitizer in the scheme it wont crash!

    iOS 8.2, iPad mini, FDWaveformView 2.2.1.

    Urban Grooves 20.caf.zip

    opened by JuanPabloBoero 6
  • Added unversioned TeamID infrastructure.

    Added unversioned TeamID infrastructure.

    This change allows keeping the TeamID out of the project files. This way people can just clone the git repo, add their TeamID in a copy of the file "DEVELOPMENT_TEAM.xcconfig.template" then named "DEVELOPMENT_TEAM.xcconfig" and signing of the iOS Example will magically work.

    This is described in detail in the file "Shared.xcconfig".

    opened by JanX2 6
  • Outdated README: play progress and supports animation features

    Outdated README: play progress and supports animation features

    The README file uses this code sample:

    self.waveform.progressSamples = self.waveform.totalSamples / 2
    

    To illustrate the Set play progress feature (also applies to the Supports animation feature).

    Latest code version requires something like this:

    let samplesToHighlight = waveformView.totalSamples / 2
     waveformView.highlightedSamples = 0 ..< samplesToHighlight
    

    Suggestion: Update the README to reflect this code change.

    opened by Dario-Gasquez 1
  • iOS Example: FDWaveformView failed to load AVAssetTrack for ogg file

    iOS Example: FDWaveformView failed to load AVAssetTrack for ogg file

    Hi,

    I tried the sample iOS app, it works with the .mp3 and .aac sample files, but when I try connecting and loading the ogg file it gives me the following error: FDWaveformView failed to load AVAssetTrack

    An additional screenshot showing the change made to load the ogg file and the place where the error occurs: LoadOGG-error

    Is ogg currently not supported?

    Thanks in advance.

    opened by Dario-Gasquez 4
  • Discussion: separate rendering from display

    Discussion: separate rendering from display

    Here is a competing product: https://github.com/dmrschmidt/DSWaveformImage

    They separate the rendering step from the display/interaction control. It is possible for us to do this as well. Considering if this should be in-scope for the project.

    Also they have nice rendering styles which we should consider: gradient and bars ("lo fi").

    opened by fulldecent 0
Releases(5.0.1)
Owner
William Entriken
EN/中文 [email protected]
William Entriken
The Amazing Audio Engine is a sophisticated framework for iOS audio applications, built so you don't have to.

Important Notice: The Amazing Audio Engine has been retired. See the announcement here The Amazing Audio Engine The Amazing Audio Engine is a sophisti

null 523 Nov 12, 2022
AudiosPlugin is a Godot iOS Audio Plugin that resolves the audio recording issue in iOS for Godot Engine.

This plugin solves the Godot game engine audio recording and playback issue in iOS devices. Please open the Audios Plugin XCode Project and compile the project. You can also use the libaudios_plugin.a binary in your project.

null 3 Dec 22, 2022
🖥 Control your display's brightness & volume on your Mac as if it was a native Apple Display

?? Control your display's brightness & volume on your Mac as if it was a native Apple Display. Use Apple Keyboard keys or custom shortcuts. Shows the native macOS OSDs.

null 20k Dec 29, 2022
AIB indicates for your app users which audio is playing. Just like the Podcasts app.

Audio Indicator Bars for iOS and tvOS Indicates for your app users which audio is playing. Just like the Podcasts app. Index Requirements and Details

Leonardo Cardoso 285 Nov 23, 2022
KeyAudioManager - A swift package to make it a lot easier to play audio in your app

KeyAudioManager A swift package to make it a lot easier to play audio in your ap

Pedro Esli 3 Apr 28, 2022
AudioPlayer is syntax and feature sugar over AVPlayer. It plays your audio files (local & remote).

AudioPlayer AudioPlayer is a wrapper around AVPlayer. It also offers cool features such as: Quality control based on number of interruption (buffering

Kevin Delannoy 676 Dec 25, 2022
Voice Memos is an audio recorder App for iPhone and iPad that covers some of the new technologies and APIs introduced in iOS 8 written in Swift.

VoiceMemos Voice Memos is a voice recorder App for iPhone and iPad that covers some of the new technologies and APIs introduced in iOS 8 written in Sw

Zhouqi Mo 322 Aug 4, 2022
App for adding and listening audio files

SomeSa SomeSa (самса) – приложение, позволяющее загружать и воспроизводить произвольные аудиофайлы. Протестировано на форматах файлов .wav и .mp3, раз

Yegor Dobrodeyev 0 Nov 7, 2021
A drop-in universal library allows to record audio within the app with a nice User Interface.

IQAudioRecorderController IQAudioRecorderController is a drop-in universal library allows to record and crop audio within the app with a nice User Int

Mohd Iftekhar Qurashi 637 Nov 17, 2022
This app demonstrates how to use the Google Cloud Speech API and Apple on-device Speech library to recognize speech in live recorded audio.

SpeechRecognitionIOS This app demonstrates how to use Google Cloud Speech API and Apple on-device Speech library to recognize speech in live audio rec

Josh Uvi 0 Mar 11, 2022
AudioKit is an audio synthesis, processing, and analysis platform for iOS, macOS, and tvOS.

AudioKit is an audio synthesis, processing, and analysis platform for iOS, macOS (including Catalyst), and tvOS. Installation To add AudioKit

AudioKit 9.5k Dec 31, 2022
AudioPlayer is a simple class for playing audio in iOS, macOS and tvOS apps.

AudioPlayer AudioPlayer is a simple class for playing audio in iOS, macOS and tvOS apps.

Tom Baranes 260 Nov 27, 2022
Beethoven is an audio processing Swift library

Beethoven is an audio processing Swift library that provides an easy-to-use interface to solve an age-old problem of pitch detection of musical signals.

Vadym Markov 735 Dec 24, 2022
SwiftAudioPlayer - Swift-based audio player with AVAudioEngine as its base

SwiftAudioPlayer Swift-based audio player with AVAudioEngine as its base. Allows for: streaming online audio, playing local file, changing audio speed

null 417 Jan 7, 2023
Swift audio synthesis, processing, & analysis platform for iOS, macOS and tvOS

AudioKit AudioKit is an audio synthesis, processing, and analysis platform for iOS, macOS (including Catalyst), and tvOS. Installation To add AudioKit

AudioKit 8.7k Sep 30, 2021
YiVideoEditor is a library for rotating, cropping, adding layers (watermark) and as well as adding audio (music) to the videos.

YiVideoEditor YiVideoEditor is a library for rotating, cropping, adding layers (watermark) and as well as adding audio (music) to the videos. YiVideoE

coderyi 97 Dec 14, 2022
Painless high-performance audio on iOS and Mac OS X

An analgesic for high-performance audio on iOS and OSX. Really fast audio in iOS and Mac OS X using Audio Units is hard, and will leave you scarred an

Alex Wiltschko 2.2k Nov 23, 2022
Audio Filters on iOS and OSX

Audio Filters on iOS and OSX Implement high quality audio filters with just a few lines of code and Novocaine, or your own audio library of choice. NV

Bart Olsthoorn 411 Dec 16, 2022
Audio visualisation of song

SonogramView Audio visualisation of song Requirements iOS 8.0+ macOS 10.10+ Xcode 8.0+ Installation: Manually First Check SonogramView.swift or MacSon

Gleb Karpushkin 66 Nov 3, 2022