LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   writing a c program in linux which plays an'.wav' file (http://www.linuxquestions.org/questions/programming-9/writing-a-c-program-in-linux-which-plays-an-wav-file-339747/)

stephenwalter 07-04-2005 12:12 AM

writing a c program in linux which plays an'.wav' file
 
right now my work requires that i need to write a program in linux using c which will play a '.wav' files i tried a lot of searching but could not find a particular function in linux which will write into the speaker port. if anybody could help me i would be very grateful for that.

freegianghu 07-04-2005 12:27 AM

Re: writing a c program in linux which plays an'.wav' file
 
Quote:

Originally posted by stephenwalter
right now my work requires that i need to write a program in linux using c which will play a '.wav' files i tried a lot of searching but could not find a particular function in linux which will write into the speaker port. if anybody could help me i would be very grateful for that.
Have a look at Audio Howto

Hopes it help
GH

64bitprocessor 07-04-2005 04:46 AM

HI,
In normal Linux distributions a special character device file /dev/dsp is used from recording an playing sound. IF something is written into this file it will be played through the computer. lly we can record sound by reading from the device file. We can use the system calls open(), close(), read(), write() etc.. in this file. ioctl calls are used for controlling the sound card. Search for some documents about OSS (Open Sound Systems) in the net.
We ha a special library libsndfile for converting sound files in Linux. It may also help you a lot. See the http://www.mega-nerd.com/libsndfile/ for more details.

newbie007007 07-04-2005 03:12 PM

HI,
In order to play a .wav file , you need to read the wav data from file and write it to /dev/dsp.
You should also set the audio device to settings of the .wav file.
I mean some files has 2 channels and some has only 1 channel.
Some files have a speed of 44100 and some have 22050.
Also the bitrate.
Every wav file has a header that gives you the above details.(channels,speed,bitrate).
After reading the above info from the .wav file you need to set the audio device to the settings of the .wav file to be played.
You can set the device by using the ioctl() system call.
Go for google to know more about ioctl system call and .wav format.
I have done it before(both playing and recording) and it worked fine for me.

regards.

meDream 07-05-2005 04:42 AM

This links I've used while introducing sound to me. I've realized that jackit is the best if you execute two or more programs using /dev/dsp. In case you want to interact with graphics try SDL! it has a good support for sound!

http://www.alsa-project.org/alsa-doc...eneric#plugins
http://jackit.sourceforge.net/docs/faq.php
http://desktops.linux.com/desktops/0...5.shtml?tid=25
http://www.desktoplinux.com/articles/AT8018846552.html
http://jackit.sourceforge.net/docs/design/
http://dis-dot-dat.net/index.cgi?ite...tuts/starting/
http://ccrma.stanford.edu/courses/42...ts/WaveFormat/
http://www.lightlink.com/tjweber/StripWav/WAVE.html
http://netghost.narod.ru/gff/graphic...ry/micriff.htm
http://www.cpp-home.com/tutorial.php?333_1
http://www.gidforums.com/t-2191.html
http://www.sonicspot.com/guide/wavefiles.html

stephenwalter 07-06-2005 01:23 AM

hi
i would like to thank all four of you for providing me with so much info. i learnt a lot on the links provided and it has made my work look easier. Thank you very much

stephenwalter 07-08-2005 06:46 AM

hi
i need to clear one more doubt does OSS(open sound system) support the AMR encoding format.

Chrax 07-08-2005 01:46 PM

I believe OSS is deprecated and ALSA is the standard.

stephenwalter 07-08-2005 11:37 PM

hi charx,
Thank you for the information . I also know that ALSA is the current standard , But iam required to work on the OSS driver currently. Do u know anyway whether the ALSA driver has support for the AMR speech encoding format.


All times are GMT -5. The time now is 07:20 AM.