Skip to content

Commit

Permalink
README.md + /imgs/
Browse files Browse the repository at this point in the history
  • Loading branch information
xk committed May 19, 2011
1 parent 9df23c9 commit 7bf27cb
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 20 deletions.
8 changes: 4 additions & 4 deletions .lock-wscript
@@ -1,9 +1,9 @@
argv = ['/Users/jorge/JAVASCRIPT/bin/node-waf', 'configure', 'clean', 'build']
blddir = '/Users/jorge/JAVASCRIPT/node_sound/build'
blddir = '/Users/jorge/JAVASCRIPT/node-sound/build'
commands = {'dist': 0, 'configure': True, 'distcheck': 0, 'install': 0, 'build': True, 'clean': True, 'distclean': 0, 'check': 0, 'uninstall': 0}
cwd = '/Users/jorge/JAVASCRIPT/node_sound'
environ = {'MAGICK_HOME': '/Users/jorge/JAVASCRIPT/bin/imagemagick', 'SSH_AUTH_SOCK': '/tmp/launch-vFSGjb/Listeners', 'VERSIONER_PYTHON_PREFER_32_BIT': 'no', 'TERM_PROGRAM_VERSION': '273.1', 'DYLD_LIBRARY_PATH': '/Users/jorge/JAVASCRIPT/bin/imagemagick/lib', 'SHELL': '/bin/bash', 'LOGNAME': 'jorge', 'USER': 'jorge', 'HOME': '/Users/jorge', 'PATH': '/Users/jorge/JAVASCRIPT/bin/imagemagick/bin:/Users/jorge/JAVASCRIPT/bin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin:/opt/local/bin', 'RUBYOPT': 'rubygems', 'DISPLAY': '/tmp/launch-13ow1k/org.x:0', 'TMPDIR': '/var/folders/+A/+Atg2INUGw4BX1NCXMla8U+++TY/-Tmp-/', 'TERM_PROGRAM': 'Apple_Terminal', 'LANG': 'es_ES.UTF-8', 'TERM': 'xterm-color', 'Apple_PubSub_Socket_Render': '/tmp/launch-kl6wbp/Render', 'VERSIONER_PYTHON_VERSION': '2.6', 'SHLVL': '1', 'OLDPWD': '/Users/jorge/JAVASCRIPT/node_sound', '__CF_USER_TEXT_ENCODING': '0x1F9:0:0', 'PWD': '/node_sound', '_': '/Users/jorge/JAVASCRIPT/bin/node-waf', 'COMMAND_MODE': 'unix2003'}
cwd = '/Users/jorge/JAVASCRIPT/node-sound'
environ = {'MAGICK_HOME': '/Users/jorge/JAVASCRIPT/bin/imagemagick', 'SSH_AUTH_SOCK': '/tmp/launch-vFSGjb/Listeners', 'VERSIONER_PYTHON_PREFER_32_BIT': 'no', 'TERM_PROGRAM_VERSION': '273.1', 'DYLD_LIBRARY_PATH': '/Users/jorge/JAVASCRIPT/bin/imagemagick/lib', 'SHELL': '/bin/bash', 'LOGNAME': 'jorge', 'USER': 'jorge', 'HOME': '/Users/jorge', 'PATH': '/Users/jorge/JAVASCRIPT/bin/imagemagick/bin:/Users/jorge/JAVASCRIPT/bin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/usr/X11/bin:/opt/local/bin', 'RUBYOPT': 'rubygems', 'DISPLAY': '/tmp/launch-13ow1k/org.x:0', 'TMPDIR': '/var/folders/+A/+Atg2INUGw4BX1NCXMla8U+++TY/-Tmp-/', 'TERM_PROGRAM': 'Apple_Terminal', 'LANG': 'es_ES.UTF-8', 'TERM': 'xterm-color', 'Apple_PubSub_Socket_Render': '/tmp/launch-kl6wbp/Render', 'VERSIONER_PYTHON_VERSION': '2.6', 'SHLVL': '1', 'OLDPWD': '/Users/jorge/JAVASCRIPT', '__CF_USER_TEXT_ENCODING': '0x1F9:0:0', 'PWD': '/Users/jorge/JAVASCRIPT/node-sound', '_': '/Users/jorge/JAVASCRIPT/bin/node-waf', 'COMMAND_MODE': 'unix2003'}
files = []
hash = 0
options = {'compile_targets': None, 'force': False, 'verbose': 0, 'nocache': False, 'progress_bar': 0, 'destdir': '', 'keep': False, 'zones': '', 'blddir': '', 'prefix': '/usr/local/', 'jobs': 2, 'srcdir': '', 'check_cxx_compiler': 'g++'}
srcdir = '/Users/jorge/JAVASCRIPT/node_sound'
srcdir = '/Users/jorge/JAVASCRIPT/node-sound'
129 changes: 129 additions & 0 deletions README.md
@@ -0,0 +1,129 @@
#node-sound The best sound library for node.js

