123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- /*
- * StreamEncoderRAW.cpp
- * --------------------
- * Purpose: Exporting streamed music files.
- * Notes : none
- * Authors: Joern Heusipp
- * OpenMPT Devs
- * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
- */
- #include "stdafx.h"
- #include "StreamEncoder.h"
- #include "StreamEncoderRAW.h"
- #include "Mptrack.h"
- #include "TrackerSettings.h"
- #include "../common/mptFileIO.h"
- #include "../soundlib/Sndfile.h"
- OPENMPT_NAMESPACE_BEGIN
- class RawStreamWriter : public IAudioStreamEncoder
- {
- private:
- const RAWEncoder &enc;
- std::ostream &f;
- Encoder::Settings settings;
- public:
- RawStreamWriter(const RAWEncoder &enc_, std::ostream &file, const Encoder::Settings &settings_, const FileTags &tags)
- : enc(enc_)
- , f(file)
- , settings(settings_)
- {
- MPT_ASSERT(settings.Format.GetSampleFormat().IsValid());
- MPT_ASSERT(settings.Samplerate > 0);
- MPT_ASSERT(settings.Channels > 0);
- MPT_UNREFERENCED_PARAMETER(tags);
- }
- SampleFormat GetSampleFormat() const override
- {
- return settings.Format.GetSampleFormat();
- }
- void WriteInterleaved(std::size_t frameCount, const double *interleaved) override
- {
- WriteInterleavedBE(f, settings.Channels, settings.Format, frameCount, interleaved);
- }
- void WriteInterleaved(std::size_t frameCount, const float *interleaved) override
- {
- WriteInterleavedBE(f, settings.Channels, settings.Format, frameCount, interleaved);
- }
- void WriteInterleaved(std::size_t frameCount, const int32 *interleaved) override
- {
- WriteInterleavedBE(f, settings.Channels, settings.Format, frameCount, interleaved);
- }
- void WriteInterleaved(std::size_t frameCount, const int24 *interleaved) override
- {
- WriteInterleavedBE(f, settings.Channels, settings.Format, frameCount, interleaved);
- }
- void WriteInterleaved(std::size_t frameCount, const int16 *interleaved) override
- {
- WriteInterleavedBE(f, settings.Channels, settings.Format, frameCount, interleaved);
- }
- void WriteInterleaved(std::size_t frameCount, const int8 *interleaved) override
- {
- WriteInterleavedBE(f, settings.Channels, settings.Format, frameCount, interleaved);
- }
- void WriteInterleaved(std::size_t frameCount, const uint8 *interleaved) override
- {
- WriteInterleavedBE(f, settings.Channels, settings.Format, frameCount, interleaved);
- }
- void WriteCues(const std::vector<uint64> &cues) override
- {
- MPT_UNREFERENCED_PARAMETER(cues);
- }
- void WriteFinalize() override
- {
- // nothing
- }
- virtual ~RawStreamWriter()
- {
- // nothing
- }
- };
- RAWEncoder::RAWEncoder()
- {
- Encoder::Traits traits;
- traits.fileExtension = P_("raw");
- traits.fileShortDescription = U_("Raw PCM");
- traits.fileDescription = U_("Headerless raw little-endian PCM");
- traits.encoderSettingsName = U_("RAW");
- traits.canTags = false;
- traits.canCues = false;
- traits.maxChannels = 4;
- traits.samplerates = TrackerSettings::Instance().GetSampleRates();
- traits.modes = Encoder::ModeLossless;
- traits.formats.push_back({ Encoder::Format::Encoding::Float, 64, mpt::endian::little });
- traits.formats.push_back({ Encoder::Format::Encoding::Float, 64, mpt::endian::big });
- traits.formats.push_back({ Encoder::Format::Encoding::Float, 32, mpt::endian::little });
- traits.formats.push_back({ Encoder::Format::Encoding::Float, 32, mpt::endian::big });
- traits.formats.push_back({ Encoder::Format::Encoding::Integer, 32, mpt::endian::little });
- traits.formats.push_back({ Encoder::Format::Encoding::Integer, 32, mpt::endian::big });
- traits.formats.push_back({ Encoder::Format::Encoding::Integer, 24, mpt::endian::little });
- traits.formats.push_back({ Encoder::Format::Encoding::Integer, 24, mpt::endian::big });
- traits.formats.push_back({ Encoder::Format::Encoding::Integer, 16, mpt::endian::little });
- traits.formats.push_back({ Encoder::Format::Encoding::Integer, 16, mpt::endian::big });
- traits.formats.push_back({ Encoder::Format::Encoding::Integer, 8, mpt::endian::little });
- traits.formats.push_back({ Encoder::Format::Encoding::Unsigned, 8, mpt::endian::little });
- traits.formats.push_back({ Encoder::Format::Encoding::Alaw, 16, mpt::get_endian() });
- traits.formats.push_back({ Encoder::Format::Encoding::ulaw, 16, mpt::get_endian() });
- traits.defaultSamplerate = 48000;
- traits.defaultChannels = 2;
- traits.defaultMode = Encoder::ModeLossless;
- traits.defaultFormat = { Encoder::Format::Encoding::Float, 32, mpt::endian::little };
- SetTraits(traits);
- }
- bool RAWEncoder::IsAvailable() const
- {
- return true;
- }
- std::unique_ptr<IAudioStreamEncoder> RAWEncoder::ConstructStreamEncoder(std::ostream &file, const Encoder::Settings &settings, const FileTags &tags) const
- {
- if(!IsAvailable())
- {
- return nullptr;
- }
- return std::make_unique<RawStreamWriter>(*this, file, settings, tags);
- }
- OPENMPT_NAMESPACE_END
|