libSDL2pp/SDL2pp/Wav.hh
2014-12-17 18:37:36 +03:00

141 lines
4.2 KiB
C++

/*
libSDL2pp - C++ wrapper for libSDL2
Copyright (C) 2014 Dmitry Marakasov <amdmi3@amdmi3.ru>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#ifndef SDL2PP_WAV_HH
#define SDL2PP_WAV_HH
#include <SDL2pp/Audio.hh>
namespace SDL2pp {
class RWops;
////////////////////////////////////////////////////////////
/// \brief Chunk of audio data read from a .WAV file
///
/// \headerfile SDL2pp/Wav.hh
///
////////////////////////////////////////////////////////////
class Wav {
private:
Uint8* audio_buffer_; ///< Raw audio data
Uint32 audio_length_; ///< Raw audio data length in bytes
AudioSpec spec_; ///< Description of audio data format
public:
////////////////////////////////////////////////////////////
/// \brief Load audio from file on disk
///
/// \param file Path to the wav file
///
////////////////////////////////////////////////////////////
Wav(const std::string& file);
////////////////////////////////////////////////////////////
/// \brief Load audio using RWops
///
/// \param rwops SDL2pp::RWops used to access wav data
///
////////////////////////////////////////////////////////////
Wav(RWops& rwops);
////////////////////////////////////////////////////////////
/// \brief Destructor
///
////////////////////////////////////////////////////////////
~Wav();
////////////////////////////////////////////////////////////
/// \brief Move constructor
///
/// \param other SDL2pp::Wav object to move data from
///
////////////////////////////////////////////////////////////
Wav(Wav&& other);
////////////////////////////////////////////////////////////
/// \brief Move assignment operator
///
/// \param other SDL2pp::Wav object to move data from
///
/// \returns Reference to self
///
////////////////////////////////////////////////////////////
Wav& operator=(Wav&& other);
// Deleted copy constructor and assignment
Wav(const Wav& other) = delete;
Wav& operator=(const Wav& other) = delete;
////////////////////////////////////////////////////////////
/// \brief Get length of audio data
///
/// \returns Length of audio data in bytes
///
////////////////////////////////////////////////////////////
Uint32 GetLength() const;
////////////////////////////////////////////////////////////
/// \brief Get pointer to raw audio data
///
/// \returns Pointer to raw audio data
///
////////////////////////////////////////////////////////////
Uint8* GetBuffer();
////////////////////////////////////////////////////////////
/// \brief Get constant pointer to raw audio data
///
/// \returns Constant pointer to raw audio data
///
////////////////////////////////////////////////////////////
const Uint8* GetBuffer() const;
////////////////////////////////////////////////////////////
/// \brief Get descriptor of audio format
///
/// \returns SDL2pp::AudioSpec describing format of audio data
///
////////////////////////////////////////////////////////////
const AudioSpec& GetSpec() const;
};
}
#endif
////////////////////////////////////////////////////////////
/// \class SDL2pp::Wav
/// \ingroup Audio
///
/// SDL2pp::Wav is a wrapper around basic SDL2 audio fragment
/// handling functionality, basically SDL_LoadWAV and related
/// functions.
///
/// The class holds raw audio data which is loaded from a disk
/// file or from an arbitrary source with SDL2pp::RWops and
/// may be used in audio playback.
///
/// See audio_wav demo for an example.
///
////////////////////////////////////////////////////////////