audio-cpp/audio_units.cpp

LocalAI · backend/cpp/audio-cpp/audio_units.cpp · cpp · MIT
voice

Provides audio frame and sample conversion utilities for C++ audio processing.

// Source: https://github.com/mudler/LocalAI | License: MIT | Copyright 2023-2025 Ettore Di Giacinto (mudler@localai.io)
// Provided via justclaw.it.com; keep this notice with the code.
#include "audio_units.h"

#include <algorithm>
#include <cmath>
#include <limits>

namespace audiocpp_backend {

std::int64_t interleaved_frame_count(std::size_t sample_count, int channels) {
    const std::size_t lanes = channels > 0 ? static_cast<std::size_t>(channels)
                                           : static_cast<std::size_t>(1);
    // Truncating division is deliberate: a trailing partial frame is not a
    // position every channel reached, so counting it would overstate the length.
    return static_cast<std::int64_t>(sample_count / lanes);
}

std::int64_t samples_to_nanoseconds(std::int64_

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key