2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
2016-02-25 09:48:28 +00:00
|
|
|
Copyright (c) 2011-2016 Bolero MURAKAMI
|
2013-08-08 09:54:33 +00:00
|
|
|
https://github.com/bolero-MURAKAMI/Sprout
|
|
|
|
|
|
|
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
=============================================================================*/
|
2012-11-08 16:09:49 +00:00
|
|
|
#ifndef SPROUT_COMPOST_SOURCES_SOURCE_HPP
|
|
|
|
#define SPROUT_COMPOST_SOURCES_SOURCE_HPP
|
|
|
|
|
|
|
|
#include <sprout/config.hpp>
|
2014-04-30 07:30:26 +00:00
|
|
|
#include <sprout/workaround/std/cstddef.hpp>
|
2013-02-07 14:12:57 +00:00
|
|
|
#include <sprout/array/array.hpp>
|
2012-11-08 16:09:49 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// COMPOST_LOAD_SOURCE
|
|
|
|
//
|
|
|
|
#define COMPOST_LOAD_SOURCE <sprout/compost/load/source.hpp>
|
|
|
|
|
|
|
|
//
|
|
|
|
// COMPOST_SRC_VERSION
|
|
|
|
//
|
|
|
|
#define COMPOST_SRC_VERSION(NUM) NUM
|
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace compost {
|
|
|
|
namespace sources {
|
|
|
|
//
|
|
|
|
// version_type
|
|
|
|
//
|
|
|
|
typedef unsigned long version_type;
|
|
|
|
//
|
|
|
|
// info_type
|
|
|
|
//
|
|
|
|
struct info_type {
|
|
|
|
public:
|
2016-04-05 09:21:13 +00:00
|
|
|
std::uint16_t format_tag; // format ID
|
|
|
|
std::uint16_t channels; // channels
|
|
|
|
std::uint32_t samples_per_sec; // sampling rate
|
|
|
|
std::uint32_t bytes_per_sec; // data speed (Byte/sec)
|
|
|
|
std::uint16_t block_size; // block size (Byte/sample*channels)
|
|
|
|
std::uint16_t bits_per_sample; // bits per sample (bit/sample)
|
|
|
|
std::size_t size; // elements
|
2012-11-08 16:09:49 +00:00
|
|
|
};
|
|
|
|
//
|
|
|
|
// sound_type
|
|
|
|
//
|
|
|
|
template<std::size_t Size, typename Elem = double>
|
|
|
|
struct sound_type {
|
|
|
|
public:
|
|
|
|
typedef Elem element_type;
|
|
|
|
typedef element_type value_type;
|
|
|
|
typedef std::size_t size_type;
|
|
|
|
SPROUT_STATIC_CONSTEXPR size_type static_size = Size;
|
|
|
|
typedef sprout::array<value_type, static_size> elements_type;
|
|
|
|
private:
|
|
|
|
elements_type elements_;
|
|
|
|
public:
|
|
|
|
template<typename... Elems>
|
|
|
|
SPROUT_CONSTEXPR sound_type(info_type const& info, Elems const&... elems)
|
|
|
|
: elements_{{
|
2012-11-24 06:57:50 +00:00
|
|
|
(info.bits_per_sample == 8 ? elems / static_cast<value_type>(0x80) - 1
|
|
|
|
: elems / static_cast<value_type>(0x8000)
|
|
|
|
)...
|
2012-11-08 16:09:49 +00:00
|
|
|
}}
|
|
|
|
{
|
|
|
|
static_assert(sizeof...(Elems) == static_size, "sound_type<>: unmatch source size");
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR value_type const&
|
|
|
|
operator()(size_type x) const {
|
|
|
|
return elements_[x];
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR size_type
|
|
|
|
size() const {
|
|
|
|
return static_size;
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR elements_type const&
|
|
|
|
elements() const {
|
|
|
|
return elements_;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
template<std::size_t Size, typename Elem>
|
|
|
|
SPROUT_CONSTEXPR_OR_CONST typename sprout::compost::sources::sound_type<Size, Elem>::size_type
|
|
|
|
sprout::compost::sources::sound_type<Size, Elem>::static_size;
|
|
|
|
} // namespace sources
|
|
|
|
} // namespace compost
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_COMPOST_SOURCES_SOURCE_HPP
|