Luanti 5.11.0-dev
 
Loading...
Searching...
No Matches
ogg_file.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
3// Copyright (C) 2022 DS
4// Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5// Copyright (C) 2011 Sebastian 'Bahamada' Rühl
6// Copyright (C) 2011 Cyriaque 'Cisoun' Skrapits <cysoun@gmail.com>
7// Copyright (C) 2011 Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
8
9#pragma once
10
11#include "al_helpers.h"
12#include <vorbis/vorbisfile.h>
13#include <optional>
14#include <string>
15
16namespace sound {
17
22 std::string buf;
23 size_t cur_offset = 0;
24
25 static size_t read_func(void *ptr, size_t size, size_t nmemb, void *datasource) noexcept;
26 static int seek_func(void *datasource, ogg_int64_t offset, int whence) noexcept;
27 static int close_func(void *datasource) noexcept;
28 static long tell_func(void *datasource) noexcept;
29
30 static const ov_callbacks s_ov_callbacks;
31};
32
38 std::string name_for_logging;
40 ALenum format; // AL_FORMAT_MONO16 or AL_FORMAT_STEREO16
42 ALsizei freq;
43 ALuint length_samples = 0;
44 f32 length_seconds = 0.0f;
45};
46
51 bool m_needs_clear = false;
52 OggVorbis_File m_file;
53
54 RAIIOggFile() = default;
55
57
58 ~RAIIOggFile() noexcept
59 {
60 if (m_needs_clear)
61 ov_clear(&m_file);
62 }
63
64 OggVorbis_File *get() { return &m_file; }
65
66 std::optional<OggFileDecodeInfo> getDecodeInfo(const std::string &filename_for_logging);
67
78 RAIIALSoundBuffer loadBuffer(const OggFileDecodeInfo &decode_info, ALuint pcm_start,
79 ALuint pcm_end);
80};
81
82} // namespace sound
#define DISABLE_CLASS_COPY(C)
Definition basic_macros.h:26
Definition al_extensions.cpp:11
Metadata of an Ogg-Vorbis file, used for decoding.
Definition ogg_file.h:37
bool is_stereo
Definition ogg_file.h:39
ALuint length_samples
Definition ogg_file.h:43
std::string name_for_logging
Definition ogg_file.h:38
f32 length_seconds
Definition ogg_file.h:44
ALenum format
Definition ogg_file.h:40
ALsizei freq
Definition ogg_file.h:42
size_t bytes_per_sample
Definition ogg_file.h:41
For vorbisfile to read from our buffer instead of from a file.
Definition ogg_file.h:21
size_t cur_offset
Definition ogg_file.h:23
static const ov_callbacks s_ov_callbacks
Definition ogg_file.h:30
static long tell_func(void *datasource) noexcept
Definition ogg_file.cpp:67
static size_t read_func(void *ptr, size_t size, size_t nmemb, void *datasource) noexcept
Definition ogg_file.cpp:21
static int close_func(void *datasource) noexcept
Definition ogg_file.cpp:60
static int seek_func(void *datasource, ogg_int64_t offset, int whence) noexcept
Definition ogg_file.cpp:31
std::string buf
Definition ogg_file.h:22
RAII wrapper for openal sound buffers.
Definition al_helpers.h:78
RAII wrapper for OggVorbis_File.
Definition ogg_file.h:50
std::optional< OggFileDecodeInfo > getDecodeInfo(const std::string &filename_for_logging)
Definition ogg_file.cpp:84
OggVorbis_File m_file
Definition ogg_file.h:52
OggVorbis_File * get()
Definition ogg_file.h:64
RAIIALSoundBuffer loadBuffer(const OggFileDecodeInfo &decode_info, ALuint pcm_start, ALuint pcm_end)
Main function for loading ogg vorbis sounds.
Definition ogg_file.cpp:161
~RAIIOggFile() noexcept
Definition ogg_file.h:58
bool m_needs_clear
Definition ogg_file.h:51
RAIIOggFile()=default