nomlib
Loading...
Searching...
No Matches
Sound.hpp
1#pragma once
2
3#include <string>
4#include "export.hpp"
5#include "nomlib/types.hpp"
6
7namespace nom {
8namespace audio {
9
10// Forward declarations
12
13class 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
27class 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
int total_bytes() const
Obtain the total number of bytes for this sound instance.
nom::real64 duration() const
Obtain the total length of this sound instance.
int channels() const
Obtain the number of audio channels of this sound instance.
nom::real32 frequency() const
Obtain the audio frequency in Hertz of this sound instance.
int format() const
Obtain the audio channel format as expressed in AL_FORMAT_XXX.
nom::int64 sample_count() const
Obtain the total sample count of this sound instance.
nom::uint & buffer()
Identifier number for the implementation-defined buffer system.