[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30754] branches/soc-2010-nexyon/intern/ audaspace: Audaspace Py API:

Joerg Mueller nexyon at gmail.com
Mon Jul 26 13:17:43 CEST 2010


Revision: 30754
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30754
Author:   nexyon
Date:     2010-07-26 13:17:43 +0200 (Mon, 26 Jul 2010)

Log Message:
-----------
Audaspace Py API:
* Renamed get_c_device() to device()
* Made the threshold parameter of Sound.square() optional
* Added a sample rate parameter for Sound.sine()
* Example updates

Modified Paths:
--------------
    branches/soc-2010-nexyon/intern/audaspace/Python/AUD_PyAPI.cpp
    branches/soc-2010-nexyon/intern/audaspace/Python/doc/examples/aud.py
    branches/soc-2010-nexyon/intern/audaspace/Python/doc/examples/tetris.py
    branches/soc-2010-nexyon/intern/audaspace/intern/AUD_C-API.cpp

Modified: branches/soc-2010-nexyon/intern/audaspace/Python/AUD_PyAPI.cpp
===================================================================
--- branches/soc-2010-nexyon/intern/audaspace/Python/AUD_PyAPI.cpp	2010-07-26 10:41:26 UTC (rev 30753)
+++ branches/soc-2010-nexyon/intern/audaspace/Python/AUD_PyAPI.cpp	2010-07-26 11:17:43 UTC (rev 30754)
@@ -118,10 +118,12 @@
 }
 
 PyDoc_STRVAR(M_aud_Sound_sine_doc,
-			 "sine(frequency)\n\n"
+			 "sine(frequency[, rate])\n\n"
 			 "Creates a sine sound wave.\n\n"
 			 ":arg frequency: The frequency of the sine wave in Hz.\n"
 			 ":type frequency: float\n"
+			 ":arg rate: The sampling rate in Hz.\n"
+			 ":type rate: int\n"
 			 ":return: The created aud.Sound object.\n"
 			 ":rtype: aud.Sound");
 
