Unlock high-performance audio analysis and manipulation with SoundML, the premier DSP library for OCaml, optimized for speed and machine learning signal processing applications.
Get Started with SoundMLExplore how SoundML, the next generation DSP library, empowers your projects with tools for advanced OCaml signal processing and machine learning signal processing tasks, ensuring precision, high performance and type-safety.
As a good Digital Signal Processing library, SoundML offers robust support for reading, writing, and processing diverse audio formats like WAV, AIFF, MP3, OGG and more, ensuring compatibility for all your DSP library needs.
Leverage sophisticated algorithms with SoundML, a fast digital signal processing library. Implement FIR/IIR filters, FFT, convolution, STFT, MFCC and more for almost any OCaml signal processing tasks that require both high performance and safety.
Programmatically generate a wide array of audio waveforms (sine, square, saw, noise) with SoundML. Build custom synthesizers and explore new frontiers in sound design using powerful digital signal processing techniques.
SoundML excels at real-time audio stream analysis, crucial for machine learning signal processing. Extract features like MFCCs and spectral centroids, perform pitch/onset detection, and implement beat tracking with this fast digital signal processing library.
Designed with a clean, modular architecture, SoundML facilitates easy extension and seamless integration into your OCaml signal processing projects. Customize and build upon this flexible DSP library.
With a clear API, comprehensive examples, and community support, SoundML streamlines development. It's the OCaml signal processing toolkit designed for rapid iteration and ease of use in your DSP library applications. Every choice is made with developer experience in mind.
See how easy it is to integrate SoundML into your OCaml projects for powerful audio processing. As a fast digital signal processing library, it makes complex tasks straightforward.
open Soundml
let () =
let input_path = "input.wav" in
let output_path = "output.ogg" in
try
(* 1. Read audio: SoXr HQ resample, 22050Hz, mono, Float32 *)
let audio_track =
Io.read ~res_typ:Io.SOXR_HQ ~sample_rate:22050 ~mono:true Bigarray.Float32
input_path
in
let reversed_audio = Audio.reverse audio_track in
(* 2. Write reversed audio to OGG Vorbis, fallback to inferred format *)
let data, sr = (Audio.data reversed_audio, Audio.sr reversed_audio) in
try
match Aformat.create ~subtype:Aformat.VORBIS Aformat.OGG with
| Ok fmt ->
Io.write ~format:fmt output_path data sr
| Error msg ->
Printf.eprintf "Warn: OGG Vorbis init: %s. Using inferred.\n" msg ;
Io.write output_path data sr ;
Printf.printf "Wrote '%s' (inferred format).\n" output_path
with
| (Io.Invalid_format _ | Io.Internal_error _) as e ->
Printf.eprintf "Write Error ('%s'): %s\n" output_path
(Printexc.to_string e)
| ex ->
Printf.eprintf "Unexpected Write Error ('%s'): %s\n" output_path
(Printexc.to_string ex)
with
| Io.File_not_found msg ->
Printf.eprintf "Read Error: Input '%s' not found: %s.\n" input_path msg
| Io.Invalid_format msg ->
Printf.eprintf "Read Error: Invalid input: %s\n" msg
| Io.Resampling_error msg ->
Printf.eprintf "Read Error: Resampling: %s\n" msg
| Io.Internal_error msg ->
Printf.eprintf "Read Error: Internal SoundML: %s\n" msg
| ex ->
Printf.eprintf "Unexpected Read Error: %s\n" (Printexc.to_string ex)
open Soundml
(* Helper to create a simple sine wave for demonstration *)
let create_sine_wave sr duration freq amplitude =
let samples = int_of_float (sr *. duration) in
let data = Audio.G.create Bigarray.Float32 [|samples|] 0. in
for i = 0 to samples - 1 do
let time = float_of_int i /. sr in
Audio.G.set data [|i|] (amplitude *. sin (2. *. Float.pi *. freq *. time))
done ;
data
let stft =
(* 1. Create a sample audio signal (e.g., 1 second of a 440Hz sine wave at 44100Hz) *)
let sample_rate = 44100.0 in
let duration = 1.0 in
let frequency = 440.0 in
let amplitude = 0.5 in
let audio_signal =
create_sine_wave sample_rate duration frequency amplitude
in
(* 2. Define STFT parameters *)
let win_length = 2048 in
let window = `Hanning in
(* Options: `Hanning, `Hamming, `Blackman, `Boxcar *)
let config = Transform.Config.{default with window; win_length} in
(* 3. Perform STFT *)
(* The 'precision' parameter (Types.B32) indicates float32 operations. *)
Transform.stft ~config Types.B32 audio_signal
open Soundml
open Soundml.Effects
let () =
(* Setup: Define file paths and parameters *)
let input_path = "input.wav" in
let output_path = "output_highpass.wav" in
let target_sample_rate = 44100 in
(* Desired sample rate in Hz for processing *)
let cutoff_frequency = 300.0 in
(* High-pass filter cutoff frequency in Hz *)
(* 1. Read the audio file *)
let audio_track =
Io.read Bigarray.Float32 ~sample_rate:target_sample_rate input_path
in
let original_audio_data = Audio.data audio_track in
let actual_sample_rate = Audio.sr audio_track in
(* 2. Create a Highpass filter instance *)
(* The filter is created with a cutoff frequency and the audio's sample rate. *)
let highpass_filter =
Filter.IIR.HighPass.create
{cutoff= cutoff_frequency; sample_rate= actual_sample_rate}
in
(* 3. Process the audio data through the filter *)
(* The process function applies the filter to the audio data. *)
let filtered_audio_data =
Filter.IIR.HighPass.process highpass_filter original_audio_data
in
(* 4. Write the filtered audio to a new file *)
Io.write output_path filtered_audio_data actual_sample_rate