ref: 85aa5dbbbbd94461e6142eab6d58a4e64c1dbd61
parent: a209fa2655bd1d0c78af833fa18594ac4de1676e
author: Mark Harris <mark.hsj@gmail.com>
date: Fri Feb 23 15:57:54 EST 2018
Attempt to make whitespace a bit more consistent
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,7 +1,7 @@
-.gitignore export-ignore
-.gitattributes export-ignore
+.gitignore export-ignore
+.gitattributes export-ignore
-update_version export-ignore
+update_version export-ignore
*.sln text eol=crlf
*.vcxproj text eol=crlf
--- a/COPYING
+++ b/COPYING
@@ -29,8 +29,8 @@
Opusinfo is a fork of ogginfo from the vorbis-tools package
(https://www.xiph.org). It is available under the GPL:
- GNU GENERAL PUBLIC LICENSE
- Version 2, June 1991
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@@ -37,7 +37,7 @@
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
- Preamble
+ Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
@@ -87,7 +87,7 @@
The precise terms and conditions for copying, distribution and
modification follow.
- GNU GENERAL PUBLIC LICENSE
+ GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
@@ -286,7 +286,7 @@
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
- NO WARRANTY
+ NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
@@ -308,9 +308,9 @@
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
- END OF TERMS AND CONDITIONS
+ END OF TERMS AND CONDITIONS
- How to Apply These Terms to Your New Programs
+ How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
--- a/configure.ac
+++ b/configure.ac
@@ -43,13 +43,13 @@
for ac_kw in __restrict __restrict__ _Restrict restrict; do
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
[[typedef int * int_ptr;
- int foo (int_ptr $ac_kw ip, int * $ac_kw baz[]) {
- return ip[0];
+ int foo (int_ptr $ac_kw ip, int * $ac_kw baz[]) {
+ return ip[0];
}]],
[[int s[1];
- int * $ac_kw t = s;
- t[0] = 0;
- return foo(t, (void *)0)]])],
+ int * $ac_kw t = s;
+ t[0] = 0;
+ return foo(t, (void *)0)]])],
[ac_cv_c_restrict=$ac_kw])
test "$ac_cv_c_restrict" != no && break
done
--- a/m4/pkg.m4
+++ b/m4/pkg.m4
@@ -1,6 +1,6 @@
# pkg.m4 - Macros to locate and utilise pkg-config. -*- Autoconf -*-
# serial 1 (pkg-config-0.24)
-#
+#
# Copyright © 2004 Scott James Remnant <scott@netsplit.com>.
#
# This program is free software; you can redistribute it and/or modify
@@ -32,17 +32,17 @@
AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
if test "x$ac_cv_env_PKG_CONFIG_set" != "xset"; then
- AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
+ AC_PATH_TOOL([PKG_CONFIG], [pkg-config])
fi
if test -n "$PKG_CONFIG"; then
- _pkg_min_version=m4_default([$1], [0.9.0])
- AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
- if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
- AC_MSG_RESULT([yes])
- else
- AC_MSG_RESULT([no])
- PKG_CONFIG=""
- fi
+ _pkg_min_version=m4_default([$1], [0.9.0])
+ AC_MSG_CHECKING([pkg-config is at least version $_pkg_min_version])
+ if $PKG_CONFIG --atleast-pkgconfig-version $_pkg_min_version; then
+ AC_MSG_RESULT([yes])
+ else
+ AC_MSG_RESULT([no])
+ PKG_CONFIG=""
+ fi
fi[]dnl
])# PKG_PROG_PKG_CONFIG
@@ -73,7 +73,7 @@
elif test -n "$PKG_CONFIG"; then
PKG_CHECK_EXISTS([$3],
[pkg_cv_[]$1=`$PKG_CONFIG --[]$2 "$3" 2>/dev/null`],
- [pkg_failed=yes])
+ [pkg_failed=yes])
else
pkg_failed=untried
fi[]dnl
@@ -117,17 +117,17 @@
See the pkg-config man page for more details.])
if test $pkg_failed = yes; then
- AC_MSG_RESULT([no])
+ AC_MSG_RESULT([no])
_PKG_SHORT_ERRORS_SUPPORTED
if test $_pkg_short_errors_supported = yes; then
- $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "$2" 2>&1`
- else
- $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors "$2" 2>&1`
+ $1[]_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "$2" 2>&1`
+ else
+ $1[]_PKG_ERRORS=`$PKG_CONFIG --print-errors "$2" 2>&1`
fi
- # Put the nasty error message in config.log where it belongs
- echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
+ # Put the nasty error message in config.log where it belongs
+ echo "$$1[]_PKG_ERRORS" >&AS_MESSAGE_LOG_FD
- m4_default([$4], [AC_MSG_ERROR(
+ m4_default([$4], [AC_MSG_ERROR(
[Package requirements ($2) were not met:
$$1_PKG_ERRORS
@@ -138,8 +138,8 @@
_PKG_TEXT])
])
elif test $pkg_failed = untried; then
- AC_MSG_RESULT([no])
- m4_default([$4], [AC_MSG_FAILURE(
+ AC_MSG_RESULT([no])
+ m4_default([$4], [AC_MSG_FAILURE(
[The pkg-config script could not be found or is too old. Make sure it
is in your PATH or set the PKG_CONFIG environment variable to the full
path to pkg-config.
@@ -149,9 +149,9 @@
To get pkg-config, see <https://pkg-config.freedesktop.org/>.])
])
else
- $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
- $1[]_LIBS=$pkg_cv_[]$1[]_LIBS
+ $1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
+ $1[]_LIBS=$pkg_cv_[]$1[]_LIBS
AC_MSG_RESULT([yes])
- $3
+ $3
fi[]dnl
])# PKG_CHECK_MODULES
--- a/src/audio-in.c
+++ b/src/audio-in.c
@@ -125,19 +125,19 @@
int buf_size=0, buf_filled=0;
int size;
- while(formats[j].id_func)
+ while (formats[j].id_func)
{
size = formats[j].id_data_len;
- if(size >= buf_size)
+ if (size >= buf_size)
{
buf = realloc(buf, size);
buf_size = size;
}
- if(size > buf_filled)
+ if (size > buf_filled)
{
buf_filled += (int)fread(buf+buf_filled, 1, buf_size-buf_filled, in);
- if(buf_filled < size)
+ if (buf_filled < size)
{ /* File truncated */
j++;
continue;
@@ -144,10 +144,10 @@
}
}
- if(formats[j].id_func(buf, buf_filled))
+ if (formats[j].id_func(buf, buf_filled))
{
/* ok, we now have something that can handle the file */
- if(formats[j].open_func(in, opt, buf, buf_filled)) {
+ if (formats[j].open_func(in, opt, buf, buf_filled)) {
free(buf);
return &formats[j];
}
@@ -163,8 +163,8 @@
static void sanitize_fourcc(unsigned char *buf)
{
int i;
- for(i = 0; i < 4; ++i)
- if(buf[i] < ' ' || buf[i] > '~')
+ for (i = 0; i < 4; ++i)
+ if (buf[i] < ' ' || buf[i] > '~')
buf[i] = '?';
}
@@ -171,7 +171,7 @@
static int seek_forward(FILE *in, ogg_int64_t length)
{
ogg_int64_t remaining = length;
- while(remaining > 0)
+ while (remaining > 0)
{
/* When OFF_T is 64 bits, only one seek is needed and the comparison
* will always be false. When OFF_T is not large enough, seek LONG_MAX
@@ -180,7 +180,7 @@
OFF_T seekstep = (OFF_T)remaining;
if (seekstep != remaining)
seekstep = LONG_MAX;
- if(FSEEK(in, seekstep, SEEK_CUR))
+ if (FSEEK(in, seekstep, SEEK_CUR))
{
/* Failed to seek; do it by reading. */
unsigned char buf[1024];
@@ -187,7 +187,7 @@
do {
size_t readstep = remaining > 1024 ? 1024 : (size_t)remaining;
readstep = fread(buf, 1, readstep, in);
- if(!readstep)
+ if (!readstep)
return 0; /* Couldn't read more, can't read file */
remaining -= readstep;
} while (remaining);
@@ -203,20 +203,20 @@
unsigned char buf[8];
unsigned int chunklen;
- while(1)
+ while (1)
{
- if(fread(buf,1,8,in) < 8) /* Suck down a chunk specifier */
+ if (fread(buf,1,8,in) < 8) /* Suck down a chunk specifier */
return 0; /* EOF before reaching the appropriate chunk */
chunklen = READ_U32_LE(buf+4);
- if(memcmp(buf, type, 4))
+ if (memcmp(buf, type, 4))
{
sanitize_fourcc(buf);
fprintf(stderr, _("Skipping chunk of type \"%.4s\", length %u\n"),
buf, chunklen);
- if(!seek_forward(in, (ogg_int64_t)chunklen + (chunklen & 1)))
+ if (!seek_forward(in, (ogg_int64_t)chunklen + (chunklen & 1)))
return 0;
}
else
@@ -233,15 +233,15 @@
unsigned int chunklen;
int restarted = 0;
- while(1)
+ while (1)
{
- if(fread(buf,1,8,in) < 8)
+ if (fread(buf,1,8,in) < 8)
{
- if(!restarted) {
+ if (!restarted) {
/* Handle out of order chunks by seeking back to the start
* to retry */
restarted = 1;
- if(!FSEEK(in, 12, SEEK_SET))
+ if (!FSEEK(in, 12, SEEK_SET))
continue;
}
return 0;
@@ -249,9 +249,9 @@
chunklen = READ_U32_BE(buf+4);
- if(memcmp(buf,type,4))
+ if (memcmp(buf,type,4))
{
- if(!seek_forward(in, (ogg_int64_t)chunklen + (chunklen & 1)))
+ if (!seek_forward(in, (ogg_int64_t)chunklen + (chunklen & 1)))
return 0;
}
else
@@ -273,10 +273,10 @@
unsigned int chunklen = *len;
unsigned int readlen = chunklen > bufsize ? bufsize : chunklen;
- if(fread(buf, 1, readlen, in) != readlen)
+ if (fread(buf, 1, readlen, in) != readlen)
return 0;
- if(!seek_forward(in, (ogg_int64_t)(chunklen - readlen) + (chunklen & 1)))
+ if (!seek_forward(in, (ogg_int64_t)(chunklen - readlen) + (chunklen & 1)))
return 0;
*len = readlen;
@@ -287,7 +287,7 @@
{
int e = READ_U16_BE(buf) & 0x7fff;
double f;
- if(e==32767)
+ if (e==32767)
/* NaNs and infinities -- their format can vary among implementations,
but for our purposes they can all be treated as infinite. */
f = HUGE_VAL;
@@ -299,15 +299,15 @@
/* AIFF/AIFC support adapted from the old OggSQUISH application */
int aiff_id(unsigned char *buf, int len)
{
- if(len<12) return 0; /* Truncated file, probably */
+ if (len<12) return 0; /* Truncated file, probably */
- if(memcmp(buf, "FORM", 4))
+ if (memcmp(buf, "FORM", 4))
return 0;
- if(memcmp(buf+8, "AIF",3))
+ if (memcmp(buf+8, "AIF",3))
return 0;
- if(buf[11]!='C' && buf[11]!='F')
+ if (buf[11]!='C' && buf[11]!='F')
return 0;
return 1;
@@ -315,12 +315,12 @@
static int aiff_permute_matrix[6][6] =
{
- {0}, /* 1.0 mono */
- {0,1}, /* 2.0 stereo */
- {0,2,1}, /* 3.0 channel ('wide') stereo */
- {0,1,2,3}, /* 4.0 discrete quadraphonic (WARN) */
- {0,2,1,3,4}, /* 5.0 surround (WARN) */
- {0,1,2,3,4,5}, /* 5.1 surround (WARN)*/
+ {0}, /* 1.0 mono */
+ {0,1}, /* 2.0 stereo */
+ {0,2,1}, /* 3.0 channel ('wide') stereo */
+ {0,1,2,3}, /* 4.0 discrete quadraphonic (WARN) */
+ {0,2,1,3,4}, /* 5.0 surround (WARN) */
+ {0,1,2,3,4,5}, /* 5.1 surround (WARN)*/
};
int aiff_open(FILE *in, oe_enc_opt *opt, unsigned char *buf, int buflen)
@@ -335,18 +335,18 @@
int i;
(void)buflen;/*unused*/
- if(buf[11]=='C')
+ if (buf[11]=='C')
aifc=1;
else
aifc=0;
- if(!find_aiff_chunk(in, "COMM", &len))
+ if (!find_aiff_chunk(in, "COMM", &len))
{
fprintf(stderr, _("ERROR: No common chunk found in AIFF file\n"));
return 0; /* EOF before COMM chunk */
}
- if(len < 18 || !read_chunk(in, buffer, sizeof(buffer), &len))
+ if (len < 18 || !read_chunk(in, buffer, sizeof(buffer), &len))
{
fprintf(stderr, _("ERROR: Incomplete common chunk in AIFF header\n"));
return 0;
@@ -357,25 +357,25 @@
format.samplesize = (short)READ_U16_BE(buffer+6);
format.rate = read_IEEE80(buffer+8);
- if(format.channels <= 0)
+ if (format.channels <= 0)
{
fprintf(stderr, _("ERROR: Invalid channel count in AIFF header\n"));
return 0;
}
- if(aifc)
+ if (aifc)
{
- if(len < 22)
+ if (len < 22)
{
fprintf(stderr, _("ERROR: AIFF-C header truncated.\n"));
return 0;
}
- if(!memcmp(buffer+18, "NONE", 4))
+ if (!memcmp(buffer+18, "NONE", 4))
{
bigendian = 1;
}
- else if(!memcmp(buffer+18, "sowt", 4))
+ else if (!memcmp(buffer+18, "sowt", 4))
{
bigendian = 0;
}
@@ -388,7 +388,7 @@
}
}
- if(!(format.rate >= 1 && format.rate <= INT_MAX))
+ if (!(format.rate >= 1 && format.rate <= INT_MAX))
{
fprintf(stderr, _("ERROR: Preposterous sample rate in AIFF header: %g Hz\n"),
format.rate);
@@ -395,19 +395,19 @@
return 0;
}
- if(!find_aiff_chunk(in, "SSND", &len))
+ if (!find_aiff_chunk(in, "SSND", &len))
{
fprintf(stderr, _("ERROR: No SSND chunk found in AIFF file\n"));
return 0; /* No SSND chunk -> no actual audio */
}
- if(len < 8)
+ if (len < 8)
{
fprintf(stderr, _("ERROR: Corrupted SSND chunk in AIFF header\n"));
return 0;
}
- if(fread(buf2,1,8, in) < 8)
+ if (fread(buf2,1,8, in) < 8)
{
fprintf(stderr, _("ERROR: Unexpected EOF reading AIFF header\n"));
return 0;
@@ -416,7 +416,7 @@
format.offset = READ_U32_BE(buf2);
format.blocksize = READ_U32_BE(buf2+4);
- if( format.blocksize == 0 &&
+ if (format.blocksize == 0 &&
(format.samplesize == 16 || format.samplesize == 8))
{
/* From here on, this is very similar to the wav code. Oh well. */
@@ -436,7 +436,7 @@
aiff->bigendian = bigendian;
aiff->unsigned8bit = 0;
- if(aiff->channels>3)
+ if (aiff->channels>3)
fprintf(stderr, _("WARNING: AIFF[-C] files with more than three channels use\n"
"speaker locations incompatible with Vorbis surround definitions.\n"
"Not performing channel location mapping.\n"));
@@ -466,14 +466,14 @@
int wav_id(unsigned char *buf, int len)
{
- if(len<12) return 0; /* Something screwed up */
+ if (len<12) return 0; /* Something screwed up */
- if(memcmp(buf, "RIFF", 4))
+ if (memcmp(buf, "RIFF", 4))
return 0; /* Not wave */
/*flen = READ_U32_LE(buf+4);*/ /* We don't use this */
- if(memcmp(buf+8, "WAVE",4))
+ if (memcmp(buf+8, "WAVE",4))
return 0; /* RIFF, but not wave */
return 1;
@@ -497,13 +497,13 @@
* as a wav file (oldbuf)
*/
- if(!find_wav_chunk(in, "fmt ", &len))
+ if (!find_wav_chunk(in, "fmt ", &len))
{
fprintf(stderr, _("ERROR: No format chunk found in WAV file\n"));
return 0;
}
- if(len < 16)
+ if (len < 16)
{
fprintf(stderr, _("ERROR: Unrecognised format chunk in WAV header\n"));
return 0; /* Weird format chunk */
@@ -516,12 +516,12 @@
* sizes other than 16 or 18 bytes in size, report a bug to the
* author.
*/
- if(len!=16 && len!=18 && len!=40)
+ if (len!=16 && len!=18 && len!=40)
fprintf(stderr,
_("Warning: INVALID format chunk in wav header.\n"
" Trying to read anyway (may not work)...\n"));
- if(!read_chunk(in, buf, sizeof(buf), &len))
+ if (!read_chunk(in, buf, sizeof(buf), &len))
{
fprintf(stderr, _("ERROR: Incomplete format chunk in WAV header\n"));
return 0;
@@ -534,72 +534,72 @@
format.align = READ_U16_LE(buf+12);
format.samplesize = READ_U16_LE(buf+14);
- if(format.channels == 0)
+ if (format.channels == 0)
{
fprintf(stderr, _("ERROR: Zero channels in WAV header\n"));
return 0;
}
- if(format.format == 0xfffe) /* WAVE_FORMAT_EXTENSIBLE */
+ if (format.format == 0xfffe) /* WAVE_FORMAT_EXTENSIBLE */
{
- if(len<40)
- {
- fprintf(stderr, _("ERROR: Extended WAV format header invalid (too small)\n"));
- return 0;
- }
+ if (len<40)
+ {
+ fprintf(stderr, _("ERROR: Extended WAV format header invalid (too small)\n"));
+ return 0;
+ }
- validbits = READ_U16_LE(buf+18);
- if(validbits < 1 || validbits > format.samplesize)
- validbits = format.samplesize;
+ validbits = READ_U16_LE(buf+18);
+ if (validbits < 1 || validbits > format.samplesize)
+ validbits = format.samplesize;
- format.mask = READ_U32_LE(buf+20);
- /* warn the user if the format mask is not a supported/expected type */
- switch(format.mask){
- case 1539: /* 4.0 using side surround instead of back */
- fprintf(stderr, _("WARNING: WAV file uses side surround instead of rear for quadraphonic;\n"
+ format.mask = READ_U32_LE(buf+20);
+ /* warn the user if the format mask is not a supported/expected type */
+ switch (format.mask) {
+ case 1539: /* 4.0 using side surround instead of back */
+ fprintf(stderr, _("WARNING: WAV file uses side surround instead of rear for quadraphonic;\n"
"remapping side speakers to rear in encoding.\n"));
- break;
- case 1551: /* 5.1 using side instead of rear */
- fprintf(stderr, _("WARNING: WAV file uses side surround instead of rear for 5.1;\n"
+ break;
+ case 1551: /* 5.1 using side instead of rear */
+ fprintf(stderr, _("WARNING: WAV file uses side surround instead of rear for 5.1;\n"
"remapping side speakers to rear in encoding.\n"));
- break;
- case 319: /* 6.1 using rear instead of side */
- fprintf(stderr, _("WARNING: WAV file uses rear surround instead of side for 6.1;\n"
+ break;
+ case 319: /* 6.1 using rear instead of side */
+ fprintf(stderr, _("WARNING: WAV file uses rear surround instead of side for 6.1;\n"
"remapping rear speakers to side in encoding.\n"));
- break;
- case 255: /* 7.1 'Widescreen' */
- fprintf(stderr, _("WARNING: WAV file is a 7.1 'Widescreen' channel mapping;\n"
+ break;
+ case 255: /* 7.1 'Widescreen' */
+ fprintf(stderr, _("WARNING: WAV file is a 7.1 'Widescreen' channel mapping;\n"
"remapping speakers to Vorbis 7.1 format.\n"));
- break;
- case 0: /* default/undeclared */
- case 1: /* mono (left only) */
- case 4: /* mono (center only) */
- case 3: /* stereo */
- case 51: /* quad */
- case 55: /* 5.0 */
- case 63: /* 5.1 */
- case 1807: /* 6.1 */
- case 1599: /* 7.1 */
- break;
- default:
- fprintf(stderr, _("WARNING: Unknown WAV surround channel mask: %u\n"
- "Blindly mapping speakers using default SMPTE/ITU ordering.\n"),
- format.mask);
- break;
- }
- format.format = READ_U16_LE(buf+24);
+ break;
+ case 0: /* default/undeclared */
+ case 1: /* mono (left only) */
+ case 4: /* mono (center only) */
+ case 3: /* stereo */
+ case 51: /* quad */
+ case 55: /* 5.0 */
+ case 63: /* 5.1 */
+ case 1807: /* 6.1 */
+ case 1599: /* 7.1 */
+ break;
+ default:
+ fprintf(stderr, _("WARNING: Unknown WAV surround channel mask: %u\n"
+ "Blindly mapping speakers using default SMPTE/ITU ordering.\n"),
+ format.mask);
+ break;
+ }
+ format.format = READ_U16_LE(buf+24);
}
else
{
- validbits = format.samplesize;
+ validbits = format.samplesize;
}
- if(format.format == 1)
+ if (format.format == 1)
{
samplesize = format.samplesize/8;
opt->read_samples = wav_read;
}
- else if(format.format == 3)
+ else if (format.format == 3)
{
validbits = 24;
samplesize = 4;
@@ -612,7 +612,7 @@
return 0;
}
- if(format.samplerate > INT_MAX)
+ if (format.samplerate > INT_MAX)
{
fprintf(stderr, _("ERROR: Preposterous sample rate in WAV header: %u Hz\n"),
format.samplerate);
@@ -619,13 +619,13 @@
return 0;
}
- if(!find_wav_chunk(in, "data", &len))
+ if (!find_wav_chunk(in, "data", &len))
{
fprintf(stderr, _("ERROR: No data chunk found in WAV file\n"));
return 0;
}
- if(format.align != format.channels * samplesize) {
+ if (format.align != format.channels * samplesize) {
/* This is incorrect according to the spec. Warn loudly, then ignore
* this value.
*/
@@ -634,7 +634,7 @@
"The software that created this file is incorrect.\n"));
}
- if(format.samplesize == samplesize*8 &&
+ if (format.samplesize == samplesize*8 &&
(format.samplesize == 24 || format.samplesize == 16 ||
format.samplesize == 8 ||
(format.samplesize == 32 && format.format == 3)))
@@ -661,7 +661,7 @@
/* Assume audio data continues until EOF.
No percent progress will be reported. */
}
- else if(len>(format.channels*samplesize*4U) && len<((1U<<31)-65536))
+ else if (len>(format.channels*samplesize*4U) && len<((1U<<31)-65536))
{
/* Chunk length is plausible. Limit the audio data read to
this length so that we do not misinterpret any additional
@@ -680,11 +680,11 @@
read until EOF even if the file grows while reading. */
OFF_T pos[2];
pos[0] = FTELL(in);
- if(pos[0] >= 0 && !FSEEK(in, 0, SEEK_END))
+ if (pos[0] >= 0 && !FSEEK(in, 0, SEEK_END))
{
pos[1] = FTELL(in);
FSEEK(in, pos[0], SEEK_SET);
- if(pos[1] > pos[0])
+ if (pos[1] > pos[0])
opt->total_samples_per_channel = (pos[1]-pos[0])/(format.channels*samplesize);
}
}
@@ -724,14 +724,14 @@
realsamples = (int)fread(buf, sampbyte*f->channels, realsamples, f->f);
f->samplesread += realsamples;
- if(f->samplesize==8)
+ if (f->samplesize==8)
{
- if(f->unsigned8bit)
+ if (f->unsigned8bit)
{
unsigned char *bufu = (unsigned char *)buf;
- for(i = 0; i < realsamples; i++)
+ for (i = 0; i < realsamples; i++)
{
- for(j=0; j < f->channels; j++)
+ for (j=0; j < f->channels; j++)
{
buffer[i*f->channels+j]=((int)(bufu[i*f->channels + ch_permute[j]])-128)/128.0f;
}
@@ -739,9 +739,9 @@
}
else
{
- for(i = 0; i < realsamples; i++)
+ for (i = 0; i < realsamples; i++)
{
- for(j=0; j < f->channels; j++)
+ for (j=0; j < f->channels; j++)
{
buffer[i*f->channels+j]=buf[i*f->channels + ch_permute[j]]/128.0f;
}
@@ -748,13 +748,13 @@
}
}
}
- else if(f->samplesize==16)
+ else if (f->samplesize==16)
{
- if(!f->bigendian)
+ if (!f->bigendian)
{
- for(i = 0; i < realsamples; i++)
+ for (i = 0; i < realsamples; i++)
{
- for(j=0; j < f->channels; j++)
+ for (j=0; j < f->channels; j++)
{
buffer[i*f->channels+j] = ((buf[i*2*f->channels + 2*ch_permute[j] + 1]<<8) |
(buf[i*2*f->channels + 2*ch_permute[j]] & 0xff))/32768.0f;
@@ -763,9 +763,9 @@
}
else
{
- for(i = 0; i < realsamples; i++)
+ for (i = 0; i < realsamples; i++)
{
- for(j=0; j < f->channels; j++)
+ for (j=0; j < f->channels; j++)
{
buffer[i*f->channels+j]=((buf[i*2*f->channels + 2*ch_permute[j]]<<8) |
(buf[i*2*f->channels + 2*ch_permute[j] + 1] & 0xff))/32768.0f;
@@ -773,12 +773,12 @@
}
}
}
- else if(f->samplesize==24)
+ else if (f->samplesize==24)
{
- if(!f->bigendian) {
- for(i = 0; i < realsamples; i++)
+ if (!f->bigendian) {
+ for (i = 0; i < realsamples; i++)
{
- for(j=0; j < f->channels; j++)
+ for (j=0; j < f->channels; j++)
{
buffer[i*f->channels+j] = ((buf[i*3*f->channels + 3*ch_permute[j] + 2] << 16) |
(((unsigned char *)buf)[i*3*f->channels + 3*ch_permute[j] + 1] << 8) |
@@ -814,8 +814,8 @@
realsamples = (int)fread(buf, 4*f->channels, realsamples, f->f);
f->samplesread += realsamples;
- for(i=0; i < realsamples; i++)
- for(j=0; j < f->channels; j++)
+ for (i=0; i < realsamples; i++)
+ for (j=0; j < f->channels; j++)
buffer[i*f->channels+j] = buf[i*f->channels + f->channel_permute[j]];
return realsamples;
@@ -860,12 +860,13 @@
float scale_factor;
} scaler;
-static long read_scaler(void *data, float *buffer, int samples) {
+static long read_scaler(void *data, float *buffer, int samples)
+{
scaler *d = data;
long in_samples = d->real_reader(d->real_readdata, buffer, samples);
int i;
- for(i=0; i < d->channels*in_samples; i++) {
+ for (i=0; i < d->channels*in_samples; i++) {
buffer[i] *= d->scale_factor;
}
@@ -872,7 +873,8 @@
return in_samples;
}
-void setup_scaler(oe_enc_opt *opt, float scale) {
+void setup_scaler(oe_enc_opt *opt, float scale)
+{
scaler *d = calloc(1, sizeof(scaler));
d->real_reader = opt->read_samples;
@@ -902,12 +904,12 @@
in_ch=d->in_channels;
out_ch=d->out_channels;
- for(i=0;i<in_samples;i++){
- for(j=0;j<out_ch;j++){
+ for (i=0;i<in_samples;i++) {
+ for (j=0;j<out_ch;j++) {
float *samp;
samp=&buffer[i*out_ch+j];
*samp=0;
- for(k=0;k<in_ch;k++){
+ for (k=0;k<in_ch;k++) {
*samp+=d->bufs[i*in_ch+k]*d->matrix[in_ch*j+k];
}
}
@@ -915,8 +917,9 @@
return in_samples;
}
-int setup_downmix(oe_enc_opt *opt, int out_channels) {
- static const float stupid_matrix[7][8][2]={
+int setup_downmix(oe_enc_opt *opt, int out_channels)
+{
+ static const float stupid_matrix[7][8][2] = {
/*2*/ {{1,0},{0,1}},
/*3*/ {{1,0},{0.7071f,0.7071f},{0,1}},
/*4*/ {{1,0},{0,1},{0.866f,0.5f},{0.5f,0.866f}},
@@ -929,12 +932,12 @@
downmix *d;
int i,j;
- if(opt->channels<=out_channels || out_channels>2 || opt->channels<=0 || out_channels<=0) {
+ if (opt->channels<=out_channels || out_channels>2 || opt->channels<=0 || out_channels<=0) {
fprintf(stderr, _("Downmix must actually downmix and only knows mono/stereo out.\n"));
return 0;
}
- if(out_channels==2 && opt->channels>8) {
+ if (out_channels==2 && opt->channels>8) {
fprintf(stderr, _("Downmix only knows how to mix >8ch to mono.\n"));
return 0;
}
@@ -947,21 +950,21 @@
d->in_channels=opt->channels;
d->out_channels=out_channels;
- if(out_channels==1&&d->in_channels>8){
- for(i=0;i<d->in_channels;i++)d->matrix[i]=1.0f/d->in_channels;
- }else if(out_channels==2){
- for(j=0;j<d->out_channels;j++)
- for(i=0;i<d->in_channels;i++)d->matrix[d->in_channels*j+i]=
+ if (out_channels==1&&d->in_channels>8) {
+ for (i=0;i<d->in_channels;i++)d->matrix[i]=1.0f/d->in_channels;
+ } else if (out_channels==2) {
+ for (j=0;j<d->out_channels;j++)
+ for (i=0;i<d->in_channels;i++)d->matrix[d->in_channels*j+i]=
stupid_matrix[opt->channels-2][i][j];
- }else{
- for(i=0;i<d->in_channels;i++)d->matrix[i]=
+ } else {
+ for (i=0;i<d->in_channels;i++)d->matrix[i]=
(stupid_matrix[opt->channels-2][i][0])+
(stupid_matrix[opt->channels-2][i][1]);
}
sum=0;
- for(i=0;i<d->in_channels*d->out_channels;i++)sum+=d->matrix[i];
+ for (i=0;i<d->in_channels*d->out_channels;i++)sum+=d->matrix[i];
sum=(float)out_channels/sum;
- for(i=0;i<d->in_channels*d->out_channels;i++)d->matrix[i]*=sum;
+ for (i=0;i<d->in_channels*d->out_channels;i++)d->matrix[i]*=sum;
opt->read_samples = read_downmix;
opt->readdata = d;
@@ -969,7 +972,8 @@
return out_channels;
}
-void clear_downmix(oe_enc_opt *opt) {
+void clear_downmix(oe_enc_opt *opt)
+{
downmix *d = opt->readdata;
opt->read_samples = d->real_reader;
--- a/src/diag_range.c
+++ b/src/diag_range.c
@@ -208,7 +208,8 @@
return count;
}
-void save_range(FILE *frange, int frame_size, const unsigned char *packet, opus_int32 nbBytes, opus_uint32 *rngs, int nb_streams){
+void save_range(FILE *frange, int frame_size, const unsigned char *packet, opus_int32 nbBytes, opus_uint32 *rngs, int nb_streams)
+{
int i;
opus_int32 parsed_size;
const unsigned char *subpkt;
@@ -217,7 +218,7 @@
fprintf(frange,"%d, %ld, ",frame_size,(long)nbBytes);
subpkt=packet;
parsed_size=nbBytes;
- for(i=0;i<nb_streams;i++){
+ for (i=0;i<nb_streams;i++) {
int j,payload_offset,nf;
opus_int32 packet_offset;
opus_int16 size[48];
--- a/src/flac.c
+++ b/src/flac.c
@@ -40,7 +40,8 @@
/*Callback to read more data for the FLAC decoder.*/
static FLAC__StreamDecoderReadStatus read_callback(
const FLAC__StreamDecoder *decoder,FLAC__byte buffer[],size_t *bytes,
- void *client_data){
+ void *client_data)
+{
flacfile *flac;
(void)decoder;
flac=(flacfile *)client_data;
@@ -74,7 +75,8 @@
/*Callback to test the stream for EOF.*/
static FLAC__bool eof_callback(const FLAC__StreamDecoder *decoder,
- void *client_data){
+ void *client_data)
+{
flacfile *flac;
(void)decoder;
flac=(flacfile *)client_data;
@@ -83,7 +85,8 @@
/*Callback to process a metadata packet.*/
static void metadata_callback(const FLAC__StreamDecoder *decoder,
- const FLAC__StreamMetadata *metadata,void *client_data){
+ const FLAC__StreamMetadata *metadata,void *client_data)
+{
flacfile *flac;
oe_enc_opt *inopt;
(void)decoder;
@@ -223,7 +226,8 @@
/*Callback to process an audio frame.*/
static FLAC__StreamDecoderWriteStatus write_callback(
const FLAC__StreamDecoder *decoder,const FLAC__Frame *frame,
- const FLAC__int32 *const buffer[],void *client_data){
+ const FLAC__int32 *const buffer[],void *client_data)
+{
flacfile *flac;
int channels;
opus_int32 blocksize;
@@ -270,13 +274,15 @@
/*Dummy error callback (required by libFLAC).*/
static void error_callback(const FLAC__StreamDecoder *decoder,
- FLAC__StreamDecoderErrorStatus status,void *client_data){
+ FLAC__StreamDecoderErrorStatus status,void *client_data)
+{
(void)decoder;
(void)status;
(void)client_data;
}
-int flac_id(unsigned char *buf,int len){
+int flac_id(unsigned char *buf,int len)
+{
/*Something screwed up.*/
if(len<4)return 0;
/*Not FLAC.*/
@@ -285,7 +291,8 @@
return 1;
}
-int oggflac_id(unsigned char *buf,int len){
+int oggflac_id(unsigned char *buf,int len)
+{
/*Something screwed up.*/
if(len<33)return 0;
/*Not Ogg.*/
@@ -297,7 +304,8 @@
}
/*Read more data for the encoder.*/
-static long flac_read(void *client_data,float *buffer,int samples){
+static long flac_read(void *client_data,float *buffer,int samples)
+{
flacfile *flac;
int channels;
float *block_buf;
@@ -336,7 +344,8 @@
return ret;
}
-int flac_open(FILE *in,oe_enc_opt *opt,unsigned char *oldbuf,int buflen){
+int flac_open(FILE *in,oe_enc_opt *opt,unsigned char *oldbuf,int buflen)
+{
flacfile *flac;
/*Ok. At this point, we know we have a FLAC or an OggFLAC file.
Set up the FLAC decoder.*/
@@ -381,7 +390,8 @@
return 0;
}
-void flac_close(void *client_data){
+void flac_close(void *client_data)
+{
flacfile *flac;
flac=(flacfile *)client_data;
free(flac->block_buf);
@@ -394,19 +404,22 @@
/*FLAC support is disabled.*/
-int flac_id(unsigned char *buf,int len){
+int flac_id(unsigned char *buf,int len)
+{
(void)buf;
(void)len;
return 0;
}
-int oggflac_id(unsigned char *buf,int len){
+int oggflac_id(unsigned char *buf,int len)
+{
(void)buf;
(void)len;
return 0;
}
-int flac_open(FILE *in,oe_enc_opt *opt,unsigned char *oldbuf,int buflen){
+int flac_open(FILE *in,oe_enc_opt *opt,unsigned char *oldbuf,int buflen)
+{
(void)in;
(void)opt;
(void)oldbuf;
@@ -414,7 +427,8 @@
return 0;
}
-void flac_close(void *client_data){
+void flac_close(void *client_data)
+{
(void)client_data;
}
--- a/src/flac.h
+++ b/src/flac.h
@@ -30,7 +30,7 @@
typedef struct flacfile flacfile;
-struct flacfile{
+struct flacfile {
FLAC__StreamDecoder *decoder;
oe_enc_opt *inopt;
short channels;
--- a/src/opusdec.c
+++ b/src/opusdec.c
@@ -129,7 +129,8 @@
};
static unsigned int rngseed = 22222;
-static inline unsigned int fast_rand(void) {
+static inline unsigned int fast_rand(void)
+{
rngseed = (rngseed * 96314165) + 907633515;
return rngseed;
}
@@ -142,7 +143,8 @@
# define fmaxf(_x,_y) ((_x)>(_y)?(_x):(_y))
#endif
-static void quit(int _x) {
+static void quit(int _x)
+{
#ifdef WIN_UNICODE
uninit_console_utf8();
#endif
@@ -358,7 +360,7 @@
quit(1);
}
fout = fdopen(audio_fd, "w");
- if(!fout)
+ if (!fout)
{
perror("Cannot open output");
quit(1);
@@ -389,7 +391,7 @@
quit(1);
}
fout = fdopen(audio_fd, "w");
- if(!fout)
+ if (!fout)
{
perror("Cannot open output");
quit(1);
@@ -507,7 +509,7 @@
maxout=((link_read/48000)*rate + (link_read%48000)*rate/48000) - link_out;
maxout=maxout<0?0:maxout;
do {
- if (resampler){
+ if (resampler) {
unsigned in_len;
output=buf;
in_len = frame_size;
@@ -522,7 +524,7 @@
frame_size=0;
}
- if(!file||!fp)
+ if (!file||!fp)
{
/*Convert to short and save to output file*/
#if defined(HAVE_SOFT_CLIP)
@@ -530,32 +532,32 @@
#else
(void)clipmem;
#endif
- if (shapemem){
+ if (shapemem) {
shape_dither_toshort(shapemem,out,output,out_len,channels);
- }else{
+ } else {
for (i=0;i<(int)out_len*channels;i++)
out[i]=(short)float2int(fmaxf(-32768,fminf(output[i]*32768.f,32767)));
}
- if ((le_short(1)!=1)&&file){
+ if ((le_short(1)!=1)&&file) {
for (i=0;i<(int)out_len*channels;i++)
out[i]=le_short(out[i]);
}
}
- if(maxout>0)
+ if (maxout>0)
{
#if defined WIN32 || defined _WIN32
- if(!file){
+ if (!file) {
ret=WIN_Play_Samples(out, sizeof(short) * channels * (out_len<maxout?out_len:maxout));
- if(ret>0)ret/=sizeof(short)*channels;
+ if (ret>0) ret/=sizeof(short)*channels;
else fprintf(stderr, "Error playing audio.\n");
- }else
+ } else
#elif defined HAVE_LIBSNDIO
- if(!file){
+ if (!file) {
ret=sio_write(hdl, out, sizeof(short) * channels * (out_len<maxout?out_len:maxout));
- if(ret>0)ret/=sizeof(short)*channels;
+ if (ret>0) ret/=sizeof(short)*channels;
else fprintf(stderr, "Error playing audio.\n");
- }else
+ } else
#endif
ret=fwrite(fp?(char *)output:(char *)out,
(fp?sizeof(float):sizeof(short))*channels,
@@ -568,7 +570,7 @@
}
typedef struct decode_cb_ctx decode_cb_ctx;
-struct decode_cb_ctx{
+struct decode_cb_ctx {
FILE *frange;
float loss_percent;
};
@@ -582,7 +584,7 @@
(void)li;
lost = ctx->loss_percent>0
&& 100*((float)rand())/RAND_MAX<ctx->loss_percent;
- switch(format)
+ switch (format)
{
case OP_DEC_FORMAT_SHORT:
{
@@ -632,7 +634,7 @@
/*This will fail with OPUS_BAD_ARG the first time we ask for a
stream that isn't there, which is currently the only way to find
out how many streams there are using the libopus API.*/
- if(err<0)break;
+ if (err<0) break;
opus_decoder_ctl(od,OPUS_GET_FINAL_RANGE(&rngs[si]));
}
save_range(ctx->frange, nsamples, op->packet, op->bytes, rngs, si);
@@ -720,7 +722,7 @@
char **argv_utf8;
#endif
- if(query_cpu_support()){
+ if (query_cpu_support()) {
fprintf(stderr,"\n\n** WARNING: This program with compiled with SSE%s\n",query_cpu_support()>1?"2":"");
fprintf(stderr," but this CPU claims to lack these instructions. **\n\n");
}
@@ -740,7 +742,7 @@
shapemem.fs=0;
/*Process options*/
- while(1)
+ while (1)
{
c = getopt_long(argc_utf8, argv_utf8, "hV",
long_options, &option_index);
@@ -747,7 +749,7 @@
if (c==-1)
break;
- switch(c)
+ switch (c)
{
case 0:
if (strcmp(long_options[option_index].name,"help")==0)
@@ -783,14 +785,15 @@
} else if (strcmp(long_options[option_index].name,"gain")==0)
{
manual_gain=atof(optarg);
- }else if(strcmp(long_options[option_index].name,"save-range")==0){
- frange=fopen_utf8(optarg,"w");
- if(frange==NULL){
- perror(optarg);
- fprintf(stderr,"Could not open save-range file: %s\n",optarg);
- fprintf(stderr,"Must provide a writable file name.\n");
- quit(1);
- }
+ } else if (strcmp(long_options[option_index].name,"save-range")==0)
+ {
+ frange=fopen_utf8(optarg,"w");
+ if (frange==NULL) {
+ perror(optarg);
+ fprintf(stderr,"Could not open save-range file: %s\n",optarg);
+ fprintf(stderr,"Must provide a writable file name.\n");
+ quit(1);
+ }
} else if (strcmp(long_options[option_index].name,"packet-loss")==0)
{
loss_percent = atof(optarg);
@@ -819,7 +822,7 @@
/*Output to a file or playback?*/
file_output=argc_utf8-optind==2;
- if (file_output){
+ if (file_output) {
/*If we're outputting to a file, should we apply a wav header?*/
int i;
char *ext;
@@ -827,11 +830,11 @@
ext=".wav";
i=strlen(outFile)-4;
wav_format=i>=0;
- while(wav_format&&ext&&outFile[i]) {
+ while (wav_format&&ext&&outFile[i]) {
wav_format&=tolower(outFile[i++])==*ext++;
}
wav_format|=forcewav;
- }else {
+ } else {
outFile="";
wav_format=0;
/*If playing to audio out, default the rate to 48000
@@ -840,12 +843,12 @@
of output files and preserving length, which aren't
relevant for playback. Many audio devices sound
better at 48kHz and not resampling also saves CPU.*/
- if(rate==0)rate=48000;
+ if (rate==0) rate=48000;
/*Playback is 16-bit only.*/
fp=0;
}
/*If the output is floating point, don't dither.*/
- if(fp)dither=0;
+ if (fp) dither=0;
/*Open input file*/
if (strcmp(inFile, "-")==0)
@@ -958,9 +961,9 @@
channels=requested_channels;
fout=out_file_open(outFile, file_output,
&wav_format, rate, head->mapping_family, &channels, fp);
- if(channels!=requested_channels)force_stereo=1;
+ if (channels!=requested_channels) force_stereo=1;
/*Setup the memory for the dithered output*/
- if(!shapemem.a_buf)
+ if (!shapemem.a_buf)
{
shapemem.a_buf=calloc(channels,sizeof(float)*4);
shapemem.b_buf=calloc(channels,sizeof(float)*4);
@@ -968,7 +971,7 @@
}
output=malloc(sizeof(float)*MAX_FRAME_SIZE*channels);
permuted_output=NULL;
- if(wav_format&&(channels==3||channels>4))
+ if (wav_format&&(channels==3||channels>4))
{
int ci;
for (ci=0;ci<channels;ci++)
@@ -977,7 +980,7 @@
}
adjust_wav_mapping(head->mapping_family, channels, channel_map);
permuted_output=malloc(sizeof(float)*MAX_FRAME_SIZE*channels);
- if(!permuted_output)
+ if (!permuted_output)
{
fprintf(stderr, "Memory allocation failure.\n");
quit(1);
--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -294,12 +294,12 @@
data->nb_encoded += nb_samples;
data->packets_out++;
data->last_length = packet_len;
- if(data->frange!=NULL){
+ if (data->frange!=NULL) {
int ret;
opus_uint32 rngs[256];
OpusEncoder *oe;
int nb_streams;
- for(nb_streams=0;;nb_streams++){
+ for (nb_streams=0;;nb_streams++) {
ret=ope_encoder_ctl(data->enc,OPUS_MULTISTREAM_GET_ENCODER_STATE(nb_streams,&oe));
if (ret != OPE_OK || oe == NULL) break;
ret=opus_encoder_ctl(oe,OPUS_GET_FINAL_RANGE(&rngs[nb_streams]));
@@ -402,7 +402,7 @@
char **argv_utf8;
#endif
- if(query_cpu_support()){
+ if (query_cpu_support()) {
fprintf(stderr,"\n\n** WARNING: This program was compiled with SSE%s\n",query_cpu_support()>1?"2":"");
fprintf(stderr," but this CPU claims to lack these instructions. **\n\n");
}
@@ -446,7 +446,7 @@
/*Process command-line options*/
cline_size=0;
data.frange = NULL;
- while(1){
+ while (1) {
int c;
int save_cmd;
int option_index;
@@ -453,10 +453,10 @@
const char *optname;
c=getopt_long(argc_utf8, argv_utf8, "hV", long_options, &option_index);
- if(c==-1)
+ if (c==-1)
break;
- switch(c){
+ switch (c) {
case 0:
optname = long_options[option_index].name;
save_cmd = 1;
@@ -496,7 +496,7 @@
inopt.rawmode=1;
inopt.samplesize=atoi(optarg);
save_cmd=0;
- if(inopt.samplesize!=8&&inopt.samplesize!=16&&inopt.samplesize!=24){
+ if (inopt.samplesize!=8&&inopt.samplesize!=16&&inopt.samplesize!=24) {
fatal("Invalid bit-depth: %s\n"
"--raw-bits must be one of 8, 16, or 24\n", optarg);
}
@@ -520,7 +520,7 @@
downmix=-1;
} else if (strcmp(optname, "expect-loss")==0) {
expect_loss=atoi(optarg);
- if(expect_loss>100||expect_loss<0){
+ if (expect_loss>100||expect_loss<0) {
fatal("Invalid expect-loss: %s\n"
"Expected loss is a percentage in the range 0 to 100.\n", optarg);
}
@@ -527,18 +527,18 @@
} else if (strcmp(optname, "comp")==0 ||
strcmp(optname, "complexity")==0) {
complexity=atoi(optarg);
- if(complexity>10||complexity<0){
+ if (complexity>10||complexity<0) {
fatal("Invalid complexity: %s\n"
"Complexity must be in the range 0 to 10.\n", optarg);
}
} else if (strcmp(optname, "framesize")==0) {
- if(strcmp(optarg,"2.5")==0)opus_frame_param=OPUS_FRAMESIZE_2_5_MS;
- else if(strcmp(optarg,"5")==0)opus_frame_param=OPUS_FRAMESIZE_5_MS;
- else if(strcmp(optarg,"10")==0)opus_frame_param=OPUS_FRAMESIZE_10_MS;
- else if(strcmp(optarg,"20")==0)opus_frame_param=OPUS_FRAMESIZE_20_MS;
- else if(strcmp(optarg,"40")==0)opus_frame_param=OPUS_FRAMESIZE_40_MS;
- else if(strcmp(optarg,"60")==0)opus_frame_param=OPUS_FRAMESIZE_60_MS;
- else{
+ if (strcmp(optarg,"2.5")==0) opus_frame_param=OPUS_FRAMESIZE_2_5_MS;
+ else if (strcmp(optarg,"5")==0) opus_frame_param=OPUS_FRAMESIZE_5_MS;
+ else if (strcmp(optarg,"10")==0) opus_frame_param=OPUS_FRAMESIZE_10_MS;
+ else if (strcmp(optarg,"20")==0) opus_frame_param=OPUS_FRAMESIZE_20_MS;
+ else if (strcmp(optarg,"40")==0) opus_frame_param=OPUS_FRAMESIZE_40_MS;
+ else if (strcmp(optarg,"60")==0) opus_frame_param=OPUS_FRAMESIZE_60_MS;
+ else {
fatal("Invalid framesize: %s\n"
"Value is in milliseconds and must be 2.5, 5, 10, 20, 40, or 60.\n",
optarg);
@@ -548,7 +548,7 @@
: (opus_frame_param - OPUS_FRAMESIZE_20_MS + 1) * 960;
} else if (strcmp(optname, "max-delay")==0) {
double val=atof(optarg);
- if(val<0.||val>1000.){
+ if (val<0.||val>1000.) {
fatal("Invalid max-delay: %s\n"
"Value is in milliseconds and must be in the range 0 to 1000.\n",
optarg);
@@ -561,22 +561,22 @@
char *spos,*tpos;
size_t len=strlen(optarg);
spos=strchr(optarg,'=');
- if(len<3||spos==NULL||(spos-optarg)<1||(size_t)(spos-optarg)>=len){
+ if (len<3||spos==NULL||(spos-optarg)<1||(size_t)(spos-optarg)>=len) {
fatal("Invalid set-ctl-int: %s\n"
"Syntax is --set-ctl-int intX=intY\n"
" or --set-ctl-int intS:intX=intY\n", optarg);
}
tpos=strchr(optarg,':');
- if(tpos==NULL){
+ if (tpos==NULL) {
target=-1;
tpos=optarg-1;
- }else target=atoi(optarg);
+ } else target=atoi(optarg);
request=atoi(tpos+1);
if ((request & 1) != 0 || request == OPE_SET_PACKET_CALLBACK_REQUEST) {
fatal("Invalid set-ctl-int: %s\n"
"Set ctl values are even.\n", optarg);
}
- if(opt_ctls==0)opt_ctls_ctlval=malloc(sizeof(int)*3);
+ if (opt_ctls==0) opt_ctls_ctlval=malloc(sizeof(int)*3);
else opt_ctls_ctlval=realloc(opt_ctls_ctlval,sizeof(int)*(opt_ctls+1)*3);
if (!opt_ctls_ctlval) fatal("Error: failed to allocate memory for ctls\n");
opt_ctls_ctlval[opt_ctls*3]=target;
@@ -586,7 +586,7 @@
} else if (strcmp(optname, "save-range")==0) {
data.frange=fopen_utf8(optarg,"w");
save_cmd=0;
- if(data.frange==NULL){
+ if (data.frange==NULL) {
perror(optarg);
fatal("Error: cannot open save-range file: %s\n"
"Must provide a writable file name.\n", optarg);
@@ -594,7 +594,7 @@
range_file=optarg;
} else if (strcmp(optname, "comment")==0) {
save_cmd=0;
- if(!strchr(optarg,'=')){
+ if (!strchr(optarg,'=')) {
fatal("Invalid comment: %s\n"
"Comments must be of the form name=value\n", optarg);
}
@@ -628,7 +628,7 @@
media_type=media_type_end=description=description_end=filename=spec;
picture_file=fopen_utf8(filename,"rb");
description_copy=NULL;
- if(picture_file==NULL&&strchr(spec,'|')){
+ if (picture_file==NULL&&strchr(spec,'|')) {
const char *p;
char *q;
unsigned long val;
@@ -635,23 +635,23 @@
/*We don't have a plain file, and there is a pipe character: assume it's
the full form of the specification.*/
val=strtoul(spec,&q,10);
- if(*q!='|'||val>20){
+ if (*q!='|'||val>20) {
fatal("Invalid picture type: %.*s\n"
"Picture type must be in the range 0 to 20; see --help-picture.\n",
(int)strcspn(spec,"|"), spec);
}
/*An empty field implies a default of 'Cover (front)'.*/
- if(spec!=q)picture_type=(int)val;
+ if (spec!=q) picture_type=(int)val;
media_type=q+1;
media_type_end=media_type+strcspn(media_type,"|");
- if(*media_type_end=='|'){
+ if (*media_type_end=='|') {
description=media_type_end+1;
description_end=description+strcspn(description,"|");
- if(*description_end=='|'){
+ if (*description_end=='|') {
p=description_end+1;
/*Ignore WIDTHxHEIGHTxDEPTH/COLORS.*/
p+=strcspn(p,"|");
- if(*p=='|'){
+ if (*p=='|') {
filename=p+1;
}
}
@@ -700,14 +700,14 @@
if (save_cmd && cline_size<(int)sizeof(ENCODER_string)) {
ret=snprintf(&ENCODER_string[cline_size], sizeof(ENCODER_string)-cline_size,
"%s--%s", cline_size==0?"":" ", optname);
- if(ret<0||ret>=((int)sizeof(ENCODER_string)-cline_size)){
+ if (ret<0||ret>=((int)sizeof(ENCODER_string)-cline_size)) {
cline_size=sizeof(ENCODER_string);
} else {
cline_size+=ret;
- if(optarg){
+ if (optarg) {
ret=snprintf(&ENCODER_string[cline_size],
sizeof(ENCODER_string)-cline_size, " %s",optarg);
- if(ret<0||ret>=((int)sizeof(ENCODER_string)-cline_size)){
+ if (ret<0||ret>=((int)sizeof(ENCODER_string)-cline_size)) {
cline_size=sizeof(ENCODER_string);
} else {
cline_size+=ret;
@@ -730,7 +730,7 @@
break;
}
}
- if(argc_utf8-optind!=2){
+ if (argc_utf8-optind!=2) {
usage();
exit(1);
}
@@ -744,7 +744,7 @@
}
}
- if(strcmp(inFile, "-")==0){
+ if (strcmp(inFile, "-")==0) {
#if defined WIN32 || defined _WIN32
_setmode(_fileno(stdin), _O_BINARY);
#elif defined OS2
@@ -751,45 +751,45 @@
_fsetmode(stdin,"b");
#endif
fin=stdin;
- }else{
+ } else {
fin=fopen_utf8(inFile, "rb");
- if(!fin){
+ if (!fin) {
perror(inFile);
exit(1);
}
}
- if(inopt.rawmode){
+ if (inopt.rawmode) {
in_format = &raw_format;
in_format->open_func(fin, &inopt, NULL, 0);
- }else in_format=open_audio_file(fin,&inopt);
+ } else in_format=open_audio_file(fin,&inopt);
- if(!in_format){
+ if (!in_format) {
fatal("Error: unsupported input file: %s\n", inFile);
}
- if(inopt.rate<100||inopt.rate>768000){
+ if (inopt.rate<100||inopt.rate>768000) {
/*Crazy rates excluded to avoid excessive memory usage for padding/resampling.*/
fatal("Error: unsupported sample rate in input file: %ld Hz\n", inopt.rate);
}
- if(inopt.channels>255||inopt.channels<1){
+ if (inopt.channels>255||inopt.channels<1) {
fatal("Error: unsupported channel count in input file: %d\n"
"Channel count must be in the range 1 to 255.\n", inopt.channels);
}
- if(downmix==0&&inopt.channels>2&&bitrate>0&&bitrate<(16000*inopt.channels)){
- if(!quiet)fprintf(stderr,"Notice: Surround bitrate less than 16 kbit/s per channel, downmixing.\n");
+ if (downmix==0&&inopt.channels>2&&bitrate>0&&bitrate<(16000*inopt.channels)) {
+ if (!quiet) fprintf(stderr,"Notice: Surround bitrate less than 16 kbit/s per channel, downmixing.\n");
downmix=inopt.channels>8?1:2;
}
- if(downmix>0&&downmix<inopt.channels)downmix=setup_downmix(&inopt,downmix);
+ if (downmix>0&&downmix<inopt.channels) downmix=setup_downmix(&inopt,downmix);
else downmix=0;
rate=inopt.rate;
chan=inopt.channels;
- if(inopt.total_samples_per_channel && rate!=48000)
+ if (inopt.total_samples_per_channel && rate!=48000)
inopt.total_samples_per_channel = (opus_int64)
((double)inopt.total_samples_per_channel * (48000./(double)rate));
@@ -823,7 +823,7 @@
fatal("Error: OPE_SET_COMMENT_PADDING failed: %s\n", ope_strerror(ret));
}
- for(nb_streams=0;;nb_streams++){
+ for (nb_streams=0;;nb_streams++) {
OpusEncoder *oe;
ret=ope_encoder_ctl(enc,OPUS_MULTISTREAM_GET_ENCODER_STATE(nb_streams,&oe));
if (ret != OPE_OK || oe == NULL) break;
@@ -830,13 +830,13 @@
}
nb_coupled = chan - nb_streams;
- if(bitrate<0){
+ if (bitrate<0) {
/*Lower default rate for sampling rates [8000-44100) by a factor of (rate+16k)/(64k)*/
bitrate=((64000*nb_streams+32000*nb_coupled)*
(IMIN(48,IMAX(8,((rate<44100?rate:48000)+1000)/1000))+16)+32)>>6;
}
- if(bitrate>(1024000*chan)||bitrate<500){
+ if (bitrate>(1024000*chan)||bitrate<500) {
fatal("Error: bitrate %d bits/sec is insane\n%s"
"--bitrate values from 6 to 256 kbit/s per channel are meaningful.\n",
bitrate, bitrate>=1000000 ? "Did you mistake bits for kilobits?\n" : "");
@@ -851,7 +851,7 @@
if (ret != OPE_OK) {
fatal("Error: OPUS_SET_VBR %d failed: %s\n", !with_hard_cbr, ope_strerror(ret));
}
- if(!with_hard_cbr){
+ if (!with_hard_cbr) {
ret = ope_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(with_cvbr));
if (ret != OPE_OK) {
fatal("Error: OPUS_SET_VBR_CONSTRAINT %d failed: %s\n",
@@ -875,15 +875,15 @@
#endif
/*This should be the last set of SET ctls, so it can override the defaults.*/
- for(i=0;i<opt_ctls;i++){
+ for (i=0;i<opt_ctls;i++) {
int target=opt_ctls_ctlval[i*3];
- if(target==-1){
+ if (target==-1) {
ret = ope_encoder_ctl(enc, opt_ctls_ctlval[i*3+1],opt_ctls_ctlval[i*3+2]);
if (ret != OPE_OK) {
fatal("Error: failed to set encoder ctl %d=%d: %s\n",
opt_ctls_ctlval[i*3+1], opt_ctls_ctlval[i*3+2], ope_strerror(ret));
}
- }else if(target<nb_streams){
+ } else if (target<nb_streams) {
OpusEncoder *oe;
ret = ope_encoder_ctl(enc, OPUS_MULTISTREAM_GET_ENCODER_STATE(target,&oe));
if (ret != OPE_OK) {
@@ -891,11 +891,11 @@
target, ope_strerror(ret));
}
ret = opus_encoder_ctl(oe, opt_ctls_ctlval[i*3+1],opt_ctls_ctlval[i*3+2]);
- if(ret!=OPUS_OK){
+ if (ret!=OPUS_OK) {
fatal("Error: failed to set stream %d encoder ctl %d=%d: %s\n",
target, opt_ctls_ctlval[i*3+1], opt_ctls_ctlval[i*3+2], opus_strerror(ret));
}
- }else{
+ } else {
fatal("Error: --set-ctl-int stream %d is higher than the highest stream number %d\n",target,nb_streams-1);
}
}
@@ -906,21 +906,21 @@
fatal("Error: OPUS_GET_LOOKAHEAD failed: %s\n", ope_strerror(ret));
}
- if(!quiet){
+ if (!quiet) {
int opus_app;
fprintf(stderr,"Encoding using %s",opus_version);
ret = ope_encoder_ctl(enc, OPUS_GET_APPLICATION(&opus_app));
if (ret != OPE_OK) fprintf(stderr, "\n");
- else if(opus_app==OPUS_APPLICATION_VOIP)fprintf(stderr," (VoIP)\n");
- else if(opus_app==OPUS_APPLICATION_AUDIO)fprintf(stderr," (audio)\n");
- else if(opus_app==OPUS_APPLICATION_RESTRICTED_LOWDELAY)fprintf(stderr," (low-delay)\n");
+ else if (opus_app==OPUS_APPLICATION_VOIP) fprintf(stderr," (VoIP)\n");
+ else if (opus_app==OPUS_APPLICATION_AUDIO) fprintf(stderr," (audio)\n");
+ else if (opus_app==OPUS_APPLICATION_RESTRICTED_LOWDELAY) fprintf(stderr," (low-delay)\n");
else fprintf(stderr," (unknown application)\n");
fprintf(stderr,"-----------------------------------------------------\n");
fprintf(stderr," Input: %0.6g kHz, %d channel%s\n",
rate/1000.,chan,chan<2?"":"s");
fprintf(stderr," Output: %d channel%s (",chan,chan<2?"":"s");
- if(nb_coupled>0)fprintf(stderr,"%d coupled",nb_coupled*2);
- if(nb_streams-nb_coupled>0)fprintf(stderr,
+ if (nb_coupled>0) fprintf(stderr,"%d coupled",nb_coupled*2);
+ if (nb_streams-nb_coupled>0) fprintf(stderr,
"%s%d uncoupled",nb_coupled>0?", ":"",
nb_streams-nb_coupled);
fprintf(stderr,")\n %0.2gms packets, %0.6g kbit/s%s\n",
@@ -933,14 +933,14 @@
fprintf(stderr,"\n");
}
- if(strcmp(outFile,"-")==0){
+ if (strcmp(outFile,"-")==0) {
#if defined WIN32 || defined _WIN32
_setmode(_fileno(stdout), _O_BINARY);
#endif
data.fout=stdout;
- }else{
+ } else {
data.fout=fopen_utf8(outFile, "wb");
- if(!data.fout){
+ if (!data.fout) {
perror(outFile);
exit(1);
}
@@ -956,42 +956,42 @@
data.last_length = 0;
input=malloc(sizeof(float)*frame_size*chan);
- if(input==NULL){
+ if (input==NULL) {
fatal("Error: failed to allocate sample buffer\n");
}
/*Main encoding loop (one frame per iteration)*/
- while(1){
+ while (1) {
nb_samples = inopt.read_samples(inopt.readdata,input,frame_size);
total_samples+=nb_samples;
ret = ope_encoder_write_float(enc, input, nb_samples);
if (ret != OPE_OK || nb_samples < frame_size) break;
- if(!quiet){
+ if (!quiet) {
stop_time = time(NULL);
- if(stop_time>last_spin){
+ if (stop_time>last_spin) {
double estbitrate;
double coded_seconds=data.nb_encoded/48000.;
double wall_time=(double)(stop_time-start_time);
char sbuf[55];
static const char spinner[]="|/-\\";
- if(with_hard_cbr){
+ if (with_hard_cbr) {
estbitrate=data.last_length*(8*48000./frame_size);
- }else if(data.nb_encoded<=0){
+ } else if (data.nb_encoded<=0) {
estbitrate=0;
- }else{
+ } else {
double tweight=1./(1+exp(-((coded_seconds/10.)-3.)));
estbitrate=(data.total_bytes*8.0/coded_seconds)*tweight+
bitrate*(1.-tweight);
}
fprintf(stderr,"\r");
- for(i=0;i<last_spin_len;i++)fprintf(stderr," ");
+ for (i=0;i<last_spin_len;i++) fprintf(stderr," ");
if (inopt.total_samples_per_channel>0 &&
data.nb_encoded<inopt.total_samples_per_channel+lookahead) {
snprintf(sbuf,54,"\r[%c] %2d%% ",spinner[last_spin&3],
(int)floor(data.nb_encoded
/(double)(inopt.total_samples_per_channel+lookahead)*100.));
- }else{
+ } else {
snprintf(sbuf,54,"\r[%c] ",spinner[last_spin&3]);
}
last_spin_len=(int)strlen(sbuf);
@@ -1019,7 +1019,7 @@
if (ret != OPE_OK) fatal("Encoding aborted: %s\n", ope_strerror(ret));
stop_time = time(NULL);
- if(!quiet){
+ if (!quiet) {
double coded_seconds=data.nb_encoded/48000.;
double wall_time=(double)(stop_time-start_time);
fprintf(stderr,"Encoding complete\n");
@@ -1029,12 +1029,12 @@
fprintf(stderr,"\n Runtime:");
print_time(wall_time);
fprintf(stderr,"\n");
- if(wall_time>0){
+ if (wall_time>0) {
fprintf(stderr," (%0.4gx realtime)\n",coded_seconds/wall_time);
}
fprintf(stderr," Wrote: %" I64FORMAT " bytes, %" I64FORMAT " packets, "
"%" I64FORMAT " pages\n",data.bytes_written,data.packets_out,data.pages_out);
- if(data.nb_encoded>0){
+ if (data.nb_encoded>0) {
fprintf(stderr," Bitrate: %0.6g kbit/s (without overhead)\n",
data.total_bytes*8.0/(coded_seconds)/1000.0);
fprintf(stderr," Instant rates: %0.6g to %0.6g kbit/s\n"
@@ -1042,7 +1042,7 @@
data.min_bytes*(8*48000./frame_size/1000.),
data.peak_bytes*(8*48000./frame_size/1000.),data.min_bytes,data.peak_bytes);
}
- if(data.bytes_written>0){
+ if (data.bytes_written>0) {
fprintf(stderr," Overhead: %0.3g%% (container+metadata)\n",
(data.bytes_written-data.total_bytes)/(double)data.bytes_written*100.);
}
@@ -1052,12 +1052,12 @@
ope_encoder_destroy(enc);
ope_comments_destroy(inopt.comments);
free(input);
- if(opt_ctls)free(opt_ctls_ctlval);
+ if (opt_ctls) free(opt_ctls_ctlval);
- if(downmix)clear_downmix(&inopt);
+ if (downmix) clear_downmix(&inopt);
in_format->close_func(inopt.readdata);
- if(fin)fclose(fin);
- if(data.frange)fclose(data.frange);
+ if (fin) fclose(fin);
+ if (data.frange) fclose(data.frange);
#ifdef WIN_UNICODE
free_commandline_arguments_utf8(&argc_utf8, &argv_utf8);
#endif
--- a/src/opusinfo.c
+++ b/src/opusinfo.c
@@ -52,7 +52,8 @@
#define CONSTRAINT_PAGE_AFTER_EOS 1
#define CONSTRAINT_MUXING_VIOLATED 2
-static stream_set *create_stream_set(void) {
+static stream_set *create_stream_set(void)
+{
stream_set *set = calloc(1, sizeof(stream_set));
set->streams = calloc(5, sizeof(stream_processor));
@@ -225,8 +226,8 @@
}
if(broken) {
- char *simple = malloc (comment_length + 1);
- char *seq = malloc (comment_length * 3 + 1);
+ char *simple = malloc(comment_length + 1);
+ char *seq = malloc(comment_length * 3 + 1);
static char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
int k, c1 = 0, c2 = 0;
@@ -246,8 +247,8 @@
"%d (stream %d): invalid sequence \"%s\": %s\n"), i,
stream->num, simple, seq);
broken = 1;
- free (simple);
- free (seq);
+ free(simple);
+ free(seq);
break;
}
@@ -825,7 +826,8 @@
return 1;
}
-static void process_file(char *filename) {
+static void process_file(char *filename)
+{
FILE *file = fopen_utf8(filename, "rb");
ogg_sync_state ogsync;
ogg_page page;
@@ -923,13 +925,15 @@
fclose(file);
}
-static void version (void) {
- printf (_("opusinfo from %s %s\n"), PACKAGE_NAME, PACKAGE_VERSION);
+static void version(void)
+{
+ printf(_("opusinfo from %s %s\n"), PACKAGE_NAME, PACKAGE_VERSION);
}
-static void usage(void) {
- version ();
- printf (_(" by the Xiph.Org Foundation (https://www.xiph.org/)\n\n"));
+static void usage(void)
+{
+ version();
+ printf(_(" by the Xiph.Org Foundation (https://www.xiph.org/)\n\n"));
printf(_("(c) 2003-2005 Michael Smith <msmith@xiph.org>\n"
"(c) 2012 Gregory Maxwell <greg@xiph.org>\n\n"
"Opusinfo is a fork of ogginfo from the vorbis-tools package\n"
@@ -941,7 +945,7 @@
"\t messages, twice will remove warnings.\n"
"\t-v Make more verbose. This may enable more detailed checks\n"
"\t for some stream types.\n"));
- printf (_("\t-V Output version information and exit.\n"));
+ printf(_("\t-V Output version information and exit.\n"));
}
int main(int argc, char **argv)
--- a/src/opusrtp.c
+++ b/src/opusrtp.c
@@ -189,7 +189,8 @@
}
/* free a packet and its contents */
-void op_free(ogg_packet *op) {
+void op_free(ogg_packet *op)
+{
if (op) {
if (op->packet) {
free(op->packet);
--- a/src/picture.c
+++ b/src/picture.c
@@ -37,7 +37,8 @@
/*A version of strncasecmp() that is guaranteed to only ignore the case of
ASCII characters.*/
-int oi_strncasecmp(const char *a, const char *b, int n){
+int oi_strncasecmp(const char *a, const char *b, int n)
+{
int i;
for(i=0;i<n;i++){
int aval;
@@ -59,15 +60,18 @@
return 0;
}
-int is_jpeg(const unsigned char *buf, size_t length){
+int is_jpeg(const unsigned char *buf, size_t length)
+{
return length>=3&&memcmp(buf,"\xFF\xD8\xFF",3)==0;
}
-int is_png(const unsigned char *buf, size_t length){
+int is_png(const unsigned char *buf, size_t length)
+{
return length>=8&&memcmp(buf,"\x89PNG\x0D\x0A\x1A\x0A",8)==0;
}
-int is_gif(const unsigned char *buf, size_t length){
+int is_gif(const unsigned char *buf, size_t length)
+{
return length>=6
&&(memcmp(buf,"GIF87a",6)==0||memcmp(buf,"GIF89a",6)==0);
}
@@ -81,7 +85,8 @@
void extract_png_params(const unsigned char *data, size_t data_length,
ogg_uint32_t *width, ogg_uint32_t *height,
ogg_uint32_t *depth, ogg_uint32_t *colors,
- int *has_palette){
+ int *has_palette)
+{
if(is_png(data,data_length)){
size_t offs;
offs=8;
@@ -125,7 +130,8 @@
void extract_gif_params(const unsigned char *data, size_t data_length,
ogg_uint32_t *width, ogg_uint32_t *height,
ogg_uint32_t *depth, ogg_uint32_t *colors,
- int *has_palette){
+ int *has_palette)
+{
if(is_gif(data,data_length)&&data_length>=14){
*width=data[6]|data[7]<<8;
*height=data[8]|data[9]<<8;
@@ -143,7 +149,8 @@
void extract_jpeg_params(const unsigned char *data, size_t data_length,
ogg_uint32_t *width, ogg_uint32_t *height,
ogg_uint32_t *depth, ogg_uint32_t *colors,
- int *has_palette){
+ int *has_palette)
+{
if(is_jpeg(data,data_length)){
size_t offs;
offs=2;
--- a/src/picture.h
+++ b/src/picture.h
@@ -1,10 +1,10 @@
#include <ogg/ogg.h>
-typedef enum{
+typedef enum {
PIC_FORMAT_JPEG,
PIC_FORMAT_PNG,
PIC_FORMAT_GIF
-}picture_format;
+} picture_format;
int oi_strncasecmp(const char *a, const char *b, int n);
--- a/src/wav_io.c
+++ b/src/wav_io.c
@@ -43,9 +43,9 @@
int i;
/* If we aren't using one of the defined semantic channel maps, or we have
more channels than we know what to do with, use a default 1-1 mapping. */
- if(mapping_family != 1 || channels > 8)
+ if (mapping_family != 1 || channels > 8)
return;
- for(i = 0; i < channels; i++)
+ for (i = 0; i < channels; i++)
{
new_stream_map[wav_permute_matrix[channels-1][i]] = stream_map[i];
}
@@ -82,35 +82,35 @@
/* >16 bit audio also requires WAVEFORMATEXTENSIBLE. */
extensible |= fp;
- ret = fprintf (file, "RIFF") >= 0;
- ret &= fwrite_le32 (0x7fffffff, file);
+ ret = fprintf(file, "RIFF") >= 0;
+ ret &= fwrite_le32(0x7fffffff, file);
- ret &= fprintf (file, "WAVEfmt ") >= 0;
- ret &= fwrite_le32 (extensible ? 40 : 16, file);
- ret &= fwrite_le16 (extensible ? 0xfffe : (fp?3:1), file);
- ret &= fwrite_le16 (channels, file);
- ret &= fwrite_le32 (rate, file);
- ret &= fwrite_le32 ((fp?4:2)*channels*rate, file);
- ret &= fwrite_le16 ((fp?4:2)*channels, file);
- ret &= fwrite_le16 (fp?32:16, file);
+ ret &= fprintf(file, "WAVEfmt ") >= 0;
+ ret &= fwrite_le32(extensible ? 40 : 16, file);
+ ret &= fwrite_le16(extensible ? 0xfffe : (fp?3:1), file);
+ ret &= fwrite_le16(channels, file);
+ ret &= fwrite_le32(rate, file);
+ ret &= fwrite_le32((fp?4:2)*channels*rate, file);
+ ret &= fwrite_le16((fp?4:2)*channels, file);
+ ret &= fwrite_le16(fp?32:16, file);
- if(extensible)
+ if (extensible)
{
- static const unsigned char ksdataformat_subtype_pcm[16]=
+ static const unsigned char ksdataformat_subtype_pcm[16] =
{
- 0x01, 0x00, 0x00, 0x00,
- 0x00, 0x00,
- 0x10, 0x00,
- 0x80, 0x00,
- 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71
+ 0x01, 0x00, 0x00, 0x00,
+ 0x00, 0x00,
+ 0x10, 0x00,
+ 0x80, 0x00,
+ 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71
};
- static const unsigned char ksdataformat_subtype_float[16]=
+ static const unsigned char ksdataformat_subtype_float[16] =
{
- 0x03, 0x00, 0x00, 0x00,
- 0x00, 0x00,
- 0x10, 0x00,
- 0x80, 0x00,
- 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71
+ 0x03, 0x00, 0x00, 0x00,
+ 0x00, 0x00,
+ 0x10, 0x00,
+ 0x80, 0x00,
+ 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71
};
static const int wav_channel_masks[8] =
{
@@ -123,19 +123,19 @@
1|2|4|8|256|512|1024, /* 6.1 */
1|2|4|8|16|32|512|1024, /* 7.1 */
};
- ret &= fwrite_le16 (22, file);
- ret &= fwrite_le16 (fp?32:16, file);
- ret &= fwrite_le32 (wav_channel_masks[channels-1], file);
+ ret &= fwrite_le16(22, file);
+ ret &= fwrite_le16(fp?32:16, file);
+ ret &= fwrite_le32(wav_channel_masks[channels-1], file);
if (!fp)
{
- ret &= fwrite (ksdataformat_subtype_pcm, 16, 1, file);
+ ret &= fwrite(ksdataformat_subtype_pcm, 16, 1, file);
} else {
- ret &= fwrite (ksdataformat_subtype_float, 16, 1, file);
+ ret &= fwrite(ksdataformat_subtype_float, 16, 1, file);
}
}
- ret &= fprintf (file, "data") >= 0;
- ret &= fwrite_le32 (0x7fffffff, file);
+ ret &= fprintf(file, "data") >= 0;
+ ret &= fwrite_le32(0x7fffffff, file);
return !ret ? -1 : extensible ? 40 : 16;
}
--- a/src/wave_out.c
+++ b/src/wave_out.c
@@ -32,7 +32,6 @@
# include "config.h"
#endif
-/* Set TABS = 4 */
/********************************************************************
function: To provide playback of 16 bit PCM wave data in Win32
@@ -56,13 +55,13 @@
static HWAVEOUT dev = NULL;
static unsigned ScheduledBlocks = 0;
static int PlayedWaveHeadersCount = 0; // free index
-static WAVEHDR* PlayedWaveHeaders [MAX_WAVEBLOCKS];
+static WAVEHDR* PlayedWaveHeaders[MAX_WAVEBLOCKS];
static int
-Box ( const char* msg )
+Box(const char* msg)
{
- MessageBox ( NULL, msg, " "PACKAGE_NAME" "PACKAGE_VERSION": Error Message . . .", MB_OK | MB_ICONEXCLAMATION );
- return -1;
+ MessageBox(NULL, msg, " "PACKAGE_NAME" "PACKAGE_VERSION": Error Message . . .", MB_OK | MB_ICONEXCLAMATION);
+ return -1;
}
@@ -71,151 +70,148 @@
*/
static void CALLBACK
-wave_callback ( HWAVE hWave, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2 )
+wave_callback(HWAVE hWave, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2)
{
- (void) hWave;
- (void) dwInstance;
- (void) dwParam2;
- if ( uMsg == WOM_DONE ) {
- EnterCriticalSection ( &cs );
- PlayedWaveHeaders [PlayedWaveHeadersCount++] = (WAVEHDR*) dwParam1;
- LeaveCriticalSection ( &cs );
- }
+ (void)hWave;
+ (void)dwInstance;
+ (void)dwParam2;
+ if (uMsg == WOM_DONE) {
+ EnterCriticalSection(&cs);
+ PlayedWaveHeaders[PlayedWaveHeadersCount++] = (WAVEHDR*)dwParam1;
+ LeaveCriticalSection(&cs);
+ }
}
static void
-free_memory ( void )
+free_memory(void)
{
- WAVEHDR* wh;
- HGLOBAL hg;
+ WAVEHDR* wh;
+ HGLOBAL hg;
- EnterCriticalSection ( &cs );
- wh = PlayedWaveHeaders [--PlayedWaveHeadersCount];
- ScheduledBlocks--; // decrease the number of USED blocks
- LeaveCriticalSection ( &cs );
+ EnterCriticalSection(&cs);
+ wh = PlayedWaveHeaders[--PlayedWaveHeadersCount];
+ ScheduledBlocks--; // decrease the number of USED blocks
+ LeaveCriticalSection(&cs);
- waveOutUnprepareHeader ( dev, wh, sizeof (WAVEHDR) );
+ waveOutUnprepareHeader(dev, wh, sizeof(WAVEHDR));
- hg = GlobalHandle ( wh -> lpData ); // Deallocate the buffer memory
- GlobalUnlock (hg);
- GlobalFree (hg);
+ hg = GlobalHandle(wh -> lpData); // Deallocate the buffer memory
+ GlobalUnlock(hg);
+ GlobalFree(hg);
- hg = GlobalHandle ( wh ); // Deallocate the header memory
- GlobalUnlock (hg);
- GlobalFree (hg);
+ hg = GlobalHandle(wh); // Deallocate the header memory
+ GlobalUnlock(hg);
+ GlobalFree(hg);
}
Int
-Set_WIN_Params ( FILE_T dummyFile ,
- Ldouble SampleFreq,
- Uint BitsPerSample,
- Uint Channels )
+Set_WIN_Params(FILE_T dummyFile, Ldouble SampleFreq, Uint BitsPerSample, Uint Channels)
{
- WAVEFORMATEX outFormat;
- UINT deviceID = WAVE_MAPPER;
+ WAVEFORMATEX outFormat;
+ UINT deviceID = WAVE_MAPPER;
- (void) dummyFile;
+ (void)dummyFile;
- if ( waveOutGetNumDevs () == 0 )
- return Box ( "No audio device present." );
+ if (waveOutGetNumDevs() == 0)
+ return Box("No audio device present.");
- outFormat.wFormatTag = WAVE_FORMAT_PCM;
- outFormat.wBitsPerSample = BitsPerSample;
- outFormat.nChannels = Channels;
- outFormat.nSamplesPerSec = (unsigned long)(SampleFreq + 0.5);
- outFormat.nBlockAlign = (outFormat.wBitsPerSample + 7) / 8 * outFormat.nChannels;
- outFormat.nAvgBytesPerSec = outFormat.nSamplesPerSec * outFormat.nBlockAlign;
+ outFormat.wFormatTag = WAVE_FORMAT_PCM;
+ outFormat.wBitsPerSample = BitsPerSample;
+ outFormat.nChannels = Channels;
+ outFormat.nSamplesPerSec = (unsigned long)(SampleFreq + 0.5);
+ outFormat.nBlockAlign = (outFormat.wBitsPerSample + 7) / 8 * outFormat.nChannels;
+ outFormat.nAvgBytesPerSec = outFormat.nSamplesPerSec * outFormat.nBlockAlign;
- switch ( waveOutOpen ( &dev, deviceID, &outFormat, (DWORD_PTR)wave_callback, 0, CALLBACK_FUNCTION ) )
- {
- case MMSYSERR_ALLOCATED: return Box ( "Device is already open." );
- case MMSYSERR_BADDEVICEID: return Box ( "The specified device is out of range." );
- case MMSYSERR_NODRIVER: return Box ( "There is no audio driver in this system." );
- case MMSYSERR_NOMEM: return Box ( "Unable to allocate sound memory." );
- case WAVERR_BADFORMAT: return Box ( "This audio format is not supported." );
- case WAVERR_SYNC: return Box ( "The device is synchronous." );
- default: return Box ( "Unknown media error." );
- case MMSYSERR_NOERROR: break;
- }
+ switch (waveOutOpen(&dev, deviceID, &outFormat, (DWORD_PTR)wave_callback, 0, CALLBACK_FUNCTION))
+ {
+ case MMSYSERR_ALLOCATED: return Box("Device is already open.");
+ case MMSYSERR_BADDEVICEID: return Box("The specified device is out of range.");
+ case MMSYSERR_NODRIVER: return Box("There is no audio driver in this system.");
+ case MMSYSERR_NOMEM: return Box("Unable to allocate sound memory.");
+ case WAVERR_BADFORMAT: return Box("This audio format is not supported.");
+ case WAVERR_SYNC: return Box("The device is synchronous.");
+ default: return Box("Unknown media error.");
+ case MMSYSERR_NOERROR: break;
+ }
- waveOutReset ( dev );
- InitializeCriticalSection ( &cs );
- SetPriorityClass ( GetCurrentProcess (), HIGH_PRIORITY_CLASS );
- return 0;
+ waveOutReset(dev);
+ InitializeCriticalSection(&cs);
+ SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS);
+ return 0;
}
int
-WIN_Play_Samples ( const void* data, size_t len )
+WIN_Play_Samples(const void* data, size_t len)
{
- HGLOBAL hg;
- HGLOBAL hg2;
- LPWAVEHDR wh;
- void* allocptr;
+ HGLOBAL hg;
+ HGLOBAL hg2;
+ LPWAVEHDR wh;
+ void* allocptr;
- do {
- while ( PlayedWaveHeadersCount > 0 ) // free used blocks ...
- free_memory ();
+ do {
+ while (PlayedWaveHeadersCount > 0) // free used blocks ...
+ free_memory();
- if ( ScheduledBlocks < sizeof(PlayedWaveHeaders)/sizeof(*PlayedWaveHeaders) ) // wait for a free block ...
- break;
- Sleep (26);
- } while (1);
+ if (ScheduledBlocks < sizeof(PlayedWaveHeaders)/sizeof(*PlayedWaveHeaders)) // wait for a free block ...
+ break;
+ Sleep(26);
+ } while (1);
- if ( (hg2 = GlobalAlloc ( GMEM_MOVEABLE, len )) == NULL ) // allocate some memory for a copy of the buffer
- return Box ( "GlobalAlloc failed." );
+ if ((hg2 = GlobalAlloc(GMEM_MOVEABLE, len)) == NULL) // allocate some memory for a copy of the buffer
+ return Box("GlobalAlloc failed.");
- allocptr = GlobalLock (hg2);
- CopyMemory ( allocptr, data, len ); // Here we can call any modification output functions we want....
+ allocptr = GlobalLock(hg2);
+ CopyMemory(allocptr, data, len); // Here we can call any modification output functions we want....
- if ( (hg = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof (WAVEHDR))) == NULL ) // now make a header and WRITE IT!
- return -1;
+ if ((hg = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(WAVEHDR))) == NULL) // now make a header and WRITE IT!
+ return -1;
- wh = GlobalLock (hg);
- wh -> dwBufferLength = len;
- wh -> lpData = allocptr;
+ wh = GlobalLock(hg);
+ wh->dwBufferLength = len;
+ wh->lpData = allocptr;
- if ( waveOutPrepareHeader ( dev, wh, sizeof (WAVEHDR)) != MMSYSERR_NOERROR ) {
- GlobalUnlock (hg);
- GlobalFree (hg);
- return -1;
- }
+ if (waveOutPrepareHeader(dev, wh, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) {
+ GlobalUnlock(hg);
+ GlobalFree(hg);
+ return -1;
+ }
- if ( waveOutWrite ( dev, wh, sizeof (WAVEHDR)) != MMSYSERR_NOERROR ) {
- GlobalUnlock (hg);
- GlobalFree (hg);
- return -1;
- }
+ if (waveOutWrite(dev, wh, sizeof(WAVEHDR)) != MMSYSERR_NOERROR) {
+ GlobalUnlock(hg);
+ GlobalFree(hg);
+ return -1;
+ }
- EnterCriticalSection ( &cs );
- ScheduledBlocks++;
- LeaveCriticalSection ( &cs );
+ EnterCriticalSection(&cs);
+ ScheduledBlocks++;
+ LeaveCriticalSection(&cs);
- return len;
+ return len;
}
int
-WIN_Audio_close ( void )
+WIN_Audio_close(void)
{
- if ( dev != NULL ) {
+ if (dev != NULL) {
- while ( ScheduledBlocks > 0 ) {
- Sleep (ScheduledBlocks);
- while ( PlayedWaveHeadersCount > 0 ) // free used blocks ...
- free_memory ();
- }
+ while (ScheduledBlocks > 0) {
+ Sleep(ScheduledBlocks);
+ while (PlayedWaveHeadersCount > 0) // free used blocks ...
+ free_memory();
+ }
- waveOutReset (dev); // reset the device
- waveOutClose (dev); // close the device
- dev = NULL;
- }
+ waveOutReset(dev); // reset the device
+ waveOutClose(dev); // close the device
+ dev = NULL;
+ }
- DeleteCriticalSection ( &cs );
- ScheduledBlocks = 0;
- return 0;
+ DeleteCriticalSection(&cs);
+ ScheduledBlocks = 0;
+ return 0;
}
#endif