[xiph-cvs] cvs commit: vorbis-python/src pyvorbiscodec.c pyvorbisfile.c pyvorbisinfo.c

Andrew Catham Master of Python andrew at xiph.org
Tue May 13 01:29:46 PDT 2003



andrew      03/05/13 04:29:46

  Modified:    .        ChangeLog
               src      pyvorbiscodec.c pyvorbisfile.c pyvorbisinfo.c
  Log:
  2003-5-13   Andrew H. Chatham <pyogg at andrewchatham.com>
          * pyvorbisinfo.c (py_info_new): Applied patch from
          Andrew Mahone to allow negative quality values
          * pyvorbisfile.c (is_big_endian): Use runtime endian test rather
          than try to figure out where everyone keeps endian.h
          * pyvorbiscodec.c (py_dsp_write_wav): Applied patch from Andrew
          Mahone to fix a truncation bug with weird wav files.

Revision  Changes    Path
1.21      +8 -0      vorbis-python/ChangeLog

Index: ChangeLog
===================================================================
RCS file: /usr/local/cvsroot/vorbis-python/ChangeLog,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- ChangeLog	8 Feb 2003 07:12:29 -0000	1.20
+++ ChangeLog	13 May 2003 08:29:45 -0000	1.21
@@ -1,3 +1,11 @@
+2003-5-13   Andrew H. Chatham <pyogg at andrewchatham.com>
+	* pyvorbisinfo.c (py_info_new): Applied patch from 
+	Andrew Mahone to allow negative quality values
+	* pyvorbisfile.c (is_big_endian): Use runtime endian test rather
+	than try to figure out where everyone keeps endian.h
+	* pyvorbiscodec.c (py_dsp_write_wav): Applied patch from Andrew
+	Mahone to fix a truncation bug with weird wav files.
+	
 2003-2-07   Andrew H. Chatham <pyogg at andrewchatham.com>
         * Applied another patch from Nicodemus to fix things windows. Pass
         the "b" flag to all file open commands.

<p><p>1.8       +89 -88    vorbis-python/src/pyvorbiscodec.c

Index: pyvorbiscodec.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-python/src/pyvorbiscodec.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- pyvorbiscodec.c	19 Jan 2003 00:50:48 -0000	1.7
+++ pyvorbiscodec.c	13 May 2003 08:29:45 -0000	1.8
@@ -11,7 +11,7 @@
 
 /**************************************************************
                          VorbisDSP Object
- **************************************************************/
+**************************************************************/
 
 FDEF(vorbis_analysis_headerout) "Create three header packets for an ogg\n"
 "stream, given an optional comment object.";
@@ -72,12 +72,12 @@
    METH_VARARGS, py_vorbis_block_init_doc},
   {"write", py_dsp_write,
    METH_VARARGS, py_dsp_write_doc},
-	{"write_wav", py_dsp_write_wav,
-	 METH_VARARGS, py_dsp_write_wav_doc},
+  {"write_wav", py_dsp_write_wav,
+   METH_VARARGS, py_dsp_write_wav_doc},
   {"close", py_dsp_close,
    METH_VARARGS, py_dsp_close_doc},
-	{"bitrate_flushpacket", py_vorbis_bitrate_flushpacket,
-	 METH_VARARGS, py_vorbis_bitrate_flushpacket_doc},
+  {"bitrate_flushpacket", py_vorbis_bitrate_flushpacket,
+   METH_VARARGS, py_vorbis_bitrate_flushpacket_doc},
   {NULL, NULL}
 };
 
@@ -107,7 +107,7 @@
     return NULL;
   
   ret = (py_dsp *) PyObject_NEW(py_dsp, &py_dsp_type);
-	ret->parent = NULL;
+  ret->parent = NULL;
   vi = &py_vi->vi;
   vorbis_synthesis_init(&vd, vi);
   return py_dsp_from_dsp(&vd, (PyObject *) py_vi);
@@ -116,7 +116,7 @@
 static void
 py_dsp_dealloc(PyObject *self)
 {
-	vorbis_dsp_clear(PY_DSP(self));
+  vorbis_dsp_clear(PY_DSP(self));
   Py_XDECREF(((py_dsp *)self)->parent);
   PyMem_DEL(self);
 }
@@ -264,11 +264,11 @@
 
   channels = dsp_self->vd.vi->channels;
 
