OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [mp3/] [sw/] [mad-xess/] [audio_oss.c] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 291 simons
/*
2
 * mad - MPEG audio decoder
3
 * Copyright (C) 2000-2001 Robert Leslie
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 *
19
 * $Id: audio_oss.c,v 1.3 2001-11-06 17:01:07 simons Exp $
20
 */
21
 
22
# ifdef HAVE_CONFIG_H
23
#  include "config.h"
24
# endif
25
 
26
#ifndef EMBED
27
# include <unistd.h>
28
# include <fcntl.h>
29
# include <sys/ioctl.h>
30
# include <sys/soundcard.h>
31
# include <errno.h>
32
 
33
# include "mad.h"
34
# include "audio.h"
35
 
36
# if !defined(AFMT_S32_NE)
37
#  if defined(WORDS_BIGENDIAN)
38
#   define AFMT_S32_NE  AFMT_S32_BE
39
#  else
40
#   define AFMT_S32_NE  AFMT_S32_LE
41
#  endif
42
# endif
43
 
44
# if !defined(AFMT_S16_NE)
45
#  if defined(WORDS_BIGENDIAN)
46
#   define AFMT_S16_NE  AFMT_S16_BE
47
#  else
48
#   define AFMT_S16_NE  AFMT_S16_LE
49
#  endif
50
# endif
51
 
52
# if !defined(SNDCTL_DSP_CHANNELS) && defined(SOUND_PCM_WRITE_CHANNELS)
53
#  define SNDCTL_DSP_CHANNELS   SOUND_PCM_WRITE_CHANNELS
54
# endif
55
 
56
# define AUDIO_DEVICE   "/dev/dsp"
57
 
58
static int sfd;
59
static unsigned int (*audio_pcm)(unsigned char *, unsigned int,
60
                                 mad_fixed_t const *, mad_fixed_t const *);
61
inline static
62
int init(struct audio_init *init)
63
{
64
  if (init->path == 0)
65
    init->path = AUDIO_DEVICE;
66
 
67
  sfd = open(init->path, O_WRONLY);
68
  if (sfd == -1) {
69
    audio_error = ":";
70
    return -1;
71
  }
72
 
73
  return 0;
74
}
75
 
76
inline static
77
int config(struct audio_config *config)
78
{
79
  int format;
80
 
81
  if (ioctl(sfd, SNDCTL_DSP_SYNC, 0) == -1) {
82
    audio_error = ":ioctl(SNDCTL_DSP_SYNC)";
83
    return -1;
84
  }
85
 
86
  format = AFMT_S16_NE;
87
 
88
  if (ioctl(sfd, SNDCTL_DSP_SETFMT, &format) == -1) {
89
    audio_error = ":ioctl(SNDCTL_DSP_SETFMT)";
90
    return -1;
91
  }
92
 
93
  audio_pcm = audio_pcm_s16le;
94
 
95
  if (ioctl(sfd, SNDCTL_DSP_CHANNELS, &config->channels) == -1) {
96
    audio_error = ":ioctl(SNDCTL_DSP_CHANNELS)";
97
    return -1;
98
  }
99
 
100
  if (ioctl(sfd, SNDCTL_DSP_SPEED, &config->speed) == -1) {
101
    audio_error = ":ioctl(SNDCTL_DSP_SPEED)";
102
    return -1;
103
  }
104
 
105
  return 0;
106
}
107
 
108
inline
109
int output_s(unsigned char const *ptr, unsigned int len)
110
{
111
  while (len) {
112
    int wrote;
113
 
114
    wrote = write(sfd, ptr, len);
115
    if (wrote == -1) {
116
      if (errno == EINTR) {
117
        printf(".");
118
        continue;
119
      }
120
      else {
121
        audio_error = ":write";
122
        return -1;
123
      }
124
    }
125
 
126
    ptr += wrote;
127
    len -= wrote;
128
  }
129
 
130
  return 0;
131
}
132
 
133
inline static
134
int finish(struct audio_finish *finish)
135
{
136
  int result = 0;
137
 
138
  if (close(sfd) == -1 && result == 0) {
139
    audio_error = ":close";
140
    result = -1;
141
  }
142
 
143
  return result;
144
}
145
 
146
inline int audio_oss(union audio_control *control)
147
{
148
  audio_error = 0;
149
 
150
  switch (control->command) {
151
  case AUDIO_COMMAND_INIT:
152
    return init(&control->init);
153
 
154
  case AUDIO_COMMAND_CONFIG:
155
    return config(&control->config);
156
 
157
  case AUDIO_COMMAND_FINISH:
158
    return finish(&control->finish);
159
  }
160
 
161
  return 0;
162
}
163
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.