PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/cdex1/tags/CDEX130B2/cdexos/vorbis/include/vorbis/codec.h

#
C++ Header | 440 lines | 255 code | 80 blank | 105 comment | 0 complexity | 1b50407f074689cc6a6d9b23b61a5fbe MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, LGPL-2.0, BSD-3-Clause, AGPL-1.0, CC-BY-SA-3.0, GPL-3.0
  1. /********************************************************************
  2. * *
  3. * THIS FILE IS PART OF THE Ogg Vorbis SOFTWARE CODEC SOURCE CODE. *
  4. * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
  5. * THE GNU PUBLIC LICENSE 2, WHICH IS INCLUDED WITH THIS SOURCE. *
  6. * PLEASE READ THESE TERMS DISTRIBUTING. *
  7. * *
  8. * THE OggSQUISH SOURCE CODE IS (C) COPYRIGHT 1994-2000 *
  9. * by Monty <monty@xiph.org> and The XIPHOPHORUS Company *
  10. * http://www.xiph.org/ *
  11. * *
  12. ********************************************************************
  13. function: libvorbis codec headers
  14. last mod: $Id: codec.h 97 2000-08-07 23:58:05Z afaber $
  15. ********************************************************************/
  16. #ifndef _vorbis_codec_h_
  17. #define _vorbis_codec_h_
  18. #ifdef __cplusplus
  19. extern "C"
  20. {
  21. #endif /* __cplusplus */
  22. #define MAX_BARK 27
  23. #include <sys/types.h>
  24. #include "os_types.h"
  25. #include "vorbis/codebook.h"
  26. #include "vorbis/internal.h"
  27. typedef void vorbis_look_transform;
  28. typedef void vorbis_info_time;
  29. typedef void vorbis_look_time;
  30. typedef void vorbis_info_floor;
  31. typedef void vorbis_look_floor;
  32. typedef void vorbis_echstate_floor;
  33. typedef void vorbis_info_residue;
  34. typedef void vorbis_look_residue;
  35. typedef void vorbis_info_mapping;
  36. typedef void vorbis_look_mapping;
  37. /* mode ************************************************************/
  38. typedef struct {
  39. int blockflag;
  40. int windowtype;
  41. int transformtype;
  42. int mapping;
  43. } vorbis_info_mode;
  44. /* psychoacoustic setup ********************************************/
  45. typedef struct vorbis_info_psy{
  46. int athp;
  47. int decayp;
  48. int smoothp;
  49. int noisefitp;
  50. int noisefit_subblock;
  51. double noisefit_threshdB;
  52. double ath_att;
  53. int tonemaskp;
  54. double toneatt_125Hz[5];
  55. double toneatt_250Hz[5];
  56. double toneatt_500Hz[5];
  57. double toneatt_1000Hz[5];
  58. double toneatt_2000Hz[5];
  59. double toneatt_4000Hz[5];
  60. double toneatt_8000Hz[5];
  61. int peakattp;
  62. double peakatt_125Hz[5];
  63. double peakatt_250Hz[5];
  64. double peakatt_500Hz[5];
  65. double peakatt_1000Hz[5];
  66. double peakatt_2000Hz[5];
  67. double peakatt_4000Hz[5];
  68. double peakatt_8000Hz[5];
  69. int noisemaskp;
  70. double noiseatt_125Hz[5];
  71. double noiseatt_250Hz[5];
  72. double noiseatt_500Hz[5];
  73. double noiseatt_1000Hz[5];
  74. double noiseatt_2000Hz[5];
  75. double noiseatt_4000Hz[5];
  76. double noiseatt_8000Hz[5];
  77. double max_curve_dB;
  78. double attack_coeff;
  79. double decay_coeff;
  80. } vorbis_info_psy;
  81. /* vorbis_info contains all the setup information specific to the
  82. specific compression/decompression mode in progress (eg,
  83. psychoacoustic settings, channel setup, options, codebook
  84. etc).
  85. *********************************************************************/
  86. typedef struct vorbis_info{
  87. int version;
  88. int channels;
  89. long rate;
  90. /* The below bitrate declarations are *hints*.
  91. Combinations of the three values carry the following implications:
  92. all three set to the same value:
  93. implies a fixed rate bitstream
  94. only nominal set:
  95. implies a VBR stream that averages the nominal bitrate. No hard
  96. upper/lower limit
  97. upper and or lower set:
  98. implies a VBR bitstream that obeys the bitrate limits. nominal
  99. may also be set to give a nominal rate.
  100. none set:
  101. the coder does not care to speculate.
  102. */
  103. long bitrate_upper;
  104. long bitrate_nominal;
  105. long bitrate_lower;
  106. /* Vorbis supports only short and long blocks, but allows the
  107. encoder to choose the sizes */
  108. long blocksizes[2];
  109. /* modes are the primary means of supporting on-the-fly different
  110. blocksizes, different channel mappings (LR or mid-side),
  111. different residue backends, etc. Each mode consists of a
  112. blocksize flag and a mapping (along with the mapping setup */
  113. int modes;
  114. int maps;
  115. int times;
  116. int floors;
  117. int residues;
  118. int books;
  119. int psys; /* encode only */
  120. vorbis_info_mode *mode_param[64];
  121. int map_type[64];
  122. vorbis_info_mapping *map_param[64];
  123. int time_type[64];
  124. vorbis_info_time *time_param[64];
  125. int floor_type[64];
  126. vorbis_info_floor *floor_param[64];
  127. int residue_type[64];
  128. vorbis_info_residue *residue_param[64];
  129. static_codebook *book_param[256];
  130. vorbis_info_psy *psy_param[64]; /* encode only */
  131. /* for block long/sort tuning; encode only */
  132. int envelopesa;
  133. double preecho_thresh;
  134. double preecho_clamp;
  135. } vorbis_info;
  136. /* ogg_page is used to encapsulate the data in one Ogg bitstream page *****/
  137. typedef struct {
  138. unsigned char *header;
  139. long header_len;
  140. unsigned char *body;
  141. long body_len;
  142. } ogg_page;
  143. /* ogg_stream_state contains the current encode/decode state of a logical
  144. Ogg bitstream **********************************************************/
  145. typedef struct {
  146. unsigned char *body_data; /* bytes from packet bodies */
  147. long body_storage; /* storage elements allocated */
  148. long body_fill; /* elements stored; fill mark */
  149. long body_returned; /* elements of fill returned */
  150. int *lacing_vals; /* The values that will go to the segment table */
  151. int64_t *pcm_vals; /* pcm_pos values for headers. Not compact
  152. this way, but it is simple coupled to the
  153. lacing fifo */
  154. long lacing_storage;
  155. long lacing_fill;
  156. long lacing_packet;
  157. long lacing_returned;
  158. unsigned char header[282]; /* working space for header encode */
  159. int header_fill;
  160. int e_o_s; /* set when we have buffered the last packet in the
  161. logical bitstream */
  162. int b_o_s; /* set after we've written the initial page
  163. of a logical bitstream */
  164. long serialno;
  165. int pageno;
  166. int64_t packetno; /* sequence number for decode; the framing
  167. knows where there's a hole in the data,
  168. but we need coupling so that the codec
  169. (which is in a seperate abstraction
  170. layer) also knows about the gap */
  171. int64_t pcmpos;
  172. } ogg_stream_state;
  173. /* ogg_packet is used to encapsulate the data and metadata belonging
  174. to a single raw Ogg/Vorbis packet *************************************/
  175. typedef struct {
  176. unsigned char *packet;
  177. long bytes;
  178. long b_o_s;
  179. long e_o_s;
  180. int64_t frameno;
  181. int64_t packetno; /* sequence number for decode; the framing
  182. knows where there's a hole in the data,
  183. but we need coupling so that the codec
  184. (which is in a seperate abstraction
  185. layer) also knows about the gap */
  186. } ogg_packet;
  187. typedef struct {
  188. unsigned char *data;
  189. int storage;
  190. int fill;
  191. int returned;
  192. int unsynced;
  193. int headerbytes;
  194. int bodybytes;
  195. } ogg_sync_state;
  196. /* vorbis_dsp_state buffers the current vorbis audio
  197. analysis/synthesis state. The DSP state belongs to a specific
  198. logical bitstream ****************************************************/
  199. typedef struct vorbis_dsp_state{
  200. int analysisp;
  201. vorbis_info *vi;
  202. int modebits;
  203. double **pcm;
  204. double **pcmret;
  205. int pcm_storage;
  206. int pcm_current;
  207. int pcm_returned;
  208. int eofflag;
  209. long lW;
  210. long W;
  211. long nW;
  212. long centerW;
  213. int64_t frameno;
  214. int64_t sequence;
  215. int64_t glue_bits;
  216. int64_t time_bits;
  217. int64_t floor_bits;
  218. int64_t res_bits;
  219. /* local lookup storage */
  220. void *ve; /* envelope lookup */
  221. double **window[2][2][2]; /* block, leadin, leadout, type */
  222. vorbis_look_transform **transform[2]; /* block, type */
  223. codebook *fullbooks;
  224. /* backend lookups are tied to the mode, not the backend or naked mapping */
  225. vorbis_look_mapping **mode;
  226. /* local storage, only used on the encoding side. This way the
  227. application does not need to worry about freeing some packets'
  228. memory and not others'; packet storage is always tracked.
  229. Cleared next call to a _dsp_ function */
  230. unsigned char *header;
  231. unsigned char *header1;
  232. unsigned char *header2;
  233. } vorbis_dsp_state;
  234. /* vorbis_block is a single block of data to be processed as part of
  235. the analysis/synthesis stream; it belongs to a specific logical
  236. bitstream, but is independant from other vorbis_blocks belonging to
  237. that logical bitstream. *************************************************/
  238. struct alloc_chain{
  239. void *ptr;
  240. struct alloc_chain *next;
  241. };
  242. typedef struct vorbis_block{
  243. /* necessary stream state for linking to the framing abstraction */
  244. double **pcm; /* this is a pointer into local storage */
  245. oggpack_buffer opb;
  246. long lW;
  247. long W;
  248. long nW;
  249. int pcmend;
  250. int mode;
  251. int eofflag;
  252. int64_t frameno;
  253. int64_t sequence;
  254. vorbis_dsp_state *vd; /* For read-only access of configuration */
  255. /* local storage to avoid remallocing; it's up to the mapping to
  256. structure it */
  257. void *localstore;
  258. long localtop;
  259. long localalloc;
  260. long totaluse;
  261. struct alloc_chain *reap;
  262. /* bitmetrics for the frame */
  263. long glue_bits;
  264. long time_bits;
  265. long floor_bits;
  266. long res_bits;
  267. } vorbis_block;
  268. #include "vorbis/backends.h"
  269. /* vorbis_info contains all the setup information specific to the
  270. specific compression/decompression mode in progress (eg,
  271. psychoacoustic settings, channel setup, options, codebook
  272. etc). vorbis_info and substructures are in backends.h.
  273. *********************************************************************/
  274. /* the comments are not part of vorbis_info so that vorbis_info can be
  275. static storage */
  276. typedef struct vorbis_comment{
  277. /* unlimited user comment fields. libvorbis writes 'libvorbis'
  278. whatever vendor is set to in encode */
  279. char **user_comments;
  280. int *comment_lengths;
  281. int comments;
  282. char *vendor;
  283. } vorbis_comment;
  284. /* libvorbis encodes in two abstraction layers; first we perform DSP
  285. and produce a packet (see docs/analysis.txt). The packet is then
  286. coded into a framed OggSquish bitstream by the second layer (see
  287. docs/framing.txt). Decode is the reverse process; we sync/frame
  288. the bitstream and extract individual packets, then decode the
  289. packet back into PCM audio.
  290. The extra framing/packetizing is used in streaming formats, such as
  291. files. Over the net (such as with UDP), the framing and
  292. packetization aren't necessary as they're provided by the transport
  293. and the streaming layer is not used */
  294. /* OggSquish BITSREAM PRIMITIVES: encoding **************************/
  295. extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
  296. extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
  297. extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
  298. /* OggSquish BITSREAM PRIMITIVES: decoding **************************/
  299. extern int ogg_sync_init(ogg_sync_state *oy);
  300. extern int ogg_sync_clear(ogg_sync_state *oy);
  301. extern int ogg_sync_destroy(ogg_sync_state *oy);
  302. extern int ogg_sync_reset(ogg_sync_state *oy);
  303. extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
  304. extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
  305. extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
  306. extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
  307. extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
  308. extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
  309. /* OggSquish BITSREAM PRIMITIVES: general ***************************/
  310. extern int ogg_stream_init(ogg_stream_state *os,int serialno);
  311. extern int ogg_stream_clear(ogg_stream_state *os);
  312. extern int ogg_stream_reset(ogg_stream_state *os);
  313. extern int ogg_stream_destroy(ogg_stream_state *os);
  314. extern int ogg_stream_eof(ogg_stream_state *os);
  315. extern int ogg_page_version(ogg_page *og);
  316. extern int ogg_page_continued(ogg_page *og);
  317. extern int ogg_page_bos(ogg_page *og);
  318. extern int ogg_page_eos(ogg_page *og);
  319. extern int64_t ogg_page_frameno(ogg_page *og);
  320. extern int ogg_page_serialno(ogg_page *og);
  321. extern int ogg_page_pageno(ogg_page *og);
  322. /* Vorbis PRIMITIVES: general ***************************************/
  323. extern void vorbis_info_init(vorbis_info *vi);
  324. extern void vorbis_info_clear(vorbis_info *vi);
  325. extern void vorbis_comment_init(vorbis_comment *vc);
  326. extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
  327. extern void vorbis_comment_add_tag(vorbis_comment *vc,
  328. char *tag, char *contents);
  329. extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
  330. extern void vorbis_comment_clear(vorbis_comment *vc);
  331. extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
  332. extern int vorbis_block_clear(vorbis_block *vb);
  333. extern void vorbis_dsp_clear(vorbis_dsp_state *v);
  334. /* Vorbis PRIMITIVES: analysis/DSP layer ****************************/
  335. extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
  336. extern int vorbis_analysis_headerout(vorbis_dsp_state *v,
  337. vorbis_comment *vc,
  338. ogg_packet *op,
  339. ogg_packet *op_comm,
  340. ogg_packet *op_code);
  341. extern double **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
  342. extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
  343. extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
  344. extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
  345. /* Vorbis PRIMITIVES: synthesis layer *******************************/
  346. extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
  347. ogg_packet *op);
  348. extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
  349. extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
  350. extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
  351. extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,double ***pcm);
  352. extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
  353. #ifdef __cplusplus
  354. }
  355. #endif /* __cplusplus */
  356. #endif