-
-
Notifications
You must be signed in to change notification settings - Fork 2
First working example and implementation of audio playback with OpenAL-soft library #33
Conversation
The AudioHandler script needs description and modularity to be added. It is nevertheless the first working example of audio playback. Many more features are going to be implemented soon.
testgame/src/game.cpp
Outdated
@@ -28,6 +29,9 @@ int main_game_logic( | |||
//tick the active world | |||
gameEngine->getActiveWorld()->tick(gameEngine->getWindow()); | |||
|
|||
redhand::AudioHandler audioHandler; | |||
audioHandler.PlaySound("sounds/test.wav"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be part of the engine for better control of the lifetime.
there should be a playSound function in the engine which plays the sound using a different thread
include/redhand/AudioHandler.hpp
Outdated
public: | ||
AudioHandler(); | ||
//~AudioHandler(); | ||
void PlaySound(const char*); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const char * should be std::string
void AudioHandler::CheckErrors() { | ||
error = alGetError(); | ||
if (error != AL_NO_ERROR){ | ||
std::cout << "There was an error" << std::endl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be std::cerr << "ERROR::LIBREDHAND::AUDIOHANDLER::AL:ERROR" << std::endl;
src/AudioHandler.cpp
Outdated
|
||
using namespace redhand; | ||
|
||
ALCenum error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error should be a private variable of the Audiohandler with a threading safe set and get function
@@ -71,6 +71,7 @@ if (UNIX) | |||
HINTS /usr/lib/x86_64-linux-gnu/ ${CMAKE_PREFIX_PATH}/deploy/) | |||
|
|||
target_link_libraries(${OUTPUT} ${GLFW}) | |||
target_link_libraries(${OUTPUT} libopenal.so libopenal.so.1.20.1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like the glfw find_library should be used
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The license of test.wav has to be added.
- Everything mentioned in the comments should be fixed
- All methods and the class are missing documentation (doxygen is used you can use the doxygen extention for vscode to help you getting started)
- The default behavior for playSound should be that the sound will be played in a different thread to allow simultanious plaing of sounds, rendering and logic calculation.
The windows build has to be fixed but I will do that |
I am going to put way more functionality into the audio handler class by the end of the week. Let's not rush pushing it to the master branch. |
Btw, how do you find the license of a sound? -_- |
Any audio file (just like every image) has some kind of license/copyright. |
This information will usually be published alongside the sound/image |
static inline ALenum to_al_format(short channels, short samples); | ||
void createDefaultDevice(ALCdevice *device); | ||
|
||
ALCdevice *device; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try to avoid raw pointers use std::shared_ptr or std::unique_ptr as much as possible.
They help avoiding nullptr exceptions and memory leaks.
If you need some audio files to test the code you can use this great free sound library |
Sorry for being absent. I'm going to continue the implementation once the lectures are over. i.e. in about 20 days |
could you fork the project and work on your fork, to allow a cleaner repository? |
closing because the main branch is now main instead of master. |
Many things have to be reviewed here since I'm not sure how well the cmake code is going to work on other machines. The most important thing is that OpenAL-soft is working and the audio playback is functioning without any problems on my machine (as long as the main audio device isn't occupied by other processes).