khora_data/assets/audio.rs
1// Copyright 2025 eraflo
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Defines the core asset type for audio data.
16
17use khora_core::asset::Asset;
18
19/// Represents a sound asset, decoded and ready for playback.
20///
21/// This struct holds audio data in a normalized, interleaved `f32` format,
22/// which is the standard for high-quality audio processing pipelines.
23/// The `AssetAgent` will manage instances of this type in its cache.
24#[derive(Debug, Clone)]
25pub struct SoundData {
26 /// The raw, interleaved audio samples.
27 /// For stereo, samples are ordered `[L, R, L, R, ...]`.
28 /// Values are expected to be in the range `[-1.0, 1.0]`.
29 pub samples: Vec<f32>,
30 /// The number of channels in the audio data (e.g., 1 for mono, 2 for stereo).
31 pub channels: u16,
32 /// The number of samples per second (e.g., 44100 Hz).
33 pub sample_rate: u32,
34}
35
36// By implementing `Asset`, `SoundData` can be used with `AssetHandle<T>`
37// and managed by the `AssetAgent`.
38impl Asset for SoundData {}