All Projects → evgenyneu → Cephalopod

evgenyneu / Cephalopod

Licence: mit
A sound fader for AVAudioPlayer written in Swift for iOS, tvOS and macOS.

Programming Languages

swift
15916 projects

Labels

Projects that are alternatives of or similar to Cephalopod

Pandoraplayer
🅿️ PandoraPlayer is a lightweight music player for iOS, based on AudioKit and completely written in Swift.
Stars: ✭ 1,037 (+906.8%)
Mutual labels:  sound
Odas web
A desktop visualization GUI for the ODAS library
Stars: ✭ 78 (-24.27%)
Mutual labels:  sound
Pizzicato
Library to simplify the way you create and manipulate sounds with the Web Audio API.
Stars: ✭ 1,296 (+1158.25%)
Mutual labels:  sound
Chime
🎵 Python sound notifications made easy
Stars: ✭ 56 (-45.63%)
Mutual labels:  sound
Hyperhdr
Open source ambilight implementation for the audio and video stream on Windows 10 and Linux (x86 and Raspberry Pi). Primarily for use with the movie content on your TV and the LED strip. Includes support for HDR10 tone mapping correction for video processing and multi-threading for better performance.
Stars: ✭ 71 (-31.07%)
Mutual labels:  sound
Figaro
Real-time voice-changer for voice-chat, etc. Will support many different voice-filters and features in the future. 🎵
Stars: ✭ 80 (-22.33%)
Mutual labels:  sound
Audio Signal Processing
Removing background noise in a sound file
Stars: ✭ 41 (-60.19%)
Mutual labels:  sound
Webmidikit
Simplest MIDI Swift library
Stars: ✭ 100 (-2.91%)
Mutual labels:  sound
Soundswitch
C# application to switch default playing device. Download: https://soundswitch.aaflalo.me/
Stars: ✭ 1,190 (+1055.34%)
Mutual labels:  sound
Audiokitsynthone
AudioKit Synth One: Open-Source iOS Synthesizer App
Stars: ✭ 1,258 (+1121.36%)
Mutual labels:  sound
Peep
Easy Sound Generator 🐥
Stars: ✭ 59 (-42.72%)
Mutual labels:  sound
Esp32 I2s Slm
Sound Level Meter with ESP32 and I2S MEMS microphone
Stars: ✭ 72 (-30.1%)
Mutual labels:  sound
Cochlea
Inner ear models for Python
Stars: ✭ 82 (-20.39%)
Mutual labels:  sound
Soloud
Free, easy, portable audio engine for games
Stars: ✭ 1,048 (+917.48%)
Mutual labels:  sound
My Appdaemon
My apps, my helpfiles, all about AppDaemon for Home Assistant
Stars: ✭ 94 (-8.74%)
Mutual labels:  sound
Simpletones.js
The goal of simpleTones.js is to provide every JavaScript developer with a lightweight solution for creating custom sounds in their web applications. This documentation has been written in hopes that the least experienced developer can read, understand and go on to do great things. You can check out several examples at this link:
Stars: ✭ 45 (-56.31%)
Mutual labels:  sound
Soundable
Soundable allows you to play sounds, single and in sequence, in a very easy way
Stars: ✭ 78 (-24.27%)
Mutual labels:  sound
React Native Sound Recorder
Simplest Sound Recorder for React Native
Stars: ✭ 103 (+0%)
Mutual labels:  sound
Processing Sound
Audio library for Processing built with JSyn
Stars: ✭ 94 (-8.74%)
Mutual labels:  sound
Minibae
The platform-neutral Beatnik Audio Engine, Mini Edition (miniBAE) is an exceptionally mature, well-rounded, and reliable computer music and sound system specially customized for small-footprint and embedded applications.
Stars: ✭ 82 (-20.39%)
Mutual labels:  sound

Cephalopod, a sound fader for AvAudioPlayer written in Swift - iOS, tvOS and macOS

Carthage compatible CocoaPods Version License Platform

This library can help fading sounds in and out with AvAudioPlayer. One can set duration, velocity of the fade and a completion function. Velocity can vary from linear to exponential.

