0% found this document useful (0 votes)
198 views

Stackoverflow PDF

Octave appears to assume that a specific sound playing utility will be available on a system but doesn't seem to provide the ability to specify an alternate. In the error below, octave is looking for ofsndplay, which is not a utility available on all systems.

Uploaded by

judapri
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
198 views

Stackoverflow PDF

Octave appears to assume that a specific sound playing utility will be available on a system but doesn't seem to provide the ability to specify an alternate. In the error below, octave is looking for ofsndplay, which is not a utility available on all systems.

Uploaded by

judapri
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

pdfcrowd.com open in browser PRO version Are you a developer?

Try out the HTML to PDF API


Questions Tags Users Badges Unanswered Ask Question
Take the 2-minute tour
Bob Cross
13.8k 5 33 74
8
4
Octave appears to assume that a specific sound playing utility will be available on a system but doesn't
seem to provide the ability to specify an alternate. In the error below, Octave is looking for ofsndplay ,
which is not a utility available on all systems.
octave:38> sound(beamformed_20)
sh: ofsndplay: command not found
Is there an Octave configuration setting or code fragment that I can use to specify an system-appropriate
utility?
linux audio signal-processing octave
share | improve this question edited Sep 26 '09 at 14:52 asked Sep 25 '09 at 15:40
asked 5 years ago
viewed 10689 times
active 1 year ago
Looking for a job?
Front End Product Engineer
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no
registration required.
How do I play a sound in Octave?
sign up

log in

tour

help

stack overflow careers

search
add a comment
pdfcrowd.com open in browser PRO version Are you a developer? Try out the HTML to PDF API
5 Answers active oldest votes
5
I've overridden the playaudio function from octave with the following function. This will work only after
installing sox.
sudo apt-get install sox
(in ubuntu)
function [ ] = playaudio (x, sampling_rate)
if nargin == 1
sampling_rate = 8000
end
file = tmpnam ();
file= [file, '.wav'];
wavwrite(x, sampling_rate, file);
['play ' file ]
system(['play ' file ]);
system(['rm ' file]);
end
A similar approach will allow you to record too:
% Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2003, 2004, 2005,
% 2006, 2007 John W. Eaton
%
% This file is part of Octave.
%
% Octave 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 3 of the License, or (at
% your option) any later version.
%
% Octave 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
Squarespace
New York, NY / relocation
javascript html5
Software Engineer
Midokura
Ocean, NJ / relocation
linux java
Get the weekly newsletter!
Top questions and answers
Important announcements
Unanswered questions
Sign up for the newsletter
see an example newsletter
Linked
0

