Cog/Frameworks/OpenMPT/OpenMPT/openmpt123/openmpt123_stdout.hpp
Christopher Snowhill da1973bcd9 Build libOpenMPT from source once again
Bundle libOpenMPT as a dynamic framework, which should be safe once
again, now that there is only one version to bundle. Also, now it is
using the versions of libvorbisfile and libmpg123 that are bundled with
the player, instead of compiling minimp3 and stbvorbis.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
2022-06-30 22:56:52 -07:00

49 lines
1.6 KiB
C++

/*
* openmpt123_stdout.hpp
* ---------------------
* Purpose: libopenmpt command line player
* Notes : (currently none)
* Authors: OpenMPT Devs
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
*/
#ifndef OPENMPT123_STDOUT_HPP
#define OPENMPT123_STDOUT_HPP
#include "openmpt123_config.hpp"
#include "openmpt123.hpp"
namespace openmpt123 {
class stdout_stream_raii : public write_buffers_interface {
private:
std::vector<float> interleaved_float_buffer;
std::vector<std::int16_t> interleaved_int_buffer;
public:
stdout_stream_raii() {
return;
}
public:
void write( const std::vector<float*> buffers, std::size_t frames ) override {
interleaved_float_buffer.clear();
for ( std::size_t frame = 0; frame < frames; frame++ ) {
for ( std::size_t channel = 0; channel < buffers.size(); channel++ ) {
interleaved_float_buffer.push_back( buffers[channel][frame] );
}
}
std::cout.write( reinterpret_cast<const char *>( interleaved_float_buffer.data() ), interleaved_float_buffer.size() * sizeof( float ) );
}
void write( const std::vector<std::int16_t*> buffers, std::size_t frames ) override {
interleaved_int_buffer.clear();
for ( std::size_t frame = 0; frame < frames; frame++ ) {
for ( std::size_t channel = 0; channel < buffers.size(); channel++ ) {
interleaved_int_buffer.push_back( buffers[channel][frame] );
}
}
std::cout.write( reinterpret_cast<const char *>( interleaved_int_buffer.data() ), interleaved_int_buffer.size() * sizeof( std::int16_t ) );
}
};
} // namespace openmpt123
#endif // OPENMPT123_STDOUT_HPP