Minetest 5.10.0-dev
 
Loading...
Searching...
No Matches
ogg_file.h
Go to the documentation of this file.
1/*
2Minetest
3Copyright (C) 2022 DS
4Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
5OpenAL support based on work by:
6Copyright (C) 2011 Sebastian 'Bahamada' Rühl
7Copyright (C) 2011 Cyriaque 'Cisoun' Skrapits <cysoun@gmail.com>
8Copyright (C) 2011 Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
9
10This program is free software; you can redistribute it and/or modify
11it under the terms of the GNU Lesser General Public License as published by
12the Free Software Foundation; either version 2.1 of the License, or
13(at your option) any later version.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU Lesser General Public License for more details.
19
20You should have received a copy of the GNU Lesser General Public License along
21with this program; if not, write to the Free Software Foundation, Inc.,
2251 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23*/
24
25#pragma once
26
27#include "al_helpers.h"
28#include <vorbis/vorbisfile.h>
29#include <optional>
30#include <string>
31
32namespace sound {
33
38 std::string buf;
39 size_t cur_offset = 0;
40
41 static size_t read_func(void *ptr, size_t size, size_t nmemb, void *datasource) noexcept;
42 static int seek_func(void *datasource, ogg_int64_t offset, int whence) noexcept;
43 static int close_func(void *datasource) noexcept;
44 static long tell_func(void *datasource) noexcept;
45
46 static const ov_callbacks s_ov_callbacks;
47};
48
54 std::string name_for_logging;
56 ALenum format; // AL_FORMAT_MONO16 or AL_FORMAT_STEREO16
58 ALsizei freq;
59 ALuint length_samples = 0;
60 f32 length_seconds = 0.0f;
61};
62
67 bool m_needs_clear = false;
68 OggVorbis_File m_file;
69
70 RAIIOggFile() = default;
71
73
74 ~RAIIOggFile() noexcept
75 {
76 if (m_needs_clear)
77 ov_clear(&m_file);
78 }
79
80 OggVorbis_File *get() { return &m_file; }
81
82 std::optional<OggFileDecodeInfo> getDecodeInfo(const std::string &filename_for_logging);
83
94 RAIIALSoundBuffer loadBuffer(const OggFileDecodeInfo &decode_info, ALuint pcm_start,
95 ALuint pcm_end);
96};
97
98} // namespace sound
#define DISABLE_CLASS_COPY(C)
Definition basic_macros.h:35
Definition al_extensions.cpp:26
Metadata of an Ogg-Vorbis file, used for decoding.
Definition ogg_file.h:53
bool is_stereo
Definition ogg_file.h:55
ALuint length_samples
Definition ogg_file.h:59
std::string name_for_logging
Definition ogg_file.h:54
f32 length_seconds
Definition ogg_file.h:60
ALenum format
Definition ogg_file.h:56
ALsizei freq
Definition ogg_file.h:58
size_t bytes_per_sample
Definition ogg_file.h:57
For vorbisfile to read from our buffer instead of from a file.
Definition ogg_file.h:37
size_t cur_offset
Definition ogg_file.h:39
static const ov_callbacks s_ov_callbacks
Definition ogg_file.h:46
static long tell_func(void *datasource) noexcept
Definition ogg_file.cpp:82
static size_t read_func(void *ptr, size_t size, size_t nmemb, void *datasource) noexcept
Definition ogg_file.cpp:36
static int close_func(void *datasource) noexcept
Definition ogg_file.cpp:75
static int seek_func(void *datasource, ogg_int64_t offset, int whence) noexcept
Definition ogg_file.cpp:46
std::string buf
Definition ogg_file.h:38
RAII wrapper for openal sound buffers.
Definition al_helpers.h:94
RAII wrapper for OggVorbis_File.
Definition ogg_file.h:66
std::optional< OggFileDecodeInfo > getDecodeInfo(const std::string &filename_for_logging)
Definition ogg_file.cpp:99
OggVorbis_File m_file
Definition ogg_file.h:68
OggVorbis_File * get()
Definition ogg_file.h:80
RAIIALSoundBuffer loadBuffer(const OggFileDecodeInfo &decode_info, ALuint pcm_start, ALuint pcm_end)
Main function for loading ogg vorbis sounds.
Definition ogg_file.cpp:176
~RAIIOggFile() noexcept
Definition ogg_file.h:74
bool m_needs_clear
Definition ogg_file.h:67
RAIIOggFile()=default