annotate src/OSS4/audio.c @ 3048:c269a0351b53

ported OSS4
author Michal Lipski <tallica@o2.pl>
date Fri, 17 Apr 2009 17:31:14 +0200
parents bd3a24b39058
children 9ec8a613a1d6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
1 /* BMP - Cross-platform multimedia player
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
2 * Copyright (C) 2003-2004 BMP development team.
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
3 *
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
4 * Based on XMMS:
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
5 * Copyright (C) 1998-2003 XMMS development team.
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
6 *
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
7 * This program is free software; you can redistribute it and/or modify
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
10 * (at your option) any later version.
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
11 *
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful,
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
15 * GNU General Public License for more details.
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
16 *
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
18 * along with this program; if not, write to the Free Software
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
20 */
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
21
3048
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
22 static void oss_describe_error();
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
23 static void close_mixer_device();
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
24
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
25 #include <glib.h>
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
26 #include <string.h>
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
27
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
28 #include <unistd.h>
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
29 #include <fcntl.h>
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
30 #include <errno.h>
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
31 #include <sys/ioctl.h>
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
32 #include <sys/time.h>
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
33
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
34 #include "OSS4.h"
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
35
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
36
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
37 #define NFRAGS 32
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
38
3048
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
39 static gint fd = -1, mixerfd = -1;
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
40 static oss_sysinfo sysinfo;
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
41 static char *buffer;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
42 static gboolean going, prebuffer, paused, unpause, do_pause, remove_prebuffer;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
43 static gint device_buffer_used, buffer_size, prebuffer_size, blk_size;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
44 static gint rd_index = 0, wr_index = 0;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
45 static gint output_time_offset = 0;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
46 static guint64 written = 0, output_bytes = 0;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
47 static gint flush;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
48 static gint fragsize, device_buffer_size;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
49 static gchar *device_name;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
50 static GThread *buffer_thread;
1686
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
51 static gboolean select_works;
2177
a838523e04b7 Restore the channel's volume after playback.
Jonathan Schleifer <js@webkeks.org>
parents: 1973
diff changeset
52 static int start_vol_l, start_vol_r;
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
53
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
54 static int (*oss_convert_func) (void **data, int length);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
55 static int (*oss_stereo_convert_func) (void **data, int length, int fmt);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
56
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
57 struct format_info {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
58 union {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
59 AFormat xmms;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
60 int oss;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
61 } format;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
62 int frequency;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
63 int channels;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
64 int bps;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
65 };
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
66
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
67
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
68 /*
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
69 * The format of the data from the input plugin
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
70 * This will never change during a song.
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
71 */
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
72 struct format_info input;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
73
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
74 /*
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
75 * The format we get from the effect plugin.
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
76 * This will be different from input if the effect plugin does
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
77 * some kind of format conversion.
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
78 */
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
79 struct format_info effect;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
80
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
81 /*
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
82 * The format of the data we actually send to the soundcard.
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
83 * This might be different from effect if we need to resample or do
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
84 * some other format conversion.
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
85 */
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
86 struct format_info output;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
87
3048
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
88 int oss_hardware_present()
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
89 {
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
90 /*
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
91 * Open the mixer device used for calling SNDCTL_SYSINFO and
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
92 * SNDCTL_AUDIOINFO.
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
93 */
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
94 if ((mixerfd = open("/dev/mixer", O_RDWR, 0)) == -1)
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
95 {
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
96 perror("/dev/mixer");
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
97 oss_describe_error();
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
98 close_mixer_device();
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
99
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
100 return 0;
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
101 }
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
102
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
103 if (ioctl(mixerfd, SNDCTL_SYSINFO, &sysinfo) == -1)
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
104 {
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
105 perror("SNDCTL_SYSINFO");
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
106 oss_describe_error();
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
107 close_mixer_device();
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
108
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
109 return 0;
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
110 }
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
111 else
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
112 {
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
113 close_mixer_device();
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
114
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
115 if (sysinfo.numaudios > 0)
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
116 {
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
117 return 1;
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
118 }
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
119 else
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
120 {
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
121 return 0;
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
122 }
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
123 }
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
124 }
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
125
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
126 static void
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
127 oss_describe_error()
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
128 {
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
129 switch (errno)
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
130 {
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
131 case ENXIO:
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
132 fprintf(stderr, "OSS has not detected any supported sound hardware in your system.\n");
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
133 break;
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
134
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
135 case EINVAL:
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
136 fprintf(stderr, "Error: OSS version 4.0 or later is required\n");
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
137 break;
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
138
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
139 case ENODEV:
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
140 fprintf(stderr, "The device file was found in /dev but\n"
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
141 "OSS is not loaded. You need to load it by executing\n"
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
142 "the soundon command.\n");
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
143 break;
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
144
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
145 case ENOSPC:
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
146 fprintf(stderr, "Your system cannot allocate memory for the device\n"
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
147 "buffers. Reboot your machine and try again.\n");
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
148 break;
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
149
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
150 case ENOENT:
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
151 fprintf(stderr, "The device file is missing from /dev.\n"
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
152 "Perhaps you have not installed and started Open Sound System yet\n");
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
153 break;
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
154
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
155 case EBUSY:
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
156 fprintf(stderr, "The device is busy. There is some other application\n"
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
157 "using it.\n");
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
158 break;
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
159
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
160 default:
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
161 fprintf(stderr, "Unknown OSS error.\n");
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
162 }
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
163 }
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
164
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
165 static void
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
166 oss_calc_device_buffer_used(void)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
167 {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
168 audio_buf_info buf_info;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
169 if (paused)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
170 device_buffer_used = 0;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
171 else if (!ioctl(fd, SNDCTL_DSP_GETOSPACE, &buf_info))
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
172 device_buffer_used =
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
173 (buf_info.fragstotal * buf_info.fragsize) - buf_info.bytes;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
174 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
175
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
176
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
177 static gint oss_downsample(gpointer ob, guint length, guint speed,
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
178 guint espeed);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
179
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
180 static int
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
181 oss_calc_bitrate(int oss_fmt, int rate, int channels)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
182 {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
183 int bitrate = rate * channels;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
184
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
185 if (oss_fmt == AFMT_U16_BE || oss_fmt == AFMT_U16_LE ||
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
186 oss_fmt == AFMT_S16_BE || oss_fmt == AFMT_S16_LE)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
187 bitrate *= 2;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
188
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
189 return bitrate;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
190 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
191
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
192 static int
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
193 oss_get_format(AFormat fmt)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
194 {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
195 int format = 0;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
196
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
197 switch (fmt) {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
198 case FMT_U8:
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
199 format = AFMT_U8;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
200 break;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
201 case FMT_S8:
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
202 format = AFMT_S8;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
203 break;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
204 case FMT_U16_LE:
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
205 format = AFMT_U16_LE;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
206 break;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
207 case FMT_U16_BE:
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
208 format = AFMT_U16_BE;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
209 break;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
210 case FMT_U16_NE:
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
211 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
212 format = AFMT_U16_BE;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
213 #else
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
214 format = AFMT_U16_LE;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
215 #endif
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
216 break;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
217 case FMT_S16_LE:
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
218 format = AFMT_S16_LE;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
219 break;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
220 case FMT_S16_BE:
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
221 format = AFMT_S16_BE;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
222 break;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
223 case FMT_S16_NE:
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
224 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
225 format = AFMT_S16_BE;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
226 #else
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
227 format = AFMT_S16_LE;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
228 #endif
2354
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
229 break;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
230 #if 0 /* OSS currently doesn't support AFMT_U24_* */
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
231 case FMT_U24_LE:
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
232 format = AFMT_U24_LE;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
233 break;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
234 case FMT_U24_BE:
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
235 format = AFMT_U24_BE;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
236 break;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
237 case FMT_U24_NE:
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
238 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
239 format = AFMT_U24_BE;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
240 #else
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
241 format = AFMT_U24_LE;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
242 #endif
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
243 break;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
244 #endif
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
245 case FMT_S24_LE:
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
246 format = AFMT_S24_LE;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
247 break;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
248 case FMT_S24_BE:
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
249 format = AFMT_S24_BE;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
250 break;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
251 case FMT_S24_NE:
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
252 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
253 format = AFMT_S24_BE;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
254 #else
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
255 format = AFMT_S24_LE;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
256 #endif
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
257 break;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
258 #if 0 /* OSS currently doesn't support AFMT_U32_* */
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
259 case FMT_U32_LE:
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
260 format = AFMT_U32_LE;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
261 break;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
262 case FMT_U32_BE:
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
263 format = AFMT_U32_BE;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
264 break;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
265 case FMT_U32_NE:
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
266 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
267 format = AFMT_U32_BE;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
268 #else
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
269 format = AFMT_U32_LE;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
270 #endif
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
271 break;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
272 #endif
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
273 case FMT_S32_LE:
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
274 format = AFMT_S32_LE;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
275 break;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
276 case FMT_S32_BE:
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
277 format = AFMT_S32_BE;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
278 break;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
279 case FMT_S32_NE:
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
280 #if (G_BYTE_ORDER == G_BIG_ENDIAN)
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
281 format = AFMT_S32_BE;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
282 #else
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
283 format = AFMT_S32_LE;
6b854a93649c introduced experimental support for 24bit and 32bit audio output
Cristi Magherusan <majeru@atheme.org>
parents: 2259
diff changeset
284 #endif
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
285 break;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
286 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
287 return format;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
288 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
289
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
290 static void
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
291 oss_setup_format(AFormat fmt, int rate, int nch)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
292 {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
293 effect.format.xmms = fmt;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
294 effect.frequency = rate;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
295 effect.channels = nch;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
296 effect.bps = oss_calc_bitrate(oss_get_format(fmt), rate, nch);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
297
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
298 output.format.oss = oss_get_format(fmt);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
299 output.frequency = rate;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
300 output.channels = nch;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
301
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
302
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
303 fragsize = 0;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
304 while ((1L << fragsize) < effect.bps / 25)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
305 fragsize++;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
306 fragsize--;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
307
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
308 device_buffer_size = ((1L << fragsize) * (NFRAGS + 1));
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
309
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
310 oss_set_audio_params();
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
311
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
312 output.bps = oss_calc_bitrate(output.format.oss, output.frequency,
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
313 output.channels);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
314 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
315
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
316
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
317 gint
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
318 oss_get_written_time(void)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
319 {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
320 if (!going)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
321 return 0;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
322 return (written * 1000) / effect.bps;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
323 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
324
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
325 gint
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
326 oss_get_output_time(void)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
327 {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
328 guint64 bytes;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
329
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
330 if (!fd || !going)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
331 return 0;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
332
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
333 bytes = output_bytes < device_buffer_used ?
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
334 0 : output_bytes - device_buffer_used;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
335
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
336 return output_time_offset + ((bytes * 1000) / output.bps);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
337 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
338
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
339 static int
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
340 oss_used(void)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
341 {
1686
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
342 if (wr_index >= rd_index)
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
343 return wr_index - rd_index;
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
344
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
345 return buffer_size - (rd_index - wr_index);
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
346 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
347
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
348 gint
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
349 oss_playing(void)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
350 {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
351 if (!going)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
352 return 0;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
353 if (!oss_used() && (device_buffer_used - (3 * blk_size)) <= 0)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
354 return FALSE;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
355
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
356 return TRUE;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
357 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
358
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
359 gint
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
360 oss_free(void)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
361 {
1686
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
362 if (remove_prebuffer && prebuffer) {
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
363 prebuffer = FALSE;
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
364 remove_prebuffer = FALSE;
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
365 }
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
366
1686
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
367 if (prebuffer)
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
368 remove_prebuffer = TRUE;
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
369
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
370 if (rd_index > wr_index)
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
371 return (rd_index - wr_index) - device_buffer_size - 1;
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
372
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
373 return (buffer_size - (wr_index - rd_index)) - device_buffer_size - 1;
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
374 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
375
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
376 static inline ssize_t
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
377 write_all(int fd, const void *buf, size_t count)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
378 {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
379 size_t done = 0;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
380 do {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
381 ssize_t n = write(fd, (gchar *) buf + done, count - done);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
382 if (n == -1) {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
383 if (errno == EINTR)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
384 continue;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
385 else
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
386 break;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
387 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
388 done += n;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
389 } while (count > done);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
390
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
391 return done;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
392 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
393
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
394 static void
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
395 oss_write_audio(gpointer data, int length)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
396 {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
397 if (oss_convert_func != NULL)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
398 length = oss_convert_func(&data, length);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
399
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
400 if (oss_stereo_convert_func != NULL)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
401 length = oss_stereo_convert_func(&data, length, output.format.oss);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
402
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
403 if (effect.frequency == output.frequency)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
404 output_bytes += write_all(fd, data, length);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
405 else
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
406 output_bytes += oss_downsample(data, length,
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
407 effect.frequency, output.frequency);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
408 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
409
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
410 static void
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
411 swap_endian(guint16 * data, int length)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
412 {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
413 int i;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
414 for (i = 0; i < length; i += 2, data++)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
415 *data = GUINT16_SWAP_LE_BE(*data);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
416 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
417
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
418 #define NOT_NATIVE_ENDIAN ((IS_BIG_ENDIAN && \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
419 (output.format.oss == AFMT_S16_LE || \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
420 output.format.oss == AFMT_U16_LE)) || \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
421 (!IS_BIG_ENDIAN && \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
422 (output.format.oss == AFMT_S16_BE || \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
423 output.format.oss == AFMT_U16_BE)))
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
424
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
425
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
426 #define RESAMPLE_STEREO(sample_type) \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
427 do { \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
428 const gint shift = sizeof (sample_type); \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
429 gint i, in_samples, out_samples, x, delta; \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
430 sample_type *inptr = (sample_type *)ob, *outptr; \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
431 guint nlen = (((length >> shift) * espeed) / speed); \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
432 if (nlen == 0) \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
433 break; \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
434 nlen <<= shift; \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
435 if (NOT_NATIVE_ENDIAN) \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
436 swap_endian(ob, length); \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
437 if(nlen > nbuffer_size) \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
438 { \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
439 nbuffer = g_realloc(nbuffer, nlen); \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
440 nbuffer_size = nlen; \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
441 } \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
442 outptr = (sample_type *)nbuffer; \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
443 in_samples = length >> shift; \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
444 out_samples = nlen >> shift; \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
445 delta = (in_samples << 12) / out_samples; \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
446 for (x = 0, i = 0; i < out_samples; i++) \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
447 { \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
448 gint x1, frac; \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
449 x1 = (x >> 12) << 12; \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
450 frac = x - x1; \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
451 *outptr++ = \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
452 (sample_type) \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
453 ((inptr[(x1 >> 12) << 1] * \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
454 ((1<<12) - frac) + \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
455 inptr[((x1 >> 12) + 1) << 1] * \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
456 frac) >> 12); \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
457 *outptr++ = \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
458 (sample_type) \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
459 ((inptr[((x1 >> 12) << 1) + 1] * \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
460 ((1<<12) - frac) + \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
461 inptr[(((x1 >> 12) + 1) << 1) + 1] * \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
462 frac) >> 12); \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
463 x += delta; \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
464 } \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
465 if (NOT_NATIVE_ENDIAN) \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
466 swap_endian(nbuffer, nlen); \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
467 w = write_all(fd, nbuffer, nlen); \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
468 } while (0)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
469
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
470
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
471 #define RESAMPLE_MONO(sample_type) \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
472 do { \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
473 const gint shift = sizeof (sample_type) - 1; \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
474 gint i, x, delta, in_samples, out_samples; \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
475 sample_type *inptr = (sample_type *)ob, *outptr; \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
476 guint nlen = (((length >> shift) * espeed) / speed); \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
477 if (nlen == 0) \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
478 break; \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
479 nlen <<= shift; \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
480 if (NOT_NATIVE_ENDIAN) \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
481 swap_endian(ob, length); \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
482 if(nlen > nbuffer_size) \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
483 { \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
484 nbuffer = g_realloc(nbuffer, nlen); \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
485 nbuffer_size = nlen; \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
486 } \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
487 outptr = (sample_type *)nbuffer; \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
488 in_samples = length >> shift; \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
489 out_samples = nlen >> shift; \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
490 delta = ((length >> shift) << 12) / out_samples; \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
491 for (x = 0, i = 0; i < out_samples; i++) \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
492 { \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
493 gint x1, frac; \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
494 x1 = (x >> 12) << 12; \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
495 frac = x - x1; \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
496 *outptr++ = \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
497 (sample_type) \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
498 ((inptr[x1 >> 12] * ((1<<12) - frac) + \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
499 inptr[(x1 >> 12) + 1] * frac) >> 12); \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
500 x += delta; \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
501 } \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
502 if (NOT_NATIVE_ENDIAN) \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
503 swap_endian(nbuffer, nlen); \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
504 w = write_all(fd, nbuffer, nlen); \
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
505 } while (0)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
506
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
507
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
508 static gint
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
509 oss_downsample(gpointer ob, guint length, guint speed, guint espeed)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
510 {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
511 guint w = 0;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
512 static gpointer nbuffer = NULL;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
513 static guint nbuffer_size = 0;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
514
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
515 switch (output.format.oss) {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
516 case AFMT_S16_BE:
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
517 case AFMT_S16_LE:
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
518 if (output.channels == 2)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
519 RESAMPLE_STEREO(gint16);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
520 else
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
521 RESAMPLE_MONO(gint16);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
522 break;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
523 case AFMT_U16_BE:
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
524 case AFMT_U16_LE:
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
525 if (output.channels == 2)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
526 RESAMPLE_STEREO(guint16);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
527 else
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
528 RESAMPLE_MONO(guint16);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
529 break;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
530 case AFMT_S8:
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
531 if (output.channels == 2)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
532 RESAMPLE_STEREO(gint8);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
533 else
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
534 RESAMPLE_MONO(gint8);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
535 break;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
536 case AFMT_U8:
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
537 if (output.channels == 2)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
538 RESAMPLE_STEREO(guint8);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
539 else
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
540 RESAMPLE_MONO(guint8);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
541 break;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
542 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
543 return w;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
544 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
545
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
546 void
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
547 oss_write(gpointer ptr, int length)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
548 {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
549 int cnt, off = 0;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
550
1686
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
551 remove_prebuffer = FALSE;
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
552
1686
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
553 written += length;
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
554 while (length > 0) {
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
555 cnt = MIN(length, buffer_size - wr_index);
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
556 memcpy(buffer + wr_index, (char *) ptr + off, cnt);
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
557 wr_index = (wr_index + cnt) % buffer_size;
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
558 length -= cnt;
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
559 off += cnt;
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
560 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
561 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
562
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
563 void
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
564 oss_close(void)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
565 {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
566 if (!going)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
567 return;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
568 going = 0;
1686
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
569
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
570 g_thread_join(buffer_thread);
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
571
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
572 g_free(device_name);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
573 oss_free_convert_buffer();
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
574 wr_index = 0;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
575 rd_index = 0;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
576
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
577 close_mixer_device();
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
578 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
579
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
580 void
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
581 oss_flush(gint time)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
582 {
1686
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
583 flush = time;
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
584 while (flush != -1)
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
585 g_usleep(10000);
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
586 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
587
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
588 void
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
589 oss_pause(short p)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
590 {
1686
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
591 if (p == TRUE)
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
592 do_pause = TRUE;
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
593 else
1686
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
594 unpause = TRUE;
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
595 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
596
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
597 gpointer
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
598 oss_loop(gpointer arg)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
599 {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
600 gint length, cnt;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
601 fd_set set;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
602 struct timeval tv;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
603
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
604 while (going) {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
605 if (oss_used() > prebuffer_size)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
606 prebuffer = FALSE;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
607 if (oss_used() > 0 && !paused && !prebuffer) {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
608 tv.tv_sec = 0;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
609 tv.tv_usec = 10000;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
610 FD_ZERO(&set);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
611 FD_SET(fd, &set);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
612 if (!select_works || (select(fd + 1, NULL, &set, NULL, &tv) > 0)) {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
613 length = MIN(blk_size, oss_used());
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
614 while (length > 0) {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
615 cnt = MIN(length, buffer_size - rd_index);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
616 oss_write_audio(buffer + rd_index, cnt);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
617 rd_index = (rd_index + cnt) % buffer_size;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
618 length -= cnt;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
619 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
620 if (!oss_used())
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
621 ioctl(fd, SNDCTL_DSP_POST, 0);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
622 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
623 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
624 else
1676
aee4ebea943a xmms_usleep() was removed, use g_usleep()
Matti Hamalainen <ccr@tnsp.org>
parents: 1244
diff changeset
625 g_usleep(10000);
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
626 oss_calc_device_buffer_used();
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
627 if (do_pause && !paused) {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
628 do_pause = FALSE;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
629 paused = TRUE;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
630 /*
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
631 * We lose some data here that is sent to the
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
632 * soundcard, but not yet played. I don't
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
633 * think this is worth fixing.
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
634 */
2252
b461d608befe replaced SNDCTL_DSP_RESET with SNDCTL_DSP_SYNC, as suggested by Michal
Cristi Magherusan <majeru@atheme-project.org>
parents: 2194
diff changeset
635 ioctl(fd, SNDCTL_DSP_SYNC, 0);
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
636 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
637 else if (unpause && paused) {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
638 unpause = FALSE;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
639 close(fd);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
640 fd = open(device_name, O_WRONLY);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
641 oss_set_audio_params();
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
642 paused = FALSE;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
643 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
644
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
645 if (flush != -1) {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
646 /*
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
647 * This close and open is a work around of a
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
648 * bug that exists in some drivers which cause
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
649 * the driver to get fucked up by a reset
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
650 */
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
651
2252
b461d608befe replaced SNDCTL_DSP_RESET with SNDCTL_DSP_SYNC, as suggested by Michal
Cristi Magherusan <majeru@atheme-project.org>
parents: 2194
diff changeset
652 ioctl(fd, SNDCTL_DSP_SYNC, 0);
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
653 close(fd);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
654 fd = open(device_name, O_WRONLY);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
655 oss_set_audio_params();
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
656 output_time_offset = flush;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
657 written = ((guint64) flush * input.bps) / 1000;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
658 rd_index = wr_index = output_bytes = 0;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
659 flush = -1;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
660 prebuffer = TRUE;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
661 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
662
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
663 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
664
2252
b461d608befe replaced SNDCTL_DSP_RESET with SNDCTL_DSP_SYNC, as suggested by Michal
Cristi Magherusan <majeru@atheme-project.org>
parents: 2194
diff changeset
665 ioctl(fd, SNDCTL_DSP_SYNC, 0);
2259
98fa8fe789a4 Actually, we have to reset in oss_loop() as this calls close().
Jonathan Schleifer <js@webkeks.org>
parents: 2257
diff changeset
666 oss_set_volume(start_vol_l, start_vol_r);
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
667 close(fd);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
668 g_free(buffer);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
669 return NULL;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
670 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
671
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
672 void
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
673 oss_set_audio_params(void)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
674 {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
675 int frag, stereo, ret;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
676 struct timeval tv;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
677 fd_set set;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
678
2252
b461d608befe replaced SNDCTL_DSP_RESET with SNDCTL_DSP_SYNC, as suggested by Michal
Cristi Magherusan <majeru@atheme-project.org>
parents: 2194
diff changeset
679 ioctl(fd, SNDCTL_DSP_SYNC, 0);
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
680 frag = (NFRAGS << 16) | fragsize;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
681 ioctl(fd, SNDCTL_DSP_SETFRAGMENT, &frag);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
682 /*
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
683 * Set the stream format. This ioctl() might fail, but should
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
684 * return a format that works if it does.
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
685 */
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
686 ioctl(fd, SNDCTL_DSP_SETFMT, &output.format.oss);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
687 if (ioctl(fd, SNDCTL_DSP_SETFMT, &output.format.oss) == -1)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
688 g_warning("SNDCTL_DSP_SETFMT ioctl failed: %s", strerror(errno));
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
689
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
690 stereo = output.channels - 1;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
691 ioctl(fd, SNDCTL_DSP_STEREO, &stereo);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
692 output.channels = stereo + 1;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
693
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
694 oss_stereo_convert_func = oss_get_stereo_convert_func(output.channels,
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
695 effect.channels);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
696
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
697 if (ioctl(fd, SNDCTL_DSP_SPEED, &output.frequency) == -1)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
698 g_warning("SNDCTL_DSP_SPEED ioctl failed: %s", strerror(errno));
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
699
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
700 if (ioctl(fd, SNDCTL_DSP_GETBLKSIZE, &blk_size) == -1)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
701 blk_size = 1L << fragsize;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
702
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
703 oss_convert_func =
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
704 oss_get_convert_func(output.format.oss,
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
705 oss_get_format(effect.format.xmms));
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
706
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
707 /*
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
708 * Stupid hack to find out if the driver support selects, some
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
709 * drivers won't work properly without a select and some won't
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
710 * work with a select :/
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
711 */
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
712
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
713 tv.tv_sec = 0;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
714 tv.tv_usec = 50000;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
715 FD_ZERO(&set);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
716 FD_SET(fd, &set);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
717 ret = select(fd + 1, NULL, &set, NULL, &tv);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
718 if (ret > 0)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
719 select_works = TRUE;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
720 else
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
721 select_works = FALSE;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
722 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
723
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
724 gint
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
725 oss_open(AFormat fmt, gint rate, gint nch)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
726 {
2194
c19a820de01e Set volume before playback for OSS4.
Jonathan Schleifer <js-audacious@webkeks.org>
parents: 2177
diff changeset
727 int l, r;
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
728
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
729 if (oss_cfg.use_alt_audio_device && oss_cfg.alt_audio_device)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
730 device_name = g_strdup(oss_cfg.alt_audio_device);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
731 else {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
732 if (oss_cfg.audio_device > 0)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
733 device_name =
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
734 g_strdup_printf("%s%d", DEV_DSP, oss_cfg.audio_device);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
735 else
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
736 device_name = g_strdup(DEV_DSP);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
737 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
738
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
739 fd = open(device_name, O_WRONLY);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
740
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
741 if (fd == -1) {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
742 g_warning("oss_open(): Failed to open audio device (%s): %s",
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
743 device_name, strerror(errno));
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
744 g_free(device_name);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
745 return 0;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
746 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
747
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
748 input.format.xmms = fmt;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
749 input.frequency = rate;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
750 input.channels = nch;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
751 input.bps = oss_calc_bitrate(oss_get_format(fmt), rate, nch);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
752
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
753 oss_setup_format(fmt, rate, nch);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
754
1686
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
755 buffer_size = (oss_cfg.buffer_size * input.bps) / 1000;
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
756
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
757 if (buffer_size < 8192)
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
758 buffer_size = 8192;
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
759
1686
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
760 prebuffer_size = (buffer_size * oss_cfg.prebuffer) / 100;
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
761 if (buffer_size - prebuffer_size < 4096)
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
762 prebuffer_size = buffer_size - 4096;
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
763
1686
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
764 buffer_size += device_buffer_size;
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
765 buffer = g_malloc0(buffer_size);
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
766
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
767 flush = -1;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
768 prebuffer = TRUE;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
769 wr_index = rd_index = output_time_offset = written = output_bytes = 0;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
770 paused = FALSE;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
771 do_pause = FALSE;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
772 unpause = FALSE;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
773 remove_prebuffer = FALSE;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
774
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
775 going = 1;
1686
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
776
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
777 buffer_thread = g_thread_create(oss_loop, NULL, TRUE, NULL);
2e8adf61c54f remove realtime craq from the code
William Pitcock <nenolod@atheme.org>
parents: 1685
diff changeset
778
2177
a838523e04b7 Restore the channel's volume after playback.
Jonathan Schleifer <js@webkeks.org>
parents: 1973
diff changeset
779 oss_get_volume(&start_vol_l, &start_vol_r);
2194
c19a820de01e Set volume before playback for OSS4.
Jonathan Schleifer <js-audacious@webkeks.org>
parents: 2177
diff changeset
780 aud_input_get_volume(&l, &r);
c19a820de01e Set volume before playback for OSS4.
Jonathan Schleifer <js-audacious@webkeks.org>
parents: 2177
diff changeset
781 oss_set_volume(l, r);
2177
a838523e04b7 Restore the channel's volume after playback.
Jonathan Schleifer <js@webkeks.org>
parents: 1973
diff changeset
782
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
783 return 1;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
784 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
785
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
786 void oss_tell(AFormat * fmt, gint * rate, gint * nch)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
787 {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
788 (*fmt) = input.format.xmms;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
789 (*rate) = input.frequency;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
790 (*nch) = input.channels;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
791 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
792
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
793 //-----------------------------OSS4 MIXER CODE-----------------------------
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
794 void oss_get_volume(int *l, int *r)
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
795 {
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
796 int v;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
797 long cmd=SNDCTL_DSP_GETPLAYVOL;
1243
4cf6ccace89c made OSS report latest set volume when not having opened a vmix device;
Cristi Magherusan <majeru@atheme-project.org>
parents: 1216
diff changeset
798 if(ioctl(fd, cmd, &v) == -1)
1244
d0f1e147cf62 now it saves VMIX volume between sessions
Cristi Magherusan <majeru@atheme-project.org>
parents: 1243
diff changeset
799 v=vol;
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
800 *r = (v & 0xFF00) >> 8;
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
801 *l = (v & 0x00FF);
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
802 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
803
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
804 void
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
805 oss_set_volume(int l, int r)
1216
cc04ccffaa8d ignore the VMIX balance setting until it gets fixed by the OSS4 devs
Cristi Magherusan <majeru@atheme-project.org>
parents: 1214
diff changeset
806 {
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
807 long cmd=SNDCTL_DSP_SETPLAYVOL;
1244
d0f1e147cf62 now it saves VMIX volume between sessions
Cristi Magherusan <majeru@atheme-project.org>
parents: 1243
diff changeset
808 vol = (r << 8) | l;
d0f1e147cf62 now it saves VMIX volume between sessions
Cristi Magherusan <majeru@atheme-project.org>
parents: 1243
diff changeset
809 ioctl(fd, cmd, &vol);
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
810 }
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
811
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
812 void
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
813 close_mixer_device()
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
814 {
3048
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
815 if (fd != -1)
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
816 {
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
817 close(fd);
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
818 fd = -1;
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
819 }
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
820
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
821 if (mixerfd != -1)
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
822 {
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
823 close(mixerfd);
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
824 mixerfd = -1;
c269a0351b53 ported OSS4
Michal Lipski <tallica@o2.pl>
parents: 2576
diff changeset
825 }
1214
2a722c3ccd9e damn, I forgot to 'hg add' the sources
Cristi Magherusan <majeru@atheme-project.org>
parents:
diff changeset
826 }