aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/audio/SDL/sdl_audio.h
blob: 48081189a86983dfd20b86837e9081bf753f6d30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#ifndef __JE_AUDIO_SDL_H__
#define __JE_AUDIO_SDL_H__
#include "../../core/configuration.h"
#if defined(jin_audio) && (jin_audio == jin_audio_sdl)

#include <vector>

#include "../audio_manager.h"

#include "sdl_source.h"

namespace JinEngine
{
    namespace Audio
    {
        namespace SDL
        {

#define SDLAUDIO_BITDEPTH 16
#define SDLAUDIO_BYTEDEPTH (SDLAUDIO_BITDEPTH  >> 3)
#define SDLAUDIO_CHANNELS  2

            ///
            /// Audio system SDL implementation.
            ///
            class SDLAudio : public AudioManager<SDLAudio>
            {
            public:
                ///
                /// SDL audio setting.
                ///
                struct Setting : SettingBase
                {
                public:
                    int samplerate; // Ƶ
                    int samples;    // sample<=samplerate
                };

                ///
                /// SDL audio constructor.
                ///
                SDLAudio() {};

                ///
                /// SDL audio destructor.
                ///
                ~SDLAudio() {};

                ///
                /// Play all sources whose state is playing.
                ///
                void play() override;

                ///
                /// Stop and remove all sources from the queue. 
                ///
                void stop() override;

                ///
                /// Pause audio.
                ///
                void pause() override;

                ///
                /// Resume audio.
                ///
                void resume() override;

                ///
                /// Set global audio volume.
                ///
                void setVolume(float volume) override;

                ///
                /// Process all commands in the queue.
                ///
                void processCommands();

                ///
                /// Process all sources.
                /// 
                /// @param buffer Source buffer.
                /// @param len Source length.
                ///
                void processSources(void* buffer, size_t len);

                ///
                /// Process audio buffer.
                /// 
                /// @param buffer Audio stream buffer.
                /// @param len Length of stream buffer.
                ///
                void processBuffer(void* buffer, size_t len);

                ///
                /// Goon process.
                /// 
                /// @return True if sucessful, otherwise return false.
                ///
                bool goOnProcess();

                ///
                /// Lock audio device.
                ///
                void lock();

                ///
                /// Unlock audio device.
                ///
                void unlock();

            private:
                ///
                /// Initialize audio system.
                ///
                /// @param setting Audio setting.
                ///
                bool startSystem(const SettingBase* setting) override;

                ///
                /// Quit audio system.
                ///
                void quitSystem() override;

                // Audio device id.
                unsigned int audioDevice;

            };

        } // namespace SDL 
    } // namespace Audio
} // namespace JinEngine

#endif // (jin_audio) && (jin_audio == jin_audio_sdl)

#endif // __JE_AUDIO_SDL_H__