[xiph-commits] r18679 - trunk/squishyio
xiphmont at svn.xiph.org
xiphmont at svn.xiph.org
Sun Oct 28 00:47:59 PDT 2012
Author: xiphmont
Date: 2012-10-28 00:47:59 -0700 (Sun, 28 Oct 2012)
New Revision: 18679
Modified:
trunk/squishyio/configure.ac
trunk/squishyio/squishyio.c
trunk/squishyio/squishyio.h
Log:
Add Opus support to squishyio (via opusfile)
Modified: trunk/squishyio/configure.ac
===================================================================
--- trunk/squishyio/configure.ac 2012-10-28 07:46:27 UTC (rev 18678)
+++ trunk/squishyio/configure.ac 2012-10-28 07:47:59 UTC (rev 18679)
@@ -4,12 +4,12 @@
cflags_save="$CFLAGS"
AC_PREREQ(2.57)
AC_INIT(squishyio.c)
-AM_INIT_AUTOMAKE(squishyio, 20101208, [vorbis-dev at xiph.org])
+AM_INIT_AUTOMAKE(squishyio, 20121028, [vorbis-dev at xiph.org])
AC_CONFIG_FILES([Makefile])
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])], [AC_SUBST([AM_DEFAULT_VERBOSITY], [1])])
SqI_LIB_CURRENT=0
-SqI_LIB_REVISION=0
+SqI_LIB_REVISION=1
SqI_LIB_AGE=0
AC_SUBST(SqI_LIB_CURRENT)
AC_SUBST(SqI_LIB_REVISION)
@@ -22,6 +22,7 @@
# Checks for libraries.
PKG_CHECK_MODULES([vorbisfile], [vorbisfile])
+PKG_CHECK_MODULES([opusfile], [opusfile])
PKG_CHECK_MODULES([FLAC], [flac >= 0.8.0])
PKG_CHECK_MODULES([ao], [ao > 1.0.0])
AC_CHECK_LIB([m], [cos])
@@ -31,6 +32,7 @@
AC_HEADER_STDC
AC_CHECK_HEADERS([stdlib.h string.h])
AC_CHECK_HEADERS([vorbis/vorbisfile.h])
+AC_CHECK_HEADERS([opus/opusfile.h])
AC_CHECK_HEADERS([ao/ao.h])
AC_CHECK_HEADERS([FLAC/stream_decoder.h])
@@ -80,11 +82,11 @@
esac
fi
-COMMON_FLAGS="$cflags_save $vorbisfile_CFLAGS $ao_CFLAGS $FLAC_CFLAGS -DUSE_FKEYSF=$USE_FKEYSF"
+COMMON_FLAGS="$cflags_save $vorbisfile_CFLAGS $opusfile_CFLAGS $ao_CFLAGS $FLAC_CFLAGS -DUSE_FKEYSF=$USE_FKEYSF"
CFLAGS="$CFLAGS -DVERSION='\"$VERSION\"' $COMMON_FLAGS"
DEBUG="$DEBUG -DVERSION='\\\"$VERSION\\\"' $COMMON_FLAGS"
PROFILE="$PROFILE -DVERSION='\\\"$VERSION\\\"' $COMMON_FLAGS"
-LIBS="$LIBS $vorbisfile_LIBS $ao_LIBS $FLAC_LIBS"
+LIBS="$LIBS $vorbisfile_LIBS $opusfile_LIBS $ao_LIBS $FLAC_LIBS"
AC_SUBST(DEBUG)
AC_SUBST(PROFILE)
Modified: trunk/squishyio/squishyio.c
===================================================================
--- trunk/squishyio/squishyio.c 2012-10-28 07:46:27 UTC (rev 18678)
+++ trunk/squishyio/squishyio.c 2012-10-28 07:47:59 UTC (rev 18679)
@@ -2,7 +2,7 @@
*
* squishyio
*
- * Copyright (C) 2010 Xiph.Org
+ * Copyright (C) 2010-2012 Xiph.Org
*
* squishyball is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -32,6 +32,7 @@
#include <errno.h>
#include <ao/ao.h>
#include <vorbis/vorbisfile.h>
+#include <opus/opusfile.h>
#include <FLAC/stream_decoder.h>
#include <unistd.h>
#include "squishyio.h"
@@ -119,6 +120,11 @@
memcmp (buf+28, "\x01vorbis", 7) == 0;
}
+static int opus_id(const char *path,unsigned char *buf){
+ return memcmp(buf, "OggS", 4) == 0 &&
+ memcmp (buf+28, "OpusHead", 8) == 0;
+}
+
static int sw_id(const char *path,unsigned char *buf){
/* if all else fails, look for JM's favorite extension */
return memcmp(path+strlen(path)-3,".sw",3)==0;
@@ -992,7 +998,132 @@
return NULL;
}
-#define MAX_ID_LEN 35
+/* Opus load support **************************************************************************/
+
+int opc_read(void *_stream,unsigned char *_ptr,int _nbytes){
+ return fread(_ptr,1,_nbytes,_stream);
+}
+
+int opc_seek(void *_stream,opus_int64 _offset,int _whence){
+ return fseek(_stream,_offset,_whence);
+}
+
+opus_int64 opc_tell(void *_stream){
+ return ftell(_stream);
+}
+
+int opc_close(void *_stream){
+ return 0;
+}
+
+static OpusFileCallbacks opus_callbacks =
+ { opc_read,opc_seek,opc_tell,opc_close };
+
+static pcm_t *opus_load(const char *path, FILE *in){
+ OggOpusFile *of;
+ pcm_t *pcm=NULL;
+ off_t fill=0;
+ int last_section=-1;
+ int i,j;
+
+ if(fseek(in,0,SEEK_SET)==-1){
+ fprintf(stderr,"%s: Failed to seek\n",path);
+ goto err;
+ }
+
+ of = op_open_callbacks(in, &opus_callbacks , NULL, 0, NULL);
+ if(!of){
+ fprintf(stderr,"Input does not appear to be an Opus bitstream.\n");
+ goto err;
+ }
+
+ pcm = calloc(1,sizeof(pcm_t));
+ pcm->name=strdup(trim_path(path));
+ pcm->savebits=16;
+ pcm->ch=op_channel_count(of,-1);
+ pcm->rate=48000;
+ pcm->samples=op_pcm_total(of,-1);
+
+ pcm->data = calloc(pcm->ch,sizeof(*pcm->data));
+ if(pcm->data == NULL){
+ fprintf(stderr,"Unable to allocate enough memory to load sample into memory\n");
+ goto err;
+ }
+ for(i=0;i<pcm->ch;i++){
+ pcm->data[i] = calloc(pcm->samples,sizeof(**pcm->data));
+ if(pcm->data[i] == NULL){
+ fprintf(stderr,"Unable to allocate enough memory to load sample into memory\n");
+ goto err;
+ }
+ }
+
+ switch(pcm->ch){
+ case 1:
+ pcm->matrix = strdup("M");
+ break;
+ case 2:
+ pcm->matrix = strdup("L,R");
+ break;
+ case 3:
+ pcm->matrix = strdup("L,C,R");
+ break;
+ case 4:
+ pcm->matrix = strdup("L,R,BL,BR");
+ break;
+ case 5:
+ pcm->matrix = strdup("L,C,R,BL,BR");
+ break;
+ case 6:
+ pcm->matrix = strdup("L,C,R,BL,BR,LFE");
+ break;
+ case 7:
+ pcm->matrix = strdup("L,C,R,SL,SR,BC,LFE");
+ break;
+ default:
+ pcm->matrix = strdup("L,C,R,SL,SR,BL,BR,LFE");
+ break;
+ }
+
+ while(fill<pcm->samples){
+ int current_section;
+ int i;
+ float pcmout[4096];
+ long ret=op_read_float(of,pcmout,4096,¤t_section);
+
+ if(current_section!=last_section){
+ last_section=current_section;
+ if(op_channel_count(of,-1) != pcm->ch){
+ fprintf(stderr,"%s: Chained file changes channel count\n",path);
+ goto err;
+ }
+ }
+
+ if(ret<0){
+ fprintf(stderr,"%s: Error while decoding file\n",path);
+ goto err;
+ }
+ if(ret==0){
+ fprintf(stderr,"%s: Audio data ended prematurely\n",path);
+ goto err;
+ }
+
+ for(j=0;j<ret;j++){
+ for(i=0;i<pcm->ch;i++)
+ pcm->data[i][j]=pcmout[fill+i];
+ fill+=pcm->ch;
+ }
+
+ }
+ op_free(of);
+
+ return pcm;
+ err:
+ op_clear(of);
+ free_pcm(pcm);
+ return NULL;
+}
+
+#define MAX_ID_LEN 36
unsigned char buf[MAX_ID_LEN];
/* Define the supported formats here */
@@ -1002,6 +1133,7 @@
{flac_id, flac_load, "flac"},
{oggflac_id, oggflac_load,"oggflac"},
{vorbis_id, vorbis_load, "oggvorbis"},
+ {opus_id, opus_load, "oggopus"},
{sw_id, sw_load, "sw"},
{NULL, NULL, NULL}
};
@@ -1159,4 +1291,3 @@
return 1;
}
}
-
Modified: trunk/squishyio/squishyio.h
===================================================================
--- trunk/squishyio/squishyio.h 2012-10-28 07:46:27 UTC (rev 18678)
+++ trunk/squishyio/squishyio.h 2012-10-28 07:47:59 UTC (rev 18679)
@@ -2,7 +2,7 @@
*
* squishyio
*
- * Copyright (C) 2010 Xiph.Org
+ * Copyright (C) 2010-2012 Xiph.Org
*
* squishyball is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
More information about the commits
mailing list