-	if (PyTuple_Size(args) == 1 && PyTuple_GET_ITEM(args, 0) == Py_None) {
-		vorbis_analysis_wrote(&dsp_self->vd, 0);
-		Py_INCREF(Py_None);
-		return Py_None;
-	}
+  if (PyTuple_Size(args) == 1 && PyTuple_GET_ITEM(args, 0) == Py_None) {
+    vorbis_analysis_wrote(&dsp_self->vd, 0);
+    Py_INCREF(Py_None);
+    return Py_None;
+  }
   if (PyTuple_Size(args) != channels) {
     snprintf(err_msg, sizeof(err_msg), 
              "Expected %d strings as arguments; found %d arguments",
@@ -309,58 +309,59 @@
 
 static void
 parse_wav_data(const char *byte_data, float **buff, 
-							 int channels, int samples)
+	       int channels, int samples)
 {
-	const float adjust = 1/32768.0;
-	int j, k;
-	for (j = 0; j < samples; j++) {
-		for (k = 0; k < channels; k++) {
-			float val = ((byte_data[j * 2 * channels + 2 * k + 1] << 8) | 
-									 (byte_data[j * 2 * channels + 2 * k] & 0xff)) * adjust;
-			buff[k][j] = val;
-		}
-	}
+  const float adjust = 1/32768.0;
+  int j, k;
+  for (j = 0; j < samples; j++) {
+    for (k = 0; k < channels; k++) {
+      float val = ((byte_data[j * 2 * channels + 2 * k + 1] << 8) | 
+		   (byte_data[j * 2 * channels + 2 * k] & 0xff)) * adjust;
+      buff[k][j] = val;
+    }
+  }
 }
 
 static PyObject *
 py_dsp_write_wav(PyObject *self, PyObject *args) 
 {
-	const char *byte_data;
-	int num_bytes, channels, k;
-	long samples;
-	const int samples_per_it = 1024;
-	py_dsp *dsp = (py_dsp *) self;
-	float **analysis_buffer;
-	int sample_width;
-
-	channels = dsp->vd.vi->channels;
-	sample_width = channels * 2;
-
-	if (!PyArg_ParseTuple(args, "s#", &byte_data, &num_bytes))
-		return NULL;
-
-	if (num_bytes % (channels * 2) != 0) {
-		PyErr_SetString(Py_VorbisError,
-										"Data is not a multiple of (2 * # of channels)");
-		return NULL;
-	}
-	samples = num_bytes / sample_width;
-	
-	for (k = 0; k < samples / samples_per_it; k++) {
-		int to_write = MIN(samples - k * samples_per_it, samples_per_it);
+  const char *byte_data;
+  int num_bytes, channels, k;
+  long samples;
+  const int samples_per_it = 1024;
+  py_dsp *dsp = (py_dsp *) self;
+  float **analysis_buffer;
+  int sample_width;
 
-		analysis_buffer = vorbis_analysis_buffer(&dsp->vd, 
-																						 to_write * sizeof(float));
-		/* Parse the wav data directly into the analysis buffer. */
-		parse_wav_data(byte_data, analysis_buffer, channels, to_write);
+  channels = dsp->vd.vi->channels;
+  sample_width = channels * 2;
 
-		/* Skip any data we've already passed by incrementing the pointer */
-		byte_data += to_write * sample_width;
+  if (!PyArg_ParseTuple(args, "s#", &byte_data, &num_bytes))
+    return NULL;
 
-		vorbis_analysis_wrote(&dsp->vd, to_write);
-	}
+  if (num_bytes % sample_width != 0) {
+    PyErr_SetString(Py_VorbisError,
+		    "Data is not a multiple of (2 * # of channels)");
+    return NULL;
+  }
+  samples = num_bytes / sample_width;
         
-	return PyInt_FromLong(samples);
+  for (k = 0; 
+       k < (samples + samples_per_it - 1) / samples_per_it; k++) {
+    int to_write = MIN(samples - k * samples_per_it, samples_per_it);
+
+    analysis_buffer = vorbis_analysis_buffer(&dsp->vd, 
+					     to_write * sizeof(float));
+    /* Parse the wav data directly into the analysis buffer. */
+    parse_wav_data(byte_data, analysis_buffer, channels, to_write);
+
+    /* Skip any data we've already passed by incrementing the pointer */
+    byte_data += to_write * sample_width;
+
+    vorbis_analysis_wrote(&dsp->vd, to_write);
+  }
+	
+  return PyInt_FromLong(samples);
 }
 
 static PyObject *
@@ -375,27 +376,27 @@
 static PyObject *
 py_vorbis_bitrate_flushpacket(PyObject *self, PyObject *args)
 {
-	ogg_packet op;
-	int ret;
+  ogg_packet op;
+  int ret;
         
-	if (!PyArg_ParseTuple(args, ""))
-		return NULL;
+  if (!PyArg_ParseTuple(args, ""))
+    return NULL;
 
-	ret = vorbis_bitrate_flushpacket(PY_DSP(self), &op);
-	if (ret == 1) 
-		return modinfo->ogg_packet_from_packet(&op);
-	else if (ret == 0) {
-		Py_INCREF(Py_None);
-		return Py_None;
-	} else {
-		PyErr_SetString(Py_VorbisError, "Unknown return code from flushpacket");
-		return NULL;
-	}
+  ret = vorbis_bitrate_flushpacket(PY_DSP(self), &op);
+  if (ret == 1) 
+    return modinfo->ogg_packet_from_packet(&op);
+  else if (ret == 0) {
+    Py_INCREF(Py_None);
+    return Py_None;
+  } else {
+    PyErr_SetString(Py_VorbisError, "Unknown return code from flushpacket");
+    return NULL;
+  }
 }
 
 /*********************************************************
                         VorbisBlock
- *********************************************************/
+*********************************************************/
 static void py_block_dealloc(PyObject *);
 static PyObject *py_block_getattr(PyObject *, char*);
 
@@ -436,8 +437,8 @@
 static PyMethodDef Block_methods[] = {
   {"analysis", py_vorbis_analysis,
    METH_VARARGS, py_vorbis_analysis_doc},
-	{"addblock", py_vorbis_bitrate_addblock,
-	 METH_VARARGS, py_vorbis_bitrate_addblock_doc},
+  {"addblock", py_vorbis_bitrate_addblock,
+   METH_VARARGS, py_vorbis_bitrate_addblock_doc},
   {NULL, NULL}
 };
 
@@ -458,34 +459,34 @@
 static PyObject*
 py_vorbis_analysis(PyObject *self, PyObject *args)
 {
-	int ret;
+  int ret;
   py_block *b_self = (py_block *) self;
 
   if (!PyArg_ParseTuple(args, ""))
     return NULL;
 
   ret = vorbis_analysis(&b_self->vb, NULL);
-	if (ret < 0) {
-		PyErr_SetString(Py_VorbisError, "vorbis_analysis failure");
-		return NULL;
-	}
-	Py_INCREF(Py_None);
-	return Py_None;
+  if (ret < 0) {
+    PyErr_SetString(Py_VorbisError, "vorbis_analysis failure");
+    return NULL;
+  }
+  Py_INCREF(Py_None);
+  return Py_None;
 }
 
 static PyObject *
 py_vorbis_bitrate_addblock(PyObject *self, PyObject *args)
 {
-	int ret;
-	if (!PyArg_ParseTuple(args, ""))
-		return NULL;
-	ret = vorbis_bitrate_addblock(PY_BLOCK(self));
-	if (ret < 0) {
-		PyErr_SetString(Py_VorbisError, "addblock failed");
-		return NULL;
-	}
-	Py_INCREF(Py_None);
-	return Py_None;
+  int ret;
+  if (!PyArg_ParseTuple(args, ""))
+    return NULL;
+  ret = vorbis_bitrate_addblock(PY_BLOCK(self));
+  if (ret < 0) {
+    PyErr_SetString(Py_VorbisError, "addblock failed");
+    return NULL;
+  }
+  Py_INCREF(Py_None);
+  return Py_None;
 }
 
 PyObject *

<p><p>1.10      +8 -1      vorbis-python/src/pyvorbisfile.c

Index: pyvorbisfile.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-python/src/pyvorbisfile.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- pyvorbisfile.c	8 Feb 2003 07:12:29 -0000	1.9
+++ pyvorbisfile.c	13 May 2003 08:29:45 -0000	1.10
@@ -264,6 +264,12 @@
 
 static char *read_kwlist[] = {"length", "bigendian", "word", "signed", NULL};
 
+static int is_big_endian() {
+  static int x = 0x1;
+  char x_as_char = *(char *) &x;
+  return x_as_char == 0x1 ? 0 : 1;
+}
+
 static PyObject *
 py_ov_read(PyObject *self, PyObject *args, PyObject *kwdict)
 {
@@ -278,7 +284,8 @@
   int length, word, sgned, bitstream;
   int bigendianp;
 
-  bigendianp = (BYTE_ORDER == BIG_ENDIAN);
+  // Default to host order
+  bigendianp = is_big_endian();
   length = 4096;
   word = 2;
   sgned = 1;

<p><p>1.16      +1 -1      vorbis-python/src/pyvorbisinfo.c

Index: pyvorbisinfo.c
===================================================================
RCS file: /usr/local/cvsroot/vorbis-python/src/pyvorbisinfo.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- pyvorbisinfo.c	8 Feb 2003 07:12:29 -0000	1.15
+++ pyvorbisinfo.c	13 May 2003 08:29:46 -0000	1.16
@@ -100,7 +100,7 @@
     return NULL;
   vorbis_info_init(&vi);
 
-  if (quality > 0.0) {
+  if (quality > -1.0) {
     res = vorbis_encode_init_vbr(&vi, channels, rate, quality);
   } else {
     res = vorbis_encode_init(&vi, channels, rate,

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list