encoders.c
上传用户:wstnjxml
上传日期:2014-04-03
资源大小:7248k
文件大小:45k
源码类别:

Windows CE

开发平台:

C/C++

  1. /* test_libOggFLAC - Unit tester for libOggFLAC
  2.  * Copyright (C) 2002,2003,2004,2005  Josh Coalson
  3.  *
  4.  * This program is free software; you can redistribute it and/or
  5.  * modify it under the terms of the GNU General Public License
  6.  * as published by the Free Software Foundation; either version 2
  7.  * of the License, or (at your option) any later version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, write to the Free Software
  16.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  17.  */
  18. #include "encoders.h"
  19. #include "file_utils.h"
  20. #include "metadata_utils.h"
  21. #include "FLAC/assert.h"
  22. #include "OggFLAC/file_encoder.h"
  23. #include "OggFLAC/seekable_stream_encoder.h"
  24. #include "OggFLAC/stream_encoder.h"
  25. #include "share/grabbag.h"
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. static FLAC__StreamMetadata streaminfo_, padding_, seektable_, application1_, application2_, vorbiscomment_, cuesheet_, unknown_;
  30. static FLAC__StreamMetadata *metadata_sequence_[] = { &vorbiscomment_, &padding_, &seektable_, &application1_, &application2_, &cuesheet_, &unknown_ };
  31. static const unsigned num_metadata_ = sizeof(metadata_sequence_) / sizeof(metadata_sequence_[0]);
  32. static const char *oggflacfilename_ = "metadata.ogg";
  33. static FLAC__bool die_s_(const char *msg, const OggFLAC__StreamEncoder *encoder)
  34. {
  35. OggFLAC__StreamEncoderState state = OggFLAC__stream_encoder_get_state(encoder);
  36. if(msg)
  37. printf("FAILED, %s", msg);
  38. else
  39. printf("FAILED");
  40. printf(", state = %u (%s)n", (unsigned)state, OggFLAC__StreamEncoderStateString[state]);
  41. if(state == OggFLAC__STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR) {
  42. FLAC__StreamEncoderState state_ = OggFLAC__stream_encoder_get_FLAC_stream_encoder_state(encoder);
  43. printf("      FLAC stream encoder state = %u (%s)n", (unsigned)state_, FLAC__StreamEncoderStateString[state_]);
  44. if(state_ == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
  45. FLAC__StreamDecoderState dstate = OggFLAC__stream_encoder_get_verify_decoder_state(encoder);
  46. printf("      verify decoder state = %u (%s)n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
  47. }
  48. }
  49. return false;
  50. }
  51. static FLAC__bool die_ss_(const char *msg, const OggFLAC__SeekableStreamEncoder *encoder)
  52. {
  53. OggFLAC__SeekableStreamEncoderState state = OggFLAC__seekable_stream_encoder_get_state(encoder);
  54. if(msg)
  55. printf("FAILED, %s", msg);
  56. else
  57. printf("FAILED");
  58. printf(", state = %u (%s)n", (unsigned)state, OggFLAC__SeekableStreamEncoderStateString[state]);
  59. if(state == OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR) {
  60. FLAC__StreamEncoderState state_ = OggFLAC__seekable_stream_encoder_get_FLAC_stream_encoder_state(encoder);
  61. printf("      FLAC stream encoder state = %u (%s)n", (unsigned)state_, FLAC__StreamEncoderStateString[state_]);
  62. if(state_ == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
  63. FLAC__StreamDecoderState dstate = OggFLAC__seekable_stream_encoder_get_verify_decoder_state(encoder);
  64. printf("      verify decoder state = %u (%s)n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
  65. }
  66. }
  67. return false;
  68. }
  69. static FLAC__bool die_f_(const char *msg, const OggFLAC__FileEncoder *encoder)
  70. {
  71. OggFLAC__FileEncoderState state = OggFLAC__file_encoder_get_state(encoder);
  72. if(msg)
  73. printf("FAILED, %s", msg);
  74. else
  75. printf("FAILED");
  76. printf(", state = %u (%s)n", (unsigned)state, OggFLAC__SeekableStreamEncoderStateString[state]);
  77. if(state == OggFLAC__FILE_ENCODER_SEEKABLE_STREAM_ENCODER_ERROR) {
  78. OggFLAC__SeekableStreamEncoderState state_ = OggFLAC__file_encoder_get_seekable_stream_encoder_state(encoder);
  79. printf("      seekable stream encoder state = %u (%s)n", (unsigned)state_, OggFLAC__SeekableStreamEncoderStateString[state_]);
  80. if(state_ == OggFLAC__SEEKABLE_STREAM_ENCODER_FLAC_STREAM_ENCODER_ERROR) {
  81. FLAC__StreamEncoderState state__ = OggFLAC__file_encoder_get_FLAC_stream_encoder_state(encoder);
  82. printf("      FLAC stream encoder state = %u (%s)n", (unsigned)state__, FLAC__StreamEncoderStateString[state__]);
  83. if(state__ == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
  84. FLAC__StreamDecoderState dstate = OggFLAC__file_encoder_get_verify_decoder_state(encoder);
  85. printf("      verify decoder state = %u (%s)n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
  86. }
  87. }
  88. }
  89. return false;
  90. }
  91. static void init_metadata_blocks_()
  92. {
  93. mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_);
  94. }
  95. static void free_metadata_blocks_()
  96. {
  97. mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_);
  98. }
  99. static FLAC__StreamEncoderWriteStatus stream_encoder_write_callback_(const OggFLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)
  100. {
  101. (void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data;
  102. return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
  103. }
  104. static void stream_encoder_metadata_callback_(const OggFLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data)
  105. {
  106. (void)encoder, (void)metadata, (void)client_data;
  107. }
  108. static FLAC__bool test_stream_encoder()
  109. {
  110. OggFLAC__StreamEncoder *encoder;
  111. OggFLAC__StreamEncoderState state;
  112. FLAC__StreamEncoderState fstate;
  113. FLAC__StreamDecoderState dstate;
  114. FLAC__int32 samples[1024];
  115. FLAC__int32 *samples_array[1];
  116. unsigned i;
  117. samples_array[0] = samples;
  118. printf("n+++ libOggFLAC unit test: OggFLAC__StreamEncodernn");
  119. printf("testing OggFLAC__stream_encoder_new()... ");
  120. encoder = OggFLAC__stream_encoder_new();
  121. if(0 == encoder) {
  122. printf("FAILED, returned NULLn");
  123. return false;
  124. }
  125. printf("OKn");
  126. printf("testing OggFLAC__stream_encoder_set_serial_number()... ");
  127. if(!OggFLAC__stream_encoder_set_serial_number(encoder, file_utils__serial_number))
  128. return die_s_("returned false", encoder);
  129. printf("OKn");
  130. printf("testing OggFLAC__stream_encoder_set_verify()... ");
  131. if(!OggFLAC__stream_encoder_set_verify(encoder, true))
  132. return die_s_("returned false", encoder);
  133. printf("OKn");
  134. printf("testing OggFLAC__stream_encoder_set_streamable_subset()... ");
  135. if(!OggFLAC__stream_encoder_set_streamable_subset(encoder, true))
  136. return die_s_("returned false", encoder);
  137. printf("OKn");
  138. printf("testing OggFLAC__stream_encoder_set_do_mid_side_stereo()... ");
  139. if(!OggFLAC__stream_encoder_set_do_mid_side_stereo(encoder, false))
  140. return die_s_("returned false", encoder);
  141. printf("OKn");
  142. printf("testing OggFLAC__stream_encoder_set_loose_mid_side_stereo()... ");
  143. if(!OggFLAC__stream_encoder_set_loose_mid_side_stereo(encoder, false))
  144. return die_s_("returned false", encoder);
  145. printf("OKn");
  146. printf("testing OggFLAC__stream_encoder_set_channels()... ");
  147. if(!OggFLAC__stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
  148. return die_s_("returned false", encoder);
  149. printf("OKn");
  150. printf("testing OggFLAC__stream_encoder_set_bits_per_sample()... ");
  151. if(!OggFLAC__stream_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
  152. return die_s_("returned false", encoder);
  153. printf("OKn");
  154. printf("testing OggFLAC__stream_encoder_set_sample_rate()... ");
  155. if(!OggFLAC__stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
  156. return die_s_("returned false", encoder);
  157. printf("OKn");
  158. printf("testing OggFLAC__stream_encoder_set_blocksize()... ");
  159. if(!OggFLAC__stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
  160. return die_s_("returned false", encoder);
  161. printf("OKn");
  162. printf("testing OggFLAC__stream_encoder_set_max_lpc_order()... ");
  163. if(!OggFLAC__stream_encoder_set_max_lpc_order(encoder, 0))
  164. return die_s_("returned false", encoder);
  165. printf("OKn");
  166. printf("testing OggFLAC__stream_encoder_set_qlp_coeff_precision()... ");
  167. if(!OggFLAC__stream_encoder_set_qlp_coeff_precision(encoder, 0))
  168. return die_s_("returned false", encoder);
  169. printf("OKn");
  170. printf("testing OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search()... ");
  171. if(!OggFLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder, false))
  172. return die_s_("returned false", encoder);
  173. printf("OKn");
  174. printf("testing OggFLAC__stream_encoder_set_do_escape_coding()... ");
  175. if(!OggFLAC__stream_encoder_set_do_escape_coding(encoder, false))
  176. return die_s_("returned false", encoder);
  177. printf("OKn");
  178. printf("testing OggFLAC__stream_encoder_set_do_exhaustive_model_search()... ");
  179. if(!OggFLAC__stream_encoder_set_do_exhaustive_model_search(encoder, false))
  180. return die_s_("returned false", encoder);
  181. printf("OKn");
  182. printf("testing OggFLAC__stream_encoder_set_min_residual_partition_order()... ");
  183. if(!OggFLAC__stream_encoder_set_min_residual_partition_order(encoder, 0))
  184. return die_s_("returned false", encoder);
  185. printf("OKn");
  186. printf("testing OggFLAC__stream_encoder_set_max_residual_partition_order()... ");
  187. if(!OggFLAC__stream_encoder_set_max_residual_partition_order(encoder, 0))
  188. return die_s_("returned false", encoder);
  189. printf("OKn");
  190. printf("testing OggFLAC__stream_encoder_set_rice_parameter_search_dist()... ");
  191. if(!OggFLAC__stream_encoder_set_rice_parameter_search_dist(encoder, 0))
  192. return die_s_("returned false", encoder);
  193. printf("OKn");
  194. printf("testing OggFLAC__stream_encoder_set_total_samples_estimate()... ");
  195. if(!OggFLAC__stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
  196. return die_s_("returned false", encoder);
  197. printf("OKn");
  198. printf("testing OggFLAC__stream_encoder_set_metadata()... ");
  199. if(!OggFLAC__stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
  200. return die_s_("returned false", encoder);
  201. printf("OKn");
  202. printf("testing OggFLAC__stream_encoder_set_write_callback()... ");
  203. if(!OggFLAC__stream_encoder_set_write_callback(encoder, stream_encoder_write_callback_))
  204. return die_s_("returned false", encoder);
  205. printf("OKn");
  206. printf("testing OggFLAC__stream_encoder_set_metadata_callback()... ");
  207. if(!OggFLAC__stream_encoder_set_metadata_callback(encoder, stream_encoder_metadata_callback_))
  208. return die_s_("returned false", encoder);
  209. printf("OKn");
  210. printf("testing OggFLAC__stream_encoder_set_client_data()... ");
  211. if(!OggFLAC__stream_encoder_set_client_data(encoder, 0))
  212. return die_s_("returned false", encoder);
  213. printf("OKn");
  214. printf("testing OggFLAC__stream_encoder_init()... ");
  215. if(OggFLAC__stream_encoder_init(encoder) != FLAC__STREAM_ENCODER_OK)
  216. return die_s_(0, encoder);
  217. printf("OKn");
  218. printf("testing OggFLAC__stream_encoder_get_state()... ");
  219. state = OggFLAC__stream_encoder_get_state(encoder);
  220. printf("returned state = %u (%s)... OKn", (unsigned)state, OggFLAC__StreamEncoderStateString[state]);
  221. printf("testing OggFLAC__stream_encoder_get_FLAC_stream_encoder_state()... ");
  222. fstate = OggFLAC__stream_encoder_get_FLAC_stream_encoder_state(encoder);
  223. printf("returned state = %u (%s)... OKn", (unsigned)fstate, FLAC__StreamEncoderStateString[fstate]);
  224. printf("testing OggFLAC__stream_encoder_get_verify_decoder_state()... ");
  225. dstate = OggFLAC__stream_encoder_get_verify_decoder_state(encoder);
  226. printf("returned state = %u (%s)... OKn", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
  227. {
  228. FLAC__uint64 absolute_sample;
  229. unsigned frame_number;
  230. unsigned channel;
  231. unsigned sample;
  232. FLAC__int32 expected;
  233. FLAC__int32 got;
  234. printf("testing OggFLAC__stream_encoder_get_verify_decoder_error_stats()... ");
  235. OggFLAC__stream_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
  236. printf("OKn");
  237. }
  238. printf("testing OggFLAC__stream_encoder_get_verify()... ");
  239. if(OggFLAC__stream_encoder_get_verify(encoder) != true) {
  240. printf("FAILED, expected true, got falsen");
  241. return false;
  242. }
  243. printf("OKn");
  244. printf("testing OggFLAC__stream_encoder_get_streamable_subset()... ");
  245. if(OggFLAC__stream_encoder_get_streamable_subset(encoder) != true) {
  246. printf("FAILED, expected true, got falsen");
  247. return false;
  248. }
  249. printf("OKn");
  250. printf("testing OggFLAC__stream_encoder_get_do_mid_side_stereo()... ");
  251. if(OggFLAC__stream_encoder_get_do_mid_side_stereo(encoder) != false) {
  252. printf("FAILED, expected false, got truen");
  253. return false;
  254. }
  255. printf("OKn");
  256. printf("testing OggFLAC__stream_encoder_get_loose_mid_side_stereo()... ");
  257. if(OggFLAC__stream_encoder_get_loose_mid_side_stereo(encoder) != false) {
  258. printf("FAILED, expected false, got truen");
  259. return false;
  260. }
  261. printf("OKn");
  262. printf("testing OggFLAC__stream_encoder_get_channels()... ");
  263. if(OggFLAC__stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
  264. printf("FAILED, expected %u, got %un", streaminfo_.data.stream_info.channels, OggFLAC__stream_encoder_get_channels(encoder));
  265. return false;
  266. }
  267. printf("OKn");
  268. printf("testing OggFLAC__stream_encoder_get_bits_per_sample()... ");
  269. if(OggFLAC__stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
  270. printf("FAILED, expected %u, got %un", streaminfo_.data.stream_info.bits_per_sample, OggFLAC__stream_encoder_get_bits_per_sample(encoder));
  271. return false;
  272. }
  273. printf("OKn");
  274. printf("testing OggFLAC__stream_encoder_get_sample_rate()... ");
  275. if(OggFLAC__stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
  276. printf("FAILED, expected %u, got %un", streaminfo_.data.stream_info.sample_rate, OggFLAC__stream_encoder_get_sample_rate(encoder));
  277. return false;
  278. }
  279. printf("OKn");
  280. printf("testing OggFLAC__stream_encoder_get_blocksize()... ");
  281. if(OggFLAC__stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
  282. printf("FAILED, expected %u, got %un", streaminfo_.data.stream_info.min_blocksize, OggFLAC__stream_encoder_get_blocksize(encoder));
  283. return false;
  284. }
  285. printf("OKn");
  286. printf("testing OggFLAC__stream_encoder_get_max_lpc_order()... ");
  287. if(OggFLAC__stream_encoder_get_max_lpc_order(encoder) != 0) {
  288. printf("FAILED, expected %u, got %un", 0, OggFLAC__stream_encoder_get_max_lpc_order(encoder));
  289. return false;
  290. }
  291. printf("OKn");
  292. printf("testing OggFLAC__stream_encoder_get_qlp_coeff_precision()... ");
  293. (void)OggFLAC__stream_encoder_get_qlp_coeff_precision(encoder);
  294. /* we asked the encoder to auto select this so we accept anything */
  295. printf("OKn");
  296. printf("testing OggFLAC__stream_encoder_get_do_qlp_coeff_prec_search()... ");
  297. if(OggFLAC__stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
  298. printf("FAILED, expected false, got truen");
  299. return false;
  300. }
  301. printf("OKn");
  302. printf("testing OggFLAC__stream_encoder_get_do_escape_coding()... ");
  303. if(OggFLAC__stream_encoder_get_do_escape_coding(encoder) != false) {
  304. printf("FAILED, expected false, got truen");
  305. return false;
  306. }
  307. printf("OKn");
  308. printf("testing OggFLAC__stream_encoder_get_do_exhaustive_model_search()... ");
  309. if(OggFLAC__stream_encoder_get_do_exhaustive_model_search(encoder) != false) {
  310. printf("FAILED, expected false, got truen");
  311. return false;
  312. }
  313. printf("OKn");
  314. printf("testing OggFLAC__stream_encoder_get_min_residual_partition_order()... ");
  315. if(OggFLAC__stream_encoder_get_min_residual_partition_order(encoder) != 0) {
  316. printf("FAILED, expected %u, got %un", 0, OggFLAC__stream_encoder_get_min_residual_partition_order(encoder));
  317. return false;
  318. }
  319. printf("OKn");
  320. printf("testing OggFLAC__stream_encoder_get_max_residual_partition_order()... ");
  321. if(OggFLAC__stream_encoder_get_max_residual_partition_order(encoder) != 0) {
  322. printf("FAILED, expected %u, got %un", 0, OggFLAC__stream_encoder_get_max_residual_partition_order(encoder));
  323. return false;
  324. }
  325. printf("OKn");
  326. printf("testing OggFLAC__stream_encoder_get_rice_parameter_search_dist()... ");
  327. if(OggFLAC__stream_encoder_get_rice_parameter_search_dist(encoder) != 0) {
  328. printf("FAILED, expected %u, got %un", 0, OggFLAC__stream_encoder_get_rice_parameter_search_dist(encoder));
  329. return false;
  330. }
  331. printf("OKn");
  332. printf("testing OggFLAC__stream_encoder_get_total_samples_estimate()... ");
  333. if(OggFLAC__stream_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
  334. printf("FAILED, expected %llu, got %llun", streaminfo_.data.stream_info.total_samples, OggFLAC__stream_encoder_get_total_samples_estimate(encoder));
  335. return false;
  336. }
  337. printf("OKn");
  338. /* init the dummy sample buffer */
  339. for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
  340. samples[i] = i & 7;
  341. printf("testing OggFLAC__stream_encoder_process()... ");
  342. if(!OggFLAC__stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
  343. return die_s_("returned false", encoder);
  344. printf("OKn");
  345. printf("testing OggFLAC__stream_encoder_process_interleaved()... ");
  346. if(!OggFLAC__stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
  347. return die_s_("returned false", encoder);
  348. printf("OKn");
  349. printf("testing OggFLAC__stream_encoder_finish()... ");
  350. OggFLAC__stream_encoder_finish(encoder);
  351. printf("OKn");
  352. printf("testing OggFLAC__stream_encoder_delete()... ");
  353. OggFLAC__stream_encoder_delete(encoder);
  354. printf("OKn");
  355. printf("nPASSED!n");
  356. return true;
  357. }
  358. OggFLAC__SeekableStreamEncoderReadStatus seekable_stream_encoder_read_callback_(const OggFLAC__SeekableStreamEncoder *encoder, FLAC__byte buffer[], unsigned *bytes, void *client_data)
  359. {
  360. (void)encoder, (void)buffer, (void)bytes, (void)client_data;
  361. memset(buffer, 0, *bytes); /* init buffer to avoid valgrind errors */
  362. return OggFLAC__SEEKABLE_STREAM_ENCODER_READ_STATUS_CONTINUE;
  363. }
  364. FLAC__SeekableStreamEncoderSeekStatus seekable_stream_encoder_seek_callback_(const OggFLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  365. {
  366. (void)encoder, (void)absolute_byte_offset, (void)client_data;
  367. return FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK;
  368. }
  369. FLAC__SeekableStreamEncoderTellStatus seekable_stream_encoder_tell_callback_(const OggFLAC__SeekableStreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  370. {
  371. (void)encoder, (void)client_data;
  372. *absolute_byte_offset = 0;
  373. return FLAC__SEEKABLE_STREAM_ENCODER_TELL_STATUS_OK;
  374. }
  375. FLAC__StreamEncoderWriteStatus seekable_stream_encoder_write_callback_(const OggFLAC__SeekableStreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)
  376. {
  377. (void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data;
  378. return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
  379. }
  380. static FLAC__bool test_seekable_stream_encoder()
  381. {
  382. OggFLAC__SeekableStreamEncoder *encoder;
  383. OggFLAC__SeekableStreamEncoderState state;
  384. FLAC__StreamEncoderState fstate;
  385. FLAC__StreamDecoderState dstate;
  386. FLAC__int32 samples[1024];
  387. FLAC__int32 *samples_array[1];
  388. unsigned i;
  389. samples_array[0] = samples;
  390. printf("n+++ libOggFLAC unit test: OggFLAC__SeekableStreamEncodernn");
  391. printf("testing OggFLAC__seekable_stream_encoder_new()... ");
  392. encoder = OggFLAC__seekable_stream_encoder_new();
  393. if(0 == encoder) {
  394. printf("FAILED, returned NULLn");
  395. return false;
  396. }
  397. printf("OKn");
  398. printf("testing OggFLAC__seekable_stream_encoder_set_serial_number()... ");
  399. if(!OggFLAC__seekable_stream_encoder_set_serial_number(encoder, file_utils__serial_number))
  400. return die_ss_("returned false", encoder);
  401. printf("OKn");
  402. printf("testing OggFLAC__seekable_stream_encoder_set_verify()... ");
  403. if(!OggFLAC__seekable_stream_encoder_set_verify(encoder, true))
  404. return die_ss_("returned false", encoder);
  405. printf("OKn");
  406. printf("testing OggFLAC__seekable_stream_encoder_set_streamable_subset()... ");
  407. if(!OggFLAC__seekable_stream_encoder_set_streamable_subset(encoder, true))
  408. return die_ss_("returned false", encoder);
  409. printf("OKn");
  410. printf("testing OggFLAC__seekable_stream_encoder_set_do_mid_side_stereo()... ");
  411. if(!OggFLAC__seekable_stream_encoder_set_do_mid_side_stereo(encoder, false))
  412. return die_ss_("returned false", encoder);
  413. printf("OKn");
  414. printf("testing OggFLAC__seekable_stream_encoder_set_loose_mid_side_stereo()... ");
  415. if(!OggFLAC__seekable_stream_encoder_set_loose_mid_side_stereo(encoder, false))
  416. return die_ss_("returned false", encoder);
  417. printf("OKn");
  418. printf("testing OggFLAC__seekable_stream_encoder_set_channels()... ");
  419. if(!OggFLAC__seekable_stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
  420. return die_ss_("returned false", encoder);
  421. printf("OKn");
  422. printf("testing OggFLAC__seekable_stream_encoder_set_bits_per_sample()... ");
  423. if(!OggFLAC__seekable_stream_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
  424. return die_ss_("returned false", encoder);
  425. printf("OKn");
  426. printf("testing OggFLAC__seekable_stream_encoder_set_sample_rate()... ");
  427. if(!OggFLAC__seekable_stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
  428. return die_ss_("returned false", encoder);
  429. printf("OKn");
  430. printf("testing OggFLAC__seekable_stream_encoder_set_blocksize()... ");
  431. if(!OggFLAC__seekable_stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
  432. return die_ss_("returned false", encoder);
  433. printf("OKn");
  434. printf("testing OggFLAC__seekable_stream_encoder_set_max_lpc_order()... ");
  435. if(!OggFLAC__seekable_stream_encoder_set_max_lpc_order(encoder, 0))
  436. return die_ss_("returned false", encoder);
  437. printf("OKn");
  438. printf("testing OggFLAC__seekable_stream_encoder_set_qlp_coeff_precision()... ");
  439. if(!OggFLAC__seekable_stream_encoder_set_qlp_coeff_precision(encoder, 0))
  440. return die_ss_("returned false", encoder);
  441. printf("OKn");
  442. printf("testing OggFLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search()... ");
  443. if(!OggFLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search(encoder, false))
  444. return die_ss_("returned false", encoder);
  445. printf("OKn");
  446. printf("testing OggFLAC__seekable_stream_encoder_set_do_escape_coding()... ");
  447. if(!OggFLAC__seekable_stream_encoder_set_do_escape_coding(encoder, false))
  448. return die_ss_("returned false", encoder);
  449. printf("OKn");
  450. printf("testing OggFLAC__seekable_stream_encoder_set_do_exhaustive_model_search()... ");
  451. if(!OggFLAC__seekable_stream_encoder_set_do_exhaustive_model_search(encoder, false))
  452. return die_ss_("returned false", encoder);
  453. printf("OKn");
  454. printf("testing OggFLAC__seekable_stream_encoder_set_min_residual_partition_order()... ");
  455. if(!OggFLAC__seekable_stream_encoder_set_min_residual_partition_order(encoder, 0))
  456. return die_ss_("returned false", encoder);
  457. printf("OKn");
  458. printf("testing OggFLAC__seekable_stream_encoder_set_max_residual_partition_order()... ");
  459. if(!OggFLAC__seekable_stream_encoder_set_max_residual_partition_order(encoder, 0))
  460. return die_ss_("returned false", encoder);
  461. printf("OKn");
  462. printf("testing OggFLAC__seekable_stream_encoder_set_rice_parameter_search_dist()... ");
  463. if(!OggFLAC__seekable_stream_encoder_set_rice_parameter_search_dist(encoder, 0))
  464. return die_ss_("returned false", encoder);
  465. printf("OKn");
  466. printf("testing OggFLAC__seekable_stream_encoder_set_total_samples_estimate()... ");
  467. if(!OggFLAC__seekable_stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
  468. return die_ss_("returned false", encoder);
  469. printf("OKn");
  470. printf("testing OggFLAC__seekable_stream_encoder_set_metadata()... ");
  471. if(!OggFLAC__seekable_stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
  472. return die_ss_("returned false", encoder);
  473. printf("OKn");
  474. printf("testing OggFLAC__seekable_stream_encoder_set_read_callback()... ");
  475. if(!OggFLAC__seekable_stream_encoder_set_read_callback(encoder, seekable_stream_encoder_read_callback_))
  476. return die_ss_("returned false", encoder);
  477. printf("OKn");
  478. printf("testing OggFLAC__seekable_stream_encoder_set_seek_callback()... ");
  479. if(!OggFLAC__seekable_stream_encoder_set_seek_callback(encoder, seekable_stream_encoder_seek_callback_))
  480. return die_ss_("returned false", encoder);
  481. printf("OKn");
  482. printf("testing OggFLAC__seekable_stream_encoder_set_tell_callback()... ");
  483. if(!OggFLAC__seekable_stream_encoder_set_tell_callback(encoder, seekable_stream_encoder_tell_callback_))
  484. return die_ss_("returned false", encoder);
  485. printf("OKn");
  486. printf("testing OggFLAC__seekable_stream_encoder_set_write_callback()... ");
  487. if(!OggFLAC__seekable_stream_encoder_set_write_callback(encoder, seekable_stream_encoder_write_callback_))
  488. return die_ss_("returned false", encoder);
  489. printf("OKn");
  490. printf("testing OggFLAC__seekable_stream_encoder_set_client_data()... ");
  491. if(!OggFLAC__seekable_stream_encoder_set_client_data(encoder, 0))
  492. return die_ss_("returned false", encoder);
  493. printf("OKn");
  494. printf("testing OggFLAC__seekable_stream_encoder_init()... ");
  495. if(OggFLAC__seekable_stream_encoder_init(encoder) != OggFLAC__SEEKABLE_STREAM_ENCODER_OK)
  496. return die_ss_(0, encoder);
  497. printf("OKn");
  498. printf("testing OggFLAC__seekable_stream_encoder_get_state()... ");
  499. state = OggFLAC__seekable_stream_encoder_get_state(encoder);
  500. printf("returned state = %u (%s)... OKn", (unsigned)state, OggFLAC__SeekableStreamEncoderStateString[state]);
  501. printf("testing OggFLAC__seekable_stream_encoder_get_FLAC_stream_encoder_state()... ");
  502. fstate = OggFLAC__seekable_stream_encoder_get_FLAC_stream_encoder_state(encoder);
  503. printf("returned state = %u (%s)... OKn", (unsigned)fstate, FLAC__StreamEncoderStateString[fstate]);
  504. printf("testing OggFLAC__seekable_stream_encoder_get_verify_decoder_state()... ");
  505. dstate = OggFLAC__seekable_stream_encoder_get_verify_decoder_state(encoder);
  506. printf("returned state = %u (%s)... OKn", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
  507. {
  508. FLAC__uint64 absolute_sample;
  509. unsigned frame_number;
  510. unsigned channel;
  511. unsigned sample;
  512. FLAC__int32 expected;
  513. FLAC__int32 got;
  514. printf("testing OggFLAC__seekable_stream_encoder_get_verify_decoder_error_stats()... ");
  515. OggFLAC__seekable_stream_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
  516. printf("OKn");
  517. }
  518. printf("testing OggFLAC__seekable_stream_encoder_get_verify()... ");
  519. if(OggFLAC__seekable_stream_encoder_get_verify(encoder) != true) {
  520. printf("FAILED, expected true, got falsen");
  521. return false;
  522. }
  523. printf("OKn");
  524. printf("testing OggFLAC__seekable_stream_encoder_get_streamable_subset()... ");
  525. if(OggFLAC__seekable_stream_encoder_get_streamable_subset(encoder) != true) {
  526. printf("FAILED, expected true, got falsen");
  527. return false;
  528. }
  529. printf("OKn");
  530. printf("testing OggFLAC__seekable_stream_encoder_get_do_mid_side_stereo()... ");
  531. if(OggFLAC__seekable_stream_encoder_get_do_mid_side_stereo(encoder) != false) {
  532. printf("FAILED, expected false, got truen");
  533. return false;
  534. }
  535. printf("OKn");
  536. printf("testing OggFLAC__seekable_stream_encoder_get_loose_mid_side_stereo()... ");
  537. if(OggFLAC__seekable_stream_encoder_get_loose_mid_side_stereo(encoder) != false) {
  538. printf("FAILED, expected false, got truen");
  539. return false;
  540. }
  541. printf("OKn");
  542. printf("testing OggFLAC__seekable_stream_encoder_get_channels()... ");
  543. if(OggFLAC__seekable_stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
  544. printf("FAILED, expected %u, got %un", streaminfo_.data.stream_info.channels, OggFLAC__seekable_stream_encoder_get_channels(encoder));
  545. return false;
  546. }
  547. printf("OKn");
  548. printf("testing OggFLAC__seekable_stream_encoder_get_bits_per_sample()... ");
  549. if(OggFLAC__seekable_stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
  550. printf("FAILED, expected %u, got %un", streaminfo_.data.stream_info.bits_per_sample, OggFLAC__seekable_stream_encoder_get_bits_per_sample(encoder));
  551. return false;
  552. }
  553. printf("OKn");
  554. printf("testing OggFLAC__seekable_stream_encoder_get_sample_rate()... ");
  555. if(OggFLAC__seekable_stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
  556. printf("FAILED, expected %u, got %un", streaminfo_.data.stream_info.sample_rate, OggFLAC__seekable_stream_encoder_get_sample_rate(encoder));
  557. return false;
  558. }
  559. printf("OKn");
  560. printf("testing OggFLAC__seekable_stream_encoder_get_blocksize()... ");
  561. if(OggFLAC__seekable_stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
  562. printf("FAILED, expected %u, got %un", streaminfo_.data.stream_info.min_blocksize, OggFLAC__seekable_stream_encoder_get_blocksize(encoder));
  563. return false;
  564. }
  565. printf("OKn");
  566. printf("testing OggFLAC__seekable_stream_encoder_get_max_lpc_order()... ");
  567. if(OggFLAC__seekable_stream_encoder_get_max_lpc_order(encoder) != 0) {
  568. printf("FAILED, expected %u, got %un", 0, OggFLAC__seekable_stream_encoder_get_max_lpc_order(encoder));
  569. return false;
  570. }
  571. printf("OKn");
  572. printf("testing OggFLAC__seekable_stream_encoder_get_qlp_coeff_precision()... ");
  573. (void)OggFLAC__seekable_stream_encoder_get_qlp_coeff_precision(encoder);
  574. /* we asked the encoder to auto select this so we accept anything */
  575. printf("OKn");
  576. printf("testing OggFLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search()... ");
  577. if(OggFLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
  578. printf("FAILED, expected false, got truen");
  579. return false;
  580. }
  581. printf("OKn");
  582. printf("testing OggFLAC__seekable_stream_encoder_get_do_escape_coding()... ");
  583. if(OggFLAC__seekable_stream_encoder_get_do_escape_coding(encoder) != false) {
  584. printf("FAILED, expected false, got truen");
  585. return false;
  586. }
  587. printf("OKn");
  588. printf("testing OggFLAC__seekable_stream_encoder_get_do_exhaustive_model_search()... ");
  589. if(OggFLAC__seekable_stream_encoder_get_do_exhaustive_model_search(encoder) != false) {
  590. printf("FAILED, expected false, got truen");
  591. return false;
  592. }
  593. printf("OKn");
  594. printf("testing OggFLAC__seekable_stream_encoder_get_min_residual_partition_order()... ");
  595. if(OggFLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder) != 0) {
  596. printf("FAILED, expected %u, got %un", 0, OggFLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder));
  597. return false;
  598. }
  599. printf("OKn");
  600. printf("testing OggFLAC__seekable_stream_encoder_get_max_residual_partition_order()... ");
  601. if(OggFLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder) != 0) {
  602. printf("FAILED, expected %u, got %un", 0, OggFLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder));
  603. return false;
  604. }
  605. printf("OKn");
  606. printf("testing OggFLAC__seekable_stream_encoder_get_rice_parameter_search_dist()... ");
  607. if(OggFLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder) != 0) {
  608. printf("FAILED, expected %u, got %un", 0, OggFLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder));
  609. return false;
  610. }
  611. printf("OKn");
  612. printf("testing OggFLAC__seekable_stream_encoder_get_total_samples_estimate()... ");
  613. if(OggFLAC__seekable_stream_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
  614. printf("FAILED, expected %llu, got %llun", streaminfo_.data.stream_info.total_samples, OggFLAC__seekable_stream_encoder_get_total_samples_estimate(encoder));
  615. return false;
  616. }
  617. printf("OKn");
  618. /* init the dummy sample buffer */
  619. for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
  620. samples[i] = i & 7;
  621. printf("testing OggFLAC__seekable_stream_encoder_process()... ");
  622. if(!OggFLAC__seekable_stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
  623. return die_ss_("returned false", encoder);
  624. printf("OKn");
  625. printf("testing OggFLAC__seekable_stream_encoder_process_interleaved()... ");
  626. if(!OggFLAC__seekable_stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
  627. return die_ss_("returned false", encoder);
  628. printf("OKn");
  629. printf("testing OggFLAC__seekable_stream_encoder_finish()... ");
  630. OggFLAC__seekable_stream_encoder_finish(encoder);
  631. printf("OKn");
  632. printf("testing OggFLAC__seekable_stream_encoder_delete()... ");
  633. OggFLAC__seekable_stream_encoder_delete(encoder);
  634. printf("OKn");
  635. printf("nPASSED!n");
  636. return true;
  637. }
  638. static void file_encoder_progress_callback_(const OggFLAC__FileEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data)
  639. {
  640. (void)encoder, (void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate, (void)client_data;
  641. }
  642. static FLAC__bool test_file_encoder()
  643. {
  644. OggFLAC__FileEncoder *encoder;
  645. OggFLAC__FileEncoderState state;
  646. OggFLAC__SeekableStreamEncoderState sstate;
  647. FLAC__StreamEncoderState fstate;
  648. FLAC__StreamDecoderState dstate;
  649. FLAC__int32 samples[1024];
  650. FLAC__int32 *samples_array[1];
  651. unsigned i;
  652. samples_array[0] = samples;
  653. printf("n+++ libOggFLAC unit test: OggFLAC__FileEncodernn");
  654. printf("testing OggFLAC__file_encoder_new()... ");
  655. encoder = OggFLAC__file_encoder_new();
  656. if(0 == encoder) {
  657. printf("FAILED, returned NULLn");
  658. return false;
  659. }
  660. printf("OKn");
  661. printf("testing OggFLAC__file_encoder_set_serial_number()... ");
  662. if(!OggFLAC__file_encoder_set_serial_number(encoder, file_utils__serial_number))
  663. return die_f_("returned false", encoder);
  664. printf("OKn");
  665. printf("testing OggFLAC__file_encoder_set_verify()... ");
  666. if(!OggFLAC__file_encoder_set_verify(encoder, true))
  667. return die_f_("returned false", encoder);
  668. printf("OKn");
  669. printf("testing OggFLAC__file_encoder_set_streamable_subset()... ");
  670. if(!OggFLAC__file_encoder_set_streamable_subset(encoder, true))
  671. return die_f_("returned false", encoder);
  672. printf("OKn");
  673. printf("testing OggFLAC__file_encoder_set_do_mid_side_stereo()... ");
  674. if(!OggFLAC__file_encoder_set_do_mid_side_stereo(encoder, false))
  675. return die_f_("returned false", encoder);
  676. printf("OKn");
  677. printf("testing OggFLAC__file_encoder_set_loose_mid_side_stereo()... ");
  678. if(!OggFLAC__file_encoder_set_loose_mid_side_stereo(encoder, false))
  679. return die_f_("returned false", encoder);
  680. printf("OKn");
  681. printf("testing OggFLAC__file_encoder_set_channels()... ");
  682. if(!OggFLAC__file_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
  683. return die_f_("returned false", encoder);
  684. printf("OKn");
  685. printf("testing OggFLAC__file_encoder_set_bits_per_sample()... ");
  686. if(!OggFLAC__file_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
  687. return die_f_("returned false", encoder);
  688. printf("OKn");
  689. printf("testing OggFLAC__file_encoder_set_sample_rate()... ");
  690. if(!OggFLAC__file_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
  691. return die_f_("returned false", encoder);
  692. printf("OKn");
  693. printf("testing OggFLAC__file_encoder_set_blocksize()... ");
  694. if(!OggFLAC__file_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
  695. return die_f_("returned false", encoder);
  696. printf("OKn");
  697. printf("testing OggFLAC__file_encoder_set_max_lpc_order()... ");
  698. if(!OggFLAC__file_encoder_set_max_lpc_order(encoder, 0))
  699. return die_f_("returned false", encoder);
  700. printf("OKn");
  701. printf("testing OggFLAC__file_encoder_set_qlp_coeff_precision()... ");
  702. if(!OggFLAC__file_encoder_set_qlp_coeff_precision(encoder, 0))
  703. return die_f_("returned false", encoder);
  704. printf("OKn");
  705. printf("testing OggFLAC__file_encoder_set_do_qlp_coeff_prec_search()... ");
  706. if(!OggFLAC__file_encoder_set_do_qlp_coeff_prec_search(encoder, false))
  707. return die_f_("returned false", encoder);
  708. printf("OKn");
  709. printf("testing OggFLAC__file_encoder_set_do_escape_coding()... ");
  710. if(!OggFLAC__file_encoder_set_do_escape_coding(encoder, false))
  711. return die_f_("returned false", encoder);
  712. printf("OKn");
  713. printf("testing OggFLAC__file_encoder_set_do_exhaustive_model_search()... ");
  714. if(!OggFLAC__file_encoder_set_do_exhaustive_model_search(encoder, false))
  715. return die_f_("returned false", encoder);
  716. printf("OKn");
  717. printf("testing OggFLAC__file_encoder_set_min_residual_partition_order()... ");
  718. if(!OggFLAC__file_encoder_set_min_residual_partition_order(encoder, 0))
  719. return die_f_("returned false", encoder);
  720. printf("OKn");
  721. printf("testing OggFLAC__file_encoder_set_max_residual_partition_order()... ");
  722. if(!OggFLAC__file_encoder_set_max_residual_partition_order(encoder, 0))
  723. return die_f_("returned false", encoder);
  724. printf("OKn");
  725. printf("testing OggFLAC__file_encoder_set_rice_parameter_search_dist()... ");
  726. if(!OggFLAC__file_encoder_set_rice_parameter_search_dist(encoder, 0))
  727. return die_f_("returned false", encoder);
  728. printf("OKn");
  729. printf("testing OggFLAC__file_encoder_set_total_samples_estimate()... ");
  730. if(!OggFLAC__file_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
  731. return die_f_("returned false", encoder);
  732. printf("OKn");
  733. printf("testing OggFLAC__file_encoder_set_metadata()... ");
  734. if(!OggFLAC__file_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
  735. return die_f_("returned false", encoder);
  736. printf("OKn");
  737. printf("testing OggFLAC__file_encoder_set_filename()... ");
  738. if(!OggFLAC__file_encoder_set_filename(encoder, oggflacfilename_))
  739. return die_f_("returned false", encoder);
  740. printf("OKn");
  741. printf("testing OggFLAC__file_encoder_set_progress_callback()... ");
  742. if(!OggFLAC__file_encoder_set_progress_callback(encoder, file_encoder_progress_callback_))
  743. return die_f_("returned false", encoder);
  744. printf("OKn");
  745. printf("testing OggFLAC__file_encoder_set_client_data()... ");
  746. if(!OggFLAC__file_encoder_set_client_data(encoder, 0))
  747. return die_f_("returned false", encoder);
  748. printf("OKn");
  749. printf("testing OggFLAC__file_encoder_init()... ");
  750. if(OggFLAC__file_encoder_init(encoder) != OggFLAC__FILE_ENCODER_OK)
  751. return die_f_(0, encoder);
  752. printf("OKn");
  753. printf("testing OggFLAC__file_encoder_get_state()... ");
  754. state = OggFLAC__file_encoder_get_state(encoder);
  755. printf("returned state = %u (%s)... OKn", (unsigned)state, OggFLAC__FileEncoderStateString[state]);
  756. printf("testing OggFLAC__file_encoder_get_seekable_stream_encoder_state()... ");
  757. sstate = OggFLAC__file_encoder_get_seekable_stream_encoder_state(encoder);
  758. printf("returned state = %u (%s)... OKn", (unsigned)sstate, OggFLAC__SeekableStreamEncoderStateString[sstate]);
  759. printf("testing OggFLAC__file_encoder_get_FLAC_stream_encoder_state()... ");
  760. fstate = OggFLAC__file_encoder_get_FLAC_stream_encoder_state(encoder);
  761. printf("returned state = %u (%s)... OKn", (unsigned)fstate, FLAC__StreamEncoderStateString[fstate]);
  762. printf("testing OggFLAC__file_encoder_get_verify_decoder_state()... ");
  763. dstate = OggFLAC__file_encoder_get_verify_decoder_state(encoder);
  764. printf("returned state = %u (%s)... OKn", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
  765. {
  766. FLAC__uint64 absolute_sample;
  767. unsigned frame_number;
  768. unsigned channel;
  769. unsigned sample;
  770. FLAC__int32 expected;
  771. FLAC__int32 got;
  772. printf("testing OggFLAC__file_encoder_get_verify_decoder_error_stats()... ");
  773. OggFLAC__file_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
  774. printf("OKn");
  775. }
  776. printf("testing OggFLAC__file_encoder_get_verify()... ");
  777. if(OggFLAC__file_encoder_get_verify(encoder) != true) {
  778. printf("FAILED, expected true, got falsen");
  779. return false;
  780. }
  781. printf("OKn");
  782. printf("testing OggFLAC__file_encoder_get_streamable_subset()... ");
  783. if(OggFLAC__file_encoder_get_streamable_subset(encoder) != true) {
  784. printf("FAILED, expected true, got falsen");
  785. return false;
  786. }
  787. printf("OKn");
  788. printf("testing OggFLAC__file_encoder_get_do_mid_side_stereo()... ");
  789. if(OggFLAC__file_encoder_get_do_mid_side_stereo(encoder) != false) {
  790. printf("FAILED, expected false, got truen");
  791. return false;
  792. }
  793. printf("OKn");
  794. printf("testing OggFLAC__file_encoder_get_loose_mid_side_stereo()... ");
  795. if(OggFLAC__file_encoder_get_loose_mid_side_stereo(encoder) != false) {
  796. printf("FAILED, expected false, got truen");
  797. return false;
  798. }
  799. printf("OKn");
  800. printf("testing OggFLAC__file_encoder_get_channels()... ");
  801. if(OggFLAC__file_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
  802. printf("FAILED, expected %u, got %un", streaminfo_.data.stream_info.channels, OggFLAC__file_encoder_get_channels(encoder));
  803. return false;
  804. }
  805. printf("OKn");
  806. printf("testing OggFLAC__file_encoder_get_bits_per_sample()... ");
  807. if(OggFLAC__file_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
  808. printf("FAILED, expected %u, got %un", streaminfo_.data.stream_info.bits_per_sample, OggFLAC__file_encoder_get_bits_per_sample(encoder));
  809. return false;
  810. }
  811. printf("OKn");
  812. printf("testing OggFLAC__file_encoder_get_sample_rate()... ");
  813. if(OggFLAC__file_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
  814. printf("FAILED, expected %u, got %un", streaminfo_.data.stream_info.sample_rate, OggFLAC__file_encoder_get_sample_rate(encoder));
  815. return false;
  816. }
  817. printf("OKn");
  818. printf("testing OggFLAC__file_encoder_get_blocksize()... ");
  819. if(OggFLAC__file_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
  820. printf("FAILED, expected %u, got %un", streaminfo_.data.stream_info.min_blocksize, OggFLAC__file_encoder_get_blocksize(encoder));
  821. return false;
  822. }
  823. printf("OKn");
  824. printf("testing OggFLAC__file_encoder_get_max_lpc_order()... ");
  825. if(OggFLAC__file_encoder_get_max_lpc_order(encoder) != 0) {
  826. printf("FAILED, expected %u, got %un", 0, OggFLAC__file_encoder_get_max_lpc_order(encoder));
  827. return false;
  828. }
  829. printf("OKn");
  830. printf("testing OggFLAC__file_encoder_get_qlp_coeff_precision()... ");
  831. (void)OggFLAC__file_encoder_get_qlp_coeff_precision(encoder);
  832. /* we asked the encoder to auto select this so we accept anything */
  833. printf("OKn");
  834. printf("testing OggFLAC__file_encoder_get_do_qlp_coeff_prec_search()... ");
  835. if(OggFLAC__file_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
  836. printf("FAILED, expected false, got truen");
  837. return false;
  838. }
  839. printf("OKn");
  840. printf("testing OggFLAC__file_encoder_get_do_escape_coding()... ");
  841. if(OggFLAC__file_encoder_get_do_escape_coding(encoder) != false) {
  842. printf("FAILED, expected false, got truen");
  843. return false;
  844. }
  845. printf("OKn");
  846. printf("testing OggFLAC__file_encoder_get_do_exhaustive_model_search()... ");
  847. if(OggFLAC__file_encoder_get_do_exhaustive_model_search(encoder) != false) {
  848. printf("FAILED, expected false, got truen");
  849. return false;
  850. }
  851. printf("OKn");
  852. printf("testing OggFLAC__file_encoder_get_min_residual_partition_order()... ");
  853. if(OggFLAC__file_encoder_get_min_residual_partition_order(encoder) != 0) {
  854. printf("FAILED, expected %u, got %un", 0, OggFLAC__file_encoder_get_min_residual_partition_order(encoder));
  855. return false;
  856. }
  857. printf("OKn");
  858. printf("testing OggFLAC__file_encoder_get_max_residual_partition_order()... ");
  859. if(OggFLAC__file_encoder_get_max_residual_partition_order(encoder) != 0) {
  860. printf("FAILED, expected %u, got %un", 0, OggFLAC__file_encoder_get_max_residual_partition_order(encoder));
  861. return false;
  862. }
  863. printf("OKn");
  864. printf("testing OggFLAC__file_encoder_get_rice_parameter_search_dist()... ");
  865. if(OggFLAC__file_encoder_get_rice_parameter_search_dist(encoder) != 0) {
  866. printf("FAILED, expected %u, got %un", 0, OggFLAC__file_encoder_get_rice_parameter_search_dist(encoder));
  867. return false;
  868. }
  869. printf("OKn");
  870. printf("testing OggFLAC__file_encoder_get_total_samples_estimate()... ");
  871. if(OggFLAC__file_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
  872. printf("FAILED, expected %llu, got %llun", streaminfo_.data.stream_info.total_samples, OggFLAC__file_encoder_get_total_samples_estimate(encoder));
  873. return false;
  874. }
  875. printf("OKn");
  876. /* init the dummy sample buffer */
  877. for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
  878. samples[i] = i & 7;
  879. printf("testing OggFLAC__file_encoder_process()... ");
  880. if(!OggFLAC__file_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
  881. return die_f_("returned false", encoder);
  882. printf("OKn");
  883. printf("testing OggFLAC__file_encoder_process_interleaved()... ");
  884. if(!OggFLAC__file_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
  885. return die_f_("returned false", encoder);
  886. printf("OKn");
  887. printf("testing OggFLAC__file_encoder_finish()... ");
  888. OggFLAC__file_encoder_finish(encoder);
  889. printf("OKn");
  890. printf("testing OggFLAC__file_encoder_delete()... ");
  891. OggFLAC__file_encoder_delete(encoder);
  892. printf("OKn");
  893. printf("nPASSED!n");
  894. return true;
  895. }
  896. FLAC__bool test_encoders()
  897. {
  898. init_metadata_blocks_();
  899. if(!test_stream_encoder())
  900. return false;
  901. if(!test_seekable_stream_encoder())
  902. return false;
  903. if(!test_file_encoder())
  904. return false;
  905. (void) grabbag__file_remove_file(oggflacfilename_);
  906. free_metadata_blocks_();
  907. return true;
  908. }