diff --git a/testspr/test.sh b/testspr/test.sh index db9b89c5..dd7eb7a5 100755 --- a/testspr/test.sh +++ b/testspr/test.sh @@ -11,6 +11,8 @@ gcc_version="4.7.0 4.7.1 4.7.2 4.7.3 4.8.0 4.8.1" clang_version="3.2 3.3" declare -a user_macros user_macros=() +declare -a include_paths +include_paths=() force=0 declare -A version_specific_options version_specific_options=( @@ -36,9 +38,9 @@ execute() { fi } -args=`getopt -o S:D:f -l stagedir:,gcc-version:,clang-version:,define:,force -- "$@"` +args=`getopt -o S:D:I:f -l stagedir:,gcc-version:,clang-version:,define:,include:,force -- "$@"` if [ "$?" -ne 0 ]; then - echo >&2 -e ": \e[31musage: $0 [-S|--stagedir=path] [--gcc-version=versions] [--clang-version=versions] [-D|--define=identifier]* [-f|-force]\e[m" + echo >&2 -e ": \e[31musage: $0 [-S|--stagedir=path] [--gcc-version=versions] [--clang-version=versions] [-D|--define=identifier]* [-I|--include=path]* [-f|-force]\e[m" exit 1 fi eval set -- ${args} @@ -48,6 +50,7 @@ while [ -n "$1" ]; do --gcc-version) gcc_version="$2"; shift 2;; --clang-version) clang_version="$2"; shift 2;; -D|--define) user_macros=(${user_macros[@]} "$2"); shift 2;; + -I|--include) include_paths=(${include_paths[@]} "$2"); shift 2;; -f|--force) force=1; shift;; --) shift; break;; *) echo >&2 -e ": \e[31munknown option($1) used.\e[m"; exit 1;; @@ -58,6 +61,7 @@ echo ": stagedir = \"${stagedir}\"" echo ": gcc-version = (${gcc_version})" echo ": clang-version = (${clang_version})" echo ": user-macros = (${user_macros[*]})" +echo ": include-paths = (${include_paths[*]})" echo ": force = ${force}" if [ -d "${stagedir}" ]; then @@ -75,12 +79,16 @@ for user_macro in ${user_macros}; do define_options="${define_options} -D${user_macro}" done +for include_path in ${include_paths}; do + include_options="${include_options} -I${include_path}" +done + for version in ${gcc_version}; do - compile gcc ${version} $(cd $(dirname $0); pwd)/sprout.cpp "${define_options} ${version_specific_options[gcc-${version}]}" + compile gcc ${version} $(cd $(dirname $0); pwd)/sprout.cpp "${define_options} ${include_options} ${version_specific_options[gcc-${version}]}" done for version in ${clang_version}; do - compile clang ${version} $(cd $(dirname $0); pwd)/sprout.cpp "${define_options} ${version_specific_options[clang-${version}]}" + compile clang ${version} $(cd $(dirname $0); pwd)/sprout.cpp "${define_options} ${include_options} ${version_specific_options[clang-${version}]}" done for version in ${gcc_version}; do diff --git a/tools/compost/wavconv.cpp b/tools/compost/wavconv.cpp index d54ca12c..d47636ea 100644 --- a/tools/compost/wavconv.cpp +++ b/tools/compost/wavconv.cpp @@ -15,23 +15,25 @@ #include #include -template -std::string read_chunk(InputIterator& it) { - std::string s; - for (std::size_t i = 0; i != N; ++i, ++it) { - s.push_back(*it); +namespace toolspr { + template + std::string read_chunk(InputIterator& it) { + std::string s; + for (std::size_t i = 0; i != N; ++i, ++it) { + s.push_back(*it); + } + return s; } - return s; -} -template -IntType read_int(InputIterator& it) { - IntType n = 0; - for (std::size_t i = 0; i != sizeof(IntType); ++i, ++it) { - n |= static_cast(static_cast(*it)) << (i * CHAR_BIT); + template + IntType read_int(InputIterator& it) { + IntType n = 0; + for (std::size_t i = 0; i != sizeof(IntType); ++i, ++it) { + n |= static_cast(static_cast(*it)) << (i * CHAR_BIT); + } + return n; } - return n; -} +} // namespace toolspr int main(int argc, char* argv[]) { if (argc < 2) { @@ -54,15 +56,15 @@ int main(int argc, char* argv[]) { "\n" ; - if (read_chunk(it) != "RIFF") { + if (toolspr::read_chunk(it) != "RIFF") { std::cerr << "#error not RIFF file.\n" << std::flush ; return EXIT_FAILURE; } - /*auto file_size = */read_int(it); - if (read_chunk(it) != "WAVE") { + /*auto file_size = */toolspr::read_int(it); + if (toolspr::read_chunk(it) != "WAVE") { std::cerr << "#error not WAVE format.\n" << std::flush @@ -70,17 +72,17 @@ int main(int argc, char* argv[]) { return EXIT_FAILURE; } - while (read_chunk(it) != "fmt ") { - auto chunk_size = read_int(it); + while (toolspr::read_chunk(it) != "fmt ") { + auto chunk_size = toolspr::read_int(it); std::advance(it, chunk_size); } - auto fmt_size = read_int(it); - auto format_tag = read_int(it); - auto channels = read_int(it); - auto samples_per_sec = read_int(it); - auto bytes_per_sec = read_int(it); - auto block_size = read_int(it); - auto bits_per_sample = read_int(it); + auto fmt_size = toolspr::read_int(it); + auto format_tag = toolspr::read_int(it); + auto channels = toolspr::read_int(it); + auto samples_per_sec = toolspr::read_int(it); + auto bytes_per_sec = toolspr::read_int(it); + auto block_size = toolspr::read_int(it); + auto bits_per_sample = toolspr::read_int(it); std::cout << format_tag << ",\n" << channels << ",\n" @@ -91,11 +93,11 @@ int main(int argc, char* argv[]) { ; std::advance(it, fmt_size - 16); - while (read_chunk(it) != "data") { - auto chunk_size = read_int(it); + while (toolspr::read_chunk(it) != "data") { + auto chunk_size = toolspr::read_int(it); std::advance(it, chunk_size); } - auto data_size = read_int(it); + auto data_size = toolspr::read_int(it); std::size_t size = data_size / (bits_per_sample / CHAR_BIT); std::cout << size << "\n" @@ -107,20 +109,20 @@ int main(int argc, char* argv[]) { if (bits_per_sample == 16) { for (std::size_t i = 1; i != size; ++i) { std::cout - << read_int(it) << ",\n" + << toolspr::read_int(it) << ",\n" ; } std::cout - << read_int(it) << "\n" + << toolspr::read_int(it) << "\n" ; } else if (bits_per_sample == 8) { for (std::size_t i = 1; i != size; ++i) { std::cout - << read_int(it) << ",\n" + << toolspr::read_int(it) << ",\n" ; } std::cout - << read_int(it) << "\n" + << toolspr::read_int(it) << "\n" ; } } @@ -131,4 +133,3 @@ int main(int argc, char* argv[]) { << std::flush ; } - diff --git a/tools/compost/wave_io.hpp b/tools/compost/wave_io.hpp new file mode 100644 index 00000000..c8cc611f --- /dev/null +++ b/tools/compost/wave_io.hpp @@ -0,0 +1,176 @@ +/*============================================================================= + Copyright (c) 2011-2013 Bolero MURAKAMI + 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) +=============================================================================*/ +#ifndef TOOLS_COMPOST_WAVE_IO_HPP +#define TOOLS_COMPOST_WAVE_IO_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace toolspr { + // + // output_plot + // + // output for gnuplot + // + template + std::basic_ostream& output_plot(std::basic_ostream& os, InputRange const& range) { + os << std::fixed; + unsigned x = 0; + for (auto const& e : range) { + os << x++ << ',' << e << '\n'; + } + return os; + } + template + std::basic_ostream& output_plot(std::string const& filename, InputRange const& range) { + std::ofstream os(filename); + output_plot(os, range); + } + + // + // output_plot_real + // + // output for gnuplot (only real part) + // + template + std::basic_ostream& output_plot_real(std::basic_ostream& os, InputRange const& range) { + os << std::fixed; + unsigned x = 0; + for (auto const& e : range) { + os << x++ << ',' << real(e) << '\n'; + } + return os; + } + template + std::basic_ostream& output_plot_real(std::string const& filename, InputRange const& range) { + std::ofstream os(filename); + output_plot_real(os, range); + } + + // + // write_chunk + // write_int + // write_wav + // + // write data for wav format + // + template + void write_chunk(OutputIterator& it, std::string const& s) { + it = std::copy(s.begin(), s.end(), it); + } + template + void write_int(OutputIterator& it, IntType const& n) { + for (std::size_t i = 0; i != sizeof(IntType); ++i, ++it) { + *it = static_cast((static_cast::type>(n) >> (i * CHAR_BIT)) & 0xFF); + } + } + template + void write_wav(OutputIterator& it, sprout::compost::sources::info_type const& info, InputRange const& data) { + std::size_t data_size = info.size * info.bits_per_sample / CHAR_BIT; + + write_chunk(it, "RIFF"); + write_int(it, 36 + data_size); + write_chunk(it, "WAVE"); + write_chunk(it, "fmt "); + write_int(it, 16); + write_int(it, info.format_tag); + write_int(it, info.channels); + write_int(it, info.samples_per_sec); + write_int(it, info.bytes_per_sec); + write_int(it, info.block_size); + write_int(it, info.bits_per_sample); + write_chunk(it, "data"); + write_int(it, data_size); + if (info.bits_per_sample == 16) { + for (auto e : data) { + write_int(it, e); + } + } else if (info.bits_per_sample == 8) { + for (auto e : data) { + write_int(it, e); + } + } + } + + // + // output_wav + // + // output for wav format + // + template + void output_wav(std::basic_ostream& os, sprout::compost::sources::info_type const& info, InputRange const& data) { + std::ostreambuf_iterator it(os); + write_wav(it, info, data); + } + template + void output_wav(std::string const& filename, sprout::compost::sources::info_type const& info, InputRange const& data) { + std::ofstream os(filename, std::ios_base::out | std::ios_base::binary); + output_wav(os, info, data); + } + + // + // setup_dev_dsp + // + // Setting up dsp device + // + int setup_dev_dsp(sprout::compost::sources::info_type const& info) { + /* open of dsp device */ + int fd = open("/dev/dsp", O_RDWR); + if (fd < 0) { + std::cerr << "open of /dev/dsp failed" << std::endl; + return -1; + } + + /* initializations of dsp device */ + int arg = 0; + int status = 0; + /* sampling bit rate */ + arg = info.bits_per_sample; + status = ioctl(fd, SOUND_PCM_WRITE_BITS, &arg); + if (status == -1 || arg != info.bits_per_sample) { + return -1; + } + /* stereo or monoral */ + arg = info.channels; + status = ioctl(fd, SOUND_PCM_WRITE_CHANNELS, &arg); + if (status == -1 || arg != info.channels) { + return -1; + } + /* sampling frequency */ + arg = info.samples_per_sec; + status = ioctl(fd, SOUND_PCM_WRITE_RATE, &arg); + if (status == -1 || arg != static_cast(info.samples_per_sec)) { + return -1; + } + + return fd; + } + + // + // write_dev_dsp + // + // write to dsp device + // + ssize_t write_dev_dsp(int fd, void const* buf, std::size_t n) { + return write(fd, buf, n); + } +} // namespace toolspr + +#endif // #ifndef TOOLS_COMPOST_WAVE_IO_HPP diff --git a/tools/darkroom/darkcult.sh b/tools/darkroom/darkcult.sh index 2b05dbff..263b9fd8 100755 --- a/tools/darkroom/darkcult.sh +++ b/tools/darkroom/darkcult.sh @@ -7,7 +7,7 @@ # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) # ============================================================================= # -# requires: ImageMagick (http://www.imagemagick.org/script/index.php) +# requires: Netpbm (http://netpbm.sourceforge.net/) # src="../../example/darkroom/two_spheres.hpp" stagedir="darkroom" @@ -15,11 +15,13 @@ width=16 height=16 tile_width=16 tile_height=16 +declare -a include_paths +include_paths=() force=0 -args=`getopt -o s:S:w:h:W:H:f -l source:,stagedir:,width:,height:,tile-width:,tile-height:,force -- "$@"` +args=`getopt -o s:S:w:h:W:H:I:f -l source:,stagedir:,width:,height:,tile-width:,tile-height:,include:,force -- "$@"` if [ "$?" -ne 0 ]; then - echo >&2 -e ": \e[31musage: $0 [-s|--source=file] [-S|--stagedir=path] [-w|--width=value] [-h|--height=value] [-W|--tile-width=value] [-H|--tile-height=value] [-f|-force]\e[m" + echo >&2 -e ": \e[31musage: $0 [-s|--source=file] [-S|--stagedir=path] [-w|--width=value] [-h|--height=value] [-W|--tile-width=value] [-H|--tile-height=value] [-I|--include=path]* [-f|-force]\e[m" exit 1 fi eval set -- ${args} @@ -31,6 +33,7 @@ while [ -n "$1" ]; do -h|--height) height=$2; shift 2;; -W|--tile-width) tile_width=$2; shift 2;; -H|--tile-height) tile_height=$2; shift 2;; + -I|--include) include_paths=(${include_paths[@]} "$2"); shift 2;; -f|--force) force=1; shift;; --) shift; break;; *) echo >&2 -e ": \e[31munknown option($1) used.\e[m"; exit 1;; @@ -44,6 +47,7 @@ echo ": width = ${width}" echo ": height = ${height}" echo ": tile-width = ${tile_width}" echo ": tile-height = ${tile_height}" +echo ": include-paths = (${include_paths[*]})" echo ": force = ${force}" if [ ! -f "${src}" -a ! -f "$(cd $(dirname $0); pwd)/${src}" ]; then @@ -62,6 +66,10 @@ else mkdir -p ${stagedir} fi +for include_path in ${include_paths}; do + include_options="${include_options} -I${include_path}" +done + echo ": start." start=${SECONDS} @@ -73,6 +81,7 @@ for ((y=0; y ${stagedir}/${y}/${x}.ppm -# rm ${binname} done pushd ${stagedir}/${y}/ > /dev/null - convert +append $(ls *.ppm | sort -n) ../${y}.ppm +# convert +append $(ls *.ppm | sort -n) ../${y}.ppm + pnmcat -lr $(ls *.ppm | sort -n) > ../${y}.ppm popd > /dev/null let "y_elapsed=${SECONDS}-${y_start}" echo ": elapsed = ${y_elapsed}s" done pushd ${stagedir} > /dev/null -convert -append $(ls *.ppm | sort -n) out.ppm +#convert -append $(ls *.ppm | sort -n) out.ppm +pnmcat -tb $(ls *.ppm | sort -n) > out.ppm popd > /dev/null let "elapsed=${SECONDS}-${start}" diff --git a/tools/darkroom/texconv.cpp b/tools/darkroom/texconv.cpp index ce2e7f17..5a07d014 100644 --- a/tools/darkroom/texconv.cpp +++ b/tools/darkroom/texconv.cpp @@ -69,4 +69,3 @@ int main(int argc, char* argv[]) { << std::flush ; } -