mirror of
https://gitee.com/openharmony/third_party_libsnd
synced 2025-02-17 01:20:02 +00:00
src/VORBIS : Sync to SVN, including addition of test suite, hook into build.
This commit is contained in:
parent
c166e0dc72
commit
a43ca08f9b
@ -84,3 +84,4 @@ tests/sfversion
|
||||
tests/utils.c
|
||||
tests/utils.h
|
||||
tests/write_read_test.c
|
||||
src/VORBIS/test/test
|
||||
|
@ -620,7 +620,8 @@ AC_CONFIG_FILES([ \
|
||||
src/VORBIS/Makefile src/VORBIS/lib/Makefile src/VORBIS/include/Makefile \
|
||||
src/VORBIS/include/vorbis/Makefile src/VORBIS/lib/modes/Makefile \
|
||||
src/VORBIS/lib/books/floor/Makefile src/VORBIS/lib/books/coupled/Makefile \
|
||||
src/VORBIS/lib/books/uncoupled/Makefile src/VORBIS/lib/books/Makefile
|
||||
src/VORBIS/lib/books/uncoupled/Makefile src/VORBIS/lib/books/Makefile \
|
||||
src/VORBIS/test/Makefile \
|
||||
\
|
||||
src/OGG/include/ogg/Makefile src/OGG/include/Makefile src/OGG/Makefile \
|
||||
man/Makefile examples/Makefile tests/Makefile regtest/Makefile \
|
||||
|
@ -1,6 +1,6 @@
|
||||
## Process this file with automake to produce Makefile.in
|
||||
|
||||
SUBDIRS = lib include
|
||||
SUBDIRS = lib include test
|
||||
|
||||
EXTRA_DIST = CHANGES COPYING
|
||||
|
||||
|
@ -403,7 +403,7 @@ float **vorbis_analysis_buffer(vorbis_dsp_state *v, int vals){
|
||||
|
||||
static void _preextrapolate_helper(vorbis_dsp_state *v){
|
||||
int i;
|
||||
int order=32;
|
||||
int order=16;
|
||||
float *lpc=alloca(order*sizeof(*lpc));
|
||||
float *work=alloca(v->pcm_current*sizeof(*work));
|
||||
long j;
|
||||
@ -417,7 +417,18 @@ static void _preextrapolate_helper(vorbis_dsp_state *v){
|
||||
|
||||
/* prime as above */
|
||||
vorbis_lpc_from_data(work,lpc,v->pcm_current-v->centerW,order);
|
||||
|
||||
|
||||
#if 0
|
||||
if(v->vi->channels==2){
|
||||
if(i==0)
|
||||
_analysis_output("predataL",0,work,v->pcm_current-v->centerW,0,0,0);
|
||||
else
|
||||
_analysis_output("predataR",0,work,v->pcm_current-v->centerW,0,0,0);
|
||||
}else{
|
||||
_analysis_output("predata",0,work,v->pcm_current-v->centerW,0,0,0);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* run the predictor filter */
|
||||
vorbis_lpc_predict(lpc,work+v->pcm_current-v->centerW-order,
|
||||
order,
|
||||
|
@ -11,7 +11,7 @@
|
||||
********************************************************************
|
||||
|
||||
function: LPC low level routines
|
||||
last mod: $Id: lpc.c 13293 2007-07-24 00:09:47Z xiphmont $
|
||||
last mod: $Id: lpc.c 13657 2007-08-30 02:40:29Z xiphmont $
|
||||
|
||||
********************************************************************/
|
||||
|
||||
@ -62,6 +62,7 @@ float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
|
||||
double *aut=alloca(sizeof(*aut)*(m+1));
|
||||
double *lpc=alloca(sizeof(*lpc)*(m));
|
||||
double error;
|
||||
double epsilon;
|
||||
int i,j;
|
||||
|
||||
/* autocorrelation, p+1 lag coefficients */
|
||||
@ -74,14 +75,16 @@ float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
|
||||
|
||||
/* Generate lpc coefficients from autocorr values */
|
||||
|
||||
error=aut[0];
|
||||
|
||||
/* set our noise floor to about -100dB */
|
||||
error=aut[0] * (1. + 1e-10);
|
||||
epsilon=1e-9*aut[0]+1e-10;
|
||||
|
||||
for(i=0;i<m;i++){
|
||||
double r= -aut[i+1];
|
||||
|
||||
if(error==0){
|
||||
memset(lpci,0,m*sizeof(*lpci));
|
||||
return 0;
|
||||
if(error<epsilon){
|
||||
memset(lpc+i,0,(m-i)*sizeof(*lpc));
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Sum up this iteration's reflection coefficient; note that in
|
||||
@ -101,9 +104,22 @@ float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
|
||||
lpc[j]+=r*lpc[i-1-j];
|
||||
lpc[i-1-j]+=r*tmp;
|
||||
}
|
||||
if(i%2)lpc[j]+=lpc[j]*r;
|
||||
if(i&1)lpc[j]+=lpc[j]*r;
|
||||
|
||||
error*=1.f-r*r;
|
||||
error*=1.-r*r;
|
||||
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
/* slightly damp the filter */
|
||||
{
|
||||
double g = .99;
|
||||
double damp = g;
|
||||
for(j=0;j<m;j++){
|
||||
lpc[j]*=damp;
|
||||
damp*=g;
|
||||
}
|
||||
}
|
||||
|
||||
for(j=0;j<m;j++)lpci[j]=(float)lpc[j];
|
||||
|
@ -11,7 +11,7 @@
|
||||
********************************************************************
|
||||
|
||||
function: channel mapping 0 implementation
|
||||
last mod: $Id: mapping0.c 13578 2007-08-20 10:44:04Z erikd $
|
||||
last mod: $Id: mapping0.c 13657 2007-08-30 02:40:29Z xiphmont $
|
||||
|
||||
********************************************************************/
|
||||
|
||||
@ -280,22 +280,28 @@ static int mapping0_forward(vorbis_block *vb){
|
||||
next major model upgrade. */
|
||||
|
||||
#if 0
|
||||
if(vi->channels==2)
|
||||
if(vi->channels==2){
|
||||
if(i==0)
|
||||
_analysis_output("pcmL",seq,pcm,n,0,0,total-n/2);
|
||||
else
|
||||
_analysis_output("pcmR",seq,pcm,n,0,0,total-n/2);
|
||||
}else{
|
||||
_analysis_output("pcm",seq,pcm,n,0,0,total-n/2);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* window the PCM data */
|
||||
_vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
|
||||
|
||||
#if 0
|
||||
if(vi->channels==2)
|
||||
if(vi->channels==2){
|
||||
if(i==0)
|
||||
_analysis_output("windowedL",seq,pcm,n,0,0,total-n/2);
|
||||
else
|
||||
_analysis_output("windowedR",seq,pcm,n,0,0,total-n/2);
|
||||
}else{
|
||||
_analysis_output("windowed",seq,pcm,n,0,0,total-n/2);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* transform the PCM data */
|
||||
@ -349,6 +355,8 @@ static int mapping0_forward(vorbis_block *vb){
|
||||
}else{
|
||||
_analysis_output("fftR",seq,logfft,n/2,1,0,0);
|
||||
}
|
||||
}else{
|
||||
_analysis_output("fft",seq,logfft,n/2,1,0,0);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -419,6 +427,8 @@ static int mapping0_forward(vorbis_block *vb){
|
||||
_analysis_output("noiseL",seq,noise,n/2,1,0,0);
|
||||
else
|
||||
_analysis_output("noiseR",seq,noise,n/2,1,0,0);
|
||||
}else{
|
||||
_analysis_output("noise",seq,noise,n/2,1,0,0);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -438,6 +448,8 @@ static int mapping0_forward(vorbis_block *vb){
|
||||
_analysis_output("toneL",seq,tone,n/2,1,0,0);
|
||||
else
|
||||
_analysis_output("toneR",seq,tone,n/2,1,0,0);
|
||||
}else{
|
||||
_analysis_output("tone",seq,tone,n/2,1,0,0);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -465,6 +477,8 @@ static int mapping0_forward(vorbis_block *vb){
|
||||
_analysis_output("aotuvM1_L",seq,aotuv,psy_look->n,1,1,0);
|
||||
else
|
||||
_analysis_output("aotuvM1_R",seq,aotuv,psy_look->n,1,1,0);
|
||||
}else{
|
||||
_analysis_output("aotuvM1",seq,aotuv,psy_look->n,1,1,0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -476,6 +490,8 @@ static int mapping0_forward(vorbis_block *vb){
|
||||
_analysis_output("mask1L",seq,logmask,n/2,1,0,0);
|
||||
else
|
||||
_analysis_output("mask1R",seq,logmask,n/2,1,0,0);
|
||||
}else{
|
||||
_analysis_output("mask1",seq,logmask,n/2,1,0,0);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -508,6 +524,8 @@ static int mapping0_forward(vorbis_block *vb){
|
||||
_analysis_output("mask2L",seq,logmask,n/2,1,0,0);
|
||||
else
|
||||
_analysis_output("mask2R",seq,logmask,n/2,1,0,0);
|
||||
}else{
|
||||
_analysis_output("mask2",seq,logmask,n/2,1,0,0);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -526,11 +544,14 @@ static int mapping0_forward(vorbis_block *vb){
|
||||
logmdct);
|
||||
|
||||
#if 0
|
||||
if(vi->channels==2)
|
||||
if(vi->channels==2){
|
||||
if(i==0)
|
||||
_analysis_output("mask0L",seq,logmask,n/2,1,0,0);
|
||||
else
|
||||
_analysis_output("mask0R",seq,logmask,n/2,1,0,0);
|
||||
}else{
|
||||
_analysis_output("mask0",seq,logmask,n/2,1,0,0);
|
||||
}
|
||||
#endif
|
||||
|
||||
floor_posts[i][0]=
|
||||
|
@ -11,7 +11,7 @@
|
||||
********************************************************************
|
||||
|
||||
function: 16kHz settings
|
||||
last mod: $Id: setup_16.h 13293 2007-07-24 00:09:47Z xiphmont $
|
||||
last mod: $Id: setup_16.h 13651 2007-08-29 11:25:58Z xiphmont $
|
||||
|
||||
********************************************************************/
|
||||
|
||||
@ -116,7 +116,7 @@ ve_setup_data_template ve_setup_16_uncoupled={
|
||||
_vp_tonemask_adj_16,
|
||||
_vp_tonemask_adj_16,
|
||||
|
||||
_psy_noiseguards_8,
|
||||
_psy_noiseguards_16,
|
||||
_psy_noisebias_16_impulse,
|
||||
_psy_noisebias_16_short,
|
||||
_psy_noisebias_16_short,
|
||||
|
@ -21,6 +21,11 @@
|
||||
#include <math.h>
|
||||
#include "os.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
/* MS Visual Studio doesn't have C99 inline keyword. */
|
||||
#define inline __inline
|
||||
#endif
|
||||
|
||||
/* 20log10(x) */
|
||||
#define VORBIS_IEEE_FLOAT32 1
|
||||
#ifdef VORBIS_IEEE_FLOAT32
|
||||
|
20
src/VORBIS/test/Makefile.am
Normal file
20
src/VORBIS/test/Makefile.am
Normal file
@ -0,0 +1,20 @@
|
||||
## Process this file with automake to produce Makefile.in
|
||||
|
||||
AUTOMAKE_OPTIONS = foreign
|
||||
|
||||
INCLUDES = -I$(top_srcdir)/src/VORBIS/include -I$(top_srcdir)/src/OGG/include
|
||||
|
||||
noinst_PROGRAMS = test
|
||||
|
||||
test_SOURCES = util.c util.h write_read.c write_read.h test.c
|
||||
test_LDADD = ../lib/libvorbisenc.la ../lib/libvorbis.la $(top_builddir)/src/OGG/libogg.la
|
||||
|
||||
debug:
|
||||
$(MAKE) all CFLAGS="@DEBUG@"
|
||||
|
||||
profile:
|
||||
$(MAKE) all CFLAGS="@PROFILE@"
|
||||
|
||||
check: test
|
||||
./test
|
||||
|
92
src/VORBIS/test/test.c
Normal file
92
src/VORBIS/test/test.c
Normal file
@ -0,0 +1,92 @@
|
||||
/********************************************************************
|
||||
* *
|
||||
* THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
|
||||
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
|
||||
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
|
||||
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
|
||||
* *
|
||||
* THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 *
|
||||
* by the Xiph.Org Foundation http://www.xiph.org/ *
|
||||
* *
|
||||
********************************************************************
|
||||
|
||||
function: vorbis coded test suite using vorbisfile
|
||||
last mod: $Id: test.c 13293 2007-07-24 00:09:47Z erikd $
|
||||
|
||||
********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "write_read.h"
|
||||
|
||||
#define DATA_LEN 2048
|
||||
|
||||
#define MAX(a,b) ((a) > (b) ? (a) : (b))
|
||||
|
||||
|
||||
static int check_output (const float * data_in, unsigned len);
|
||||
|
||||
int
|
||||
main(void){
|
||||
static float data_out [DATA_LEN] ;
|
||||
static float data_in [DATA_LEN] ;
|
||||
|
||||
/* Do safest and most used sample rates first. */
|
||||
int sample_rates [] = { 44100, 48000, 32000, 22050, 16000, 96000 } ;
|
||||
unsigned k ;
|
||||
int errors = 0 ;
|
||||
|
||||
gen_windowed_sine (data_out, ARRAY_LEN (data_out), 0.95);
|
||||
|
||||
for (k = 0 ; k < ARRAY_LEN (sample_rates); k ++) {
|
||||
char filename [64] ;
|
||||
snprintf (filename, sizeof (filename), "vorbis_%u.oga", sample_rates [k]);
|
||||
|
||||
printf (" %-20s : ", filename);
|
||||
fflush (stdout);
|
||||
|
||||
/* Set to know value. */
|
||||
set_data_in (data_in, ARRAY_LEN (data_in), 3.141);
|
||||
|
||||
write_vorbis_data_or_die (filename, sample_rates [k], data_out, ARRAY_LEN (data_out));
|
||||
read_vorbis_data_or_die (filename, sample_rates [k], data_in, ARRAY_LEN (data_in));
|
||||
|
||||
if (check_output (data_in, ARRAY_LEN (data_in)) != 0)
|
||||
errors ++ ;
|
||||
else {
|
||||
puts ("ok");
|
||||
remove (filename);
|
||||
}
|
||||
}
|
||||
|
||||
if (errors)
|
||||
exit (1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
check_output (const float * data_in, unsigned len)
|
||||
{
|
||||
float max_abs = 0.0 ;
|
||||
unsigned k ;
|
||||
|
||||
for (k = 0 ; k < len ; k++) {
|
||||
float temp = fabs (data_in [k]);
|
||||
max_abs = MAX (max_abs, temp);
|
||||
}
|
||||
|
||||
if (max_abs < 0.9) {
|
||||
printf ("Error : max_abs (%f) too small.\n", max_abs);
|
||||
return 1 ;
|
||||
} else if (max_abs > 1.0) {
|
||||
printf ("Error : max_abs (%f) too big.\n", max_abs);
|
||||
return 1 ;
|
||||
}
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
|
53
src/VORBIS/test/util.c
Normal file
53
src/VORBIS/test/util.c
Normal file
@ -0,0 +1,53 @@
|
||||
/********************************************************************
|
||||
* *
|
||||
* THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
|
||||
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
|
||||
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
|
||||
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
|
||||
* *
|
||||
* THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 *
|
||||
* by the Xiph.Org Foundation http://www.xiph.org/ *
|
||||
* *
|
||||
********************************************************************
|
||||
|
||||
function: utility functions for vorbis codec test suite.
|
||||
last mod: $Id: util.c 13293 2007-07-24 00:09:47Z erikd $
|
||||
|
||||
********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <vorbis/codec.h>
|
||||
#include <vorbis/vorbisenc.h>
|
||||
|
||||
#include "util.h"
|
||||
|
||||
void
|
||||
gen_windowed_sine (float *data, int len, float maximum)
|
||||
{ int k ;
|
||||
|
||||
memset (data, 0, len * sizeof (float)) ;
|
||||
|
||||
len /= 2 ;
|
||||
|
||||
for (k = 0 ; k < len ; k++)
|
||||
{ data [k] = sin (2.0 * k * M_PI * 1.0 / 32.0 + 0.4) ;
|
||||
|
||||
/* Apply Hanning Window. */
|
||||
data [k] *= maximum * (0.5 - 0.5 * cos (2.0 * M_PI * k / ((len) - 1))) ;
|
||||
}
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
void
|
||||
set_data_in (float * data, unsigned len, float value)
|
||||
{ unsigned k ;
|
||||
|
||||
for (k = 0 ; k < len ; k++)
|
||||
data [k] = value ;
|
||||
}
|
24
src/VORBIS/test/util.h
Normal file
24
src/VORBIS/test/util.h
Normal file
@ -0,0 +1,24 @@
|
||||
/********************************************************************
|
||||
* *
|
||||
* THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
|
||||
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
|
||||
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
|
||||
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
|
||||
* *
|
||||
* THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 *
|
||||
* by the Xiph.Org Foundation http://www.xiph.org/ *
|
||||
* *
|
||||
********************************************************************
|
||||
|
||||
function: utility functions for vorbis codec test suite.
|
||||
last mod: $Id: util.c 13293 2007-07-24 00:09:47Z erikd $
|
||||
|
||||
********************************************************************/
|
||||
|
||||
#define ARRAY_LEN(x) (sizeof(x)/sizeof(x[0]))
|
||||
|
||||
/* Create simple test data consisting of a windowed sine wave. */
|
||||
void gen_windowed_sine (float *data, int len, float maximum) ;
|
||||
|
||||
/* Set len values of data array to given value. */
|
||||
void set_data_in (float * data, unsigned len, float value) ;
|
301
src/VORBIS/test/write_read.c
Normal file
301
src/VORBIS/test/write_read.c
Normal file
@ -0,0 +1,301 @@
|
||||
/********************************************************************
|
||||
* *
|
||||
* THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
|
||||
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
|
||||
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
|
||||
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
|
||||
* *
|
||||
* THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 *
|
||||
* by the Xiph.Org Foundation http://www.xiph.org/ *
|
||||
* *
|
||||
********************************************************************
|
||||
|
||||
function: utility functions for vorbis codec test suite.
|
||||
last mod: $Id: util.c 13293 2007-07-24 00:09:47Z erikd $
|
||||
|
||||
********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <vorbis/codec.h>
|
||||
#include <vorbis/vorbisenc.h>
|
||||
|
||||
#include "write_read.h"
|
||||
|
||||
/* Why oh why, oh why is it so difficult to read and write Ogg/Vorbis files. */
|
||||
|
||||
/* The following function is basically a hacked version of the code in
|
||||
* examples/encoder_example.c */
|
||||
void
|
||||
write_vorbis_data_or_die (const char *filename, int srate, const float * data, int count)
|
||||
{
|
||||
FILE * file ;
|
||||
ogg_stream_state os;
|
||||
ogg_page og;
|
||||
ogg_packet op;
|
||||
vorbis_info vi;
|
||||
vorbis_comment vc;
|
||||
vorbis_dsp_state vd;
|
||||
vorbis_block vb;
|
||||
|
||||
int eos = 0, ret;
|
||||
|
||||
if ((file = fopen (filename, "wb")) == NULL) {
|
||||
printf("\n\nError : fopen failed : %s\n", strerror (errno)) ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
/********** Encode setup ************/
|
||||
|
||||
vorbis_info_init (&vi);
|
||||
|
||||
ret = vorbis_encode_init_vbr (&vi,1,srate,0.8);
|
||||
if (ret) {
|
||||
printf ("vorbis_encode_init_vbr return %d\n", ret) ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
vorbis_comment_init (&vc);
|
||||
vorbis_comment_add_tag (&vc,"ENCODER","test/util.c");
|
||||
vorbis_analysis_init (&vd,&vi);
|
||||
vorbis_block_init (&vd,&vb);
|
||||
|
||||
ogg_stream_init (&os,12345678);
|
||||
|
||||
{
|
||||
ogg_packet header;
|
||||
ogg_packet header_comm;
|
||||
ogg_packet header_code;
|
||||
|
||||
vorbis_analysis_headerout (&vd,&vc,&header,&header_comm,&header_code);
|
||||
ogg_stream_packetin (&os,&header);
|
||||
ogg_stream_packetin (&os,&header_comm);
|
||||
ogg_stream_packetin (&os,&header_code);
|
||||
|
||||
/* Ensures the audio data will start on a new page. */
|
||||
while (!eos){
|
||||
int result = ogg_stream_flush (&os,&og);
|
||||
if (result == 0)
|
||||
break;
|
||||
fwrite (og.header,1,og.header_len,file);
|
||||
fwrite (og.body,1,og.body_len,file);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
/* expose the buffer to submit data */
|
||||
float **buffer = vorbis_analysis_buffer (&vd,count);
|
||||
|
||||
memcpy (buffer [0], data, count * sizeof (float)) ;
|
||||
|
||||
/* tell the library how much we actually submitted */
|
||||
vorbis_analysis_wrote (&vd,count);
|
||||
vorbis_analysis_wrote (&vd,0);
|
||||
}
|
||||
|
||||
while (vorbis_analysis_blockout (&vd,&vb) == 1) {
|
||||
vorbis_analysis (&vb,NULL);
|
||||
vorbis_bitrate_addblock (&vb);
|
||||
|
||||
while (vorbis_bitrate_flushpacket (&vd,&op)) {
|
||||
ogg_stream_packetin (&os,&op);
|
||||
|
||||
while (!eos) {
|
||||
int result = ogg_stream_pageout (&os,&og);
|
||||
if (result == 0)
|
||||
break;
|
||||
fwrite (og.header,1,og.header_len,file);
|
||||
fwrite (og.body,1,og.body_len,file);
|
||||
|
||||
if (ogg_page_eos (&og))
|
||||
eos = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ogg_stream_clear (&os);
|
||||
vorbis_block_clear (&vb);
|
||||
vorbis_dsp_clear (&vd);
|
||||
vorbis_comment_clear (&vc);
|
||||
vorbis_info_clear (&vi);
|
||||
|
||||
fclose (file) ;
|
||||
}
|
||||
|
||||
/* The following function is basically a hacked version of the code in
|
||||
* examples/decoder_example.c */
|
||||
void
|
||||
read_vorbis_data_or_die (const char *filename, int srate, float * data, int count)
|
||||
{
|
||||
ogg_sync_state oy;
|
||||
ogg_stream_state os;
|
||||
ogg_page og;
|
||||
ogg_packet op;
|
||||
|
||||
vorbis_info vi;
|
||||
vorbis_comment vc;
|
||||
vorbis_dsp_state vd;
|
||||
vorbis_block vb;
|
||||
|
||||
FILE *file;
|
||||
char *buffer;
|
||||
int bytes;
|
||||
int eos = 0;
|
||||
int i;
|
||||
int read_total = 0 ;
|
||||
|
||||
if ((file = fopen (filename, "rb")) == NULL) {
|
||||
printf("\n\nError : fopen failed : %s\n", strerror (errno)) ;
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
ogg_sync_init (&oy);
|
||||
|
||||
{
|
||||
buffer = ogg_sync_buffer (&oy,4096);
|
||||
bytes = fread (buffer,1,4096,file);
|
||||
ogg_sync_wrote (&oy,bytes);
|
||||
|
||||
if(ogg_sync_pageout (&oy,&og) != 1) {
|
||||
if(bytes < 4096) {
|
||||
printf ("Out of data.\n") ;
|
||||
goto done_decode ;
|
||||
}
|
||||
|
||||
fprintf (stderr,"Input does not appear to be an Ogg bitstream.\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
ogg_stream_init (&os,ogg_page_serialno(&og));
|
||||
|
||||
vorbis_info_init (&vi);
|
||||
vorbis_comment_init (&vc);
|
||||
if (ogg_stream_pagein (&os,&og) < 0) {
|
||||
fprintf (stderr,"Error reading first page of Ogg bitstream data.\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (ogg_stream_packetout(&os,&op) != 1) {
|
||||
fprintf (stderr,"Error reading initial header packet.\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (vorbis_synthesis_headerin (&vi,&vc,&op) < 0) {
|
||||
fprintf (stderr,"This Ogg bitstream does not contain Vorbis "
|
||||
"audio data.\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while ( i < 2) {
|
||||
while (i < 2) {
|
||||
int result = ogg_sync_pageout (&oy,&og);
|
||||
if(result == 0)
|
||||
break;
|
||||
if(result==1) {
|
||||
ogg_stream_pagein(&os,&og);
|
||||
|
||||
while (i < 2) {
|
||||
result = ogg_stream_packetout (&os,&op);
|
||||
if (result == 0)
|
||||
goto done_decode;
|
||||
if (result < 0) {
|
||||
fprintf (stderr,"Corrupt secondary header. Exiting.\n");
|
||||
exit(1);
|
||||
}
|
||||
vorbis_synthesis_headerin (&vi,&vc,&op);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buffer = ogg_sync_buffer (&oy,4096);
|
||||
bytes = fread (buffer,1,4096,file);
|
||||
if (bytes == 0 && i < 2) {
|
||||
fprintf (stderr,"End of file before finding all Vorbis headers!\n");
|
||||
exit (1);
|
||||
}
|
||||
|
||||
ogg_sync_wrote (&oy,bytes);
|
||||
}
|
||||
|
||||
if (vi.rate != srate) {
|
||||
printf ("\n\nError : File '%s' has sample rate of %ld when it should be %d.\n\n", filename, vi.rate, srate);
|
||||
exit (1) ;
|
||||
}
|
||||
if (vi.channels != 1) {
|
||||
printf ("\n\nError : File '%s' has %d channels, but should be mono.\n\n", filename, vi.channels);
|
||||
exit (1) ;
|
||||
}
|
||||
|
||||
vorbis_synthesis_init (&vd,&vi);
|
||||
vorbis_block_init (&vd,&vb);
|
||||
|
||||
while(!eos) {
|
||||
while (!eos) {
|
||||
int result = ogg_sync_pageout (&oy,&og);
|
||||
if (result == 0)
|
||||
break;
|
||||
if (result < 0) {
|
||||
fprintf (stderr,"Corrupt or missing data in bitstream; "
|
||||
"continuing...\n");
|
||||
} else {
|
||||
ogg_stream_pagein (&os,&og);
|
||||
while (1) {
|
||||
result = ogg_stream_packetout (&os,&op);
|
||||
|
||||
if (result == 0)
|
||||
break;
|
||||
if (result < 0) {
|
||||
/* no reason to complain; already complained above */
|
||||
} else {
|
||||
float **pcm;
|
||||
int samples;
|
||||
|
||||
if (vorbis_synthesis (&vb,&op) == 0)
|
||||
vorbis_synthesis_blockin(&vd,&vb);
|
||||
while ((samples = vorbis_synthesis_pcmout (&vd,&pcm)) > 0 && read_total < count) {
|
||||
int bout = samples < count ? samples : count;
|
||||
bout = read_total + bout > count ? count - read_total : bout;
|
||||
|
||||
memcpy (data + read_total, pcm[0], bout * sizeof (float)) ;
|
||||
|
||||
vorbis_synthesis_read (&vd,bout);
|
||||
read_total += bout ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ogg_page_eos (&og)) eos = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!eos) {
|
||||
buffer = ogg_sync_buffer (&oy,4096);
|
||||
bytes = fread (buffer,1,4096,file);
|
||||
ogg_sync_wrote (&oy,bytes);
|
||||
if (bytes == 0) eos = 1;
|
||||
}
|
||||
}
|
||||
|
||||
ogg_stream_clear (&os);
|
||||
|
||||
vorbis_block_clear (&vb);
|
||||
vorbis_dsp_clear (&vd);
|
||||
vorbis_comment_clear (&vc);
|
||||
vorbis_info_clear (&vi);
|
||||
|
||||
}
|
||||
done_decode:
|
||||
|
||||
/* OK, clean up the framer */
|
||||
ogg_sync_clear (&oy);
|
||||
|
||||
fclose (file) ;
|
||||
}
|
||||
|
28
src/VORBIS/test/write_read.h
Normal file
28
src/VORBIS/test/write_read.h
Normal file
@ -0,0 +1,28 @@
|
||||
/********************************************************************
|
||||
* *
|
||||
* THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
|
||||
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
|
||||
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
|
||||
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
|
||||
* *
|
||||
* THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2007 *
|
||||
* by the Xiph.Org Foundation http://www.xiph.org/ *
|
||||
* *
|
||||
********************************************************************
|
||||
|
||||
function: utility functions for vorbis codec test suite.
|
||||
last mod: $Id: util.c 13293 2007-07-24 00:09:47Z erikd $
|
||||
|
||||
********************************************************************/
|
||||
|
||||
/* Write supplied data to an Ogg/Vorbis file with specified filename at
|
||||
* specified sample rate. Assumes a single channel of audio. */
|
||||
void write_vorbis_data_or_die (const char *filename, int srate,
|
||||
const float * data, int count) ;
|
||||
|
||||
/* Read given Ogg/Vorbis file into data specified data array. This
|
||||
* function is basically the inverse of the one above. Again, assumes
|
||||
* a single channel of audio. */
|
||||
void read_vorbis_data_or_die (const char *filename, int srate,
|
||||
float * data, int count) ;
|
||||
|
Loading…
x
Reference in New Issue
Block a user