##Instalar

**You need node v0.3 or higher to run this program**

Node-sound es un módulo nativo para node.js. Nativo significa fundamentalmente dos cosas: que está escrito en C y que para poder usarlo hay que compilarlo primero.

Es muy fácil de hacer, suponiendo que ya tengas node.js instalado (y compilado y funcionando).

Lo primero es descargar el .zip o el .tar.gz dando al botón *DOWNLOADS* que hay ahí arriba a la derecha en esta misma página:

<img src= "https://github.com/xk/node-sound/raw/master/imgs/downloads.png" border= "0">

Después descomprimes ese fichero y creará una carpeta *xk-node-sound-xxxx*. Puedes borrar el -xxxx y dejarla en *xk-node-sound* a secas.

Por último, para compilar el módulo teclea:

cd xk-node-sound
node-waf configure clean build

En mi Mac eso produce algo así, donde lo más importante es la última línea: *'build' finished successfully*:

<img src= "https://github.com/xk/node-sound/raw/master/imgs/node-waf-output.png" border= "0">

Si todo ha ido bien, el módulo compilado se encontrará en *xk-node-sound/build/default/sound.node*

<p>&nbsp;</p>
##Manual de instrucciones:

### Require('sound')

Lo primero es cargar el módulo y asignarle un nombre (por ejemplo *Sound*) en la aplicación:

var Sound= require('sound');

Si node no es capaz de encontralo, tienes dos opciones.

La mejor opción: translada el fichero *sound.node* a la carpeta *node_modules*, o bien, especifica el path completo hasta la carpeta en la que se encuentra *sound.node* :

require('/absolute/path/to/sound.node's/folder/sound'); // ugh !

El módulo (que una vez `require()`d se llama *Sound*) tiene 4 métodos:


<p>&nbsp;</p>
###Sound.create(buffer)

Crea un sonido a partir de un *buffer*.

var buffer= new Buffer(8192); // Crear un buffer de 8kB

var i= buffer.length;
while (i--) buffer[i]= i%256; // Rellenar el buffer con algo que "suene"

var sonido1= Sound.create(buffer); // Crear el sonido.

sonido1.loop(5).volume(0.5).play(); // Y hacerlo sonar 5 veces seguidas con el volumen al 50%


<p>&nbsp;</p>
###Sound.bufferifySync(path)

Lee un fichero de sonido, preferiblemente :-) y lo transforma en un *buffer*. Admite casi cualquier formato de sonido: .wav, .mp3, .aif, .m4a, etc.

var buffer = Sound.bufferifySync('unPingüinoEnMiAscensor.mp3');
var sonido2= Sound.create(buffer);

//o simplemente:

var sonido2= Sound.create( Sound.bufferifySync(path) );

//Y luego le damos a play:

sonido2.play();

<p>&nbsp;</p>
###Sound.bufferify(path, callback)

Es la versión asíncrona de `bufferifySync()`, hace lo mismo pero (en una thread en paralelo) sin bloquear, y cuando ha acabado llama a *callback* y le pasa el *buffer* si no ha habido ningún *error* :

Sound.bufferify('/path/to/a/sound.file', cb)
function cb (error, buffer) {
if (!error) {
var sonido2= Sound.create(buffer);
}
}

<p>&nbsp;</p>
###Sound.stream(path)

Aún no va (2011-05-19). Mejor lo dejamos para otro momento.

var sonido3= Sound.stream(path)

<p>&nbsp;</p>
###Los métodos de los sonidos:

`Sound.create(buffer)` devuelve un objeto sonido que tiene los siguentes métodos:

.play() // evidente.
.play(callback) // Igual, pero al acabar llama a callback
.loop(veces) // repite el sonido en bucle *veces* veces
.volume( 0..1 ) // 0 es silencio, 1 es a tope, cualquier cosa intermedia vale también.
.pause() // pues eso.

Cada vez que se llama a cualquiera de ellos, devuelve el objeto sonido otra vez, lo que permite encadenar las llamadas:

En vez de:

sonido.loop(5);
sonido.volume(1);
sonido.play();

Puedes hacerlo en una sola línea:

sonido.loop(5).volume(1).play();

Además, cada objeto sonido tiene estos otros 2 atributos:

.id // Un número de serie que se asigna secuencialmente.
.data // Una referencia al buffer con el que se ha creado.

En resumen:

<img src= "https://github.com/xk/node-sound/raw/master/imgs/resumen.png" border= "0">

***
© Jorge Chamorro Bieling, 2011. Ver la <a href = "https://github.com/xk/node-sound/raw/master/LICENSE">Licencia</a>
Binary file modified Sous La Pluie.mp3
Binary file not shown.
Binary file modified build/.wafpickle-7
Binary file not shown.
6 changes: 3 additions & 3 deletions build/config.log
@@ -1,15 +1,15 @@
# project noname (0.0.1) configured on Thu May 19 09:27:52 2011 by
# project noname (0.0.1) configured on Thu May 19 21:59:03 2011 by
# waf 1.5.16 (abi 7, python 20601f0 on darwin)
# using /Users/jorge/JAVASCRIPT/bin/node-waf configure clean build
#