cephalopod = Cephalopod(player: player)
cephalopod?.fadeIn()
Juvenile cuttlefish camouflaged against the seafloor

Juvenile cuttlefish camouflaged against the seafloor. Photo taken by Raul654. Source: Wikimedia Commons.

Setup

There are three ways you can add Cephalopod to your Xcode project.

Add source (iOS 7+)

Simply add the CephalopodDistrib.swift file to your project.

Setup with Carthage (iOS 8+)

Alternatively, add github "evgenyneu/Cephalopod" ~> 4.0 to your Cartfile and run carthage update.

Setup with CocoaPods (iOS 8+)

If you are using CocoaPods add this text to your Podfile and run pod install.

use_frameworks!
target 'Your target name'
pod 'Cephalopod', '~> 4.0'

Legacy Swift versions

Setup a previous version of the library if you use an older version of Swift.

Usage

The following example shows how to play an mp3 file with a fade in effect.

import AVFoundation
import Cephalopod // For CocoaPods and Carthage
// ---

var playerInstance: AVAudioPlayer?
var cephalopod: Cephalopod?

override func viewDidLoad() {
  super.viewDidLoad()

  // Create a player instance
  guard let path = Bundle.main.path(forResource: "squid", ofType: "mp3") else { return }
  guard let player = try? AVAudioPlayer(contentsOf: URL(fileURLWithPath: path)) else { return }
  playerInstance = player

  // Start audio playback
  player.play()
  player.volume = 0

  // Fade in the sound
  cephalopod = Cephalopod(player: player)
  cephalopod?.fadeIn()
}

Fade in / fade out

cephalopod?.fadeIn()
cephalopod?.fadeOut()

// Supply fade duration and velocity, in seconds
cephalopod?.fadeIn(duration: 3, velocity: 2)
cephalopod?.fadeOut(duration: 3, velocity: 2)

// Supply finish closure
cephalopod?.fadeIn(duration: 3, velocity: 2) { finished in }
cephalopod?.fadeOut(duration: 3, velocity: 2)  { finished in }

Supply fade start/end volume and completion callback

cephalopod?.fade(fromVolume: 0.3, toVolume: 0.7, duration: 3, velocity: 2) { finished in
  print("Finished fading")
}

Arguments:

fromVolume - the start volume, a number between 0 and 1.

toVolume - the end volume, a number between 0 and 1.

duration - duration of the fade, in seconds. Default duration: 3 seconds.

velocity - a number specifying how fast the sound volume is changing. Velocity of 0 creates a linear fade. Values greater than zero produce more exponential fade affect. Exponential fade sounds more gradual to a human ear. The fade sounds most natural with velocity parameter from 2 to 5. Default value: 2.

onFinished - an optional closure that will be called after the fade has ended. The closure will be passed a boolean parameter finished indicating whether the fading has reached its end value (true) or if the fading has been cancelled (false).

Set the quality of fade

cephalopod?.volumeAlterationsPerSecond = 20

Larger numbers will produce finer fade effect at expense of CPU juice. Default value: 30.

Stop the volume change

One can cancel the ongoing volume change by calling the stop() method. Note that it stops changing the volume but does not stop the playback.

cephalopod?.stop()

Volume functions

The following graph shows how sound volume changes during the fade.

Sound fade logarithmic velocity function for iOS/Swift

Fade in formula

Sound fade out logarithmic formula

Fade out formula

Sound fade in logarithmic formula

Where x is time and v is velocity.

Velocity of 0 creates a linear fade. Values greater than zero produce more exponential fade affect. Exponential fade sounds more gradual to a human ear. I personally use velocity values from 2 to 5.

Live graph demo: https://www.desmos.com/calculator/wnstesdf0h

Demo app

Cephalopod sound fader for iOS written in swift

Alternative solutions

Here is a list of other sound libraries for iOS.

Thanks 👍

  • nschucky for updating to Swift 2.2 selector syntax.

Credits

License

Cephalopod is released under the MIT License.

Feedback is welcome

If you notice any issue, got stuck or just want to chat feel free to create an issue. I will be happy to help you.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].