sndfile

libsndfile audio file I/O library bindings for Kit

Files

FileDescription
.editorconfigEditor formatting configuration
.gitignoreGit ignore rules for build artifacts and dependencies
.tool-versionsasdf tool versions (Zig, Kit)
LICENSEMIT license file
README.mdThis file
c/kit_sndfile.cC FFI wrapper
c/kit_sndfile.hC header for FFI wrapper
examples/basic.kitBasic usage example
kit.tomlPackage manifest with metadata and dependencies
src/sndfile.kitKit Sndfile - Audio file I/O library bindings
tests/sndfile.test.kitTests for sndfile

Dependencies

No Kit package dependencies.

Installation

kit add gitlab.com/kit-lang/packages/kit-sndfile.git

System Requirements

PlatformCommand
macOSbrew install libsndfile
Ubuntusudo apt install libsndfile1-dev
Fedorasudo dnf install libsndfile-devel

Usage

import Kit.SndFile as Sndfile

main = fn =>
  println ("libsndfile version: " ++ Sndfile.version)

  # Read an audio file
  match Sndfile.open-read "audio.wav"
    | Ok handle ->
      println ("Format: " ++ (Sndfile.format-name handle))
      println ("Sample rate: " ++ (show (Sndfile.get-samplerate handle)) ++ " Hz")
      println ("Channels: " ++ (show (Sndfile.get-channels handle)))
      println ("Frames: " ++ (show (Sndfile.get-frames handle)))
      println ("Duration: " ++ (show (Sndfile.get-duration handle)) ++ " seconds")
      match Sndfile.close handle
        | Ok _ -> println "File closed"
        | Err e -> println ("Close error: " ++ e)
    | Err e -> println ("Open error: " ++ e)

  # Create a WAV file
  wav-format = Sndfile.format-wav + Sndfile.format-pcm16
  match Sndfile.open-write "output.wav" wav-format 1 44100
    | Ok handle ->
      println "Created WAV (1ch, 44100Hz, PCM16)"
      match Sndfile.close handle
        | Ok _ -> println "File closed"
        | Err e -> println ("Close error: " ++ e)
    | Err e -> println ("Create error: " ++ e)

main

Development

Running Examples

Run examples with the interpreter:

kit run examples/basic.kit

Compile examples to a native binary:

kit build examples/basic.kit && ./basic

Running Tests

Run the test suite:

kit test

Run the test suite with coverage:

kit test --coverage

Running kit dev

Run the standard development workflow (format, check, test):

kit dev

This will:

  1. Format and check source files in src/
  2. Run tests in tests/ with coverage

Generating Documentation

Generate API documentation from doc comments:

kit doc

Note: Kit sources with doc comments (##) will generate HTML documents in docs/*.html

Cleaning Build Artifacts

Remove generated files, caches, and build artifacts:

kit task clean

Note: Defined in kit.toml.

Local Installation

To install this package locally for development:

kit install

This installs the package to ~/.kit/packages/@kit/sndfile/, making it available for import as Kit.SndFile in other projects.

License

This package is released under the MIT License - see LICENSE for details.

libsndfile is released under the LGPL 2.1 / LGPL 3.0 License.

Exported Functions & Types

format-wav

WAV file format constant.

Int

format-flac

FLAC file format constant.

Int

format-ogg

OGG container format constant.

Int

format-aiff

AIFF file format constant.

Int

format-pcm16

16-bit PCM encoding constant.

Int

format-pcm24

24-bit PCM encoding constant.

Int

format-float

32-bit float encoding constant.

Int

format-vorbis

Vorbis encoding constant (for use with OGG container).

Int

open-read

Open an audio file for reading.

Parameters:

Returns:

NonEmptyString -> Result Ptr String

open-write

Open an audio file for writing.

Parameters:

Returns:

NonEmptyString -> Int -> PositiveInt -> PositiveInt -> Result Ptr String

close

Close an audio file and free its resources.

Parameters:

Returns:

Ptr -> Result Unit String

get-frames

Get the total number of audio frames in the file.

Parameters:

Returns:

Ptr -> Int

get-samplerate

Get the sample rate of the audio file in Hz.

Parameters:

Returns:

Ptr -> Int

get-channels

Get the number of audio channels.

Parameters:

Returns:

Ptr -> Int

get-format

Get the raw format code of the audio file.

Parameters:

Returns:

Ptr -> Int

get-duration

Get the duration of the audio file in seconds.

Parameters:

Returns:

Ptr -> Float

format-name

Get the human-readable format name (e.g., "WAV", "FLAC").

Parameters:

Returns:

Ptr -> String

version

Get the libsndfile version string.

Returns:

String