Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.83 KB | None | 0 0
  1. #define _WIN32_WINNT 0x0501
  2. #include <foobar2000.h>
  3.  
  4. #include "../helpers/dropdown_helper.h"
  5. #include "../ATLHelpers/ATLHelpers.h"
  6.  
  7. #include "fclib/fc14audiodecoder.h"
  8. #include "fclib/FC.h"
  9. #include "fclib/LamePaula.h"
  10.  
  11.  
  12.  
  13. static const char * extensions[]=
  14. {
  15. // hope kode54 wont mind :3
  16. "fc", "fc13", "fc14"
  17. };
  18.  
  19. static bool g_test_extension(const char * ext)
  20. {
  21. int n;
  22. for(n=0;n<3;n++)
  23. {
  24. if (!stricmp(ext,extensions[n])) return true;
  25. }
  26. return false;
  27. }
  28.  
  29. class input_fc
  30. {
  31. FC fc_decoder;
  32. LamePaulaMixer fc_mixer;
  33. t_filestats m_stats;
  34. long length;
  35. int is_playing;
  36. bool first_block,loop;
  37. pfc::array_t< t_int16 > sample_buffer;
  38. pfc::array_t< t_uint8 > file_buffer;
  39. public:
  40. input_fc()
  41. {
  42.  
  43. }
  44.  
  45. ~input_fc()
  46. {
  47.  
  48. }
  49.  
  50. void open( service_ptr_t<file> m_file, const char * p_path, t_input_open_reason p_reason, abort_callback & p_abort )
  51. {
  52. if ( p_reason == input_open_info_write ) throw exception_io_data();
  53. input_open_file_helper( m_file, p_path, p_reason, p_abort );
  54. m_stats = m_file->get_stats( p_abort );
  55. t_uint8 * ptr;
  56. unsigned size;
  57. t_filesize size64 = m_file->get_size_ex( p_abort );
  58. if ( size64 > ( 1 << 24 ) )
  59. throw exception_io_data();
  60. size = (unsigned) size64;
  61. file_buffer.set_size( size );
  62. ptr = file_buffer.get_ptr();
  63. m_file->read_object( ptr, size, p_abort );
  64.  
  65. fc_decoder.setMixer(&fc_mixer);
  66. bool moo = fc_decoder.init(ptr,size);
  67. if ( !moo ) throw exception_io_data();
  68. }
  69.  
  70. void get_info( file_info & p_info, abort_callback & p_abort )
  71. {
  72. FC meow_decoder;
  73. LamePaulaMixer meow_mixer;
  74. meow_decoder.setMixer(&meow_mixer);
  75. meow_decoder.init(file_buffer.get_ptr(), file_buffer.get_size());
  76. p_info.info_set( "encoding", "synthesized" );
  77. p_info.info_set( "codec", pfc::stringcvt::string_utf8_from_ansi( meow_decoder.formatName.c_str() ) );
  78. p_info.info_set_int( "channels", 2 );
  79. unsigned long int ms = 0;
  80. do {
  81. meow_decoder.run();
  82. ms += 20;
  83. } while ( !meow_decoder.songEnd );
  84. meow_decoder.restart();
  85. ms /= 1000;
  86. p_info.set_length(ms);
  87. }
  88.  
  89. t_filestats get_file_stats( abort_callback & p_abort )
  90. {
  91. return m_stats;
  92. }
  93.  
  94. void decode_initialize( unsigned p_flags, abort_callback & p_abort )
  95. {
  96. fc_mixer.init(44100,16,2,0x0000);
  97. first_block = true;
  98. is_playing = 1;
  99. loop = false;
  100. }
  101.  
  102. bool decode_run( audio_chunk & p_chunk, abort_callback & p_abort )
  103. {
  104. if (!loop && fc_decoder.songEnd) return false;
  105. int nbSample = 512*(16/8)*2;
  106. sample_buffer.grow_size( nbSample );
  107. fc_mixer.fillBuffer(sample_buffer.get_ptr(), nbSample,&fc_decoder);
  108. p_chunk.set_data_fixedpoint( sample_buffer.get_ptr(), nbSample, 44100, 2,16, audio_chunk::channel_config_stereo );
  109. return true;
  110. }
  111.  
  112. void decode_seek( double p_seconds,abort_callback & p_abort )
  113. {
  114. long seek_ms = audio_math::time_to_samples( p_seconds, 1000 );
  115. fc_decoder.restart();
  116. while (seek_ms>=0) {
  117. fc_decoder.run();
  118. seek_ms -= 20;
  119. if ( fc_decoder.songEnd ) {
  120. break;
  121. }
  122. };
  123. first_block = true;
  124. }
  125.  
  126. bool decode_can_seek()
  127. {
  128. return true;
  129. }
  130.  
  131. bool decode_get_dynamic_info( file_info & p_out, double & p_timestamp_delta )
  132. {
  133. if ( first_block )
  134. {
  135. first_block = false;
  136. p_out.info_set_int( "samplerate", 44100 );
  137. return true;
  138. }
  139. return false;
  140. }
  141.  
  142. bool decode_get_dynamic_info_track( file_info & p_out, double & p_timestamp_delta )
  143. {
  144. return false;
  145. }
  146.  
  147. void decode_on_idle( abort_callback & p_abort ) { }
  148.  
  149. void retag( const file_info & p_info, abort_callback & p_abort )
  150. {
  151. throw exception_io_data();
  152. }
  153.  
  154. static bool g_is_our_content_type( const char * p_content_type )
  155. {
  156. return false;
  157. }
  158.  
  159. static bool g_is_our_path( const char * p_path, const char * p_extension )
  160. {
  161. return g_test_extension( p_extension );
  162. }
  163.  
  164. };
  165.  
  166. class mod_file_types : public input_file_type
  167. {
  168. virtual unsigned get_count()
  169. {
  170. return 1;
  171. }
  172.  
  173. virtual bool get_name(unsigned idx, pfc::string_base & out)
  174. {
  175. if (idx > 0) return false;
  176. out = "Module files";
  177. return true;
  178. }
  179.  
  180. virtual bool get_mask(unsigned idx, pfc::string_base & out)
  181. {
  182. if (idx > 0) return false;
  183. out.reset();
  184. for (int n = 0; n < 3; n++)
  185. {
  186. if (n) out.add_byte(';');
  187. out << "*." << extensions[n];
  188. }
  189. return true;
  190. }
  191.  
  192. virtual bool is_associatable(unsigned idx)
  193. {
  194. return true;
  195. }
  196. };
  197.  
  198.  
  199. static input_singletrack_factory_t< input_fc > g_input_factory_modplug;
  200. static service_factory_single_t <mod_file_types> g_input_file_type_hvl_factory;
  201.  
  202. #define MYVERSION "0.1"
  203.  
  204. DECLARE_COMPONENT_VERSION("Future Composer Decoder",
  205. MYVERSION,
  206. pfc::stringcvt::string_utf8_from_os(L"A Future Composer module player for foobar2000 1.1 ->\nWritten by mudlord\n Decoding code by Jochen Hippel"));
  207. VALIDATE_COMPONENT_FILENAME("foo_input_fc.dll");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement