AudioFileOgg.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * AudioFileOgg.h - Audio-device which encodes wave-stream and writes it
  3. * into an OGG-file. This is used for song-export.
  4. *
  5. * Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  6. *
  7. * This file is part of LMMS - https://lmms.io
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2 of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public
  20. * License along with this program (see COPYING); if not, write to the
  21. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  22. * Boston, MA 02110-1301 USA.
  23. *
  24. */
  25. #ifndef AUDIO_FILE_OGG_H
  26. #define AUDIO_FILE_OGG_H
  27. #include "lmmsconfig.h"
  28. #ifdef LMMS_HAVE_OGGVORBIS
  29. #include <vorbis/codec.h>
  30. #include "AudioFileDevice.h"
  31. class AudioFileOgg : public AudioFileDevice
  32. {
  33. public:
  34. AudioFileOgg( OutputSettings const & outputSettings,
  35. const ch_cnt_t _channels,
  36. bool & _success_ful,
  37. const QString & _file,
  38. AudioEngine* audioEngine );
  39. virtual ~AudioFileOgg();
  40. static AudioFileDevice * getInst( const QString & outputFilename,
  41. OutputSettings const & outputSettings,
  42. const ch_cnt_t channels,
  43. AudioEngine* audioEngine,
  44. bool & successful )
  45. {
  46. return new AudioFileOgg( outputSettings, channels, successful, outputFilename, audioEngine );
  47. }
  48. private:
  49. virtual void writeBuffer( const surroundSampleFrame * _ab,
  50. const fpp_t _frames,
  51. const float _master_gain ) override;
  52. bool startEncoding();
  53. void finishEncoding();
  54. inline int writePage();
  55. inline bitrate_t nominalBitrate() const
  56. {
  57. return getOutputSettings().getBitRateSettings().getBitRate();
  58. }
  59. inline bitrate_t minBitrate() const
  60. {
  61. if (nominalBitrate() > 64)
  62. {
  63. return nominalBitrate() - 64;
  64. }
  65. else
  66. {
  67. return 64;
  68. }
  69. }
  70. inline bitrate_t maxBitrate() const
  71. {
  72. return nominalBitrate() + 64;
  73. }
  74. private:
  75. bool m_ok;
  76. ch_cnt_t m_channels;
  77. sample_rate_t m_rate;
  78. uint32_t m_serialNo;
  79. vorbis_comment * m_comments;
  80. // encoding setup - init by init_ogg_encoding
  81. ogg_stream_state m_os;
  82. ogg_page m_og;
  83. ogg_packet m_op;
  84. vorbis_dsp_state m_vd;
  85. vorbis_block m_vb;
  86. vorbis_info m_vi;
  87. } ;
  88. #endif
  89. #endif