Skip to content

Commit

Permalink
Clean-up for alternate configurations.
Browse files Browse the repository at this point in the history
* s/op_read_stereo_float/op_read_float_stereo/ for the fixed-point
   API.
* Fix compiler warnings exposed when optimizations are enabled.
* Fix opusfile_example to work with --enable-fixed-point
   --disable-float
* Fix seeking_example to not re-define OP_FIXED_POINT if it's
   already been defined.
  • Loading branch information
Timothy B. Terriberry committed Sep 29, 2012
1 parent 1886f65 commit 2132235
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
12 changes: 10 additions & 2 deletions examples/opusfile_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
#endif
#include <opusfile.h>

#if defined(OP_FIXED_POINT)
typedef opus_int16 op_sample;
# define op_read_native_stereo op_read_stereo
#else
typedef float op_sample;
# define op_read_native_stereo op_read_float_stereo
#endif

int main(int _argc,const char **_argv){
OggOpusFile *of;
ogg_int64_t pcm_offset;
Expand Down Expand Up @@ -85,9 +93,9 @@ int main(int _argc,const char **_argv){
}
for(;;){
ogg_int64_t next_pcm_offset;
float pcm[120*48*2];
op_sample pcm[120*48*2];
int li;
ret=op_read_float_stereo(of,pcm,sizeof(pcm)/sizeof(*pcm));
ret=op_read_native_stereo(of,pcm,sizeof(pcm)/sizeof(*pcm));
if(ret<0){
fprintf(stderr,"Error decoding '%s': %i\n",_argv[1],ret);
ret=EXIT_FAILURE;
Expand Down
6 changes: 4 additions & 2 deletions examples/seeking_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
#include <opusfile.h>

/*Use shorts, they're smaller.*/
#define OP_FIXED_POINT (1)
#if !defined(OP_FIXED_POINT)
# define OP_FIXED_POINT (1)
#endif

#if defined(OP_FIXED_POINT)

Expand Down Expand Up @@ -436,8 +438,8 @@ int main(int _argc,const char **_argv){
fprintf(stderr,")...\n");
max_seeks=0;
for(i=0;i<NSEEK_TESTS;i++){
long nseeks_tmp;
ogg_int64_t pcm_offset2;
long nseeks_tmp;
nseeks_tmp=nreal_seeks;
pcm_offset=(ogg_int64_t)(rand()/(double)RAND_MAX*pcm_length);
fprintf(stderr,"\r\t%3i [PCM position %li]... ",
Expand Down
8 changes: 7 additions & 1 deletion src/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ static int op_parse_url_impl(OpusParsedURL *_dst,const char *_src){
hostport=userinfo_end+1;
}
else{
user=NULL;
/*We shouldn't have to initialize user_end, but gcc is too dumb to figure
out that user!=NULL below means we didn't take this else branch.*/
user=user_end=NULL;
pass=NULL;
hostport=authority;
}
Expand Down Expand Up @@ -1251,6 +1253,10 @@ static int op_http_stream_open(OpusHTTPStream *_stream,const char *_url,
int ret;
if(_proxy_host!=NULL&&OP_UNLIKELY(_proxy_port>65535U))return OP_EINVAL;
last_host=NULL;
/*We shouldn't have to initialize last_port, but gcc is too dumb to figure
out that last_host!=NULL implies we've already taken one trip through the
loop.*/
last_port=0;
ret=op_parse_url(&_stream->url,_url);
if(OP_UNLIKELY(ret<0))return ret;
for(nredirs=0;nredirs<OP_REDIRECT_LIMIT;nredirs++){
Expand Down
8 changes: 7 additions & 1 deletion src/opusfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,11 @@ static int op_find_initial_pcm_offset(OggOpusFile *_of,
if(_og==NULL)_og=&og;
serialno=_of->os.serialno;
cur_page_gp=-1;
op_count=0;
/*We shouldn't have to initialize total_duration, but gcc is too dumb to
figure out that op_count>0 implies we've been through the whole loop at
least once.*/
total_duration=0;
do{
/*We should get a page unless the file is truncated or mangled.
Otherwise there are no audio data packets in the whole logical stream.*/
Expand Down Expand Up @@ -2553,6 +2558,7 @@ static int op_short2float_filter(OggOpusFile *_of,void *_dst,int _dst_sz,
op_sample *_src,int _nsamples,int _nchannels){
float *dst;
int i;
_of=_of;
dst=(float *)_dst;
if(OP_UNLIKELY(_nsamples*_nchannels>_dst_sz))_nsamples=_dst_sz/_nchannels;
_dst_sz=_nsamples*_nchannels;
Expand Down Expand Up @@ -2586,7 +2592,7 @@ static int op_short2float_stereo_filter(OggOpusFile *_of,
return op_short2float_filter(_of,dst,_dst_sz,_src,_nsamples,2);
}

int op_read_stereo_float(OggOpusFile *_of,opus_int16 *_pcm,int _buf_size){
int op_read_float_stereo(OggOpusFile *_of,float *_pcm,int _buf_size){
return op_read_native_filter(_of,_pcm,_buf_size,
op_short2float_stereo_filter,NULL);
}
Expand Down

0 comments on commit 2132235

Please sign in to comment.