sndfile
| Kind | ffi-c |
|---|---|
| Capabilities | ffi |
| Categories | audio ffi |
| Keywords | audio sound wav flac ogg sndfile |
libsndfile audio file I/O library bindings for Kit
Files
| File | Description |
|---|---|
.editorconfig | Editor formatting configuration |
.gitignore | Git ignore rules for build artifacts and dependencies |
.tool-versions | asdf tool versions (Zig, Kit) |
LICENSE | MIT license file |
README.md | This file |
c/kit_sndfile.c | C FFI wrapper |
c/kit_sndfile.h | C header for FFI wrapper |
examples/basic.kit | Basic usage example |
kit.toml | Package manifest with metadata and dependencies |
src/sndfile.kit | Kit Sndfile - Audio file I/O library bindings |
tests/sndfile.test.kit | Tests for sndfile |
Dependencies
No Kit package dependencies.
Installation
kit add gitlab.com/kit-lang/packages/kit-sndfile.gitSystem Requirements
| Platform | Command |
|---|---|
| macOS | brew install libsndfile |
| Ubuntu | sudo apt install libsndfile1-dev |
| Fedora | sudo 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)
mainDevelopment
Running Examples
Run examples with the interpreter:
kit run examples/basic.kitCompile examples to a native binary:
kit build examples/basic.kit && ./basicRunning Tests
Run the test suite:
kit testRun the test suite with coverage:
kit test --coverageRunning kit dev
Run the standard development workflow (format, check, test):
kit devThis will:
- Format and check source files in
src/ - Run tests in
tests/with coverage
Generating Documentation
Generate API documentation from doc comments:
kit docNote: Kit sources with doc comments (##) will generate HTML documents in docs/*.html
Cleaning Build Artifacts
Remove generated files, caches, and build artifacts:
kit task cleanNote: Defined in kit.toml.
Local Installation
To install this package locally for development:
kit installThis 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