summaryrefslogtreecommitdiff
path: root/Octave
diff options
context:
space:
mode:
authorErik de Castro Lopo <erikd@mega-nerd.com>2007-05-14 19:55:24 +1000
committerErik de Castro Lopo <erikd@mega-nerd.com>2007-05-14 19:55:24 +1000
commitcb979e10a703033864f8f42c94e9d1d335e5be40 (patch)
tree6bb359e4b64f1719b7afcd887da975e1021405ec /Octave
First snapshot of the public project.
Diffstat (limited to 'Octave')
-rw-r--r--Octave/Makefile.am14
-rw-r--r--Octave/sndfile_load.m59
-rw-r--r--Octave/sndfile_play.m66
-rw-r--r--Octave/sndfile_save.m60
4 files changed, 199 insertions, 0 deletions
diff --git a/Octave/Makefile.am b/Octave/Makefile.am
new file mode 100644
index 0000000..146cd29
--- /dev/null
+++ b/Octave/Makefile.am
@@ -0,0 +1,14 @@
+## Process this file with automake to produce Makefile.in
+
+EXTRA_DIST = sndfile_load.m sndfile_save.m sndfile_play.m
+
+octconfigdir = $(exec_prefix)/share/octave/site/m
+octconfig_DATA = sndfile_load.m sndfile_save.m sndfile_play.m
+
+
+## Do not edit or modify anything in this comment block.
+## The arch-tag line is a file identity tag for the GNU Arch
+## revision control system.
+##
+## arch-tag: 56f1645a-3a13-4846-acc7-8b4abf2904ff
+
diff --git a/Octave/sndfile_load.m b/Octave/sndfile_load.m
new file mode 100644
index 0000000..a2371cc
--- /dev/null
+++ b/Octave/sndfile_load.m
@@ -0,0 +1,59 @@
+## Copyright (C) 2002 Erik de Castro Lopo
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+##
+## This program is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this file. If not, write to the Free Software Foundation,
+## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} sndfile_load (@var{filename})
+## Load data from the file given by @var{filename}.
+## @end deftypefn
+
+## Author: Erik de Castro Lopo <erikd@mega-nerd.com>
+## Description: Load the sound data from the given file name
+
+function [data fs] = sndfile_load (filename)
+
+if (nargin != 1),
+ error ("Need an input filename") ;
+ endif
+
+samplerate = -1 ;
+samplingrate = -1 ;
+wavedata = -1 ;
+
+
+eval (sprintf ('load -f %s', filename)) ;
+
+if (samplerate > 0),
+ fs = samplerate ;
+elseif (samplingrate > 0),
+ fs = samplingrate ;
+else
+ error ("Not able to find sample rate.") ;
+ endif
+
+if (max (size (wavedata)) > 1),
+ data = wavedata ;
+else
+ error ("Not able to find waveform data.") ;
+ endif
+
+endfunction
+
+# Do not edit or modify anything in this comment block.
+# The arch-tag line is a file identity tag for the GNU Arch
+# revision control system.
+#
+# arch-tag: 9d7ed7ce-41fe-4efe-8bde-f5fc6f46bb03
+
diff --git a/Octave/sndfile_play.m b/Octave/sndfile_play.m
new file mode 100644
index 0000000..b1cccab
--- /dev/null
+++ b/Octave/sndfile_play.m
@@ -0,0 +1,66 @@
+## Copyright (C) 2002 Erik de Castro Lopo
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+##
+## This program is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this file. If not, write to the Free Software Foundation,
+## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} sndfile_play (@var{data, fs})
+## Play @var{data} at sample rate @var{fs} using the sndfile-play
+## program.
+## @end deftypefn
+
+## Author: Erik de Castro Lopo <erikd@mega-nerd.com>
+## Description: Play the given data as a sound file
+
+function sndfile_play (data, fs)
+
+if nargin != 2,
+ error ("Need two input arguments: data and fs.") ;
+ endif
+
+if (max (size (fs)) > 1),
+ error ("Second parameter fs must be a single value.") ;
+ endif
+
+[nr nc] = size (data) ;
+
+if (nr > nc),
+ data = data' ;
+ endif
+
+samplerate = fs ;
+wavedata = data ;
+
+filename = tmpnam () ;
+
+cmd = sprintf ("save -mat-binary %s fs data", filename) ;
+
+eval (cmd) ;
+
+cmd = sprintf ("sndfile-play %s", filename) ;
+
+[output, status] = system (cmd) ;
+
+if (status),
+ disp (outout) ;
+ endif
+
+endfunction
+
+# Do not edit or modify anything in this comment block.
+# The arch-tag line is a file identity tag for the GNU Arch
+# revision control system.
+#
+# arch-tag: 96fb14c8-2b5a-4b93-a576-ab83a6d9026b
+
diff --git a/Octave/sndfile_save.m b/Octave/sndfile_save.m
new file mode 100644
index 0000000..1b88842
--- /dev/null
+++ b/Octave/sndfile_save.m
@@ -0,0 +1,60 @@
+## Copyright (C) 2002 Erik de Castro Lopo
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+##
+## This program is distributed in the hope that it will be useful, but
+## WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+## General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this file. If not, write to the Free Software Foundation,
+## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {} sndfile_save (@var{filename, data, fs})
+## Save the given @var{data} as audio data to the given at @var{fs}. Set
+## the sample rate to @var{fs}.
+## @end deftypefn
+
+## Author: Erik de Castro Lopo <erikd@mega-nerd.com>
+## Description: Save data as a sound file
+
+function sndfile_save (filename, data, fs)
+
+if nargin != 3,
+ error ("Need three input arguments: filename, data and fs.") ;
+ endif
+
+if (! isstr (filename)),
+ error ("First parameter 'filename' is must be a string.") ;
+ endif
+
+if (max (size (fs)) > 1),
+ error ("Second parameter 'fs' must be a single value, not an array or matrix.") ;
+ endif
+
+[nr nc] = size (data) ;
+
+if (nr > nc),
+ data = data' ;
+ endif
+
+samplerate = fs ;
+wavedata = data ;
+
+str = sprintf ("save -mat-binary %s samplerate wavedata", filename) ;
+
+eval (str) ;
+
+endfunction
+
+# Do not edit or modify anything in this comment block.
+# The arch-tag line is a file identity tag for the GNU Arch
+# revision control system.
+#
+# arch-tag: 5e44602b-940b-4927-af7c-47639769a40b
+