[xiph-cvs] cvs commit: vorbose/src map.c res.c codec.h info.c vorbose.c
Monty
xiphmont at xiph.org
Tue Jul 22 03:48:24 PDT 2003
xiphmont 03/07/22 06:48:24
Modified: src codec.h info.c vorbose.c
Added: src map.c res.c
Log:
Incremental; all header parsing works
Revision Changes Path
1.2 +9 -0 vorbose/src/codec.h
Index: codec.h
===================================================================
RCS file: /usr/local/cvsroot/vorbose/src/codec.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- codec.h 22 Jul 2003 08:24:43 -0000 1.1
+++ codec.h 22 Jul 2003 10:48:24 -0000 1.2
@@ -121,4 +121,13 @@
extern int floor_info_unpack(vorbis_info *vi,oggpack_buffer *opb,
vorbis_info_floor *fi);
+extern int res_unpack(vorbis_info_residue *info,
+ vorbis_info *vi,oggpack_buffer *opb);
+extern int res_inverse(vorbis_info *vi,
+ vorbis_info_residue *info,
+ int *nonzero,int ch,
+ oggpack_buffer *opb);
+
+extern int mapping_info_unpack(vorbis_info_mapping *info,vorbis_info *vi,
+ oggpack_buffer *opb);
<p><p>1.2 +49 -13 vorbose/src/info.c
Index: info.c
===================================================================
RCS file: /usr/local/cvsroot/vorbose/src/info.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- info.c 22 Jul 2003 08:24:43 -0000 1.1
+++ info.c 22 Jul 2003 10:48:24 -0000 1.2
@@ -7,6 +7,7 @@
extern int codebook_p;
extern int headerinfo_p;
extern int warn_p;
+extern int syncp;
/* Header packing/unpacking ********************************************/
@@ -26,6 +27,8 @@
oggpack_read(opb,32,&bitrate_nominal);
oggpack_read(opb,32,&bitrate_lower);
+ vi->channels=channels;
+
oggpack_read(opb,4,&ret);
vi->blocksizes[0]=1<<ret;
oggpack_read(opb,4,&ret);
@@ -194,7 +197,7 @@
printf("info header: Floors: %d\n\n",vi->floors);
for(i=0;i<vi->floors;i++){
if(headerinfo_p)
- printf("info header: Parsing floor %d\n",i);
+ printf("info header: Parsing floor %d ",i);
if(floor_info_unpack(vi,opb,vi->floor_param+i)){
if(warn_p || headerinfo_p)
printf("WARN header: Invalid floor; Vorbis stream not decodable.\n");
@@ -204,34 +207,55 @@
if(headerinfo_p)
printf("\n");
-#if 0
/* residue backend settings */
oggpack_read(opb,6,&ret);
vi->residues=ret+1;
- for(i=0;i<vi->residues;i++)
- if(res_unpack(vi->residue_param+i,vi,opb,print))goto err_out;
+ if(headerinfo_p)
+ printf("info header: Residues: %d\n\n",vi->residues);
+ for(i=0;i<vi->residues;i++){
+ if(headerinfo_p)
+ printf("info header: Parsing residue %d ",i);
+ if(res_unpack(vi->residue_param+i,vi,opb)){
+ if(warn_p || headerinfo_p)
+ printf("WARN header: Invalid residue; Vorbis stream not decodable.\n");
+ goto err_out;
+ }
+ }
+ if(headerinfo_p)
+ printf("\n");
/* map backend settings */
oggpack_read(opb,6,&ret);
vi->maps=ret+1;
+ if(headerinfo_p)
+ printf("info header: Mappings: %d\n\n",vi->maps);
for(i=0;i<vi->maps;i++){
- oggpack_read(opb,16,&ret);
- if(ret!=0){
+ if(headerinfo_p)
+ printf("info header: Parsing mapping %d ",i);
+ if(mapping_info_unpack(vi->map_param+i,vi,opb)){
if(headerinfo_p || warn_p)
- printf("WARN header: Map %d is an illegal type (%lu).\n\n",
+ printf("\nWARN header: Map %d is an illegal type (%lu).\n\n",
i,ret);
goto err_out;
}
- if(mapping_info_unpack(vi->map_param+i,vi,opb,print))goto err_out;
}
+ if(headerinfo_p)
+ printf("\n");
/* mode settings */
oggpack_read(opb,6,&ret);
vi->modes=ret+1;
+ if(headerinfo_p)
+ printf("info header: Modes: %d\n\n",vi->modes);
for(i=0;i<vi->modes;i++){
+ if(headerinfo_p)
+ printf("info header: Parsing mode %d\n",i);
oggpack_read(opb,1,&ret);
if(oggpack_eop(opb))goto eop;
vi->mode_param[i].blockflag=ret;
+ if(headerinfo_p)
+ printf(" block size flag: %lu (%d)\n",
+ ret,vi->blocksizes[ret]);
oggpack_read(opb,16,&ret);
if(ret){
@@ -240,6 +264,9 @@
i,ret);
goto err_out;
}
+ if(headerinfo_p)
+ printf(" window type : 0 (Vorbis window)\n");
+
oggpack_read(opb,16,&ret);
if(ret){
if(headerinfo_p || warn_p)
@@ -247,6 +274,9 @@
i,ret);
goto err_out;
}
+ if(headerinfo_p)
+ printf(" transform type : 0 (MDCT)\n");
+
oggpack_read(opb,8,&ret);
vi->mode_param[i].mapping=ret;
if(vi->mode_param[i].mapping>=vi->maps){
@@ -256,8 +286,13 @@
i,ret,vi->maps-1);
goto err_out;
}
+ if(headerinfo_p)
+ printf(" mapping : %lu\n"
+ " ---------------\n",ret);
}
-#endif
+ if(headerinfo_p)
+ printf("\n");
+
if(oggpack_eop(opb))goto eop;
@@ -293,10 +328,11 @@
temp[4]!='i' ||
temp[5]!='s'){
/* not a vorbis header */
- if(headerinfo_p || warn_p)
- printf("WARN header: Expecting a Vorbis stream header, got\n"
- " some other packet type instead. Stream is not\n"
- " decodable as Vorbis I.\n\n");
+ if(syncp)
+ if(headerinfo_p || warn_p)
+ printf("WARN header: Expecting a Vorbis stream header, got\n"
+ " some other packet type instead. Stream is not\n"
+ " decodable as Vorbis I.\n\n");
return(-1);
}
switch(packtype){
<p><p>1.2 +9 -5 vorbose/src/vorbose.c
Index: vorbose.c
===================================================================
RCS file: /usr/local/cvsroot/vorbose/src/vorbose.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- vorbose.c 22 Jul 2003 08:24:43 -0000 1.1
+++ vorbose.c 22 Jul 2003 10:48:24 -0000 1.2
@@ -61,6 +61,7 @@
int streaminfo_p=0;
int truncpacket_p=0;
int warn_p=0;
+int syncp=1;
int get_data(){
unsigned char *buf;
@@ -163,7 +164,6 @@
int c,long_option_index;
int eof=0;
int vorbiscount=0;
- int syncp=1;
/* get options */
while((c=getopt_long(argc,argv,optstring,options,&long_option_index))!=EOF){
@@ -244,12 +244,16 @@
case 1:
if((streaminfo_p || warn_p || headerinfo_p) && syncp)
printf("WARN stream: next packet is not a valid Vorbis I "
- "comment header as expected.\n\n");
+ "comment header as expected.\n"
+ " Stream is not decodable as "
+ "Vorbis I.\n\n");
break;
case 2:
if((streaminfo_p || warn_p || headerinfo_p) && syncp)
printf("WARN stream: next packet is not a valid Vorbis I "
- "setup header as expected.\n\n");
+ "setup header as expected.\n"
+ " Stream is not decodable as "
+ "Vorbis I.\n\n");
break;
}
@@ -291,8 +295,8 @@
/* initial header pages phase has ended */
if(streaminfo_p || headerinfo_p){
printf("info stream: All identification header pages parsed.\n"
- " %d logical streams muxed in this link.\n\n",
- initialphase);
+ " %d logical stream%s muxed in this link.\n\n",
+ initialphase,(initialphase==1?"":"s"));
if(initialphase>1 && (warn_p || streaminfo_p))
printf("WARN stream: A 'Vorbis I audio stream' must contain uninterleaved\n"
" Vorbis I logical streams only. This is a legal\n"
<p><p>1.1 vorbose/src/map.c
Index: map.c
===================================================================
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ogg2/ogg.h>
#include "codec.h"
extern int codebook_p;
extern int headerinfo_p;
extern int packetinfo_p;
extern int truncpacket_p;
extern int warn_p;
tatic int ilog(unsigned long v){
int ret=0;
if(v)--v;
while(v){
ret++;
v>>=1;
}
return(ret);
}
int mapping_info_unpack(vorbis_info_mapping *info,vorbis_info *vi,
oggpack_buffer *opb){
int i;
unsigned long ret;
memset(info,0,sizeof(*info));
oggpack_read(opb,16,&ret);
if(oggpack_eop(opb))goto eop;
switch(ret){
case 0:
if(headerinfo_p)
printf("(type 0; mono/polyphonic/standard surround)\n");
break;
default:
if(headerinfo_p || warn_p)
printf("\n\nWARN header: Illegal mapping type %lu. Invalid header.\n",
ret);
return 1;
}
if(oggpack_read1(opb)){
oggpack_read(opb,4,&ret);
info->submaps=ret+1;
if(oggpack_eop(opb))goto eop;
if(headerinfo_p)
printf(" multi-submap mapping\n"
" submaps : %d\n",info->submaps);
}else{
info->submaps=1;
if(headerinfo_p)
printf(" single-submap mapping\n"
" submaps : %d\n",info->submaps);
}
if(oggpack_read1(opb)){
oggpack_read(opb,8,&ret);
info->coupling_steps=ret+1;
if(oggpack_eop(opb))goto eop;
if(headerinfo_p)
printf(" channel coupling flag : set\n"
" coupling steps : %d\n",
info->coupling_steps);
for(i=0;i<info->coupling_steps;i++){
unsigned long testM;
unsigned long testA;
oggpack_read(opb,ilog(vi->channels),&testM);
oggpack_read(opb,ilog(vi->channels),&testA);
info->coupling[i].mag=testM;
info->coupling[i].ang=testA;
if(oggpack_eop(opb))goto eop;
if(headerinfo_p)
printf(" coupling step %3d : %lu <-> %lu\n",
i,testM,testA);
if(testM==testA ||
testM>=(unsigned)vi->channels ||
testA>=(unsigned)vi->channels) {
if(headerinfo_p || warn_p){
printf("WARN header: Illegal channel coupling declaration.\n\n");
}
goto err_out;
}
}
}else{
if(headerinfo_p)
printf(" channel coupling flag: not set\n");
}
if(oggpack_read1(opb)){
if(oggpack_eop(opb))goto eop;
if(headerinfo_p || warn_p)
printf("WARN header: Reserved fields not zeroed\n\n");
goto err_out; /* 2:reserved */
}
if(oggpack_read1(opb)){
if(oggpack_eop(opb))goto eop;
if(headerinfo_p || warn_p)
printf("WARN header: Reserved fields not zeroed\n\n");
goto err_out; /* 3:reserved */
}
if(info->submaps>1){
if(headerinfo_p)
printf(" channel->submap list : ");
for(i=0;i<vi->channels;i++){
oggpack_read(opb,4,&ret);
info->chmuxlist[i]=ret;
if(oggpack_eop(opb))goto eop;
if(headerinfo_p)
printf("%d/%lu ",i,ret);
if(info->chmuxlist[i]>=info->submaps){
if(headerinfo_p || warn_p)
printf("\n\nWARN header: Requested submap (%lu) out of range.\n\n",
ret);
goto err_out;
}
}
if(headerinfo_p)
printf("\n");
}
for(i=0;i<info->submaps;i++){
if(headerinfo_p)
printf(" submap %2d config : ",i);
oggpack_read(opb,8,&ret);
oggpack_read(opb,8,&ret);
info->submaplist[i].floor=ret;
if(oggpack_eop(opb))goto eop;
if(headerinfo_p)
printf("floor %lu, ",ret);
if(info->submaplist[i].floor>=vi->floors){
if(headerinfo_p || warn_p)
printf("WARN header: Requested floor (%lu) out of range.\n\n",ret);
goto err_out;
}
oggpack_read(opb,8,&ret);
if(oggpack_eop(opb))goto eop;
info->submaplist[i].residue=ret;
if(headerinfo_p)
printf("res %lu ",ret);
if(info->submaplist[i].residue>=vi->residues){
if(headerinfo_p || warn_p)
printf("WARN header: Requested residue (%lu) out of range.\n\n",ret);
goto err_out;
}
if(headerinfo_p)
printf("\n");
}
if(headerinfo_p)
printf(" ----------------------\n");
return 0;
eop:
if(headerinfo_p || warn_p)
printf("WARN header: Premature EOP while parsing mapping config.\n\n");
err_out:
if(headerinfo_p || warn_p)
printf("WARN header: Invalid mapping.\n\n");
return -1;
}
#if 0
ogg_int16_t mapping_inverse(vorbis_dsp_state *vd,vorbis_info_mapping *info){
vorbis_info *vi=vd->vi;
codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
ogg_int16_t i,j;
ogg_int32_t n=ci->blocksizes[vd->W];
ogg_int32_t **pcmbundle=_ogg_alloc(0,sizeof(*pcmbundle)*vi->channels);
ogg_int16_t *zerobundle=_ogg_alloc(0,sizeof(*zerobundle)*vi->channels);
ogg_int16_t *nonzero=_ogg_alloc(0,sizeof(*nonzero)*vi->channels);
ogg_int32_t **floormemo=_ogg_alloc(0,sizeof(*floormemo)*vi->channels);
/* recover the spectral envelope; store it in the PCM vector for now */
for(i=0;i<vi->channels;i++){
ogg_int16_t submap=0;
ogg_int16_t floorno;
if(info->submaps>1)
submap=info->chmuxlist[i];
floorno=info->submaplist[submap].floor;
if(ci->floor_type[floorno]){
/* floor 1 */
floormemo[i]=_ogg_alloc(0,sizeof(*floormemo[i])*
floor1_memosize(ci->floor_param[floorno]));
floormemo[i]=floor1_inverse1(vd,ci->floor_param[floorno],floormemo[i]);
}else{
/* floor 0 */
floormemo[i]=_ogg_alloc(0,sizeof(*floormemo[i])*
floor0_memosize(ci->floor_param[floorno]));
floormemo[i]=floor0_inverse1(vd,ci->floor_param[floorno],floormemo[i]);
}
if(floormemo[i])
nonzero[i]=1;
else
nonzero[i]=0;
_ogg_bzero(vd->work[i],sizeof(*vd->work[i])*n/2);
}
/* channel coupling can 'dirty' the nonzero listing */
for(i=0;i<info->coupling_steps;i++){
if(nonzero[info->coupling[i].mag] ||
nonzero[info->coupling[i].ang]){
nonzero[info->coupling[i].mag]=1;
nonzero[info->coupling[i].ang]=1;
}
}
/* recover the residue into our working vectors */
for(i=0;i<info->submaps;i++){
ogg_int16_t ch_in_bundle=0;
for(j=0;j<vi->channels;j++){
if(!info->chmuxlist || info->chmuxlist[j]==i){
if(nonzero[j])
zerobundle[ch_in_bundle]=1;
else
zerobundle[ch_in_bundle]=0;
pcmbundle[ch_in_bundle++]=vd->work[j];
}
}
res_inverse(vd,ci->residue_param+info->submaplist[i].residue,
pcmbundle,zerobundle,ch_in_bundle);
}
<p> _analysis("mid",seq,vd->work[0],n/2,0,0);
_analysis("side",seq,vd->work[1],n/2,0,0);
/* channel coupling */
for(i=info->coupling_steps-1;i>=0;i--){
ogg_int32_t *pcmM=vd->work[info->coupling[i].mag];
ogg_int32_t *pcmA=vd->work[info->coupling[i].ang];
for(j=0;j<n/2;j++){
ogg_int32_t mag=pcmM[j];
ogg_int32_t ang=pcmA[j];
if(mag>0)
if(ang>0){
pcmM[j]=mag;
pcmA[j]=mag-ang;
}else{
pcmA[j]=mag;
pcmM[j]=mag+ang;
}
else
if(ang>0){
pcmM[j]=mag;
pcmA[j]=mag+ang;
}else{
pcmA[j]=mag;
pcmM[j]=mag-ang;
}
}
}
_analysis("resL",seq,vd->work[0],n/2,0,0);
_analysis("resR",seq,vd->work[1],n/2,0,0);
/* compute and apply spectral envelope */
for(i=0;i<vi->channels;i++){
ogg_int32_t *pcm=vd->work[i];
ogg_int16_t submap=0;
ogg_int16_t floorno;
if(info->submaps>1)
submap=info->chmuxlist[i];
floorno=info->submaplist[submap].floor;
if(ci->floor_type[floorno]){
/* floor 1 */
floor1_inverse2(vd,ci->floor_param[floorno],floormemo[i],pcm);
}else{
/* floor 0 */
floor0_inverse2(vd,ci->floor_param[floorno],floormemo[i],pcm);
}
}
_analysis("specL",seq,vd->work[0],n/2,1,1);
_analysis("specR",seq++,vd->work[1],n/2,1,1);
/* transform the PCM data; takes PCM vector, vb; modifies PCM vector */
/* only MDCT right now.... */
for(i=0;i<vi->channels;i++)
mdct_backward(n,vd->work[i]);
_ogg_free(pcmbundle); /* need only free the lowest */
/* all done! */
return(0);
}
#endif
<p><p>1.1 vorbose/src/res.c
Index: res.c
===================================================================
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ogg2/ogg.h>
#include "codec.h"
extern int headerinfo_p;
extern int packetinfo_p;
extern int truncpacket_p;
extern int warn_p;
/* vorbis_info is for range checking */
int res_unpack(vorbis_info_residue *info,
vorbis_info *vi,oggpack_buffer *opb){
int j,k;
unsigned long ret;
memset(info,0,sizeof(*info));
oggpack_read(opb,16,&ret);
info->type=ret;
oggpack_read(opb,24,&ret);
info->begin=ret;
oggpack_read(opb,24,&ret);
info->end=ret;
oggpack_read(opb,24,&ret);
info->grouping=ret+1;
oggpack_read(opb,6,&ret);
info->partitions=ret+1;
oggpack_read(opb,8,&ret);
info->groupbook=ret;
if(oggpack_eop(opb))goto eop;
if(info->type>2 || info->type<0){
if(warn_p || headerinfo_p)
printf("WARN header: illegal residue type (%d)\n\n",info->type);
goto errout;
}
if(headerinfo_p){
switch(info->type){
case 0:
printf("(type 0; interleaved values only)\n");
break;
case 1:
printf("(type 1; uninterleaved)\n");
break;
case 2:
printf("(type 2; interleaved channels only)\n");
break;
}
printf(" sample range : %ld through %ld\n"
" partition size : %d\n"
" partition types : %d\n"
" partition book : %d\n",
info->begin,info->end,info->grouping,info->partitions,
info->groupbook);
}
if(info->groupbook>=vi->books){
if(warn_p || headerinfo_p)
printf("WARN header: requested partition book (%d) greater than\n"
" highest numbered available codebook (%d)\n\n",
info->groupbook,vi->books-1);
goto errout;
}
for(j=0;j<info->partitions;j++){
unsigned long cascade;
oggpack_read(opb,3,&cascade);
if(oggpack_read1(opb)){
oggpack_read(opb,5,&ret);
cascade|=(ret<<3);
}
info->stagemasks[j]=cascade;
}
for(j=0;j<info->partitions;j++){
if(headerinfo_p)
printf(" partition %2d books: ",j);
for(k=0;k<8;k++){
if((info->stagemasks[j]>>k)&1){
oggpack_read(opb,8,&ret);
if((signed)ret>=vi->books){
printf("\nWARN header: requested residue book (%lu) greater than\n"
" highest numbered available codebook (%d)\n\n",
ret,vi->books-1);
goto errout;
}
info->stagebooks[j*8+k]=ret;
if(k+1>info->stages)info->stages=k+1;
if(headerinfo_p)
printf("%3d ",(int)ret);
}else{
info->stagebooks[j*8+k]=-1;
if(headerinfo_p)
printf("... ");
}
}
if(headerinfo_p)
printf("\n");
}
if(headerinfo_p)
printf(" ------------------\n");
if(oggpack_eop(opb))goto eop;
return 0;
eop:
if(headerinfo_p || warn_p)
printf("WARN header: Premature EOP while parsing residue.\n\n");
errout:
if(headerinfo_p || warn_p)
printf("WARN header: Invalid residue.\n\n");
return 1;
}
int res_inverse(vorbis_info *vi,
vorbis_info_residue *info,
int *nonzero,int ch,
oggpack_buffer *opb){
long i,j,k,l,s,used=0;
codebook *phrasebook=vi->book_param+info->groupbook;
long samples_per_partition=info->grouping;
long partitions_per_word=phrasebook->dim;
long n=info->end-info->begin;
long partvals=n/samples_per_partition;
long partwords=(partvals+partitions_per_word-1)/partitions_per_word;
int **partword=0;
ogg_int16_t step=n/phrasebook->dim;
if(info->type<2){
for(i=0;i<ch;i++)if(nonzero[i])used++;
ch=used;
if(!used){
if(packetinfo_p)
printf(" zero spectral energy, residue decode skipped\n");
return 0;
}
}else{
for(i=0;i<ch;i++)if(nonzero[i])break;
if(i==ch){
if(packetinfo_p)
printf(" zero spectral energy, residue decode skipped\n");
return 0;
}
ch=1;
}
partword=alloca(ch*sizeof(*partword));
for(j=0;j<ch;j++)
partword[j]=alloca(partwords*partitions_per_word*sizeof(*partword[j]));
for(s=0;s<info->stages;s++){
for(i=0;i<partvals;){
if(s==0){
/* fetch the partition word for each channel */
partword[0][i+partitions_per_word-1]=1;
for(k=partitions_per_word-2;k>=0;k--)
partword[0][i+k]=partword[0][i+k+1]*info->partitions;
for(j=1;j<ch;j++)
for(k=partitions_per_word-1;k>=0;k--)
partword[j][i+k]=partword[j-1][i+k];
for(j=0;j<ch;j++){
ogg_int32_t temp=vorbis_book_decode(phrasebook,opb);
if(oggpack_eop(opb))goto eopbreak1;
/* this can be done quickly in assembly due to the quotient
always being at most six bits */
for(k=0;k<partitions_per_word;k++){
ogg_uint32_t div=partword[j][i+k];
partword[j][i+k]=temp/div;
temp-=partword[j][i+k]*div;
}
}
}
/* now we decode residual values for the partitions */
for(k=0;k<partitions_per_word && i<partvals;k++,i++){
for(j=0;j<ch;j++){
if(info->stagemasks[partword[j][i]]&(1<<s)){
codebook *stagebook=vi->book_param+
info->stagebooks[(partword[j][i]<<3)+s];
for (l=0;l<step;l++)
if(vorbis_book_decode(stagebook,opb))
goto eopbreak1;
}
}
}
}
}
return 0;
eopbreak1:
if(packetinfo_p || truncpacket_p)
printf(" packet truncated in residue decode\n\n");
return 0;
}
<p><p>--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list