What are the possible
ways to play audio from
octave on a Mac?
Related
3
Using soundsc in Octave,
on Windows 7
0
Reading and playing
sound in Octave on
Fedora12
2
GUI for navigating fields
add a comment
pdfcrowd.com open in browser PRO version Are you a developer? Try out the HTML to PDF API
Matyas
5,434 12 29
% General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Octave; see the file COPYING. If not, see
% <http://www.gnu.org/licenses/>.
% -*- texinfo -*-
% @deftypefn {Function File} {} record (@var{sec}, @var{sampling_rate})
% Records @var{sec} seconds of audio input into the vector @var{x}. The
% default value for @var{sampling_rate} is 8000 samples per second, or
% 8kHz. The program waits until the user types @key{RET} and then
% immediately starts to record.
% @seealso{lin2mu, mu2lin, loadaudio, saveaudio, playaudio, setaudio}
% @end deftypefn
% Author: AW <[email protected]>
% Created: 19 September 1994
% Adapted-By: jwe
% And adapted again 11/25/2010 by Rob Frohne
function X = record (sec, sampling_rate)
if (nargin == 1)
sampling_rate = 8000;
elseif (nargin != 2)
print_usage ();
endif
file = tmpnam ();
file= [file,".wav"];
input ("Please hit ENTER and speak afterwards!\n", 1);
cmd = sprintf ("rec -c1 -r%d %s trim 0 %d",
sampling_rate, file, sec)
system (cmd);
share | improve this answer answered Jan 21 '11 at 8:06
great, thanks - works perfect on my system! (Ubuntu 13.10 and Octave 3.8) Raffael Mar 13 at 9:17
3
Install alsa-utils or pulseaudio-utils and put the following in your ~/.octaverc:
global sound_play_utility = 'aplay';
2
GUI for navigating fields
in a struct in Octave?
2
How to play a A in octave
8
How to compare a sound
input with a pre-
determined sound?
1
How to play sound in
MFC using Visual C++?
3
How to Import SQLite
data (gathered by an
Android device) into
either Octave or MatLab?
2
Capture playback on
play-only sound card with
ALSA
3
How to produce a DEM
from non-gridded XZY
points?
(Octave/MATLAB)
0
Command line Octave
undefined functions
Hot Network Questions
Can you put polystyrene in the
microwave oven
Mindfulness Vs Void
Printing 100 prime numbers
What are the advantages and
disadvantages of letting the
child experience the effects of
his decisions?
add a comment
pdfcrowd.com open in browser PRO version Are you a developer? Try out the HTML to PDF API
rcs
22.9k 7 74 98
3 global sound_play_utility = 'aplay';
or
global sound_play_utility = 'paplay';
share | improve this answer answered Oct 1 '09 at 18:31
FYI: this does not work on a Fedora 11 system. The default octave install seems to override the setting for
sound_play_utility Bob Cross Oct 1 '09 at 19:21
Does not work on Ubuntu 12.10 either. I get the following error and a horrible crackling/popping sound: sh:
1: cannot create /dev/dsp: Permission denied Timmmm Mar 27 '13 at 18:47
This appears to have no effect, according to the source of playsound . It is currently (as of version 3.6.2)
hardcoded to use paplay (pulse audio), and as with all things pulse-audio, paplay is kind of shit. It also
does playback in an extremely hacky way - writing it out to a file and then using system() . Timmmm
Mar 27 '13 at 20:08
3
playaudio is broken!
It's worth reading the default implementation of playsound (version 3.6.2):
function playaudio (name, ext)
if (nargin < 1 || nargin > 2)
print_usage ();
endif
if (nargin == 1 && isnumeric (name))
## play a vector
if (! isvector (name))
error ("playaudio: X must be a vector");
endif
X = name(:) + 127;
What's that movie where the
character travels back in time
by his mind?
How does HTTP become
stateless?
I want to lock the record using
apex
Press F5 to save, compile, and
run current rust file
How can mesons have spin
greater than 1?
How to reward players that
come prepared for non-combat,
non-RP situations? I.e., real life
How does water help extinguish
fire?
Is there any value in self-
publishing a book as an
academic?
Was the rebellion of the North
really necessary?
Broker DB, Get component
content
Video cropping tool
How to identify the HTTP
methods supported by a web
server?
Accidentally caused "CR LF" to
appear. How to remove them?
How can I delete all lines on a
file using vi?
add a comment
pdfcrowd.com open in browser PRO version Are you a developer? Try out the HTML to PDF API
unwind_protect
file = tmpnam ();
fid = fopen (file, "wb");
fwrite (fid, X, "uchar");
fclose (fid);
[status, out] = system (sprintf ('cat "%s" > /dev/dsp', file));
if (status != 0)
system (sprintf ("paplay --raw \"%s\"", file))
endif
unwind_protect_cleanup
unlink (file);
end_unwind_protect
elseif (nargin >= 1 && ischar (name))
## play a file
if (nargin == 1)
name = [name ".lin"];
elseif (nargin == 2)
name = [name "." ext];
endif
if (any (strcmp (ext, {"lin", "raw"})))
[status, out] = system (sprintf ('cat "%s" > /dev/dsp', name));
if (status != 0)
system (sprintf ('paplay --raw "%s"', name))
endif
elseif (any (strcmp (ext, {"mu", "au" "snd", "ul"})))
[status, out] = system (sprintf ('cat "%s" > /dev/audio', name));
if (status != 0)
system (sprintf ('paplay "%s"', name))
endif
else
error ("playaudio: unsupported extension '%s'", ext);
endif
else
print_usage ();
endif
endfunction
There are some things to note:
1. Writing directly to /dev/dsp always fails in the latest linux distros, so every time you run the command
you will get an error (on the cat > /dev/dsp line).
2. It's hard-coded to use paplay , a command-line pulseaudio player.
3. The paplay call will never work because paplay defaults to s16ne (probably a typo; I
think they meant s16be - signed 16-bit big endian), and playaudio writes unsigned 8-bit!
4. It calls it using system() . Always a bad idea.
5. It writes the audio out to a file rather than streaming it. Might cause problems for large files.
6. Unlike matlab, it doesn't handle floating point audio. It actually only supports 8-bit audio! Kind of
stupid since that is the result returned by wavread!
7. Unlike matlab, it only supports one sample rate (44100 Hz).
This function is extremely hacky, insecure and unreliable. If it in any way represents the code quality
elsewhere in Octave... well, that is worrying. It should really really be reimplemented as proper function in
Octave using portaudio.
Why is this version of `and` in
C not short-circuit?
Change password on a LUKS
filesystem without knowing the
password
Dawkin's rebuttal to Aquinas's
'The Argument from Degree'?
Why does the International
Space Station have a
downward facing light?
How can the Starter Set wizard
have five skills?
Is "ps -u" Really a Bad Syntax?
pdfcrowd.com open in browser PRO version Are you a developer? Try out the HTML to PDF API
Slightly better version
I don't really have time or motivation to do a lot of hacking on octave, so in the mean time I suggest you
instead use this slightly better function:
function playsound(wav, samplerate)
# Play a single-channel wave at a certain sample rate (defaults to 44100 Hz).
# Input can be integer, in which case it is assumed to be signed 16-bit, or
# float, in which case it is in the range -1:1.
if (nargin < 1 || nargin > 2)
print_usage();
endif
if (nargin < 2)
samplerate = 44100;
end
if (!isvector(wav))
error("playsound: X must be a vector");
endif
# Write it as a 16-bit signed, little endian (though the amaaazing docs don't say the endianness)
# If it is integers we assume it is 16 bit signed. Otherwise we assume in the range -1:1
if (isfloat(wav))
X = min(max(wav(:), -1), 1) * 32767; # Why matlab & octave do not have a clip() function... I do not know.
else
X = min(max(wav(:), -32767), 32767) + 32767;
endif
unwind_protect
file = tmpnam ();
fid = fopen (file, "wb");
fwrite (fid, X, "int16");
fclose (fid);
# Making aplay (alsa) the default, because let's be honest: it is still way more reliable than
# the mess that is pulseaudio.
if (exist("/usr/bin/aplay") == 2)
pdfcrowd.com open in browser PRO version Are you a developer? Try out the HTML to PDF API
Timmmm
10.9k 6 85 100
Bob Cross
13.8k 5 33 74
system(sprintf("/usr/bin/aplay --format=S16_LE --channels=1 --rate=%d \"%s\"", samplerate, file))
elseif (exist("/usr/bin/paplay") == 2)
system(sprintf("/usr/bin/paplay --format=s16le --channels=1 --rate=%d --raw \"%s\"", samplerate, file))
endif
unwind_protect_cleanup
unlink (file);
end_unwind_protect
endfunction
This is still a very hacky function. But it should be at least a little bit more reliable than playaudio ! I'll
leave an implementation of soundsc as an exercise for the reader.
share | improve this answer answered Mar 27 '13 at 20:52
2
On one of my Linux machines, I created the following ofsndplay script to work around the hard-wired
dependency:
$ cat /usr/bin/ofsndplay
#!/bin/sh
## Coping with stupid dependency on ofsndplay in octave
play -t au -
This particular script uses the SoX play utility.
Admittedly, the comment is unnecessary for the functionality but it certainly made me feel better....
share | improve this answer edited Oct 9 '09 at 10:20 answered Oct 1 '09 at 19:48
1
On OSX, this is what I did to get sound working:
from the sound command help:
This function writes the audio data through a pipe to the program
"play" from the sox distribution. sox runs pretty much anywhere,
but it only has audio drivers for OSS (primarily linux and freebsd)
and SunOS. In case your local machine is not one of these, write
a shell script such as ~/bin/octaveplay, substituting AUDIO_UTILITY
add a comment
add a comment
pdfcrowd.com open in browser PRO version Are you a developer? Try out the HTML to PDF API
msutherl
315 1 3 16
with whatever audio utility you happen to have on your system:
#!/bin/sh
cat > ~/.octave_play.au
SYSTEM_AUDIO_UTILITY ~/.octave_play.au
rm -f ~/.octave_play.au
and set the global variable (e.g., in .octaverc)
global sound_play_utility="~/bin/octaveplay";
I named the following script "octaveplay" and put it in ~/bin:
cat > ~/.octave_play.aif
afplay ~/.octave_play.aif
rm -f ~/.octave_play.aif
Then I created .octaverc and added: global sound_play_utility="~/bin/octaveplay";
Voila!
share | improve this answer answered Jan 12 '10 at 8:12
Your Answer
add a comment
pdfcrowd.com open in browser PRO version Are you a developer? Try out the HTML to PDF API

