Skip to content

Beartooth/codec2-ios

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

codec2-ios

A lightweight swift wrapper for Codec 2

Codec 2 is a low bitrate speech codec with compression modes ranging from 700 bit/s to 3200 bit/s. It is useful for voice compression in bandwidth constrained environments. The codec accepts 16 bit 8Khz PCM audio as input.

This framework is based on a fork of the Codec 2 source code. The original source can be found on SVN here and on GitHub here.

Installing

Carthage

  • Add this line to your Cartfile: github "Beartooth/codec2-ios"
  • Use the typical carthage workflow to add Codec2.framework to your project.

Usage

Instantiating a codec using 1.2kbps compression:

import Codec2

let codec = Codec2(mode: ._1200)!
let nBitsPerFrame = codec.bitsPerEncFrame
let nBytesPerFrame = codec.bytesPerEncFrame
let nSamplesPerFrame = codec.samplesPerFrame

Encoding and Decoding:

import Codec2

let codec = Codec2(mode: ._1200)!

func encodeVoiceFrame(_ toEnc: inout [Int16]) -> [UInt8]? {
  guard toEnc.count == codec.samplesPerFrame else { return nil }
  return codec.encode(speech: toEnc)
}

func decodeVoiceFrame(_ toDec: inout [UInt8]) -> [Int16]? {
  guard toDec.count == codec.bytesPerEncFrame else { return nil }
  return codec.decode(frame: toDec) 
}

Building

Required tools

  • Xcode
  • Homebrew
  • Cmake (brew install cmake)
  • git (brew install git)

Build steps

  • Clone the repository: git clone --recursive https://github.com/Beartooth/codec2-ios.git
  • Build the codec2-ios scheme from XCode or using xcodebuild

Contributors

David Rowe originally developed the codec, along with support from other researchers.
Jeff Jones developed the Swift port and cross compilation build script.