-
Notifications
You must be signed in to change notification settings - Fork 174
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
Implement methods for sfx, and refactor Sound system #558
Conversation
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.
Looks good in general.
rwengine/src/audio/SfxParameters.hpp
Outdated
/// @todo some of them should return | ||
/// random(?) number in range | ||
/// see comment in second column | ||
constexpr SoundInstanceData sfxData[] = { |
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.
Can this be moved to a cpp file?
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.
I'll do.
rwengine/src/audio/Sound.hpp
Outdated
buffer->stop(); | ||
} | ||
|
||
void setPosition(const glm::vec3 position) { |
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 glm::vec3 &position
(same remark for other arguments)
Or is this more efficient? (I would let the compiler decide and use references)
rwengine/src/audio/Sound.hpp
Outdated
buffer->setLooping(looping); | ||
} | ||
|
||
void setPitch(const float pitch) { |
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.
Is the const really necessary? Same remark goes to all const arguments in this pr.
rwengine/src/audio/SoundManager.cpp
Outdated
Sound* sound = nullptr; | ||
auto soundRef = sfx.find(index); | ||
|
||
//Let's try reuse buffor |
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 reuse the buffer
(buffor -> buffer: general remark for this pr)
rwengine/src/audio/SfxParameters.hpp
Outdated
{45, 413, 80}, | ||
{46, 414, 30}, | ||
{47, 414, 30}, | ||
{48, 415, 30}, /// Marco's Bistro (no sound) |
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 comments do not have consistent layout + should not contain tabs.
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.
I forgot to reformat it. (shame)
rwengine/src/audio/SfxParameters.hpp
Outdated
#define _RWENGINE_SFX_PARAMETERS_HPP_ | ||
|
||
/// Nr of existing sfx sounds | ||
constexpr size_t kNrOfAllSfx = 3032; |
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.
What is the source of this number? Isn't this data dependent?
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.
Taken from gtamodding.
Done. ;) |
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.
Nit: Is commenting with ///
allowed? Personally I would find it better to use /* */
when multiline comment is needed.
rwengine/src/audio/SfxParameters.cpp
Outdated
{106, 176, 50}, /// bullet hit ground | ||
{107, 177, 50}, | ||
{108, 178, 50}, | ||
{110, 389, 80}, /// silent, replace the SFX or edit the memory to a |
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.
nit: inconsistent alignment of comments in this array.
rwengine/src/audio/SoundManager.cpp
Outdated
auto ref = buffers.find(name); | ||
if (ref != buffers.end()) { | ||
return ref->second; | ||
} else { // Hmm, we should reload this |
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.
nit: I think this comment is unnecessary
rwengine/src/audio/SoundManager.cpp
Outdated
Sound* sound = nullptr; | ||
auto soundRef = sfx.find(index); | ||
|
||
// Let's try reuse buffer |
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.
nit: I would rather phrase this something like Try to reuse first available buffer
and remove the comment from the loop below.
rwengine/src/audio/SoundManager.cpp
Outdated
} | ||
// Hmmm, nothing, we should create new buffer |
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.
nit: rephrase to something that indicates that there was no available buffer to be reused so that's why new one is created.
rwengine/src/audio/SoundManager.hpp
Outdated
#include "audio/SfxParameters.hpp" | ||
|
||
/// Game's sound manager. | ||
/// It handles all staff conntected with sounds. |
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.
Typos (stuff
and connected
)
|
||
if (len >= 0 && gotFrame) { | ||
// Write samples to audio buffer | ||
|
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.
Unnecessary empty line
rwengine/src/audio/SfxParameters.hpp
Outdated
#include <cstddef> | ||
|
||
/// Nr of existing sfx sounds | ||
constexpr size_t kNrOfAllSfx = 3032; |
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 @madebr noted previously this looks to depend of the game and this is correct only for GTA III?
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.
Yeah. I'll rename it.
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.
I think Todo might be enough at this point (as also the SfxData array in SfxParameters.cpp is valid only for GTAIII?)
rwengine/src/audio/SfxParameters.cpp
Outdated
{34, 405, 30}, | ||
{35, 405, 30}, | ||
{36, 407 /*-408*/, | ||
30}, /// 407 plays continuously |
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 can be on same line (at line 94).
rwengine/src/audio/SfxParameters.cpp
Outdated
{60, 406, 30}, /// Salvatore's place | ||
{61, 406, 80}, | ||
{62, 432 /*-434*/, | ||
20}, /// South of Sex Club Seven |
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 could fit into line 123.
rwengine/src/audio/SfxParameters.cpp
Outdated
/// and intermittently | ||
{63, 432 /*-434*/, 80}, | ||
{64, 435 /*-437*/, | ||
20}, /// East of Portland |
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 could fit into line 130.
rwengine/src/audio/SfxParameters.cpp
Outdated
return data.id == scriptId; | ||
}); | ||
if (finded != std::end(sfxData)) { | ||
return finded->sfx; |
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 range
.
Up. :) |
rwengine/src/audio/SoundManager.cpp
Outdated
} | ||
av_free_packet(&readingPacket); | ||
sound->source = std::make_shared<SoundSource>(); | ||
sound->source->loadSfx(path, i); |
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.
loadSfx
has too much responsibility.
Since it's called in a loop here it would make more sense to create a LoaderSDT
here and pass it in.
if (receiveFrame == 0 && sendPacket == 0) { | ||
// Write samples to audio buffer | ||
|
||
for (size_t i = 0; |
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.
Is there any way to extract this inner loop so it can be shared between all of the frame handling paths?
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.
Discussed on IRC: task to do in later pull.
Small up. Reusing instance of LoaderSDT and cleanup of headers. |
} | ||
|
||
|
||
sdt.load(path / "audio/sfx"); |
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.
It should be done only once in ctor of SoundManager. @madebr can/should we keep path in SoundManager?
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.
To do later.
|
||
size_t SoundManager::createSfxInstance(size_t index) { | ||
Sound* sound = nullptr; | ||
auto soundRef = sfx.find(index); |
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.
Here we can check, if sound is loaded, and if there's need load it. But it would require storing game path in SoundManager.
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.
To do later.
@ShFil119 Do you intend to take care of those comments in this PR? |
I'll take care about these features later. |
rwengine/src/audio/SfxParameters.cpp
Outdated
}; | ||
} // namespace | ||
|
||
int convertScriptIndexIntoSfx(int scriptId) { |
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.
Does SoundInstanceData
need to be hidden? A simpler interface could just be const SoundInstanceData& getScriptSoundInstanceData(int scriptId)
.
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.
Not sure if we need/want this interface in script. If you want, I can change.
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.
Yeah. This seems to be unused in this PR, could you move it into the next PR?
SoundBuffer and SoundSource got their own files.
SoundBuffer and SoundSource got their own files.
Also has been added hardcoded metadata of sfx. (Like in origin)
It's continuation of backporting code from #420.