nomlib
Toggle main menu visibility
Loading...
Searching...
No Matches
include
nomlib
audio
Sound.hpp
1
#pragma once
2
3
#include <string>
4
#include "export.hpp"
5
#include "nomlib/types.hpp"
6
7
namespace
nom {
8
namespace
audio {
9
10
// Forward declarations
11
class
ISoundFileReader
;
12
13
class
NOM_EXPORT ISound {
14
public
:
15
ISound() {};
16
virtual
~ISound() {}
17
// TODO(JEFF): Change return type of bool to void?
18
virtual
bool
open(
const
std::string& filename) = 0;
19
20
// Not implemented
21
virtual
double
stream(nom::uint32 buffer, nom::real64 pos) = 0;
22
//virtual bool stream__(uint32 buffer, real64 pos) = 0;
23
protected
:
24
};
25
26
//class Sound: public ISound
27
class
NOM_EXPORT Sound
28
{
29
public
:
30
// Default init ctr for fp_
31
Sound();
32
// init with fp_ and filename
33
Sound(
const
std::string& name);
34
virtual
~Sound();
35
36
// getters for the data fields of each sound read in by init method
38
nom::uint&
buffer
()
/*const*/
;
39
nom::int16* data()
/*const*/
;
40
nom::uint64 bitrate()
const
;
41
43
nom::real32
frequency
()
const
;
44
46
int
channels
()
const
;
47
49
int
total_bytes
()
const
;
50
53
int
format
()
const
;
54
56
nom::real64
duration
()
const
;
57
59
nom::int64
sample_count
()
const
;
60
61
// Part 2 -- file chunk playback
62
bool
streaming()
const
;
63
64
// TODO(JEFF): Change return type of bool to void?
65
virtual
bool
open(
const
std::string& filename);
66
67
// Not implemented
68
virtual
double
stream(nom::uint32
buffer
, nom::real64 pos);
69
virtual
bool
stream__(nom::uint32
buffer
, nom::real64 pos);
70
71
#if defined(DEBUG)
72
std::string filename_;
73
#endif
74
protected
:
75
// init with filename and fp_
76
void
init(
const
std::string& filename);
77
// Init with sample data using fp_
78
void
init(nom::int16* samples, nom::uint32
format
,
int
num_channels);
79
80
nom::audio::ISoundFileReader
* fp_;
// sound file reader impl pointer
81
nom::int16* samples_;
// samples in 16 bit (native)
82
nom::int64 sample_count_;
// total number of frames (samples)
83
nom::uint buffer_id_;
// >= 0 && <= UINT_MAX
84
nom::uint64 bitrate_;
// bits per second
85
nom::real32 frequency_;
// sample rate (frequency)
86
nom::real64 duration_;
// time_left
87
int
total_bytes_;
// storage size on disk
88
int
num_channels_;
// MONO (1) || STEREO (2)
89
nom::uint32 format_;
// AUDIO_FORMAT_XXX
90
bool
streaming_;
// AL_STATIC || AL_STREAMING
91
private
:
92
// Non-member functions
93
void
* allocate_samples(nom::size_type bytes,
int
num_channels, nom::uint32 fmt);
94
nom::int16* allocate_samples(nom::size_type bytes,
int
channels
);
95
};
96
97
//void* allocate_samples(size_type bytes, int num_channels, uint32 fmt);
98
99
}
// namespace audio
100
}
// namespace nom
nom::audio::ISoundFileReader
Definition
ISoundFileReader.hpp:42
nom::audio::Sound::total_bytes
int total_bytes() const
Obtain the total number of bytes for this sound instance.
nom::audio::Sound::duration
nom::real64 duration() const
Obtain the total length of this sound instance.
nom::audio::Sound::channels
int channels() const
Obtain the number of audio channels of this sound instance.
nom::audio::Sound::frequency
nom::real32 frequency() const
Obtain the audio frequency in Hertz of this sound instance.
nom::audio::Sound::format
int format() const
Obtain the audio channel format as expressed in AL_FORMAT_XXX.
nom::audio::Sound::sample_count
nom::int64 sample_count() const
Obtain the total sample count of this sound instance.
nom::audio::Sound::buffer
nom::uint & buffer()
Identifier number for the implementation-defined buffer system.
Generated on
for nomlib by
1.18.0