00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
#include <stdio.h>
00036
#include <fcntl.h>
00037
#include <unistd.h>
00038
00039
#if (FREEBSD_4 || FREEBSD_5)
00040
#include <sys/soundcard.h>
00041
#endif
00042
00043
#ifdef NETBSD
00044
#include <sys/ioccom.h>
00045
#include <soundcard.h>
00046
#endif
00047
00048
#ifdef LINUX
00049
#include <sys/ioctl.h>
00050
#include <linux/soundcard.h>
00051
#endif
00052
00053
#include <libdv/dv.h>
00054
00055
#include "xdvshow-audio.h"
00056
00060 int audio_fd;
00061
00062
static int _init_audio_device __P((dv_audio_t *));
00063
00075
int
00076 xdvshow_init_audio(
char *audio_dev, dv_audio_t *audio)
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 }
00097
00110
int
00111 xdvshow_play_audio(dv_audio_t *audio, int16_t **audio_buffers)
00112 {
00113
00114
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
00132
00133
00134
00135
00136
00137
00138
return(1);
00139 }
00140
00154
static int
00155 _init_audio_device(dv_audio_t *audio)
00156 {
00157
int ret;
00158
int format;
00159
int fragment_request;
00160
int channels;
00161
int rate;
00162
00163
00164
00165
00166
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
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 }