Skip to content

Commit

Permalink
Add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Laguna1989 committed Dec 18, 2023
1 parent d9b87b1 commit 835e484
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
2 changes: 2 additions & 0 deletions impl/oalpp/sound_context/sound_context_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define OPENALPP_SOUNDCONTEXTINTERFACE_HPP

namespace oalpp {

class SoundContextInterface {
public:
virtual ~SoundContextInterface() = default;
Expand All @@ -16,6 +17,7 @@ class SoundContextInterface {
// allow default construction for derived classes
SoundContextInterface() = default;
};

} // namespace oalpp

#endif // OPENALPP_SOUNDCONTEXTINTERFACE_HPP
4 changes: 4 additions & 0 deletions impl/oalpp/sound_data/sound_data_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ oalpp::SoundData oalpp::SoundDataBuilder::create()
return oalpp::SoundData { m_data, m_sampleRate, m_numberOfChannels };
}

// TODO does not need to be part of builder, extract into free function
#if false
oalpp::SoundDataBuilder& oalpp::SoundDataBuilder::toString(std::string& str)
{
str = "# Sound Data\n";
Expand All @@ -31,6 +33,8 @@ oalpp::SoundDataBuilder& oalpp::SoundDataBuilder::toString(std::string& str)
return *this;
}

#endif

oalpp::SoundDataBuilder& oalpp::SoundDataBuilder::withEffect(
oalpp::effects::MonoEffectInterface& effect)
{
Expand Down
22 changes: 21 additions & 1 deletion impl/oalpp/sound_data/sound_data_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,33 @@ namespace oalpp {

class SoundDataBuilder {
public:
/// create SoundData from the builder
/// \return SoundData object
[[nodiscard]] SoundData create();

/// Load SoundData content from file. This will overwrite any previously stored SoundData
/// \param file path to the file
/// \return SoundDataBuilder object (fluent interface)
[[nodiscard]] SoundDataBuilder& fromFile(std::string const& file);
[[nodiscard]] SoundDataBuilder& toString(std::string& str);

/// Apply an effect to the SoundData
/// \param effect effect to be applied
/// \return SoundDataBuilder object (fluent interface)
[[nodiscard]] SoundDataBuilder& withEffect(oalpp::effects::MonoEffectInterface& effect);

/// Use only the left channel of the SoundData. If this is called on any non-stereo SoundData,
/// an exception is raised.
/// \return SoundDataBuilder object (fluent interface)
[[nodiscard]] SoundDataBuilder& onlyLeftChannel();

/// Use only the right channel of the SoundData. If this is called on any non-stereo SoundData,
/// an exception is raised.
/// \return SoundDataBuilder object (fluent interface)
[[nodiscard]] SoundDataBuilder& onlyRightChannel();

/// Convert a mono SoundData to a stereo SoundData. If this is called on any non-mono
/// SoundData, an exception is raised.
/// \return SoundDataBuilder object (fluent interface)
[[nodiscard]] SoundDataBuilder& toStereo();

private:
Expand Down
16 changes: 13 additions & 3 deletions impl/oalpp/sound_data/sound_data_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,30 @@ namespace oalpp {

class SoundDataInterface {
public:
virtual ~SoundDataInterface() = default;

/// Get number of channels. This will return 1 for mono and 2 for stereo SoundData
/// \return number of channels
virtual int getNumberOfChannels() const = 0;

/// Get sample rate
/// \return sample rate in Hz
virtual int getSampleRate() const = 0;

/// access samples
/// \return reference to const data
virtual std::vector<float> const& getSamples() const = 0;


// virtual destructor, avoid leaking data
virtual ~SoundDataInterface() = default;

// avoid slicing via polymorphic copy or move
SoundDataInterface(SoundDataInterface const& /*other*/) = delete;
SoundDataInterface(SoundDataInterface&& /*other*/) = delete;
SoundDataInterface& operator=(SoundDataInterface const&) = delete;
SoundDataInterface& operator=(SoundDataInterface&&) = delete;

protected:
// allow default construction for derived classes
// allow default construction only for derived classes
SoundDataInterface() = default;
};

Expand Down

0 comments on commit 835e484

Please sign in to comment.