octave.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <HTML>
  3. <HEAD>
  4. <TITLE>
  5. libsndfile and GNU Octave
  6. </TITLE>
  7. <META NAME="Author" CONTENT="Erik de Castro Lopo (erikd AT mega-nerd DOT com)">
  8. <LINK REL="stylesheet" HREF="libsndfile.css" TYPE="text/css" MEDIA="all">
  9. <LINK REL="stylesheet" HREF="print.css" TYPE="text/css" MEDIA="print">
  10. </HEAD>
  11. <BODY>
  12. <BR>
  13. <H1><B>libsndfile and GNU Octave</B></H1>
  14. <P>
  15. <A HREF="http://www.octave.org/">GNU Octave</A> is a high-level interactive
  16. language for numerical computations.
  17. There are currently two development streams, a stable 2.0.X series and a
  18. development 2.1.X series.
  19. Octave reads and writes data in binary formats that were originally developed
  20. for
  21. <A HREF="http://www.mathworks.com/">MATLAB</A>.
  22. Version 2.0.X of Octave uses binary data files compatible with MATLAB
  23. version 4.2 while Octave 2.1.X uses binary data files compatible
  24. with MATLAB version 5.0 as well as being able to read the older MATLAB 4.2
  25. format.
  26. </P>
  27. <P>
  28. From version 1.0.1 of libsndfile onwards, libsndfile has the ability of reading
  29. and writing a small subset of the binary data files used by both versions
  30. of GNU Octave.
  31. This gives people using GNU Octave for audio based work an easy method of
  32. moving audio data between GNU Octave and other programs which use libsndfile.
  33. </P>
  34. <P>
  35. For instance it is now possible to do the following:
  36. </P>
  37. <UL>
  38. <LI> Load a WAV file into a sound file editor such as
  39. <A HREF="http://www.metadecks.org/software/sweep/">Sweep</A>.
  40. <LI> Save it as a MAT4 file.
  41. <LI> Load the data into Octave for manipulation.
  42. <LI> Save the modified data.
  43. <LI> Reload it in Sweep.
  44. </UL>
  45. <P>
  46. Another example would be using the MAT4 or MAT5 file formats as a format which
  47. can be easily loaded into Octave for viewing/analyzing as well as a format
  48. which can be played with command line players such as the one included with
  49. libsndfile.
  50. </P>
  51. <H2><B>Details</B></H2>
  52. <P>
  53. Octave, like most programming languages, uses variables to store data, and
  54. Octave variables can contain both arrays and matrices.
  55. It is also able to store one or more of these variables in a file.
  56. When reading Octave files, libsndfile expects a file to contain two
  57. variables and their associated data.
  58. The first variable should contain a variable holding the file sample rate
  59. while the second variable contains the audio data.
  60. </P>
  61. <P>
  62. For example, to generate a sine wave and store it as a binary file which
  63. is compatible with libsndfile, do the following:
  64. </P>
  65. <PRE>
  66. octave:1 > samplerate = 44100 ;
  67. octave:2 > wavedata = sin ((0:1023)*2*pi/1024) ;
  68. octave:3 > save sine.mat samplerate wavedata
  69. </PRE>
  70. <P>
  71. The process of reading and writing files compatible with libsndfile can be
  72. made easier by use of two Octave script files :
  73. </P>
  74. <PRE>
  75. octave:4 > [data fs] = sndfile_load ("sine.mat") ;
  76. octave:5 > sndfile_save ("sine2.mat", data, fs) ;
  77. </PRE>
  78. <P>
  79. In addition, libsndfile contains a command line program which which is able
  80. to play the correct types of Octave files.
  81. Using this command line player <B>sndfile-play</B> and a third Octave script
  82. file allows Octave data to be played from within Octave on any of the platforms
  83. which <B>sndfile-play</B> supports (at the moment: Linux, MacOS X, Solaris and
  84. Win32).
  85. </P>
  86. <PRE>
  87. octave:6 > sndfile_play (data, fs) ;
  88. </PRE>
  89. <P>
  90. These three Octave scripts are installed automatically in Octave's site
  91. script directory when libsndfile is installed (except on Win32) ie when
  92. libsndfile is being installed into /usr/local, the Octave scripts will
  93. be installed in /usr/local/share/octave/site/m/.
  94. </P>
  95. <P>
  96. There are some other Octave scripts for audio to be found
  97. <A HREF="http://octave.sourceforge.net/audio/index.html">here</A>.
  98. </P>
  99. <BR>
  100. <!-- ========================================================================= -->
  101. <HR>
  102. <P>
  103. The libsndfile home page is here :
  104. <A HREF="http://www.mega-nerd.com/libsndfile/">
  105. http://www.mega-nerd.com/libsndfile/</A>.
  106. </P>
  107. </BODY>
  108. </HTML>