Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

xdvshow-audio.c File Reference

#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/soundcard.h>
#include <sys/ioctl.h>
#include <linux/soundcard.h>
#include <libdv/dv.h>
#include "xdvshow-audio.h"

Include dependency graph for xdvshow-audio.c:

Include dependency graph

Go to the source code of this file.

Functions

int _init_audio_device __P ((dv_audio_t *))
int xdvshow_init_audio (char *audio_dev, dv_audio_t *audio)
 Public interface for _init_audio_device fuction.

int xdvshow_play_audio (dv_audio_t *audio, int16_t **audio_buffers)
 Audio playing function.

int _init_audio_device (dv_audio_t *audio)
 This is the internal audio initialization fuction.


Variables

int audio_fd
 is the audio device file descriptor.


Function Documentation

int _init_audio_device __P (dv_audio_t *)   )  [static]
 

int _init_audio_device dv_audio_t *  audio  )  [static]
 

This is the internal audio initialization fuction.

Function has its own parts for Linux and FreeBSD. Perhaps the initialization code should be the same for both systems. Anyway it's necessary to set the endianity, number of channels and sampling rate. These values must be set strictly in this order to intialize the audio properly.

Parameters:
*audio is a dv_audio_t structure
Returns:
1 for success. -1 otherwise. The function also sets errno when anything goes wrong.

Definition at line 155 of file xdvshow-audio.c.

References audio_fd.

Referenced by xdvshow_init_audio().

00156 { 00157 int ret; 00158 int format; 00159 int fragment_request; 00160 int channels; 00161 int rate; 00162 00163 /* 00164 AFMT_S16_LE = little endian, 00165 AFMT_S16_BE = big endian, 00166 AFMT_S16_NE = native endianity of the machine; 00167 */ 00168 format = AFMT_S16_NE; 00169 fragment_request = 0x000300B; 00170 channels = audio->num_channels; 00171 rate = audio->frequency; 00172 00173 #ifdef LINUX 00174 ret = ioctl(audio_fd, SNDCTL_DSP_SETFMT, &format); 00175 if (ret < 0) { 00176 perror("SNDCTL_DSP_SETFMT"); 00177 return(-1); 00178 } 00179 00180 ret = ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &channels); 00181 if (ret < 0) { 00182 perror("SNDCTL_DSP_CHANNELS"); 00183 return (-1); 00184 } 00185 00186 ret = ioctl(audio_fd, SNDCTL_DSP_SPEED, &rate); 00187 if (ret < 0) { 00188 perror("SNDCTL_DSP_SPEED"); 00189 return (-1); 00190 } 00191 00192 #else /* FreeBSD and perhaps others */ 00193 00194 ret = ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &fragment_request); 00195 if (ret < 0) { 00196 perror("SNDCTL_DSP_SETFRAGMENT"); 00197 return(-1); 00198 } 00199 00200 ret = ioctl(audio_fd, SOUND_PCM_WRITE_BITS, &format); 00201 if (ret < 0) { 00202 perror("SOUND_PCM_WRITE_BITS"); 00203 return(-1); 00204 } 00205 00206 ret = ioctl(audio_fd, SOUND_PCM_WRITE_CHANNELS, &channels); 00207 if (ret < 0) { 00208 perror("SOUND_PCM_WRITE_CHANNELS"); 00209 return(-1); 00210 } 00211 00212 ret = ioctl(audio_fd, SOUND_PCM_WRITE_RATE, &rate); 00213 if (ret < 0) { 00214 perror("SOUND_PCM_WRITE_RATE"); 00215 fprintf(stderr, "rate : %d\n", rate); 00216 return(-1); 00217 } 00218 00219 #endif 00220 00221 return(1); 00222 }

int xdvshow_init_audio char *  audio_dev,
dv_audio_t *  audio
 

Public interface for _init_audio_device fuction.

xdvshow_init_audio opens given audio device and then calls internal function _init_audio_device.

Parameters:
*audio_dev name of the audio device
*audio dv_audio_t structure
Returns:
1 for success. -1 otherwise. The function also sets errno when anything goes wrong.

Definition at line 76 of file xdvshow-audio.c.

References _init_audio_device(), and audio_fd.

Referenced by main().

00077 { 00078 int ret; 00079 00080 if (audio_dev == NULL) { 00081 return(-1); 00082 } 00083 00084 audio_fd = open(audio_dev, O_WRONLY); 00085 if (audio_fd < 0) { 00086 perror("open audio"); 00087 return(-1); 00088 } 00089 00090 ret = _init_audio_device(audio); 00091 if (ret < 0) { 00092 return(-1); 00093 } 00094 00095 return(1); 00096 }

Here is the call graph for this function:

int xdvshow_play_audio dv_audio_t *  audio,
int16_t **  audio_buffers
 

Audio playing function.

xdvshow_play_audio() just writes the previously decoded audio data to the audio device. The device must be initialized in advance by xdvshow_init_audio().

Parameters:
*audio is a dv_audio_t structure
**audio_buffers buffers storing decoded audio data
Returns:
1. There is no other return in this function.

Definition at line 111 of file xdvshow-audio.c.

References audio_buffers, and audio_fd.

Referenced by audio_thread_func().

00112 { 00113 /* 00114 int ret; 00115 */ 00116 int ch, i, j=0; 00117 static int16_t outbuf[DV_AUDIO_MAX_SAMPLES * 4]; 00118 00119 for (i=0; i<audio->samples_this_frame; i++) { 00120 for (ch=0; ch<audio->num_channels; ch++) { 00121 outbuf[j] = audio_buffers[ch][i]; 00122 j++; 00123 } 00124 } 00125 00126 write(audio_fd, 00127 outbuf, 00128 audio->samples_this_frame * audio->num_channels * sizeof(u_int16_t)); 00129 00130 /* 00131 ret = ioctl(audio_fd, SNDCTL_DSP_POST, NULL); 00132 if (ret < 0) { 00133 perror("SNDCTL_DSP_POST"); 00134 return (-1); 00135 } 00136 */ 00137 00138 return(1); 00139 }


Variable Documentation

int audio_fd
 

is the audio device file descriptor.

Definition at line 60 of file xdvshow-audio.c.

Referenced by _init_audio_device(), xdvshow_init_audio(), and xdvshow_play_audio().


Generated on Wed Nov 3 19:19:02 2004 for xdvshow by doxygen 1.3.7