Thanks.
-- ========================================= DEVERRE Vincent - MCII : vdev...@mcii.fr =========================================
You could for example use a pipe to start an external player:
#include <stdio.h>
main(int argc, char **argv)
{
FILE *fptr;
char temp[521];
sprintf(temp, "play %s", argv[1]);
fptr = popen(temp, "r");
pclose(fptr);
exit(0);
}
Modify as required :)
Please reade the files in /usr/info/libc... for info on C programming.
I hope you have these installed.
Jan.
Send it to /dev/dsp (although you will probably need
to have the sampling rate right first).
--
Dave Blake
dbl...@phy.ucsf.edu
> Please reade the files in /usr/info/libc... for info on C
> programming. I hope you have these installed.
Now if only there were an appropriate way to read them online
without grokking using emacs.
gnome-help-browser is OK, but lacks searching capabilities.
info is a wicked core of a program that is totally unfriendly.
Emacs is, well, emacs. Not everyone likes it, and it is not
friendly for grokking through info pages for a non-emacs user.
--
Dave Blake
dbl...@phy.ucsf.edu
I use tkinfo.
Peter
Use joe (and its search functions) on mymanual
You is the best editor in my known universe (for C programming).
Jan
I have written a library for reading and writing sound file formats
including WAV. It is located at:
http://www.zip.com.au/~erikd/libsndfile/
I have also written a very simple demonstration program which plays
a sound file under Liunx. It is located at :
http://www.zip.com.au/~erikd/libsndfile/sfplay.c
and it requires the installation of the library above.
Erik
--
+-------------------------------------------------+
Erik de Castro Lopo er...@zip.com.au
+-------------------------------------------------+
Running MS-Windows on a Pentium is like having a brand new Porsche
but only be able to drive backwards with the handbrake on.
Also, the WAV file needs to be decoded first. WAV isn't just the raw
samples, it has a structure in it. I don't remember what it's like but it is
documented in the Microsoft SDK documentation which is (or at least used to
be) available online.
--
Sami Tikka, s...@iki.fi, http://www.iki.fi/sti/
"There is no spoon."
Look up www.wotsit.org.
But you should get a recognisable result just senting it to /dev/dsp.
Regards
ROSCO
A compact Linux streaming sound player is another of those applications
needed to keep Linux up to date.
For some purposes, yes... for Internet streaming and broadcasting of
music, these formats are much more bandwidth-affordable.
For other purposes, no. .WAV files are still very useful as
containers for PCM audio. Anybody doing pro-sound composition or
editing, signal processing, etc. would certainly not be willing to
store their sounds in either RealAudio or MP3 format - these are
"lossy" schemes.
I spend a fair bit of time using my Linux systems to digitize my
obscure out-of-print LPs, de-noise them (via automated or manual
techniques), and burning them to CD-R. The .WAV format is either
understood by, or is the native format of almost all of the software
tools used to do this sort of thing.
To answer the original question: I suggest you get ahold of the
"wavplay" application and see how it does the job. Basically, there
are several parts to the problem: you must open the .WAV file and parse
the chunks to determine the content format (number of channels, number
of bits per sample, number of samples per second), you must open the
Linux sound driver (usually /dev/dsp) and use ioctls to configure it
to play data of the indicated format, and you must locate the
sample-data chunk in the .WAV file and read it in (a big hunk at a
time) and write it into the sound device.
There are a bunch of complications which may or may not be relevant to
your situation. Depending on your sound card's capabilities, and on
the specific .WAV file you're playing, you may find that your sound
card can't handle the specific data type in which the .WAV is
recorded. This would mean that you'd have to convert the data before
playing - possibly in real time, or possibly via a preprocessing step.
If you're running Linux on a big-endian machine (e.g. PowerMac) you'd
need to byte-swap almost everything you read from the .WAV file, since
these files are written with all multi-byte integers being represented
in little-endian (Intel) representation.
>A compact Linux streaming sound player is another of those applications
>needed to keep Linux up to date.
Agreed.
--
Dave Platt dpl...@radagast.org
Visit the Jade Warrior home page: http://www.radagast.org/jade-warrior/
I do _not_ wish to receive unsolicited commercial email, and I will
boycott any company which has the gall to send me such ads!
<snip>
> To answer the original question: I suggest you get ahold of the
> "wavplay" application and see how it does the job. Basically, there
> are several parts to the problem: you must open the .WAV file and parse
> the chunks to determine the content format (number of channels, number
> of bits per sample, number of samples per second), you must open the
> Linux sound driver (usually /dev/dsp) and use ioctls to configure it
> to play data of the indicated format, and you must locate the
> sample-data chunk in the .WAV file and read it in (a big hunk at a
> time) and write it into the sound device.
>
> There are a bunch of complications which may or may not be relevant to
> your situation. Depending on your sound card's capabilities, and on
> the specific .WAV file you're playing, you may find that your sound
> card can't handle the specific data type in which the .WAV is
> recorded. This would mean that you'd have to convert the data before
> playing - possibly in real time, or possibly via a preprocessing step.
> If you're running Linux on a big-endian machine (e.g. PowerMac) you'd
> need to byte-swap almost everything you read from the .WAV file, since
> these files are written with all multi-byte integers being represented
> in little-endian (Intel) representation.
For a SIMPLE solution to this problem which will work on big and little
endian machine get the libsndfile library from:
http://www.zip.com.au/~erikd/libsndfile/
and then get the sample code for a player at :
http://www.zip.com.au/~erikd/libsndfile/sfplay.c
This solution also allows you to play both variants of ADPCM encoded
WAV files as well as A-law and u-law encoded WAV files. In the near
future GSM 6.10 encoded WAV files will be added to that list. In
addition to all this, sfplay (because it is using libsndfile) will
also be able to play most AIFF, AU, and IFF/SVX files.
Erik
--
+-------------------------------------------------+
Erik de Castro Lopo er...@zip.com.au
+-------------------------------------------------+
"I contend that we are both atheists. I just believe in one fewer god
than you do. When you understand why you dismiss all the other possible
gods, you will understand why I dismiss yours." -- Stephen Roberts
Then ... ?
(Sorry for my english. Oupds)
Vincent wrote:
> Hi!
> How can I play WAV file in C language ?
>
As someone else stated, libsndfile should compile and run correctly
on any Unix with an ANSI C compiler, a Bourne Shell compatible shell
and a make utility. It even runs on IRIX, the least statndard of all
the unices I have used (haven't used HP-UX unfortunately).
As for playing the sound, I don't know how the sound output devices
might be different on HP-US in comparison to Linux which is what I
use for coding. You will have to consult someone with detailed
HP-UX knowledge to answer this question, but you should still be able
to use libsndfile to read and decode the sound file.
Hope this helps,
Erik
--
+-------------------------------------------------+
Erik de Castro Lopo er...@zip.com.au
+-------------------------------------------------+
Windows 2000 : The Tyranosaurus Rex of the software
world. Large, ferocious and soon to be extinct.