Skip to content
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

Merged
merged 1 commit into from Aug 8, 2018
Merged

Implement methods for sfx, and refactor Sound system #558

merged 1 commit into from Aug 8, 2018

Conversation

ghost
Copy link

@ghost ghost commented Jul 26, 2018

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.

Copy link
Contributor

@madebr madebr left a 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.

/// @todo some of them should return
/// random(?) number in range
/// see comment in second column
constexpr SoundInstanceData sfxData[] = {
Copy link
Contributor

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?

Copy link
Author

@ghost ghost Jul 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do.

buffer->stop();
}

void setPosition(const glm::vec3 position) {
Copy link
Contributor

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)

buffer->setLooping(looping);
}

void setPitch(const float pitch) {
Copy link
Contributor

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.

Sound* sound = nullptr;
auto soundRef = sfx.find(index);

//Let's try reuse buffor
Copy link
Contributor

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)

{45, 413, 80},
{46, 414, 30},
{47, 414, 30},
{48, 415, 30}, /// Marco's Bistro (no sound)
Copy link
Contributor

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.

Copy link
Author

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)

#define _RWENGINE_SFX_PARAMETERS_HPP_

/// Nr of existing sfx sounds
constexpr size_t kNrOfAllSfx = 3032;
Copy link
Contributor

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken from gtamodding.

@ghost
Copy link
Author

ghost commented Jul 27, 2018

Done. ;)

@ghost ghost changed the title Implement methods for sfx, and refactor Sound system [To rebase]Implement methods for sfx, and refactor Sound system Jul 29, 2018
@ghost ghost changed the title [To rebase]Implement methods for sfx, and refactor Sound system Implement methods for sfx, and refactor Sound system Jul 29, 2018
Copy link
Contributor

@Lihis Lihis left a 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.

{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
Copy link
Contributor

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.

auto ref = buffers.find(name);
if (ref != buffers.end()) {
return ref->second;
} else { // Hmm, we should reload this
Copy link
Contributor

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

Sound* sound = nullptr;
auto soundRef = sfx.find(index);

// Let's try reuse buffer
Copy link
Contributor

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.

}
// Hmmm, nothing, we should create new buffer
Copy link
Contributor

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.

#include "audio/SfxParameters.hpp"

/// Game's sound manager.
/// It handles all staff conntected with sounds.
Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary empty line

#include <cstddef>

/// Nr of existing sfx sounds
constexpr size_t kNrOfAllSfx = 3032;
Copy link
Contributor

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?

Copy link
Author

@ghost ghost Aug 1, 2018

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.

Copy link
Contributor

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?)

{34, 405, 30},
{35, 405, 30},
{36, 407 /*-408*/,
30}, /// 407 plays continuously
Copy link
Contributor

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).

{60, 406, 30}, /// Salvatore's place
{61, 406, 80},
{62, 432 /*-434*/,
20}, /// South of Sex Club Seven
Copy link
Contributor

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.

/// and intermittently
{63, 432 /*-434*/, 80},
{64, 435 /*-437*/,
20}, /// East of Portland
Copy link
Contributor

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.

return data.id == scriptId;
});
if (finded != std::end(sfxData)) {
return finded->sfx;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be range.

@ghost
Copy link
Author

ghost commented Aug 5, 2018

Up. :)

}
av_free_packet(&readingPacket);
sound->source = std::make_shared<SoundSource>();
sound->source->loadSfx(path, i);
Copy link
Member

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;
Copy link
Member

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?

Copy link
Author

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.

@ghost
Copy link
Author

ghost commented Aug 6, 2018

Small up. Reusing instance of LoaderSDT and cleanup of headers.

}


sdt.load(path / "audio/sfx");
Copy link
Author

@ghost ghost Aug 6, 2018

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?

Copy link
Author

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);
Copy link
Author

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To do later.

@danhedron
Copy link
Member

@ShFil119 Do you intend to take care of those comments in this PR?

@ghost
Copy link
Author

ghost commented Aug 7, 2018

I'll take care about these features later.

};
} // namespace

int convertScriptIndexIntoSfx(int scriptId) {
Copy link
Member

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).

Copy link
Author

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.

Copy link
Member

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.
@danhedron danhedron merged commit 844fdf8 into rwengine:master Aug 8, 2018
@ghost ghost deleted the soundRefactor branch August 8, 2018 23:20
@ghost ghost mentioned this pull request Aug 11, 2018
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants