audio.h 1.24 KB
Newer Older
RobLoach's avatar
RobLoach committed
1
2
#ifndef SRC_LOVE_AUDIO_H_
#define SRC_LOVE_AUDIO_H_
RobLoach's avatar
RobLoach committed
3

RobLoach's avatar
RobLoach committed
4
#include "Types/Audio/SoundData.h"
5
6
#include "sound.h"

RobLoach's avatar
RobLoach committed
7
8
using love::Types::Audio::SoundData;

RobLoach's avatar
RobLoach committed
9
namespace love {
RobLoach's avatar
RobLoach committed
10
11

/**
RobLoach's avatar
RobLoach committed
12
 * Provides an interface to output sound to the user's speakers.
RobLoach's avatar
RobLoach committed
13
14
 */
class audio {
RobLoach's avatar
RobLoach committed
15
	public:
RobLoach's avatar
RobLoach committed
16
	/**
RobLoach's avatar
RobLoach committed
17
	 * Plays the specified sound.
RobLoach's avatar
RobLoach committed
18
19
	 *
	 * @param soundData The sound to play.
RobLoach's avatar
RobLoach committed
20
	 */
RobLoach's avatar
RobLoach committed
21
	void play(SoundData* soundData);
RobLoach's avatar
RobLoach committed
22
23

	/**
RobLoach's avatar
RobLoach committed
24
	 * Creates a new audio source from a file.
RobLoach's avatar
RobLoach committed
25
26
	 *
	 * @param filename The .wav file to load.
RobLoach's avatar
RobLoach committed
27
28
29
	 * @param type ("static") The type of audio source to load ("static", "stream"). Optional.
	 *
	 * @return The new SoundData if it loaded correctly, NULL otherwise.
RobLoach's avatar
RobLoach committed
30
	 */
RobLoach's avatar
RobLoach committed
31
	SoundData* newSource(const std::string& filename, const std::string& type);
RobLoach's avatar
RobLoach committed
32
	SoundData* newSource(const std::string& filename);
RobLoach's avatar
RobLoach committed
33
34
35

	void mixer_render(int16_t *buffer);

RobLoach's avatar
RobLoach committed
36
	int AUDIO_FRAMES = 735;  // 44100 / 60
RobLoach's avatar
RobLoach committed
37
38
39
40
	int WAV_HEADER_SIZE = 44;
	float m_volume = 1.0f;

	/**
RobLoach's avatar
RobLoach committed
41
	 * Returns the master volume.
RobLoach's avatar
RobLoach committed
42
43
44
45
46
	 *
	 * @return The current master volume between 0.0f and 1.0f.
	 */
	float getVolume();

RobLoach's avatar
RobLoach committed
47
	/**
RobLoach's avatar
RobLoach committed
48
	 * Set the master volume.
RobLoach's avatar
RobLoach committed
49
50
	 *
	 * @param volume 1.0f is max and 0.0f is off.
RobLoach's avatar
RobLoach committed
51
52
	 *
	 * @return The audio module, to allow method chaining.
RobLoach's avatar
RobLoach committed
53
	 */
RobLoach's avatar
RobLoach committed
54
	audio& setVolume(float volume);
RobLoach's avatar
RobLoach committed
55
56
};

RobLoach's avatar
RobLoach committed
57
}  // namespace love
RobLoach's avatar
RobLoach committed
58

RobLoach's avatar
RobLoach committed
59
#endif  // SRC_LOVE_AUDIO_H_