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

Windows CE

开发平台:

C/C++

  1. /* test_libFLAC - Unit tester for libFLAC
  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 "FLAC/file_encoder.h"
  23. #include "FLAC/seekable_stream_encoder.h"
  24. #include "FLAC/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_[] = { &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_ };
  31. static const unsigned num_metadata_ = sizeof(metadata_sequence_) / sizeof(metadata_sequence_[0]);
  32. static const char *flacfilename_ = "metadata.flac";
  33. static FLAC__bool die_s_(const char *msg, const FLAC__StreamEncoder *encoder)
  34. {
  35. FLAC__StreamEncoderState state = FLAC__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, FLAC__StreamEncoderStateString[state]);
  41. if(state == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
  42. FLAC__StreamDecoderState dstate = FLAC__stream_encoder_get_verify_decoder_state(encoder);
  43. printf("      verify decoder state = %u (%s)n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
  44. }
  45. return false;
  46. }
  47. static FLAC__bool die_ss_(const char *msg, const FLAC__SeekableStreamEncoder *encoder)
  48. {
  49. FLAC__SeekableStreamEncoderState state = FLAC__seekable_stream_encoder_get_state(encoder);
  50. if(msg)
  51. printf("FAILED, %s", msg);
  52. else
  53. printf("FAILED");
  54. printf(", state = %u (%s)n", (unsigned)state, FLAC__SeekableStreamEncoderStateString[state]);
  55. if(state == FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR) {
  56. FLAC__StreamEncoderState state_ = FLAC__seekable_stream_encoder_get_stream_encoder_state(encoder);
  57. printf("      stream encoder state = %u (%s)n", (unsigned)state_, FLAC__StreamEncoderStateString[state_]);
  58. if(state_ == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
  59. FLAC__StreamDecoderState dstate = FLAC__seekable_stream_encoder_get_verify_decoder_state(encoder);
  60. printf("      verify decoder state = %u (%s)n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
  61. }
  62. }
  63. return false;
  64. }
  65. static FLAC__bool die_f_(const char *msg, const FLAC__FileEncoder *encoder)
  66. {
  67. FLAC__FileEncoderState state = FLAC__file_encoder_get_state(encoder);
  68. if(msg)
  69. printf("FAILED, %s", msg);
  70. else
  71. printf("FAILED");
  72. printf(", state = %u (%s)n", (unsigned)state, FLAC__FileEncoderStateString[state]);
  73. if(state == FLAC__FILE_ENCODER_SEEKABLE_STREAM_ENCODER_ERROR) {
  74. FLAC__SeekableStreamEncoderState state_ = FLAC__file_encoder_get_seekable_stream_encoder_state(encoder);
  75. printf("      seekable stream encoder state = %u (%s)n", (unsigned)state_, FLAC__SeekableStreamEncoderStateString[state_]);
  76. if(state_ == FLAC__SEEKABLE_STREAM_ENCODER_STREAM_ENCODER_ERROR) {
  77. FLAC__StreamEncoderState state__ = FLAC__file_encoder_get_stream_encoder_state(encoder);
  78. printf("      stream encoder state = %u (%s)n", (unsigned)state__, FLAC__StreamEncoderStateString[state__]);
  79. if(state__ == FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR) {
  80. FLAC__StreamDecoderState dstate = FLAC__file_encoder_get_verify_decoder_state(encoder);
  81. printf("      verify decoder state = %u (%s)n", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
  82. }
  83. }
  84. }
  85. return false;
  86. }
  87. static void init_metadata_blocks_()
  88. {
  89. mutils__init_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_);
  90. }
  91. static void free_metadata_blocks_()
  92. {
  93. mutils__free_metadata_blocks(&streaminfo_, &padding_, &seektable_, &application1_, &application2_, &vorbiscomment_, &cuesheet_, &unknown_);
  94. }
  95. static FLAC__StreamEncoderWriteStatus stream_encoder_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)
  96. {
  97. (void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data;
  98. return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
  99. }
  100. static void stream_encoder_metadata_callback_(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data)
  101. {
  102. (void)encoder, (void)metadata, (void)client_data;
  103. }
  104. static FLAC__bool test_stream_encoder()
  105. {
  106. FLAC__StreamEncoder *encoder;
  107. FLAC__StreamEncoderState state;
  108. FLAC__StreamDecoderState dstate;
  109. FLAC__int32 samples[1024];
  110. FLAC__int32 *samples_array[1];
  111. unsigned i;
  112. samples_array[0] = samples;
  113. printf("n+++ libFLAC unit test: FLAC__StreamEncodernn");
  114. printf("testing FLAC__stream_encoder_new()... ");
  115. encoder = FLAC__stream_encoder_new();
  116. if(0 == encoder) {
  117. printf("FAILED, returned NULLn");
  118. return false;
  119. }
  120. printf("OKn");
  121. printf("testing FLAC__stream_encoder_set_verify()... ");
  122. if(!FLAC__stream_encoder_set_verify(encoder, true))
  123. return die_s_("returned false", encoder);
  124. printf("OKn");
  125. printf("testing FLAC__stream_encoder_set_streamable_subset()... ");
  126. if(!FLAC__stream_encoder_set_streamable_subset(encoder, true))
  127. return die_s_("returned false", encoder);
  128. printf("OKn");
  129. printf("testing FLAC__stream_encoder_set_do_mid_side_stereo()... ");
  130. if(!FLAC__stream_encoder_set_do_mid_side_stereo(encoder, false))
  131. return die_s_("returned false", encoder);
  132. printf("OKn");
  133. printf("testing FLAC__stream_encoder_set_loose_mid_side_stereo()... ");
  134. if(!FLAC__stream_encoder_set_loose_mid_side_stereo(encoder, false))
  135. return die_s_("returned false", encoder);
  136. printf("OKn");
  137. printf("testing FLAC__stream_encoder_set_channels()... ");
  138. if(!FLAC__stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
  139. return die_s_("returned false", encoder);
  140. printf("OKn");
  141. printf("testing FLAC__stream_encoder_set_bits_per_sample()... ");
  142. if(!FLAC__stream_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
  143. return die_s_("returned false", encoder);
  144. printf("OKn");
  145. printf("testing FLAC__stream_encoder_set_sample_rate()... ");
  146. if(!FLAC__stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
  147. return die_s_("returned false", encoder);
  148. printf("OKn");
  149. printf("testing FLAC__stream_encoder_set_blocksize()... ");
  150. if(!FLAC__stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
  151. return die_s_("returned false", encoder);
  152. printf("OKn");
  153. printf("testing FLAC__stream_encoder_set_max_lpc_order()... ");
  154. if(!FLAC__stream_encoder_set_max_lpc_order(encoder, 0))
  155. return die_s_("returned false", encoder);
  156. printf("OKn");
  157. printf("testing FLAC__stream_encoder_set_qlp_coeff_precision()... ");
  158. if(!FLAC__stream_encoder_set_qlp_coeff_precision(encoder, 0))
  159. return die_s_("returned false", encoder);
  160. printf("OKn");
  161. printf("testing FLAC__stream_encoder_set_do_qlp_coeff_prec_search()... ");
  162. if(!FLAC__stream_encoder_set_do_qlp_coeff_prec_search(encoder, false))
  163. return die_s_("returned false", encoder);
  164. printf("OKn");
  165. printf("testing FLAC__stream_encoder_set_do_escape_coding()... ");
  166. if(!FLAC__stream_encoder_set_do_escape_coding(encoder, false))
  167. return die_s_("returned false", encoder);
  168. printf("OKn");
  169. printf("testing FLAC__stream_encoder_set_do_exhaustive_model_search()... ");
  170. if(!FLAC__stream_encoder_set_do_exhaustive_model_search(encoder, false))
  171. return die_s_("returned false", encoder);
  172. printf("OKn");
  173. printf("testing FLAC__stream_encoder_set_min_residual_partition_order()... ");
  174. if(!FLAC__stream_encoder_set_min_residual_partition_order(encoder, 0))
  175. return die_s_("returned false", encoder);
  176. printf("OKn");
  177. printf("testing FLAC__stream_encoder_set_max_residual_partition_order()... ");
  178. if(!FLAC__stream_encoder_set_max_residual_partition_order(encoder, 0))
  179. return die_s_("returned false", encoder);
  180. printf("OKn");
  181. printf("testing FLAC__stream_encoder_set_rice_parameter_search_dist()... ");
  182. if(!FLAC__stream_encoder_set_rice_parameter_search_dist(encoder, 0))
  183. return die_s_("returned false", encoder);
  184. printf("OKn");
  185. printf("testing FLAC__stream_encoder_set_total_samples_estimate()... ");
  186. if(!FLAC__stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
  187. return die_s_("returned false", encoder);
  188. printf("OKn");
  189. printf("testing FLAC__stream_encoder_set_metadata()... ");
  190. if(!FLAC__stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
  191. return die_s_("returned false", encoder);
  192. printf("OKn");
  193. printf("testing FLAC__stream_encoder_set_write_callback()... ");
  194. if(!FLAC__stream_encoder_set_write_callback(encoder, stream_encoder_write_callback_))
  195. return die_s_("returned false", encoder);
  196. printf("OKn");
  197. printf("testing FLAC__stream_encoder_set_metadata_callback()... ");
  198. if(!FLAC__stream_encoder_set_metadata_callback(encoder, stream_encoder_metadata_callback_))
  199. return die_s_("returned false", encoder);
  200. printf("OKn");
  201. printf("testing FLAC__stream_encoder_set_client_data()... ");
  202. if(!FLAC__stream_encoder_set_client_data(encoder, 0))
  203. return die_s_("returned false", encoder);
  204. printf("OKn");
  205. printf("testing FLAC__stream_encoder_init()... ");
  206. if(FLAC__stream_encoder_init(encoder) != FLAC__STREAM_ENCODER_OK)
  207. return die_s_(0, encoder);
  208. printf("OKn");
  209. printf("testing FLAC__stream_encoder_get_state()... ");
  210. state = FLAC__stream_encoder_get_state(encoder);
  211. printf("returned state = %u (%s)... OKn", (unsigned)state, FLAC__StreamEncoderStateString[state]);
  212. printf("testing FLAC__stream_encoder_get_verify_decoder_state()... ");
  213. dstate = FLAC__stream_encoder_get_verify_decoder_state(encoder);
  214. printf("returned state = %u (%s)... OKn", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
  215. {
  216. FLAC__uint64 absolute_sample;
  217. unsigned frame_number;
  218. unsigned channel;
  219. unsigned sample;
  220. FLAC__int32 expected;
  221. FLAC__int32 got;
  222. printf("testing FLAC__stream_encoder_get_verify_decoder_error_stats()... ");
  223. FLAC__stream_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
  224. printf("OKn");
  225. }
  226. printf("testing FLAC__stream_encoder_get_verify()... ");
  227. if(FLAC__stream_encoder_get_verify(encoder) != true) {
  228. printf("FAILED, expected true, got falsen");
  229. return false;
  230. }
  231. printf("OKn");
  232. printf("testing FLAC__stream_encoder_get_streamable_subset()... ");
  233. if(FLAC__stream_encoder_get_streamable_subset(encoder) != true) {
  234. printf("FAILED, expected true, got falsen");
  235. return false;
  236. }
  237. printf("OKn");
  238. printf("testing FLAC__stream_encoder_get_do_mid_side_stereo()... ");
  239. if(FLAC__stream_encoder_get_do_mid_side_stereo(encoder) != false) {
  240. printf("FAILED, expected false, got truen");
  241. return false;
  242. }
  243. printf("OKn");
  244. printf("testing FLAC__stream_encoder_get_loose_mid_side_stereo()... ");
  245. if(FLAC__stream_encoder_get_loose_mid_side_stereo(encoder) != false) {
  246. printf("FAILED, expected false, got truen");
  247. return false;
  248. }
  249. printf("OKn");
  250. printf("testing FLAC__stream_encoder_get_channels()... ");
  251. if(FLAC__stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
  252. printf("FAILED, expected %u, got %un", streaminfo_.data.stream_info.channels, FLAC__stream_encoder_get_channels(encoder));
  253. return false;
  254. }
  255. printf("OKn");
  256. printf("testing FLAC__stream_encoder_get_bits_per_sample()... ");
  257. if(FLAC__stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
  258. printf("FAILED, expected %u, got %un", streaminfo_.data.stream_info.bits_per_sample, FLAC__stream_encoder_get_bits_per_sample(encoder));
  259. return false;
  260. }
  261. printf("OKn");
  262. printf("testing FLAC__stream_encoder_get_sample_rate()... ");
  263. if(FLAC__stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
  264. printf("FAILED, expected %u, got %un", streaminfo_.data.stream_info.sample_rate, FLAC__stream_encoder_get_sample_rate(encoder));
  265. return false;
  266. }
  267. printf("OKn");
  268. printf("testing FLAC__stream_encoder_get_blocksize()... ");
  269. if(FLAC__stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
  270. printf("FAILED, expected %u, got %un", streaminfo_.data.stream_info.min_blocksize, FLAC__stream_encoder_get_blocksize(encoder));
  271. return false;
  272. }
  273. printf("OKn");
  274. printf("testing FLAC__stream_encoder_get_max_lpc_order()... ");
  275. if(FLAC__stream_encoder_get_max_lpc_order(encoder) != 0) {
  276. printf("FAILED, expected %u, got %un", 0, FLAC__stream_encoder_get_max_lpc_order(encoder));
  277. return false;
  278. }
  279. printf("OKn");
  280. printf("testing FLAC__stream_encoder_get_qlp_coeff_precision()... ");
  281. (void)FLAC__stream_encoder_get_qlp_coeff_precision(encoder);
  282. /* we asked the encoder to auto select this so we accept anything */
  283. printf("OKn");
  284. printf("testing FLAC__stream_encoder_get_do_qlp_coeff_prec_search()... ");
  285. if(FLAC__stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
  286. printf("FAILED, expected false, got truen");
  287. return false;
  288. }
  289. printf("OKn");
  290. printf("testing FLAC__stream_encoder_get_do_escape_coding()... ");
  291. if(FLAC__stream_encoder_get_do_escape_coding(encoder) != false) {
  292. printf("FAILED, expected false, got truen");
  293. return false;
  294. }
  295. printf("OKn");
  296. printf("testing FLAC__stream_encoder_get_do_exhaustive_model_search()... ");
  297. if(FLAC__stream_encoder_get_do_exhaustive_model_search(encoder) != false) {
  298. printf("FAILED, expected false, got truen");
  299. return false;
  300. }
  301. printf("OKn");
  302. printf("testing FLAC__stream_encoder_get_min_residual_partition_order()... ");
  303. if(FLAC__stream_encoder_get_min_residual_partition_order(encoder) != 0) {
  304. printf("FAILED, expected %u, got %un", 0, FLAC__stream_encoder_get_min_residual_partition_order(encoder));
  305. return false;
  306. }
  307. printf("OKn");
  308. printf("testing FLAC__stream_encoder_get_max_residual_partition_order()... ");
  309. if(FLAC__stream_encoder_get_max_residual_partition_order(encoder) != 0) {
  310. printf("FAILED, expected %u, got %un", 0, FLAC__stream_encoder_get_max_residual_partition_order(encoder));
  311. return false;
  312. }
  313. printf("OKn");
  314. printf("testing FLAC__stream_encoder_get_rice_parameter_search_dist()... ");
  315. if(FLAC__stream_encoder_get_rice_parameter_search_dist(encoder) != 0) {
  316. printf("FAILED, expected %u, got %un", 0, FLAC__stream_encoder_get_rice_parameter_search_dist(encoder));
  317. return false;
  318. }
  319. printf("OKn");
  320. printf("testing FLAC__stream_encoder_get_total_samples_estimate()... ");
  321. if(FLAC__stream_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
  322. printf("FAILED, expected %llu, got %llun", streaminfo_.data.stream_info.total_samples, FLAC__stream_encoder_get_total_samples_estimate(encoder));
  323. return false;
  324. }
  325. printf("OKn");
  326. /* init the dummy sample buffer */
  327. for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
  328. samples[i] = i & 7;
  329. printf("testing FLAC__stream_encoder_process()... ");
  330. if(!FLAC__stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
  331. return die_s_("returned false", encoder);
  332. printf("OKn");
  333. printf("testing FLAC__stream_encoder_process_interleaved()... ");
  334. if(!FLAC__stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
  335. return die_s_("returned false", encoder);
  336. printf("OKn");
  337. printf("testing FLAC__stream_encoder_finish()... ");
  338. FLAC__stream_encoder_finish(encoder);
  339. printf("OKn");
  340. printf("testing FLAC__stream_encoder_delete()... ");
  341. FLAC__stream_encoder_delete(encoder);
  342. printf("OKn");
  343. printf("nPASSED!n");
  344. return true;
  345. }
  346. FLAC__SeekableStreamEncoderSeekStatus seekable_stream_encoder_seek_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  347. {
  348. (void)encoder, (void)absolute_byte_offset, (void)client_data;
  349. return FLAC__SEEKABLE_STREAM_ENCODER_SEEK_STATUS_OK;
  350. }
  351. FLAC__SeekableStreamEncoderTellStatus seekable_stream_encoder_tell_callback_(const FLAC__SeekableStreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  352. {
  353. (void)encoder, (void)client_data;
  354. *absolute_byte_offset = 0;
  355. return FLAC__SEEKABLE_STREAM_ENCODER_TELL_STATUS_OK;
  356. }
  357. FLAC__StreamEncoderWriteStatus seekable_stream_encoder_write_callback_(const FLAC__SeekableStreamEncoder *encoder, const FLAC__byte buffer[], unsigned bytes, unsigned samples, unsigned current_frame, void *client_data)
  358. {
  359. (void)encoder, (void)buffer, (void)bytes, (void)samples, (void)current_frame, (void)client_data;
  360. return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
  361. }
  362. static FLAC__bool test_seekable_stream_encoder()
  363. {
  364. FLAC__SeekableStreamEncoder *encoder;
  365. FLAC__SeekableStreamEncoderState state;
  366. FLAC__StreamEncoderState state_;
  367. FLAC__StreamDecoderState dstate;
  368. FLAC__int32 samples[1024];
  369. FLAC__int32 *samples_array[1];
  370. unsigned i;
  371. samples_array[0] = samples;
  372. printf("n+++ libFLAC unit test: FLAC__SeekableStreamEncodernn");
  373. printf("testing FLAC__seekable_stream_encoder_new()... ");
  374. encoder = FLAC__seekable_stream_encoder_new();
  375. if(0 == encoder) {
  376. printf("FAILED, returned NULLn");
  377. return false;
  378. }
  379. printf("OKn");
  380. printf("testing FLAC__seekable_stream_encoder_set_verify()... ");
  381. if(!FLAC__seekable_stream_encoder_set_verify(encoder, true))
  382. return die_ss_("returned false", encoder);
  383. printf("OKn");
  384. printf("testing FLAC__seekable_stream_encoder_set_streamable_subset()... ");
  385. if(!FLAC__seekable_stream_encoder_set_streamable_subset(encoder, true))
  386. return die_ss_("returned false", encoder);
  387. printf("OKn");
  388. printf("testing FLAC__seekable_stream_encoder_set_do_mid_side_stereo()... ");
  389. if(!FLAC__seekable_stream_encoder_set_do_mid_side_stereo(encoder, false))
  390. return die_ss_("returned false", encoder);
  391. printf("OKn");
  392. printf("testing FLAC__seekable_stream_encoder_set_loose_mid_side_stereo()... ");
  393. if(!FLAC__seekable_stream_encoder_set_loose_mid_side_stereo(encoder, false))
  394. return die_ss_("returned false", encoder);
  395. printf("OKn");
  396. printf("testing FLAC__seekable_stream_encoder_set_channels()... ");
  397. if(!FLAC__seekable_stream_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
  398. return die_ss_("returned false", encoder);
  399. printf("OKn");
  400. printf("testing FLAC__seekable_stream_encoder_set_bits_per_sample()... ");
  401. if(!FLAC__seekable_stream_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
  402. return die_ss_("returned false", encoder);
  403. printf("OKn");
  404. printf("testing FLAC__seekable_stream_encoder_set_sample_rate()... ");
  405. if(!FLAC__seekable_stream_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
  406. return die_ss_("returned false", encoder);
  407. printf("OKn");
  408. printf("testing FLAC__seekable_stream_encoder_set_blocksize()... ");
  409. if(!FLAC__seekable_stream_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
  410. return die_ss_("returned false", encoder);
  411. printf("OKn");
  412. printf("testing FLAC__seekable_stream_encoder_set_max_lpc_order()... ");
  413. if(!FLAC__seekable_stream_encoder_set_max_lpc_order(encoder, 0))
  414. return die_ss_("returned false", encoder);
  415. printf("OKn");
  416. printf("testing FLAC__seekable_stream_encoder_set_qlp_coeff_precision()... ");
  417. if(!FLAC__seekable_stream_encoder_set_qlp_coeff_precision(encoder, 0))
  418. return die_ss_("returned false", encoder);
  419. printf("OKn");
  420. printf("testing FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search()... ");
  421. if(!FLAC__seekable_stream_encoder_set_do_qlp_coeff_prec_search(encoder, false))
  422. return die_ss_("returned false", encoder);
  423. printf("OKn");
  424. printf("testing FLAC__seekable_stream_encoder_set_do_escape_coding()... ");
  425. if(!FLAC__seekable_stream_encoder_set_do_escape_coding(encoder, false))
  426. return die_ss_("returned false", encoder);
  427. printf("OKn");
  428. printf("testing FLAC__seekable_stream_encoder_set_do_exhaustive_model_search()... ");
  429. if(!FLAC__seekable_stream_encoder_set_do_exhaustive_model_search(encoder, false))
  430. return die_ss_("returned false", encoder);
  431. printf("OKn");
  432. printf("testing FLAC__seekable_stream_encoder_set_min_residual_partition_order()... ");
  433. if(!FLAC__seekable_stream_encoder_set_min_residual_partition_order(encoder, 0))
  434. return die_ss_("returned false", encoder);
  435. printf("OKn");
  436. printf("testing FLAC__seekable_stream_encoder_set_max_residual_partition_order()... ");
  437. if(!FLAC__seekable_stream_encoder_set_max_residual_partition_order(encoder, 0))
  438. return die_ss_("returned false", encoder);
  439. printf("OKn");
  440. printf("testing FLAC__seekable_stream_encoder_set_rice_parameter_search_dist()... ");
  441. if(!FLAC__seekable_stream_encoder_set_rice_parameter_search_dist(encoder, 0))
  442. return die_ss_("returned false", encoder);
  443. printf("OKn");
  444. printf("testing FLAC__seekable_stream_encoder_set_total_samples_estimate()... ");
  445. if(!FLAC__seekable_stream_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
  446. return die_ss_("returned false", encoder);
  447. printf("OKn");
  448. printf("testing FLAC__seekable_stream_encoder_set_metadata()... ");
  449. if(!FLAC__seekable_stream_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
  450. return die_ss_("returned false", encoder);
  451. printf("OKn");
  452. printf("testing FLAC__seekable_stream_encoder_set_seek_callback()... ");
  453. if(!FLAC__seekable_stream_encoder_set_seek_callback(encoder, seekable_stream_encoder_seek_callback_))
  454. return die_ss_("returned false", encoder);
  455. printf("OKn");
  456. printf("testing FLAC__seekable_stream_encoder_set_tell_callback()... ");
  457. if(!FLAC__seekable_stream_encoder_set_tell_callback(encoder, seekable_stream_encoder_tell_callback_))
  458. return die_ss_("returned false", encoder);
  459. printf("OKn");
  460. printf("testing FLAC__seekable_stream_encoder_set_write_callback()... ");
  461. if(!FLAC__seekable_stream_encoder_set_write_callback(encoder, seekable_stream_encoder_write_callback_))
  462. return die_ss_("returned false", encoder);
  463. printf("OKn");
  464. printf("testing FLAC__seekable_stream_encoder_set_client_data()... ");
  465. if(!FLAC__seekable_stream_encoder_set_client_data(encoder, 0))
  466. return die_ss_("returned false", encoder);
  467. printf("OKn");
  468. printf("testing FLAC__seekable_stream_encoder_init()... ");
  469. if(FLAC__seekable_stream_encoder_init(encoder) != FLAC__SEEKABLE_STREAM_ENCODER_OK)
  470. return die_ss_(0, encoder);
  471. printf("OKn");
  472. printf("testing FLAC__seekable_stream_encoder_get_state()... ");
  473. state = FLAC__seekable_stream_encoder_get_state(encoder);
  474. printf("returned state = %u (%s)... OKn", (unsigned)state, FLAC__SeekableStreamEncoderStateString[state]);
  475. printf("testing FLAC__seekable_stream_encoder_get_stream_encoder_state()... ");
  476. state_ = FLAC__seekable_stream_encoder_get_stream_encoder_state(encoder);
  477. printf("returned state = %u (%s)... OKn", (unsigned)state_, FLAC__StreamEncoderStateString[state_]);
  478. printf("testing FLAC__seekable_stream_encoder_get_verify_decoder_state()... ");
  479. dstate = FLAC__seekable_stream_encoder_get_verify_decoder_state(encoder);
  480. printf("returned state = %u (%s)... OKn", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
  481. {
  482. FLAC__uint64 absolute_sample;
  483. unsigned frame_number;
  484. unsigned channel;
  485. unsigned sample;
  486. FLAC__int32 expected;
  487. FLAC__int32 got;
  488. printf("testing FLAC__seekable_stream_encoder_get_verify_decoder_error_stats()... ");
  489. FLAC__seekable_stream_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
  490. printf("OKn");
  491. }
  492. printf("testing FLAC__seekable_stream_encoder_get_verify()... ");
  493. if(FLAC__seekable_stream_encoder_get_verify(encoder) != true) {
  494. printf("FAILED, expected true, got falsen");
  495. return false;
  496. }
  497. printf("OKn");
  498. printf("testing FLAC__seekable_stream_encoder_get_streamable_subset()... ");
  499. if(FLAC__seekable_stream_encoder_get_streamable_subset(encoder) != true) {
  500. printf("FAILED, expected true, got falsen");
  501. return false;
  502. }
  503. printf("OKn");
  504. printf("testing FLAC__seekable_stream_encoder_get_do_mid_side_stereo()... ");
  505. if(FLAC__seekable_stream_encoder_get_do_mid_side_stereo(encoder) != false) {
  506. printf("FAILED, expected false, got truen");
  507. return false;
  508. }
  509. printf("OKn");
  510. printf("testing FLAC__seekable_stream_encoder_get_loose_mid_side_stereo()... ");
  511. if(FLAC__seekable_stream_encoder_get_loose_mid_side_stereo(encoder) != false) {
  512. printf("FAILED, expected false, got truen");
  513. return false;
  514. }
  515. printf("OKn");
  516. printf("testing FLAC__seekable_stream_encoder_get_channels()... ");
  517. if(FLAC__seekable_stream_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
  518. printf("FAILED, expected %u, got %un", streaminfo_.data.stream_info.channels, FLAC__seekable_stream_encoder_get_channels(encoder));
  519. return false;
  520. }
  521. printf("OKn");
  522. printf("testing FLAC__seekable_stream_encoder_get_bits_per_sample()... ");
  523. if(FLAC__seekable_stream_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
  524. printf("FAILED, expected %u, got %un", streaminfo_.data.stream_info.bits_per_sample, FLAC__seekable_stream_encoder_get_bits_per_sample(encoder));
  525. return false;
  526. }
  527. printf("OKn");
  528. printf("testing FLAC__seekable_stream_encoder_get_sample_rate()... ");
  529. if(FLAC__seekable_stream_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
  530. printf("FAILED, expected %u, got %un", streaminfo_.data.stream_info.sample_rate, FLAC__seekable_stream_encoder_get_sample_rate(encoder));
  531. return false;
  532. }
  533. printf("OKn");
  534. printf("testing FLAC__seekable_stream_encoder_get_blocksize()... ");
  535. if(FLAC__seekable_stream_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
  536. printf("FAILED, expected %u, got %un", streaminfo_.data.stream_info.min_blocksize, FLAC__seekable_stream_encoder_get_blocksize(encoder));
  537. return false;
  538. }
  539. printf("OKn");
  540. printf("testing FLAC__seekable_stream_encoder_get_max_lpc_order()... ");
  541. if(FLAC__seekable_stream_encoder_get_max_lpc_order(encoder) != 0) {
  542. printf("FAILED, expected %u, got %un", 0, FLAC__seekable_stream_encoder_get_max_lpc_order(encoder));
  543. return false;
  544. }
  545. printf("OKn");
  546. printf("testing FLAC__seekable_stream_encoder_get_qlp_coeff_precision()... ");
  547. (void)FLAC__seekable_stream_encoder_get_qlp_coeff_precision(encoder);
  548. /* we asked the encoder to auto select this so we accept anything */
  549. printf("OKn");
  550. printf("testing FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search()... ");
  551. if(FLAC__seekable_stream_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
  552. printf("FAILED, expected false, got truen");
  553. return false;
  554. }
  555. printf("OKn");
  556. printf("testing FLAC__seekable_stream_encoder_get_do_escape_coding()... ");
  557. if(FLAC__seekable_stream_encoder_get_do_escape_coding(encoder) != false) {
  558. printf("FAILED, expected false, got truen");
  559. return false;
  560. }
  561. printf("OKn");
  562. printf("testing FLAC__seekable_stream_encoder_get_do_exhaustive_model_search()... ");
  563. if(FLAC__seekable_stream_encoder_get_do_exhaustive_model_search(encoder) != false) {
  564. printf("FAILED, expected false, got truen");
  565. return false;
  566. }
  567. printf("OKn");
  568. printf("testing FLAC__seekable_stream_encoder_get_min_residual_partition_order()... ");
  569. if(FLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder) != 0) {
  570. printf("FAILED, expected %u, got %un", 0, FLAC__seekable_stream_encoder_get_min_residual_partition_order(encoder));
  571. return false;
  572. }
  573. printf("OKn");
  574. printf("testing FLAC__seekable_stream_encoder_get_max_residual_partition_order()... ");
  575. if(FLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder) != 0) {
  576. printf("FAILED, expected %u, got %un", 0, FLAC__seekable_stream_encoder_get_max_residual_partition_order(encoder));
  577. return false;
  578. }
  579. printf("OKn");
  580. printf("testing FLAC__seekable_stream_encoder_get_rice_parameter_search_dist()... ");
  581. if(FLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder) != 0) {
  582. printf("FAILED, expected %u, got %un", 0, FLAC__seekable_stream_encoder_get_rice_parameter_search_dist(encoder));
  583. return false;
  584. }
  585. printf("OKn");
  586. printf("testing FLAC__seekable_stream_encoder_get_total_samples_estimate()... ");
  587. if(FLAC__seekable_stream_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
  588. printf("FAILED, expected %llu, got %llun", streaminfo_.data.stream_info.total_samples, FLAC__seekable_stream_encoder_get_total_samples_estimate(encoder));
  589. return false;
  590. }
  591. printf("OKn");
  592. /* init the dummy sample buffer */
  593. for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
  594. samples[i] = i & 7;
  595. printf("testing FLAC__seekable_stream_encoder_process()... ");
  596. if(!FLAC__seekable_stream_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
  597. return die_ss_("returned false", encoder);
  598. printf("OKn");
  599. printf("testing FLAC__seekable_stream_encoder_process_interleaved()... ");
  600. if(!FLAC__seekable_stream_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
  601. return die_ss_("returned false", encoder);
  602. printf("OKn");
  603. printf("testing FLAC__seekable_stream_encoder_finish()... ");
  604. FLAC__seekable_stream_encoder_finish(encoder);
  605. printf("OKn");
  606. printf("testing FLAC__seekable_stream_encoder_delete()... ");
  607. FLAC__seekable_stream_encoder_delete(encoder);
  608. printf("OKn");
  609. printf("nPASSED!n");
  610. return true;
  611. }
  612. static void file_encoder_progress_callback_(const FLAC__FileEncoder *encoder, FLAC__uint64 bytes_written, FLAC__uint64 samples_written, unsigned frames_written, unsigned total_frames_estimate, void *client_data)
  613. {
  614. (void)encoder, (void)bytes_written, (void)samples_written, (void)frames_written, (void)total_frames_estimate, (void)client_data;
  615. }
  616. static FLAC__bool test_file_encoder()
  617. {
  618. FLAC__FileEncoder *encoder;
  619. FLAC__FileEncoderState state;
  620. FLAC__SeekableStreamEncoderState state_;
  621. FLAC__StreamEncoderState state__;
  622. FLAC__StreamDecoderState dstate;
  623. FLAC__int32 samples[1024];
  624. FLAC__int32 *samples_array[1];
  625. unsigned i;
  626. samples_array[0] = samples;
  627. printf("n+++ libFLAC unit test: FLAC__FileEncodernn");
  628. printf("testing FLAC__file_encoder_new()... ");
  629. encoder = FLAC__file_encoder_new();
  630. if(0 == encoder) {
  631. printf("FAILED, returned NULLn");
  632. return false;
  633. }
  634. printf("OKn");
  635. printf("testing FLAC__file_encoder_set_verify()... ");
  636. if(!FLAC__file_encoder_set_verify(encoder, true))
  637. return die_f_("returned false", encoder);
  638. printf("OKn");
  639. printf("testing FLAC__file_encoder_set_streamable_subset()... ");
  640. if(!FLAC__file_encoder_set_streamable_subset(encoder, true))
  641. return die_f_("returned false", encoder);
  642. printf("OKn");
  643. printf("testing FLAC__file_encoder_set_do_mid_side_stereo()... ");
  644. if(!FLAC__file_encoder_set_do_mid_side_stereo(encoder, false))
  645. return die_f_("returned false", encoder);
  646. printf("OKn");
  647. printf("testing FLAC__file_encoder_set_loose_mid_side_stereo()... ");
  648. if(!FLAC__file_encoder_set_loose_mid_side_stereo(encoder, false))
  649. return die_f_("returned false", encoder);
  650. printf("OKn");
  651. printf("testing FLAC__file_encoder_set_channels()... ");
  652. if(!FLAC__file_encoder_set_channels(encoder, streaminfo_.data.stream_info.channels))
  653. return die_f_("returned false", encoder);
  654. printf("OKn");
  655. printf("testing FLAC__file_encoder_set_bits_per_sample()... ");
  656. if(!FLAC__file_encoder_set_bits_per_sample(encoder, streaminfo_.data.stream_info.bits_per_sample))
  657. return die_f_("returned false", encoder);
  658. printf("OKn");
  659. printf("testing FLAC__file_encoder_set_sample_rate()... ");
  660. if(!FLAC__file_encoder_set_sample_rate(encoder, streaminfo_.data.stream_info.sample_rate))
  661. return die_f_("returned false", encoder);
  662. printf("OKn");
  663. printf("testing FLAC__file_encoder_set_blocksize()... ");
  664. if(!FLAC__file_encoder_set_blocksize(encoder, streaminfo_.data.stream_info.min_blocksize))
  665. return die_f_("returned false", encoder);
  666. printf("OKn");
  667. printf("testing FLAC__file_encoder_set_max_lpc_order()... ");
  668. if(!FLAC__file_encoder_set_max_lpc_order(encoder, 0))
  669. return die_f_("returned false", encoder);
  670. printf("OKn");
  671. printf("testing FLAC__file_encoder_set_qlp_coeff_precision()... ");
  672. if(!FLAC__file_encoder_set_qlp_coeff_precision(encoder, 0))
  673. return die_f_("returned false", encoder);
  674. printf("OKn");
  675. printf("testing FLAC__file_encoder_set_do_qlp_coeff_prec_search()... ");
  676. if(!FLAC__file_encoder_set_do_qlp_coeff_prec_search(encoder, false))
  677. return die_f_("returned false", encoder);
  678. printf("OKn");
  679. printf("testing FLAC__file_encoder_set_do_escape_coding()... ");
  680. if(!FLAC__file_encoder_set_do_escape_coding(encoder, false))
  681. return die_f_("returned false", encoder);
  682. printf("OKn");
  683. printf("testing FLAC__file_encoder_set_do_exhaustive_model_search()... ");
  684. if(!FLAC__file_encoder_set_do_exhaustive_model_search(encoder, false))
  685. return die_f_("returned false", encoder);
  686. printf("OKn");
  687. printf("testing FLAC__file_encoder_set_min_residual_partition_order()... ");
  688. if(!FLAC__file_encoder_set_min_residual_partition_order(encoder, 0))
  689. return die_f_("returned false", encoder);
  690. printf("OKn");
  691. printf("testing FLAC__file_encoder_set_max_residual_partition_order()... ");
  692. if(!FLAC__file_encoder_set_max_residual_partition_order(encoder, 0))
  693. return die_f_("returned false", encoder);
  694. printf("OKn");
  695. printf("testing FLAC__file_encoder_set_rice_parameter_search_dist()... ");
  696. if(!FLAC__file_encoder_set_rice_parameter_search_dist(encoder, 0))
  697. return die_f_("returned false", encoder);
  698. printf("OKn");
  699. printf("testing FLAC__file_encoder_set_total_samples_estimate()... ");
  700. if(!FLAC__file_encoder_set_total_samples_estimate(encoder, streaminfo_.data.stream_info.total_samples))
  701. return die_f_("returned false", encoder);
  702. printf("OKn");
  703. printf("testing FLAC__file_encoder_set_metadata()... ");
  704. if(!FLAC__file_encoder_set_metadata(encoder, metadata_sequence_, num_metadata_))
  705. return die_f_("returned false", encoder);
  706. printf("OKn");
  707. printf("testing FLAC__file_encoder_set_filename()... ");
  708. if(!FLAC__file_encoder_set_filename(encoder, flacfilename_))
  709. return die_f_("returned false", encoder);
  710. printf("OKn");
  711. printf("testing FLAC__file_encoder_set_progress_callback()... ");
  712. if(!FLAC__file_encoder_set_progress_callback(encoder, file_encoder_progress_callback_))
  713. return die_f_("returned false", encoder);
  714. printf("OKn");
  715. printf("testing FLAC__file_encoder_set_client_data()... ");
  716. if(!FLAC__file_encoder_set_client_data(encoder, 0))
  717. return die_f_("returned false", encoder);
  718. printf("OKn");
  719. printf("testing FLAC__file_encoder_init()... ");
  720. if(FLAC__file_encoder_init(encoder) != FLAC__FILE_ENCODER_OK)
  721. return die_f_(0, encoder);
  722. printf("OKn");
  723. printf("testing FLAC__file_encoder_get_state()... ");
  724. state = FLAC__file_encoder_get_state(encoder);
  725. printf("returned state = %u (%s)... OKn", (unsigned)state, FLAC__FileEncoderStateString[state]);
  726. printf("testing FLAC__file_encoder_get_seekable_stream_encoder_state()... ");
  727. state_ = FLAC__file_encoder_get_seekable_stream_encoder_state(encoder);
  728. printf("returned state = %u (%s)... OKn", (unsigned)state_, FLAC__SeekableStreamEncoderStateString[state_]);
  729. printf("testing FLAC__file_encoder_get_stream_encoder_state()... ");
  730. state__ = FLAC__file_encoder_get_stream_encoder_state(encoder);
  731. printf("returned state = %u (%s)... OKn", (unsigned)state__, FLAC__StreamEncoderStateString[state__]);
  732. printf("testing FLAC__file_encoder_get_verify_decoder_state()... ");
  733. dstate = FLAC__file_encoder_get_verify_decoder_state(encoder);
  734. printf("returned state = %u (%s)... OKn", (unsigned)dstate, FLAC__StreamDecoderStateString[dstate]);
  735. {
  736. FLAC__uint64 absolute_sample;
  737. unsigned frame_number;
  738. unsigned channel;
  739. unsigned sample;
  740. FLAC__int32 expected;
  741. FLAC__int32 got;
  742. printf("testing FLAC__file_encoder_get_verify_decoder_error_stats()... ");
  743. FLAC__file_encoder_get_verify_decoder_error_stats(encoder, &absolute_sample, &frame_number, &channel, &sample, &expected, &got);
  744. printf("OKn");
  745. }
  746. printf("testing FLAC__file_encoder_get_verify()... ");
  747. if(FLAC__file_encoder_get_verify(encoder) != true) {
  748. printf("FAILED, expected true, got falsen");
  749. return false;
  750. }
  751. printf("OKn");
  752. printf("testing FLAC__file_encoder_get_streamable_subset()... ");
  753. if(FLAC__file_encoder_get_streamable_subset(encoder) != true) {
  754. printf("FAILED, expected true, got falsen");
  755. return false;
  756. }
  757. printf("OKn");
  758. printf("testing FLAC__file_encoder_get_do_mid_side_stereo()... ");
  759. if(FLAC__file_encoder_get_do_mid_side_stereo(encoder) != false) {
  760. printf("FAILED, expected false, got truen");
  761. return false;
  762. }
  763. printf("OKn");
  764. printf("testing FLAC__file_encoder_get_loose_mid_side_stereo()... ");
  765. if(FLAC__file_encoder_get_loose_mid_side_stereo(encoder) != false) {
  766. printf("FAILED, expected false, got truen");
  767. return false;
  768. }
  769. printf("OKn");
  770. printf("testing FLAC__file_encoder_get_channels()... ");
  771. if(FLAC__file_encoder_get_channels(encoder) != streaminfo_.data.stream_info.channels) {
  772. printf("FAILED, expected %u, got %un", streaminfo_.data.stream_info.channels, FLAC__file_encoder_get_channels(encoder));
  773. return false;
  774. }
  775. printf("OKn");
  776. printf("testing FLAC__file_encoder_get_bits_per_sample()... ");
  777. if(FLAC__file_encoder_get_bits_per_sample(encoder) != streaminfo_.data.stream_info.bits_per_sample) {
  778. printf("FAILED, expected %u, got %un", streaminfo_.data.stream_info.bits_per_sample, FLAC__file_encoder_get_bits_per_sample(encoder));
  779. return false;
  780. }
  781. printf("OKn");
  782. printf("testing FLAC__file_encoder_get_sample_rate()... ");
  783. if(FLAC__file_encoder_get_sample_rate(encoder) != streaminfo_.data.stream_info.sample_rate) {
  784. printf("FAILED, expected %u, got %un", streaminfo_.data.stream_info.sample_rate, FLAC__file_encoder_get_sample_rate(encoder));
  785. return false;
  786. }
  787. printf("OKn");
  788. printf("testing FLAC__file_encoder_get_blocksize()... ");
  789. if(FLAC__file_encoder_get_blocksize(encoder) != streaminfo_.data.stream_info.min_blocksize) {
  790. printf("FAILED, expected %u, got %un", streaminfo_.data.stream_info.min_blocksize, FLAC__file_encoder_get_blocksize(encoder));
  791. return false;
  792. }
  793. printf("OKn");
  794. printf("testing FLAC__file_encoder_get_max_lpc_order()... ");
  795. if(FLAC__file_encoder_get_max_lpc_order(encoder) != 0) {
  796. printf("FAILED, expected %u, got %un", 0, FLAC__file_encoder_get_max_lpc_order(encoder));
  797. return false;
  798. }
  799. printf("OKn");
  800. printf("testing FLAC__file_encoder_get_qlp_coeff_precision()... ");
  801. (void)FLAC__file_encoder_get_qlp_coeff_precision(encoder);
  802. /* we asked the encoder to auto select this so we accept anything */
  803. printf("OKn");
  804. printf("testing FLAC__file_encoder_get_do_qlp_coeff_prec_search()... ");
  805. if(FLAC__file_encoder_get_do_qlp_coeff_prec_search(encoder) != false) {
  806. printf("FAILED, expected false, got truen");
  807. return false;
  808. }
  809. printf("OKn");
  810. printf("testing FLAC__file_encoder_get_do_escape_coding()... ");
  811. if(FLAC__file_encoder_get_do_escape_coding(encoder) != false) {
  812. printf("FAILED, expected false, got truen");
  813. return false;
  814. }
  815. printf("OKn");
  816. printf("testing FLAC__file_encoder_get_do_exhaustive_model_search()... ");
  817. if(FLAC__file_encoder_get_do_exhaustive_model_search(encoder) != false) {
  818. printf("FAILED, expected false, got truen");
  819. return false;
  820. }
  821. printf("OKn");
  822. printf("testing FLAC__file_encoder_get_min_residual_partition_order()... ");
  823. if(FLAC__file_encoder_get_min_residual_partition_order(encoder) != 0) {
  824. printf("FAILED, expected %u, got %un", 0, FLAC__file_encoder_get_min_residual_partition_order(encoder));
  825. return false;
  826. }
  827. printf("OKn");
  828. printf("testing FLAC__file_encoder_get_max_residual_partition_order()... ");
  829. if(FLAC__file_encoder_get_max_residual_partition_order(encoder) != 0) {
  830. printf("FAILED, expected %u, got %un", 0, FLAC__file_encoder_get_max_residual_partition_order(encoder));
  831. return false;
  832. }
  833. printf("OKn");
  834. printf("testing FLAC__file_encoder_get_rice_parameter_search_dist()... ");
  835. if(FLAC__file_encoder_get_rice_parameter_search_dist(encoder) != 0) {
  836. printf("FAILED, expected %u, got %un", 0, FLAC__file_encoder_get_rice_parameter_search_dist(encoder));
  837. return false;
  838. }
  839. printf("OKn");
  840. printf("testing FLAC__file_encoder_get_total_samples_estimate()... ");
  841. if(FLAC__file_encoder_get_total_samples_estimate(encoder) != streaminfo_.data.stream_info.total_samples) {
  842. printf("FAILED, expected %llu, got %llun", streaminfo_.data.stream_info.total_samples, FLAC__file_encoder_get_total_samples_estimate(encoder));
  843. return false;
  844. }
  845. printf("OKn");
  846. /* init the dummy sample buffer */
  847. for(i = 0; i < sizeof(samples) / sizeof(FLAC__int32); i++)
  848. samples[i] = i & 7;
  849. printf("testing FLAC__file_encoder_process()... ");
  850. if(!FLAC__file_encoder_process(encoder, (const FLAC__int32 * const *)samples_array, sizeof(samples) / sizeof(FLAC__int32)))
  851. return die_f_("returned false", encoder);
  852. printf("OKn");
  853. printf("testing FLAC__file_encoder_process_interleaved()... ");
  854. if(!FLAC__file_encoder_process_interleaved(encoder, samples, sizeof(samples) / sizeof(FLAC__int32)))
  855. return die_f_("returned false", encoder);
  856. printf("OKn");
  857. printf("testing FLAC__file_encoder_finish()... ");
  858. FLAC__file_encoder_finish(encoder);
  859. printf("OKn");
  860. printf("testing FLAC__file_encoder_delete()... ");
  861. FLAC__file_encoder_delete(encoder);
  862. printf("OKn");
  863. printf("nPASSED!n");
  864. return true;
  865. }
  866. FLAC__bool test_encoders()
  867. {
  868. init_metadata_blocks_();
  869. if(!test_stream_encoder())
  870. return false;
  871. if(!test_seekable_stream_encoder())
  872. return false;
  873. if(!test_file_encoder())
  874. return false;
  875. (void) grabbag__file_remove_file(flacfilename_);
  876. free_metadata_blocks_();
  877. return true;
  878. }