----------------------------------------
Setting srcdir to
/Users/jorge/JAVASCRIPT/node_sound
/Users/jorge/JAVASCRIPT/node-sound

----------------------------------------
Setting blddir to
/Users/jorge/JAVASCRIPT/node_sound/build
/Users/jorge/JAVASCRIPT/node-sound/build

----------------------------------------
Checking for program g++ or c++
Expand Down
Binary file modified build/default/sound.node
Binary file not shown.
Binary file modified build/default/sound_1.o
Binary file not shown.
Binary file added imgs/downloads.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/node-waf-output.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/resumen.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 15 additions & 13 deletions sound.cc
Expand Up @@ -74,10 +74,10 @@ typedef struct bufferStruct {
#define kBufferListQueueItemType 3
#define kRenderJobsListQueueItemType 4
typedef struct queueStruct {
int type;
void* item;
queueStruct* next;
queueStruct* last;
int type;
} queueStruct;
static queueStruct* callbacksQueue= NULL;
static queueStruct* renderJobsQueue= NULL;
Expand All @@ -88,8 +88,8 @@ pthread_mutex_t renderJobsQueue_mutex = PTHREAD_MUTEX_INITIALIZER;
typedef struct renderJob {
char* str;
ssize_t strLen;
queueStruct* qHead;
ssize_t bytesRead;
queueStruct* qHead;
v8::Persistent<v8::Object> JSCallback;
} renderJob;
static pthread_t theRenderThread;
Expand Down Expand Up @@ -763,9 +763,9 @@ v8::Handle<Value> Create (const Arguments &args) {

JSObject->Set(id_symbol, Integer::New(player->id));
JSObject->Set(play_symbol, play_function);
JSObject->Set(loop_symbol, loop_function);
JSObject->Set(pause_symbol, pause_function);
JSObject->Set(volume_symbol, volume_function);
JSObject->Set(loop_symbol, loop_function);
JSObject->Set(data_symbol, buffer);
JSObject->SetHiddenValue(hiddenPlayerPtr_symbol, External::Wrap(player));

Expand All @@ -790,22 +790,22 @@ v8::Handle<Value> Create (const Arguments &args) {

void renderSound (renderJob* job) {

#if defined (__APPLE__)

OSStatus err;
CFURLRef pathURL;
job->bytesRead= 0;
CFDataRef strChars;
CFStringRef pathStr;
queueStruct* bufferQItem;
job->qHead= bufferQItem= NULL;
job->bytesRead= 0;
ExtAudioFileRef inputAudioFile;

#if defined (__APPLE__)
CFDataRef strChars;
strChars= CFDataCreate(NULL, (UInt8*) job->str, job->strLen);

CFStringRef pathStr;
pathStr= CFStringCreateFromExternalRepresentation(NULL, strChars, kCFStringEncodingUTF8);

CFURLRef pathURL;
//pathURL= CFURLCreateWithString (NULL, pathStr, NULL);
pathURL= CFURLCreateWithFileSystemPath(NULL, pathStr, kCFURLPOSIXPathStyle, false);

OSStatus err;
ExtAudioFileRef inputAudioFile;
err= ExtAudioFileOpenURL(pathURL, &inputAudioFile);
if (err) {
fprintf(stderr, "\nERROR ExtAudioFileOpenURL [%d]", err);
Expand Down Expand Up @@ -1159,6 +1159,8 @@ v8::Handle<Value> Stream (const Arguments &args) {

HandleScope scope;

fprintf(stderr, "\nERROR *** Sound::Stream() Not yet.");

return Undefined();
}

Expand Down Expand Up @@ -1189,9 +1191,9 @@ extern "C" {
pause_function= v8::Persistent<Function>::New(FunctionTemplate::New(Pause)->GetFunction());

target->Set(String::New("create"), v8::Persistent<Function>::New(FunctionTemplate::New(Create)->GetFunction()));
target->Set(String::New("stream"), v8::Persistent<Function>::New(FunctionTemplate::New(Stream)->GetFunction()));
target->Set(String::New("bufferify"), v8::Persistent<Function>::New(FunctionTemplate::New(Bufferify)->GetFunction()));
target->Set(String::New("bufferifySync"), v8::Persistent<Function>::New(FunctionTemplate::New(BufferifySync)->GetFunction()));
target->Set(String::New("stream"), v8::Persistent<Function>::New(FunctionTemplate::New(Stream)->GetFunction()));

// Start async events for callbacks.
ev_async_init(&eio_sound_async_notifier, Callback);
Expand Down

0 comments on commit 7bf27cb

Please sign in to comment.