-
Notifications
You must be signed in to change notification settings - Fork 1
Sound Manager to master #22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
d815b88
OpenAL cmake config
Wiesiek418 1f5c995
Constructors, Destructors [Sound, Source, Clip] and SoundListener
Wiesiek418 0928d0c
Load audio file OGG
Wiesiek418 5bb0282
Fix code format
Wiesiek418 47b5eff
Commit for test raytrace
Wiesiek418 ee5c287
Rebuild Sound Manager and playing sound
Wiesiek418 e675d64
Pause, Stop sound. Comments in manager
Wiesiek418 b22e01f
Delete sound thread
Wiesiek418 4b877ea
Changing the ums_sources parameter from sso name to sso object and ad…
Wiesiek418 6b8063e
Refactore and rebuild manager, soundClip, soundSource (soundClip key …
Wiesiek418 f151877
Rebuild of sound manager (WiP), change map to vector, shared/weak poi…
Wiesiek418 19a4cdc
Fix sound debug, detect expired pointer
Wiesiek418 dc90250
Replace throw to cerr in source, manager, clip
Wiesiek418 8e920eb
External public function from manager.cpp to functions.hpp and WiP gr…
Wiesiek418 634be22
Delete SoundGroupParameters and SoundGroupMovement, add functions.hpp…
Wiesiek418 d1b951c
Sound group as a offset in sso, adds all parameters, getting only mon…
Wiesiek418 c48d3b3
Fast commit before branch engine test
Wiesiek418 6f2a24f
Comments on sound hpp files
Wiesiek418 3f7a659
WiP load WAV file, add removeObject to SoundManager
Wiesiek418 3182ba2
Merge master to sound
Wiesiek418 83952e0
Hot fixs in sound system
Wiesiek418 4e74a7c
Hot fixes v2 sound system
Wiesiek418 cecbca1
WAV file support
Wiesiek418 172fe7d
Fixing memory leaks
Wiesiek418 0cd645f
Improve update parameters system, add debug only method in manager, c…
Wiesiek418 9522062
Change arytmetic for offset group in source parameters
Wiesiek418 3b90f5d
Delete test lines in main
Wiesiek418 d4012c0
remove malloc from convert channel, few small fix
Wiesiek418 fbbd1ee
Delete some alGetError
Wiesiek418 94fc20c
GetError
Wiesiek418 a90a882
Delete const
Wiesiek418 9f1a3d5
Merge master to sound
Wiesiek418 6291dae
Merge branch 'sound' of github.com:dark-tree/checklight into sound
Wiesiek418 071e8f0
Migrate some of the console output to the logger
magistermaks d713791
Ported output to use logger
magistermaks e74630d
Added windows/VS specific build logic
magistermaks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
#include "clip.hpp" | ||
|
||
#include "debug.hpp" | ||
#include "shared/logger.hpp" | ||
|
||
SoundClip::SoundClip(){ | ||
alGetError(); | ||
alGenBuffers(1, &buffer); | ||
alCheckError("durring clip creation"); | ||
} | ||
|
||
SoundClip::~SoundClip(){ | ||
alDeleteBuffers(1, &buffer); | ||
} | ||
|
||
void SoundClip::convertChannels(int* audio_size, int channels, short* data) { | ||
/// Resize to 1 channel | ||
int new_audio_size = *audio_size / channels; | ||
/// Get data only from 1 channel | ||
int j = 0; | ||
int sum_audio = 0; | ||
for (int i = 0; i < *audio_size; i++) { | ||
sum_audio += data[i]; | ||
/// Check if we are at the end of the block of channels | ||
/// If we are, get average of the channels and save to the output | ||
/// All channels convert to mono as average of the channels | ||
if (i % channels == (channels-1)) { | ||
data[j] = sum_audio/channels; | ||
sum_audio = 0; | ||
j++; | ||
} | ||
} | ||
*audio_size = new_audio_size; | ||
} | ||
|
||
void SoundClip::loadOGGFile(const char* filename) { | ||
// clean up errors | ||
alGetError(); | ||
|
||
int channels, sample_rate; | ||
short* output; | ||
|
||
// get output, channels, sample rate from filename and size of the data | ||
ALsizei size_block = stb_vorbis_decode_filename(filename, &channels, &sample_rate, &output); | ||
|
||
if (size_block == -1) { | ||
out::error("Failed to decode OGG file '%s'!", filename); | ||
free(output); | ||
return; | ||
} | ||
this->path = filename; | ||
|
||
/// Check of the file has more than 2 channels. If it has, convert it to mono | ||
if (channels >= 2) { | ||
convertChannels(&size_block, channels, output); | ||
} | ||
|
||
ALenum format = AL_FORMAT_MONO16; | ||
ALsizei audio_size = size_block * sizeof(short); | ||
|
||
// Create buffer | ||
alBufferData(buffer, format, output, audio_size, sample_rate); | ||
free(output); | ||
|
||
if (alGetError() != AL_NO_ERROR) { | ||
FAULT("Failed to upload the sound buffer!"); | ||
} | ||
|
||
out::debug("Loaded sound '%s'", filename); | ||
} | ||
|
||
void SoundClip::loadWAVFile(const char* filename) { | ||
alGetError(); | ||
/// WAV File Header | ||
/// https://docs.fileformat.com/audio/wav/ | ||
/// http://soundfile.sapp.org/doc/WaveFormat/ | ||
struct WAVFile { | ||
char chunk_ID[4]; | ||
uint32_t chunk_size; | ||
char format[4]; | ||
|
||
char subchunk1_ID[4]; | ||
uint32_t subchunk1_size; | ||
uint16_t audio_format; | ||
uint16_t num_channels; | ||
uint32_t sample_rate; | ||
uint32_t byte_rate; | ||
uint16_t block_align; | ||
uint16_t bits_per_sample; | ||
|
||
char subchunk2_ID[4]; | ||
uint32_t subchunk2_size; | ||
}; | ||
|
||
std::ifstream wav_file(filename, std::ios::binary); | ||
WAVFile wav_header; | ||
/// Read header from file | ||
if (!wav_file.read(reinterpret_cast<char*>(&wav_header), sizeof(WAVFile))) { | ||
out::error("Failed decode WAV file '%s', can't read file header!", filename); | ||
return; | ||
} | ||
|
||
ALsizei frequency = wav_header.sample_rate; | ||
/// Read all audio data without header from file | ||
std::vector<short> data; | ||
data.resize(wav_header.subchunk2_size); | ||
|
||
if (!wav_file.read(reinterpret_cast<char*>(data.data()), wav_header.subchunk2_size)) { | ||
out::error("Failed decode WAV file '%s', can't read file chunk!", filename); | ||
return; | ||
} | ||
ALsizei audio_size = wav_header.subchunk2_size; | ||
|
||
/// Check of the file has more than 2 channels. If it has, convert it to mono | ||
if (wav_header.num_channels >= 2) { | ||
Wiesiek418 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
convertChannels(&audio_size, wav_header.num_channels, data.data()); | ||
} | ||
|
||
ALenum format; | ||
if (wav_header.bits_per_sample == 8) { | ||
format = AL_FORMAT_MONO8; | ||
} | ||
else if (wav_header.bits_per_sample == 16) { | ||
format = AL_FORMAT_MONO16; | ||
} else { | ||
out::error("Failed decode WAV file '%s', unsupported channel count, expected mono or stereo!", filename); | ||
return; | ||
} | ||
|
||
alBufferData(buffer, format, data.data(), audio_size, frequency); | ||
|
||
if (alGetError() != AL_NO_ERROR) { | ||
FAULT("Failed to upload the sound buffer!"); | ||
} | ||
|
||
out::debug("Loaded sound '%s'", filename); | ||
} | ||
|
||
void SoundClip::loadAudio(const char* filename) { | ||
std::ifstream input_file {filename, std::ios::binary}; | ||
|
||
if (!input_file) { | ||
out::error("Can't open sound file '%s'!", filename); | ||
return; | ||
} | ||
|
||
char header[4]; | ||
input_file.read(header, 4); | ||
input_file.close(); | ||
|
||
if (std::string(header, 4) == "OggS") { | ||
loadOGGFile(filename); | ||
return; | ||
} | ||
|
||
if (std::string(header, 4) == "RIFF" || std::string(header, 4) == "WAVE") { | ||
loadWAVFile(filename); | ||
return; | ||
} | ||
|
||
out::error("Can't open sound file '%s', unsupported or invalid format!", filename); | ||
|
||
} | ||
|
||
ALuint SoundClip::getBuffer() { | ||
return buffer; | ||
} | ||
|
||
std::string SoundClip::getPath() | ||
{ | ||
return path; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.