Beartooth / codec2-ios

Rowetel Codec 2 for iOS
8 stars 4 forks source link
audio-codec codec codec2 ios radio xcode

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

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

Build steps

Contributors

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