Permalink
Browse files

añadir test sinewave(s).js

  • Loading branch information...
1 parent d6bcff4 commit 583ec31512e508b529f5c0716ba8d75d70053100 @xk committed Nov 3, 2011
View
@@ -5,3 +5,8 @@ Falta añadirle un callback, y hacerla correr en un pthread.
Ver test12.js DEMO DE BUFFERIFY
+2011-11-03 Añadir tests que muestran como sintetizar una onda:
+
+test-sinewave.js
+test-sinewaves.js
+
View
Binary file not shown.
@@ -1,2 +0,0 @@
-version = 0x105016
-tools = [{'tool': 'ar', 'tooldir': None, 'funs': None}, {'tool': 'cxx', 'tooldir': None, 'funs': None}, {'tool': 'gxx', 'tooldir': None, 'funs': None}, {'tool': 'compiler_cxx', 'tooldir': None, 'funs': None}, {'tool': 'osx', 'tooldir': None, 'funs': None}, {'tool': 'node_addon', 'tooldir': None, 'funs': None}]
@@ -1,48 +0,0 @@
-AR = '/usr/bin/ar'
-ARFLAGS = 'rcs'
-CCFLAGS = ['-g']
-CCFLAGS_MACBUNDLE = ['-fPIC']
-CCFLAGS_NODE = ['-D_LARGEFILE_SOURCE', '-D_FILE_OFFSET_BITS=64']
-CC_VERSION = ('4', '2', '1')
-COMPILER_CXX = 'g++'
-CPP = '/usr/bin/cpp'
-CPPFLAGS_NODE = ['-D_GNU_SOURCE', '-DEV_MULTIPLICITY=0']
-CPPPATH_NODE = '/Users/jorge/JAVASCRIPT/include/node'
-CPPPATH_ST = '-I%s'
-CXX = ['/usr/bin/g++']
-CXXDEFINES_ST = '-D%s'
-CXXFLAGS = ['-g']
-CXXFLAGS_DEBUG = ['-g']
-CXXFLAGS_NODE = ['-D_LARGEFILE_SOURCE', '-D_FILE_OFFSET_BITS=64']
-CXXFLAGS_RELEASE = ['-O2']
-CXXLNK_SRC_F = ''
-CXXLNK_TGT_F = ['-o', '']
-CXX_NAME = 'gcc'
-CXX_SRC_F = ''
-CXX_TGT_F = ['-c', '-o', '']
-DEST_CPU = 'x86_64'
-DEST_OS = 'darwin'
-FULLSTATIC_MARKER = '-static'
-LIBDIR = '/Users/jorge/.node_libraries'
-LIBPATH_NODE = '/Users/jorge/JAVASCRIPT/lib'
-LIBPATH_ST = '-L%s'
-LIB_ST = '-l%s'
-LINKFLAGS_MACBUNDLE = ['-bundle', '-undefined', 'dynamic_lookup']
-LINK_CXX = ['/usr/bin/g++']
-NODE_PATH = '/Users/jorge/.node_libraries'
-PREFIX = '/usr/local'
-PREFIX_NODE = '/Users/jorge/JAVASCRIPT'
-RANLIB = '/usr/bin/ranlib'
-RPATH_ST = '-Wl,-rpath,%s'
-SHLIB_MARKER = ''
-SONAME_ST = ''
-STATICLIBPATH_ST = '-L%s'
-STATICLIB_MARKER = ''
-STATICLIB_ST = '-l%s'
-macbundle_PATTERN = '%s.bundle'
-program_PATTERN = '%s'
-shlib_CXXFLAGS = ['-fPIC', '-compatibility_version', '1', '-current_version', '1']
-shlib_LINKFLAGS = ['-dynamiclib']
-shlib_PATTERN = 'lib%s.dylib'
-staticlib_LINKFLAGS = []
-staticlib_PATTERN = 'lib%s.a'
View
@@ -1,44 +0,0 @@
-# project noname (0.0.1) configured on Tue Nov 1 02:20:51 2011 by
-# waf 1.5.16 (abi 7, python 20601f0 on darwin)
-# using /Users/jorge/JAVASCRIPT/bin/node-waf configure clean install
-#
-
-----------------------------------------
-Setting srcdir to
-/Users/jorge/JAVASCRIPT/node-sound
-
-----------------------------------------
-Setting blddir to
-/Users/jorge/JAVASCRIPT/node-sound/build
-
-----------------------------------------
-Checking for program g++ or c++
- find program=['g++', 'c++'] paths=[] var='CXX'
- -> '/usr/bin/g++'
-
-----------------------------------------
-Checking for program cpp
- find program=['cpp'] paths=[] var='CPP'
- -> '/usr/bin/cpp'
-
-----------------------------------------
-Checking for program ar
- find program=['ar'] paths=[] var='AR'
- -> '/usr/bin/ar'
-
-----------------------------------------
-Checking for program ranlib
- find program=['ranlib'] paths=[] var='RANLIB'
- -> '/usr/bin/ranlib'
-
-----------------------------------------
-Checking for g++
-ok
-
-----------------------------------------
-Checking for node path
-not found
-
-----------------------------------------
-Checking for node prefix
-ok /Users/jorge/JAVASCRIPT
View
Binary file not shown.
View
Binary file not shown.
View
@@ -0,0 +1,54 @@
+//2011-11-03 Jorge@jorgechamorro.com
+//Cómo sintetizar una onda sinusoidal
+
+
+function createSineWave (f /*frequency in Hz*/, seconds /*duration in seconds*/) {
+ //returns a buffer containing a sound of a sine wave of frequency f and duration seconds in PCM format
+
+ function floatToSignedInteger (value) {
+ //converts from float value in the range -1..1 to a 16bits signed integer
+
+ function lonibble (integer) {
+ return integer & 0x00ff;
+ }
+
+ function hinibble (integer) {
+ return (integer & 0xff00) >>> 8;
+ }
+
+ if (value > 1) value= 1;
+ else if (value < -1) value= -1;
+ value= Math.floor(32767*value);
+ return {hi:hinibble(value), lo:lonibble(value), v:value};
+ }
+
+ var kChannels= 2;
+ var kBytesPerSample= 2;
+ var kSamplesPerSecond= 44100;
+ var buffer= new Buffer(Math.floor(seconds*kSamplesPerSecond)* kChannels* kBytesPerSample);
+
+ var i= 0;
+ var step= kChannels* kBytesPerSample;
+ do {
+ var α= f* 2* Math.PI* i/ kSamplesPerSecond/ step;
+ var sample= floatToSignedInteger(Math.sin(α));
+ //process.stdout.write([i/step, α, sample.v, sample.hi, sample.lo] + "\r\n");
+ buffer[i]= buffer[i+2]= sample.lo;
+ buffer[i+1]= buffer[i+3]= sample.hi;
+ i+= step;
+ } while (i < buffer.length);
+
+ return buffer;
+}
+
+
+var DONE= 0;
+var Sound= require('./build/default/sound');
+var buffer= createSineWave(1e3/*f in Hz*/, 1/*duration in seconds*/);
+var sound= Sound.create(buffer);
+sound.loop(3).play(cb);
+function cb () {
+ DONE= 1;
+}
+
+(function cb () { if (!DONE) setTimeout(cb, 333); })();
View
@@ -0,0 +1,62 @@
+//2011-11-03 Jorge@jorgechamorro.com
+//Hace una musiquilla sintetizando unas cuantas sinusoidales randommente
+
+
+function createSineWave (f /*frequency in Hz*/, seconds /*duration in seconds*/) {
+ //returns a buffer containing a sound of a sine wave of frequency f and duration seconds in PCM format
+
+ function floatToSignedInteger (value) {
+ //converts from float value in the range -1..1 to a 16bits signed integer
+
+ function lonibble (integer) {
+ return integer & 0x00ff;
+ }
+
+ function hinibble (integer) {
+ return (integer & 0xff00) >>> 8;
+ }
+
+ if (value > 1) value= 1;
+ else if (value < -1) value= -1;
+ value= Math.floor(32767*value);
+ return {hi:hinibble(value), lo:lonibble(value), v:value};
+ }
+
+ var kChannels= 2;
+ var kBytesPerSample= 2;
+ var kSamplesPerSecond= 44100;
+ var buffer= new Buffer(Math.floor(seconds*kSamplesPerSecond)* kChannels* kBytesPerSample);
+
+ var i= 0;
+ var step= kChannels* kBytesPerSample;
+ do {
+ var α= f* 2* Math.PI* i/ kSamplesPerSecond/ step;
+ var sample= floatToSignedInteger(Math.sin(α));
+ //process.stdout.write([i/step, α, sample.v, sample.hi, sample.lo] + "\r\n");
+ buffer[i]= buffer[i+2]= sample.lo;
+ buffer[i+1]= buffer[i+3]= sample.hi;
+ i+= step;
+ } while (i < buffer.length);
+
+ return buffer;
+}
+
+
+var DONE= 0;
+var Sound= require('./build/default/sound');
+
+var musiquilla= [];
+var i= 10;
+while (i--) {
+ var f= 441+ (1e3* Math.random());
+ var t= 0.1+ (Math.random()/5);
+ var buffer= createSineWave(f/*f in Hz*/, t/*duration in seconds*/);
+ musiquilla.push(Sound.create(buffer));
+}
+
+(function cb () {
+ if (!musiquilla.length) return (DONE= 1);
+ musiquilla.pop().play(cb);
+})();
+
+(function cb () { if (!DONE) setTimeout(cb, 333); })();
View
File renamed without changes.
View
File renamed without changes.
View
File renamed without changes.
View
File renamed without changes.
View
File renamed without changes.
View
File renamed without changes.
View
File renamed without changes.
View
File renamed without changes.
View
File renamed without changes.
View
File renamed without changes.

0 comments on commit 583ec31

Please sign in to comment.