Copperfield Engine 0.1
C++ Game Engine
Loading...
Searching...
No Matches
soundbuffer.h
1#pragma once
2#include "AL/al.h"
3#include "AL/alc.h"
4#include <string>
5#include <optional>
6
7/*
8* Struct that holds the RIFF data of the Wave file.
9* The RIFF data is the meta data information that holds,
10* the ID, size and format of the wave file
11*/
12struct RIFF_Header {
13 char chunkID[4];
14 long chunkSize; //size not including chunkSize or chunkID
15 char format[4];
16};
17
18/*
19* Struct to hold fmt subchunk data for WAVE files.
20*/
21struct WAVE_Format {
22 char subChunkID[4];
23 long subChunkSize;
24 short audioFormat;
25 short numChannels;
26 long sampleRate;
27 long byteRate;
28 short blockAlign;
29 short bitsPerSample;
30};
31
32/*
33* Struct to hold the data of the wave file
34*/
35struct WAVE_Data {
36 char subChunkID[4]; //should contain the word data
37 long subChunk2Size; //Stores the size of the data block
38};
39
40struct SoundData {
41 ALsizei size_;
42 ALsizei frequency_;
43 ALenum format_;
44 std::string name_;
45
46 FILE* soundFile = NULL;
47 WAVE_Format wave_format;
48 RIFF_Header riff_header;
49 WAVE_Data wave_data;
50
51 unsigned char* data;
52};
53
54class ResourceManager;
55
56class SoundBuffer {
57 public:
58 static std::optional<SoundBuffer> MakeBuffer(const std::string filename,
59 const std::string name);
60 bool createSoundBuffer(ResourceManager& e);
61 SoundBuffer(SoundBuffer&& b) noexcept;
62 SoundBuffer(const SoundBuffer& b) = default;
63 SoundBuffer& operator=(SoundBuffer& other) = default;
64 SoundBuffer& operator=(SoundBuffer&& other) = default;
65 ALuint getBuffer() const;
66 int Fequency();
67 int Size();
68 int Format();
69
70 SoundBuffer(ALuint id, SoundData data);
71 ~SoundBuffer();
72
73 bool active_;
74
75 private:
76 SoundBuffer() = default;
77
78
79 ALuint buffer_;
80 SoundData sound_info_;
81
82};
Stores and offers access to all meshes, textures, and sounds of the engine.
Definition: resource_manager.hpp:27