Post Your Answer
By posting your answer, you agree to the privacy policy and terms of service.
Not the answer you're looking for? Browse other questions tagged linux audio
signal-processing octave or ask your own question.
Post as a guest
Name
Email
Sign up or log in
Sign up using Google
Sign up using Facebook
Sign up using Stack Exchange
pdfcrowd.com open in browser PRO version Are you a developer? Try out the HTML to PDF API
tour help badges blog chat data legal privacy policy work here advertising info mobile contact us feedback
TECHNOLOGY LIFE / ARTS CULTURE /
RECREATION
SCIENCE OTHER
Stack Overflow
Server Fault
Super User
Web Applications
Ask Ubuntu
Webmasters
Game Development
TeX - LaTeX
Programmers
Unix & Linux
Ask Different (Apple)
WordPress
Development
Geographic
Information Systems
Electrical Engineering
Android Enthusiasts
Information Security
Database
Administrators
Drupal Answers
SharePoint
User Experience
Mathematica
Salesforce
more (13)
Photography
Science Fiction &
Fantasy
Graphic Design
Seasoned Advice
(cooking)
Home Improvement
Personal Finance &
Money
Academia
more (10)
English Language &
Usage
Skeptics
Mi Yodeya (Judaism)
Travel
Christianity
Arqade (gaming)
Bicycles
Role-playing Games
more (21)
Mathematics
Cross Validated
(stats)
Theoretical Computer
Science
Physics
MathOverflow
more (7)
Stack Apps
Meta Stack Exchange
Area 51
Stack Overflow
Careers
question feed
site design / logo 2014 stack exchange inc; user contributions licensed under cc by-sa 3.0 with attribution required
rev 2014.10.13.1936

You might also like