@@ -310,7 +312,7 @@
 Sound_buffer(Sound* self);
 
 PyDoc_STRVAR(M_aud_Sound_square_doc,
-			 "squre(threshold)\n\n"
+			 "squre([threshold = 0])\n\n"
 			 "Makes a square wave out of an audio wave.\n\n"
 			 ":arg threshold: Threshold value over which an amplitude counts non-zero.\n"
 			 ":type threshold: float\n"
@@ -424,8 +426,9 @@
 Sound_sine(PyObject* nothing, PyObject* args)
 {
 	double frequency;
+	int rate = 44100;
 
-	if(!PyArg_ParseTuple(args, "d", &frequency))
+	if(!PyArg_ParseTuple(args, "d|i", &frequency, &rate))
 		return NULL;
 
 	Sound *self;
@@ -435,7 +438,7 @@
 	{
 		try
 		{
-			self->factory = new AUD_SinusFactory(frequency, (AUD_SampleRate)44100);
+			self->factory = new AUD_SinusFactory(frequency, (AUD_SampleRate)rate);
 		}
 		catch(AUD_Exception&)
 		{
@@ -889,9 +892,9 @@
 static PyObject *
 Sound_square(Sound* self, PyObject* args)
 {
-	float threshold;
+	float threshold = 0;
 
-	if(!PyArg_ParseTuple(args, "f", &threshold))
+	if(!PyArg_ParseTuple(args, "|f", &threshold))
 		return NULL;
 
 	Sound *parent = (Sound*)SoundType.tp_alloc(&SoundType, 0);

Modified: branches/soc-2010-nexyon/intern/audaspace/Python/doc/examples/aud.py
===================================================================
--- branches/soc-2010-nexyon/intern/audaspace/Python/doc/examples/aud.py	2010-07-26 10:41:26 UTC (rev 30753)
+++ branches/soc-2010-nexyon/intern/audaspace/Python/doc/examples/aud.py	2010-07-26 11:17:43 UTC (rev 30754)
@@ -1,5 +1,5 @@
 import aud
-device = aud.get_c_device()
+device = aud.device()
 s = aud.Sound('music.ogg')
 c = device.play(s)
 buffered = aud.Sound.buffer(s)

Modified: branches/soc-2010-nexyon/intern/audaspace/Python/doc/examples/tetris.py
===================================================================
--- branches/soc-2010-nexyon/intern/audaspace/Python/doc/examples/tetris.py	2010-07-26 10:41:26 UTC (rev 30753)
+++ branches/soc-2010-nexyon/intern/audaspace/Python/doc/examples/tetris.py	2010-07-26 11:17:43 UTC (rev 30754)
@@ -1,7 +1,7 @@
 import aud
 import math
 
-def parseNotes(notes, bpm, basefreq, notechars = "XXXCXDXEFXGXAXHcXdXefXgXaXhp"):
+def parseNotes(notes, bpm, basefreq, rate = 44100, notechars = "XXXCXDXEFXGXAXHcXdXefXgXaXhp"):
 	pos = 0
 	sound = None
 	fadelength = 60/bpm/10
@@ -29,11 +29,11 @@
 		freq = math.pow(2, freq/12)*basefreq
 		length = float(dur)*60/bpm
 
-		snd = aud.Sound.sine(freq)
+		snd = aud.Sound.sine(freq, rate)
 		if char == 'p':
 			snd = snd.volume(0)
 		else:
-			snd = snd.square(0)
+			snd = snd.square()
 		snd = snd.limit(0, length)
 		snd = snd.fadein(0, fadelength)
 		snd = snd.fadeout(length - fadelength, fadelength)
@@ -44,17 +44,21 @@
 			sound = snd
 	return sound
 
-def tetris(bpm = 300, freq = 220):
+def tetris(bpm = 300, freq = 220, rate = 44100):
 	notes = "e2Hcd2cH A2Ace2dc H3cd2e2 c2A2A4 pd2fa2gf e3ce2dc H2Hcd2e2 c2A2A2p2"
-	s11 = parseNotes(notes, bpm, freq)
+	s11 = parseNotes(notes, bpm, freq, rate)
 
 	notes = "e4c4 d4H4 c4A4 G#4p4 e4c4 d4H4 A2c2a4 g#4p4"
-	s12 = parseNotes(notes, bpm, freq)
+	s12 = parseNotes(notes, bpm, freq, rate)
 
 	notes = "EeEeEeEe AaAaAaAa AbabAbabAbabAbab AaAaAAHC DdDdDdDd CcCcCcCc HhHhHhHh AaAaA2p2"
-	s21 = parseNotes(notes, bpm, freq, notechars = "AXHCXDXEFXGXaXhcXdXefXgXp")
+	s21 = parseNotes(notes, bpm, freq, rate, notechars = "AXHCXDXEFXGXaXhcXdXefXgXp")
 
 	notes = "aeaeaeae g#dg#dg#dg#d aeaeaeae g#dg#dg#2p2 aeaeaeae g#dg#dg#dg#d aeaeaeae g#dg#dg#2p2"
-	s22 = parseNotes(notes, bpm, freq/2)
+	s22 = parseNotes(notes, bpm, freq/2, rate)
 
 	return s11.join(s12).join(s11).volume(0.5).mix(s21.join(s22).join(s21).volume(0.3))
+
+def play(bpm = 300, freq = 220):
+	dev = aud.device()
+	return dev.play(tetris(bpm, freq, dev.rate))

Modified: branches/soc-2010-nexyon/intern/audaspace/intern/AUD_C-API.cpp
===================================================================
--- branches/soc-2010-nexyon/intern/audaspace/intern/AUD_C-API.cpp	2010-07-26 10:41:26 UTC (rev 30753)
+++ branches/soc-2010-nexyon/intern/audaspace/intern/AUD_C-API.cpp	2010-07-26 11:17:43 UTC (rev 30754)
@@ -204,16 +204,16 @@
 	Py_RETURN_NONE;
 }
 
-static PyMethodDef meth_getcdevice[] = {{ "get_c_device", (PyCFunction)AUD_getCDevice, METH_NOARGS,
-										  "get_c_device()\n\n"
-										  "Returns the C API Device.\n\n"
-										  ":return: The C API Device.\n"
+static PyMethodDef meth_getcdevice[] = {{ "device", (PyCFunction)AUD_getCDevice, METH_NOARGS,
+										  "device()\n\n"
+										  "Returns the application's Device.\n\n"
+										  ":return: The application's Device.\n"
 										  ":rtype: aud.Device"}};
 
 PyObject* AUD_initPython()
 {
 	PyObject* module = PyInit_aud();
-	PyModule_AddObject(module, "get_c_device", (PyObject *)PyCFunction_New(meth_getcdevice, NULL));
+	PyModule_AddObject(module, "device", (PyObject *)PyCFunction_New(meth_getcdevice, NULL));
 	PyDict_SetItemString(PySys_GetObject("modules"), "aud", module);
 	if(AUD_device)
 	{





More information about the Bf-blender-cvs mailing list