Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
151 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> </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> </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> </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> </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> </p> | ||
###Sound.stream(path) | ||
|
||
Aún no va (2011-05-19). Mejor lo dejamos para otro momento. | ||
|
||
var sonido3= Sound.stream(path) | ||
|
||
<p> </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 not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters