diff options
author | Sean Bartell <wingedtachikoma@gmail.com> | 2011-06-25 21:32:25 -0400 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2012-04-25 22:13:20 +0200 |
commit | f40bfc9267b13b54e6379dfe7539447662879d24 (patch) | |
tree | 9b20069d5e62809ff434061ad730096836f916f2 /lib/rbcodec/codecs/libtremor/synthesis.c | |
parent | a0009907de7a0107d49040d8a180f140e2eff299 (diff) | |
download | rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.tar.gz rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.zip |
Add codecs to librbcodec.
Change-Id: Id7f4717d51ed02d67cb9f9cb3c0ada4a81843f97
Reviewed-on: http://gerrit.rockbox.org/137
Reviewed-by: Nils Wallménius <nils@rockbox.org>
Tested-by: Nils Wallménius <nils@rockbox.org>
Diffstat (limited to 'lib/rbcodec/codecs/libtremor/synthesis.c')
-rw-r--r-- | lib/rbcodec/codecs/libtremor/synthesis.c | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libtremor/synthesis.c b/lib/rbcodec/codecs/libtremor/synthesis.c new file mode 100644 index 0000000000..d1ef99ae37 --- /dev/null +++ b/lib/rbcodec/codecs/libtremor/synthesis.c | |||
@@ -0,0 +1,129 @@ | |||
1 | /******************************************************************** | ||
2 | * * | ||
3 | * THIS FILE IS PART OF THE OggVorbis 'TREMOR' CODEC SOURCE CODE. * | ||
4 | * * | ||
5 | * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * | ||
6 | * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * | ||
7 | * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * | ||
8 | * * | ||
9 | * THE OggVorbis 'TREMOR' SOURCE CODE IS (C) COPYRIGHT 1994-2003 * | ||
10 | * BY THE Xiph.Org FOUNDATION http://www.xiph.org/ * | ||
11 | * * | ||
12 | ******************************************************************** | ||
13 | |||
14 | function: single-block PCM synthesis | ||
15 | last mod: $Id$ | ||
16 | |||
17 | ********************************************************************/ | ||
18 | |||
19 | #include <stdio.h> | ||
20 | #include "ogg.h" | ||
21 | #include "ivorbiscodec.h" | ||
22 | #include "codec_internal.h" | ||
23 | #include "registry.h" | ||
24 | #include "misc.h" | ||
25 | #include "os.h" | ||
26 | |||
27 | |||
28 | static inline int _vorbis_synthesis1(vorbis_block *vb,ogg_packet *op,int decodep){ | ||
29 | vorbis_dsp_state *vd= vb ? vb->vd : 0; | ||
30 | private_state *b= vd ? (private_state *)vd->backend_state: 0; | ||
31 | vorbis_info *vi= vd ? vd->vi : 0; | ||
32 | codec_setup_info *ci= vi ? (codec_setup_info *)vi->codec_setup : 0; | ||
33 | oggpack_buffer *opb=vb ? &vb->opb : 0; | ||
34 | int type,mode; | ||
35 | |||
36 | if (!vd || !b || !vi || !ci || !opb) { | ||
37 | return OV_EBADPACKET; | ||
38 | } | ||
39 | |||
40 | /* first things first. Make sure decode is ready */ | ||
41 | _vorbis_block_ripcord(vb); | ||
42 | oggpack_readinit(opb,op->packet,op->bytes); | ||
43 | |||
44 | /* Check the packet type */ | ||
45 | if(oggpack_read(opb,1)!=0){ | ||
46 | /* Oops. This is not an audio data packet */ | ||
47 | return(OV_ENOTAUDIO); | ||
48 | } | ||
49 | |||
50 | /* read our mode and pre/post windowsize */ | ||
51 | mode=oggpack_read(opb,b->modebits); | ||
52 | if(mode==-1)return(OV_EBADPACKET); | ||
53 | |||
54 | vb->mode=mode; | ||
55 | if(!ci->mode_param[mode]){ | ||
56 | return(OV_EBADPACKET); | ||
57 | } | ||
58 | |||
59 | vb->W=ci->mode_param[mode]->blockflag; | ||
60 | if(vb->W){ | ||
61 | vb->lW=oggpack_read(opb,1); | ||
62 | vb->nW=oggpack_read(opb,1); | ||
63 | if(vb->nW==-1) return(OV_EBADPACKET); | ||
64 | }else{ | ||
65 | vb->lW=0; | ||
66 | vb->nW=0; | ||
67 | } | ||
68 | |||
69 | /* more setup */ | ||
70 | vb->granulepos=op->granulepos; | ||
71 | vb->sequence=op->packetno-3; /* first block is third packet */ | ||
72 | vb->eofflag=op->e_o_s; | ||
73 | |||
74 | if(decodep && vi->channels<=CHANNELS) | ||
75 | { | ||
76 | /* set pcm end point */ | ||
77 | vb->pcmend=ci->blocksizes[vb->W]; | ||
78 | |||
79 | /* unpack_header enforces range checking */ | ||
80 | type=ci->map_type[ci->mode_param[mode]->mapping]; | ||
81 | return(_mapping_P[type]->inverse(vb,b->mode[mode])); | ||
82 | }else{ | ||
83 | /* no pcm */ | ||
84 | vb->pcmend=0; | ||
85 | return(0); | ||
86 | } | ||
87 | } | ||
88 | |||
89 | int vorbis_synthesis(vorbis_block *vb,ogg_packet *op) | ||
90 | ICODE_ATTR_TREMOR_NOT_MDCT; | ||
91 | int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){ | ||
92 | return _vorbis_synthesis1(vb,op,1); | ||
93 | } | ||
94 | |||
95 | /* used to track pcm position without actually performing decode. | ||
96 | Useful for sequential 'fast forward' */ | ||
97 | int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){ | ||
98 | return _vorbis_synthesis1(vb,op,0); | ||
99 | } | ||
100 | |||
101 | long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){ | ||
102 | codec_setup_info *ci=(codec_setup_info *)vi->codec_setup; | ||
103 | oggpack_buffer opb; | ||
104 | int mode; | ||
105 | |||
106 | oggpack_readinit(&opb,op->packet,op->bytes); | ||
107 | |||
108 | /* Check the packet type */ | ||
109 | if(oggpack_read(&opb,1)!=0){ | ||
110 | /* Oops. This is not an audio data packet */ | ||
111 | return(OV_ENOTAUDIO); | ||
112 | } | ||
113 | |||
114 | { | ||
115 | int modebits=0; | ||
116 | int v=ci->modes; | ||
117 | while(v>1){ | ||
118 | modebits++; | ||
119 | v>>=1; | ||
120 | } | ||
121 | |||
122 | /* read our mode and pre/post windowsize */ | ||
123 | mode=oggpack_read(&opb,modebits); | ||
124 | } | ||
125 | if(mode==-1)return(OV_EBADPACKET); | ||
126 | return(ci->blocksizes[ci->mode_param[mode]->blockflag]); | ||
127 | } | ||
128 | |||
129 | |||