{"id":1405,"url":"https://github.com/evgenyneu/Cephalopod","last_synced_at":"2025-08-02T04:31:08.689Z","repository":{"id":25236096,"uuid":"28660673","full_name":"evgenyneu/Cephalopod","owner":"evgenyneu","description":"A sound fader for AVAudioPlayer written in Swift for iOS, tvOS and macOS.","archived":false,"fork":false,"pushed_at":"2019-04-20T02:21:28.000Z","size":1352,"stargazers_count":114,"open_issues_count":3,"forks_count":12,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-07-17T06:31:58.571Z","etag":null,"topics":["avaudioplayer","sound","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/evgenyneu.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-12-31T08:18:53.000Z","updated_at":"2025-05-09T06:24:25.000Z","dependencies_parsed_at":"2022-08-20T19:20:20.839Z","dependency_job_id":null,"html_url":"https://github.com/evgenyneu/Cephalopod","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/evgenyneu/Cephalopod","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evgenyneu%2FCephalopod","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evgenyneu%2FCephalopod/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evgenyneu%2FCephalopod/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evgenyneu%2FCephalopod/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evgenyneu","download_url":"https://codeload.github.com/evgenyneu/Cephalopod/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evgenyneu%2FCephalopod/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268069676,"owners_count":24190778,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-31T02:00:08.723Z","response_time":66,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["avaudioplayer","sound","swift"],"created_at":"2024-01-05T20:15:45.691Z","updated_at":"2025-08-02T04:31:08.346Z","avatar_url":"https://github.com/evgenyneu.png","language":"Swift","funding_links":[],"categories":["Media"],"sub_categories":["Audio","Other free courses"],"readme":"# Cephalopod, a sound fader for AvAudioPlayer written in Swift - iOS, tvOS and macOS\n\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![CocoaPods Version](https://img.shields.io/cocoapods/v/Cephalopod.svg?style=flat)](http://cocoadocs.org/docsets/Cephalopod)\n[![License](https://img.shields.io/cocoapods/l/Cephalopod.svg?style=flat)](LICENSE)\n[![Platform](https://img.shields.io/cocoapods/p/Cephalopod.svg?style=flat)](http://cocoadocs.org/docsets/Cephalopod)\n\nThis 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.\n\n```Swift\ncephalopod = Cephalopod(player: player)\ncephalopod?.fadeIn()\n```\n\n\n\u003cimg src='https://github.com/evgenyneu/Cephalopod/raw/master/graphics/cuttlefish.jpg' alt='Juvenile cuttlefish camouflaged against the seafloor' width='382'\u003e\n\n*Juvenile cuttlefish camouflaged against the seafloor. Photo taken by [Raul654](https://en.wikipedia.org/wiki/User:Raul654). Source: [Wikimedia Commons](https://en.wikipedia.org/wiki/File:Camouflage.jpg).*\n\n\n## Setup\n\nThere are three ways you can add Cephalopod to your Xcode project.\n\n#### Add source (iOS 7+)\n\nSimply add the [CephalopodDistrib.swift](https://github.com/evgenyneu/Cephalopod/blob/master/Distrib/CephalopodDistrib.swift) file to your project.\n\n\n#### Setup with Carthage (iOS 8+)\n\nAlternatively, add `github \"evgenyneu/Cephalopod\" ~\u003e 4.0` to your Cartfile and run `carthage update`.\n\n#### Setup with CocoaPods (iOS 8+)\n\nIf you are using CocoaPods add this text to your Podfile and run `pod install`.\n\n```\nuse_frameworks!\ntarget 'Your target name'\npod 'Cephalopod', '~\u003e 4.0'\n```\n\n\n### Legacy Swift versions\n\nSetup a [previous version](https://github.com/evgenyneu/Cephalopod/wiki/Legacy-Swift-versions) of the library if you use an older version of Swift.\n\n\n\n## Usage\n\n\nThe following example shows how to play an mp3 file with a fade in effect.\n\n```Swift\nimport AVFoundation\nimport Cephalopod // For CocoaPods and Carthage\n// ---\n\nvar playerInstance: AVAudioPlayer?\nvar cephalopod: Cephalopod?\n\noverride func viewDidLoad() {\n  super.viewDidLoad()\n\n  // Create a player instance\n  guard let path = Bundle.main.path(forResource: \"squid\", ofType: \"mp3\") else { return }\n  guard let player = try? AVAudioPlayer(contentsOf: URL(fileURLWithPath: path)) else { return }\n  playerInstance = player\n\n  // Start audio playback\n  player.play()\n  player.volume = 0\n\n  // Fade in the sound\n  cephalopod = Cephalopod(player: player)\n  cephalopod?.fadeIn()\n}\n```\n\n### Fade in / fade out\n\n```Swift\ncephalopod?.fadeIn()\ncephalopod?.fadeOut()\n\n// Supply fade duration and velocity, in seconds\ncephalopod?.fadeIn(duration: 3, velocity: 2)\ncephalopod?.fadeOut(duration: 3, velocity: 2)\n\n// Supply finish closure\ncephalopod?.fadeIn(duration: 3, velocity: 2) { finished in }\ncephalopod?.fadeOut(duration: 3, velocity: 2)  { finished in }\n```\n\n### Supply fade start/end volume and completion callback\n\n```Swift\ncephalopod?.fade(fromVolume: 0.3, toVolume: 0.7, duration: 3, velocity: 2) { finished in\n  print(\"Finished fading\")\n}\n```\n\n**Arguments**:\n\n`fromVolume` - the start volume, a number between 0 and 1.\n\n`toVolume` - the end volume, a number between 0 and 1.\n\n`duration` - duration of the fade, in seconds. Default duration: 3 seconds.\n\n`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.\n\n`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`).\n\n\n### Set the quality of fade\n\n```Swift\ncephalopod?.volumeAlterationsPerSecond = 20\n```\n\nLarger numbers will produce finer fade effect at expense of CPU juice. Default value: `30`.\n\n### Stop the volume change\n\nOne can cancel the ongoing volume change by calling the `stop()` method. Note that it stops changing the volume but does not stop the playback.\n\n```Swift\ncephalopod?.stop()\n```\n\n## Volume functions\n\nThe following graph shows how sound volume changes during the fade.\n\n\u003cimg src=\"https://raw.githubusercontent.com/evgenyneu/sound-fader-ios/master/graphics/ios-fader-formula-graph-logarithmic.png\" alt=\"Sound fade logarithmic velocity function for iOS/Swift\" width=\"457\"\u003e\n\n### Fade in formula\n\n\u003cimg src=\"https://raw.githubusercontent.com/evgenyneu/sound-fader-ios/master/graphics/audio-fade-out-formula-logarithmic.png\" alt=\"Sound fade out logarithmic formula\" width=\"160\"\u003e\n\n### Fade out formula\n\n\u003cimg src=\"https://raw.githubusercontent.com/evgenyneu/sound-fader-ios/master/graphics/audio-fade-in-formula-logarithmic.png\" alt=\"Sound fade in logarithmic formula\" width=\"192\"\u003e\n\nWhere `x` is time and `v` is velocity.\n\nVelocity 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.\n\nLive graph demo: https://www.desmos.com/calculator/wnstesdf0h\n\n## Demo app\n\n\u003cimg src=\"https://github.com/evgenyneu/Cephalopod/raw/master/graphics/cephalopod-fader-swift.png\" alt=\"Cephalopod sound fader for iOS written in swift\" width=\"320\"\u003e\n\n\n## Alternative solutions\n\nHere is a list of other sound libraries for iOS.\n\n* [AudioPlayerSwift](https://github.com/tbaranes/AudioPlayerSwift)\n* [AudioPlayer](https://github.com/delannoyk/AudioPlayer)\n\n\n## Thanks 👍\n\n* [nschucky](https://github.com/nschucky) for updating to Swift 2.2 selector syntax.\n\n## Credits\n\n* The lovely music was recorded by [Carlos Vallejo](http://www.flashkit.com/loops/Easy_Listening/Ill_Be_-Carlos_V-10012/index.php).\n\n* \"*Juvenile cuttlefish camouflaged against the seafloor*\" photo was taken by [Raul654](https://en.wikipedia.org/wiki/User:Raul654). Source: [Wikimedia Commons](https://en.wikipedia.org/wiki/File:Camouflage.jpg).\n\n\n## License\n\nCephalopod is released under the [MIT License](LICENSE).\n\n## Feedback is welcome\n\nIf you notice any issue, got stuck or just want to chat feel free to create an issue. I will be happy to help you.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevgenyneu%2FCephalopod","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevgenyneu%2FCephalopod","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevgenyneu%2FCephalopod/lists"}