![]() |
| | #1 |
| Registered User Join Date: Feb 2009
Posts: 10
| Starting Linux Audio Programming OSS I looked at the libflac C api. Compiled their example code. I looked at OSS's C api some. Just confused on how the process works. For example. Do I use OSS to open a device. Then somehow tell oss to use the libflac to read in the flac audio file. Then feed it to the device through OSS so I can hear it though my headset. Confused atm. Thanks. |
| Fujitaka is offline | |
| | #2 |
| Jaxom's & Imriel's Dad Join Date: Aug 2006 Location: Alabama
Posts: 877
| Bad idea. OSS is legacy and is marked for deletion. What you want to use is ALSA. The ALSA lib is available for download (but it is a beast -- and they REQUIRE you to use their lib to access their drivers -- I'm working on getting around that, though). It does, however, do what you want it to do. BTW, for what it is worth, ALSA used to stand for "Another Linux Sound Architecture", however, they changed the name of if a few years back to "Advanced ...". |
| Kennedy is offline | |
| | #3 |
| Registered User Join Date: Feb 2009
Posts: 10
| Ah. So my first step is to not use OSS, and go with ALSA. I might even look into SDL Audio as well. Since I have programmed with SDL before. I will go take a look at the ALSA libs then. Hopefully I won't get to confused at that. Last edited by Fujitaka; 08-05-2009 at 12:37 PM. |
| Fujitaka is offline | |
| | #4 |
| Registered User Join Date: Feb 2009
Posts: 10
| Ok. I managed to compile the example program on ALSA. Been studying it for awhile. Looking at the ALSA API too. Code: #include <stdio.h>
#include <stdlib.h>
#include <alsa/asoundlib.h>
main (int argc, char *argv[])
{
int i;
int err;
short buf[128];
snd_pcm_t *playback_handle;
snd_pcm_hw_params_t *hw_params;
if ((err = snd_pcm_open (&playback_handle, argv[1], SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
fprintf (stderr, "cannot open audio device %s (%s)\n",
argv[1],
snd_strerror (err));
exit (1);
}
if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0) {
fprintf (stderr, "cannot allocate hardware parameter structure (%s)\n",
snd_strerror (err));
exit (1);
}
if ((err = snd_pcm_hw_params_any (playback_handle, hw_params)) < 0) {
fprintf (stderr, "cannot initialize hardware parameter structure (%s)\n",
snd_strerror (err));
exit (1);
}
if ((err = snd_pcm_hw_params_set_access (playback_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) {
fprintf (stderr, "cannot set access type (%s)\n",
snd_strerror (err));
exit (1);
}
if ((err = snd_pcm_hw_params_set_format (playback_handle, hw_params, SND_PCM_FORMAT_S16_LE)) < 0) {
fprintf (stderr, "cannot set sample format (%s)\n",
snd_strerror (err));
exit (1);
}
if ((err = snd_pcm_hw_params_set_rate_resample (playback_handle, hw_params, 44100, 0)) < 0) {
fprintf (stderr, "cannot set sample rate (%s)\n",
snd_strerror (err));
exit (1);
}
if ((err = snd_pcm_hw_params_set_channels (playback_handle, hw_params, 2)) < 0) {
fprintf (stderr, "cannot set channel count (%s)\n",
snd_strerror (err));
exit (1);
}
if ((err = snd_pcm_hw_params (playback_handle, hw_params)) < 0) {
fprintf (stderr, "cannot set parameters (%s)\n",
snd_strerror (err));
exit (1);
}
snd_pcm_hw_params_free (hw_params);
if ((err = snd_pcm_prepare (playback_handle)) < 0) {
fprintf (stderr, "cannot prepare audio interface for use (%s)\n",
snd_strerror (err));
exit (1);
}
for (i = 0; i < 10; ++i) {
if ((err = snd_pcm_writei (playback_handle, buf, 128)) != 128) {
fprintf (stderr, "write to audio interface failed (%s)\n",
snd_strerror (err));
exit (1);
}
}
snd_pcm_close (playback_handle);
exit (0);
}
I studied the FLAC C decode example code, and api for a few days. SourceForge.net Repository - [flac] View of /flac/examples/c/decode/file/main.c but still not sure how ALSA and libflac can be linked together to make it work. Been searching on google for some help, but not finding much on programming ALSA. Last edited by Fujitaka; 08-05-2009 at 05:11 PM. |
| Fujitaka is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How can I compile C and C++ in Linux operating system? Please help. | MarkSquall | C Programming | 8 | 03-10-2008 12:08 PM |
| installing linux for the first time | Micko | Tech Board | 9 | 12-06-2004 05:15 AM |
| Linux: starting a prog autamatically w/KDE | MathFan | Tech Board | 5 | 06-19-2004 05:59 PM |
| Linux for Windows! | Strut | Linux Programming | 2 | 12-25-2002 11:36 AM |
| Linux? Windows Xp? | VooDoo | Linux Programming | 15 | 07-31-2002 08:18 AM |