Thursday, November 21, 2013

Octave Forge's Audio Package on Windows

To use the sound and soundsc functions in Octave, we can install the audio package in Octave Forge by installing the package in Octave -- depending on how you installed Octave, you may need administrative privilege.


octave: 1> pkg install -forge audio
 
On Linux systems, there is no problem at all. However, when I tried to duplicate the experience on Windows, I ran into a problem. Namely, when I run the "sound" function, I keep getting the error,

error: sound.m: No command line utility found for sound playing

Examining the sound.m, we see the following code,

  ## What do we use for playing?
  global sound_play_utility;
  if ~isempty(sound_play_utility),
    ## User specified command
  elseif  (file_in_path(EXEC_PATH, "ofsndplay"))
    ## Mac
    sound_play_utility = "ofsndplay -"
  elseif (file_in_path(EXEC_PATH, "play"))
    ## Linux (sox)
    sound_play_utility = "play -t AU -";
  else
    error("sound.m: No command line utility found for sound playing");
  endif

It looks that Octave needs an audio player that can play audio data piped from the standard input. A little bit web search, I found the answer. Here is the summary what I did,
  • Download sox Windows 32 binary from http://sourceforge.net/projects/sox/files/sox/
  • Install sox
  • Go to sox's installation directory, make two copies of sox.exe, one copy named as play.exe, and one named as play (without extension). From Windows command line, you would do the following,
    
    copy sox.exe play.exe
    copy sox.exe play
    

  • Update the Octave shortcut (.LNK) file by adding command line option "--exec-path "C:\Octave\sox-14-4-1". Replace sox's path with your own. 
  • Run Octave
  • Test it by playing some random noise, such as,
    
    Octave:1> y = rand(1, 10000);
    Octave:2> sound(y, 44100);
    

    You should hear the noise.