1
0

StreamEncoderRAW.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * StreamEncoderRAW.cpp
  3. * --------------------
  4. * Purpose: Exporting streamed music files.
  5. * Notes : none
  6. * Authors: Joern Heusipp
  7. * OpenMPT Devs
  8. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  9. */
  10. #include "stdafx.h"
  11. #include "StreamEncoder.h"
  12. #include "StreamEncoderRAW.h"
  13. #include "Mptrack.h"
  14. #include "TrackerSettings.h"
  15. #include "../common/mptFileIO.h"
  16. #include "../soundlib/Sndfile.h"
  17. OPENMPT_NAMESPACE_BEGIN
  18. class RawStreamWriter : public IAudioStreamEncoder
  19. {
  20. private:
  21. const RAWEncoder &enc;
  22. std::ostream &f;
  23. Encoder::Settings settings;
  24. public:
  25. RawStreamWriter(const RAWEncoder &enc_, std::ostream &file, const Encoder::Settings &settings_, const FileTags &tags)
  26. : enc(enc_)
  27. , f(file)
  28. , settings(settings_)
  29. {
  30. MPT_ASSERT(settings.Format.GetSampleFormat().IsValid());
  31. MPT_ASSERT(settings.Samplerate > 0);
  32. MPT_ASSERT(settings.Channels > 0);
  33. MPT_UNREFERENCED_PARAMETER(tags);
  34. }
  35. SampleFormat GetSampleFormat() const override
  36. {
  37. return settings.Format.GetSampleFormat();
  38. }
  39. void WriteInterleaved(std::size_t frameCount, const double *interleaved) override
  40. {
  41. WriteInterleavedBE(f, settings.Channels, settings.Format, frameCount, interleaved);
  42. }
  43. void WriteInterleaved(std::size_t frameCount, const float *interleaved) override
  44. {
  45. WriteInterleavedBE(f, settings.Channels, settings.Format, frameCount, interleaved);
  46. }
  47. void WriteInterleaved(std::size_t frameCount, const int32 *interleaved) override
  48. {
  49. WriteInterleavedBE(f, settings.Channels, settings.Format, frameCount, interleaved);
  50. }
  51. void WriteInterleaved(std::size_t frameCount, const int24 *interleaved) override
  52. {
  53. WriteInterleavedBE(f, settings.Channels, settings.Format, frameCount, interleaved);
  54. }
  55. void WriteInterleaved(std::size_t frameCount, const int16 *interleaved) override
  56. {
  57. WriteInterleavedBE(f, settings.Channels, settings.Format, frameCount, interleaved);
  58. }
  59. void WriteInterleaved(std::size_t frameCount, const int8 *interleaved) override
  60. {
  61. WriteInterleavedBE(f, settings.Channels, settings.Format, frameCount, interleaved);
  62. }
  63. void WriteInterleaved(std::size_t frameCount, const uint8 *interleaved) override
  64. {
  65. WriteInterleavedBE(f, settings.Channels, settings.Format, frameCount, interleaved);
  66. }
  67. void WriteCues(const std::vector<uint64> &cues) override
  68. {
  69. MPT_UNREFERENCED_PARAMETER(cues);
  70. }
  71. void WriteFinalize() override
  72. {
  73. // nothing
  74. }
  75. virtual ~RawStreamWriter()
  76. {
  77. // nothing
  78. }
  79. };
  80. RAWEncoder::RAWEncoder()
  81. {
  82. Encoder::Traits traits;
  83. traits.fileExtension = P_("raw");
  84. traits.fileShortDescription = U_("Raw PCM");
  85. traits.fileDescription = U_("Headerless raw little-endian PCM");
  86. traits.encoderSettingsName = U_("RAW");
  87. traits.canTags = false;
  88. traits.canCues = false;
  89. traits.maxChannels = 4;
  90. traits.samplerates = TrackerSettings::Instance().GetSampleRates();
  91. traits.modes = Encoder::ModeLossless;
  92. traits.formats.push_back({ Encoder::Format::Encoding::Float, 64, mpt::endian::little });
  93. traits.formats.push_back({ Encoder::Format::Encoding::Float, 64, mpt::endian::big });
  94. traits.formats.push_back({ Encoder::Format::Encoding::Float, 32, mpt::endian::little });
  95. traits.formats.push_back({ Encoder::Format::Encoding::Float, 32, mpt::endian::big });
  96. traits.formats.push_back({ Encoder::Format::Encoding::Integer, 32, mpt::endian::little });
  97. traits.formats.push_back({ Encoder::Format::Encoding::Integer, 32, mpt::endian::big });
  98. traits.formats.push_back({ Encoder::Format::Encoding::Integer, 24, mpt::endian::little });
  99. traits.formats.push_back({ Encoder::Format::Encoding::Integer, 24, mpt::endian::big });
  100. traits.formats.push_back({ Encoder::Format::Encoding::Integer, 16, mpt::endian::little });
  101. traits.formats.push_back({ Encoder::Format::Encoding::Integer, 16, mpt::endian::big });
  102. traits.formats.push_back({ Encoder::Format::Encoding::Integer, 8, mpt::endian::little });
  103. traits.formats.push_back({ Encoder::Format::Encoding::Unsigned, 8, mpt::endian::little });
  104. traits.formats.push_back({ Encoder::Format::Encoding::Alaw, 16, mpt::get_endian() });
  105. traits.formats.push_back({ Encoder::Format::Encoding::ulaw, 16, mpt::get_endian() });
  106. traits.defaultSamplerate = 48000;
  107. traits.defaultChannels = 2;
  108. traits.defaultMode = Encoder::ModeLossless;
  109. traits.defaultFormat = { Encoder::Format::Encoding::Float, 32, mpt::endian::little };
  110. SetTraits(traits);
  111. }
  112. bool RAWEncoder::IsAvailable() const
  113. {
  114. return true;
  115. }
  116. std::unique_ptr<IAudioStreamEncoder> RAWEncoder::ConstructStreamEncoder(std::ostream &file, const Encoder::Settings &settings, const FileTags &tags) const
  117. {
  118. if(!IsAvailable())
  119. {
  120. return nullptr;
  121. }
  122. return std::make_unique<RawStreamWriter>(*this, file, settings, tags);
  123. }
  124. OPENMPT_NAMESPACE_END