4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "audioconfig.h"
23 #include "audiodevice.inc"
25 #include "maxchannels.h"
29 #define CLAMP(x, y, z) (x) = ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x)))
31 AudioConfig::AudioConfig()
33 audio_in_driver = AUDIO_ALSA;
34 afirewire_in_port = 0;
35 afirewire_in_channel = 63;
36 strcpy(oss_in_device, "/dev/dsp");
39 strcpy(esound_in_server, "");
40 strpcy(pulse_in_server, "");
43 audio_out_driver = AUDIO_ALSA;
44 strpcy(oss_out_device, "/dev/dsp");
47 strpcy(esound_out_server, "");
48 strpcy(pulse_out_server, "");
51 audio_duplex_driver = AUDIO_ALSA;
52 strcpy(oss_duplex_device, "/dev/dsp");
53 oss_duplex_channels = 2;
55 strcpy(esound_duplex_server, "");
56 esound_duplex_port = 0;
59 AudioConfig::~AudioConfig()
63 AudioConfig& AudioConfig::operator=(AudioConfig &that)
66 audio_in_driver = that.audio_in_driver;
67 afirewire_in_port = that.afirewire_in_port;
68 afirewire_in_channel = that.afirewire_in_channel;
69 strcpy(esound_in_server, that.esound_in_server);
70 strcpy(pulse_in_server, that.pulse_in_server);
71 esound_in_port = that.esound_in_port;
72 strcpy(oss_in_device, that.oss_in_device);
73 oss_in_channels = that.oss_in_channels;
74 oss_in_bits = that.oss_in_bits;
77 audio_out_driver = that.audio_out_driver;
78 strcpy(oss_out_device, that.oss_out_device);
79 strcpy(esound_out_server, that.esound_out_server);
80 strcpy(pulse_out_server, that.pulse_out_server);
81 esound_out_port = that.esound_out_port;
82 oss_out_channels = that.oss_out_channels;
83 oss_out_bits = that.oss_out_bits;
86 audio_duplex_driver = that.audio_duplex_driver;
87 strcpy(oss_duplex_device, that.oss_duplex_device);
88 strcpy(esound_duplex_server, that.esound_duplex_server);
89 esound_duplex_port = that.esound_duplex_port;
90 oss_duplex_channels = that.oss_duplex_channels;
91 oss_duplex_bits = that.oss_duplex_bits;
92 CLAMP(oss_in_channels, 1, MAXCHANNELS);
93 CLAMP(oss_in_bits, 8, 32);
94 CLAMP(oss_duplex_channels, 1, MAXCHANNELS);
95 CLAMP(oss_duplex_bits, 8, 32);
99 int AudioConfig::load_defaults(BC_Hash *defaults)
101 audio_in_driver = defaults->get("AUDIOINDRIVER", AUDIO_ALSA);
102 afirewire_in_port = defaults->get("AFIREWIRE_IN_PORT", 0);
103 afirewire_in_channel = defaults->get("AFIREWIRE_IN_CHANNEL", 63);
104 sprintf(oss_in_device, "/dev/dsp");
105 defaults->get("OSS_IN_DEVICE", oss_in_device);
106 oss_in_channels = defaults->get("OSS_IN_CHANNELS", 2);
107 oss_in_bits = defaults->get("OSS_IN_BITS", 16);
108 sprintf(esound_in_server, "");
109 defaults->get("ESOUND_IN_SERVER", esound_in_server);
110 sprintf(pulse_in_server, "");
111 defaults->get("PULSE_IN_SERVER", pulse_in_server);
112 esound_in_port = defaults->get("ESOUND_IN_PORT", 0);
114 audio_out_driver = defaults->get("AUDIO_OUT_DRIVER", AUDIO_ALSA);
115 audio_duplex_driver = defaults->get("AUDIO_DUPLEX_DRIVER", AUDIO_ALSA);
116 sprintf(oss_out_device, "/dev/dsp");
117 defaults->get("OSS_OUT_DEVICE", oss_out_device);
118 oss_out_channels = defaults->get("OUT_CHANNELS", 2);
119 oss_out_bits = defaults->get("OUT_BITS", 16);
120 sprintf(esound_out_server, "");
121 defaults->get("ESOUND_OUT_SERVER", esound_out_server);
122 sprintf(pulse_out_server, "");
123 defaults->get("PULSE_OUT_SERVER", pulse_out_server);
124 esound_out_port = defaults->get("ESOUND_OUT_PORT", 0);
126 audio_duplex_driver = defaults->get("AUDIO_DUPLEX_DRIVER", AUDIO_ALSA);
127 sprintf(oss_duplex_device, "/dev/dsp");
128 defaults->get("OSS_DUPLEX_DEVICE", oss_duplex_device);
129 oss_duplex_channels = defaults->get("DUPLEX_CHANNELS", 2);
130 oss_duplex_bits = defaults->get("DUPLEX_BITS", 16);
131 sprintf(esound_duplex_server, "");
132 defaults->get("ESOUND_DUPLEX_SERVER", esound_duplex_server);
133 esound_duplex_port = defaults->get("ESOUND_DUPLEX_PORT", 0);
137 int AudioConfig::save_defaults(BC_Hash *defaults)
139 defaults->update("AUDIOINDRIVER", audio_in_driver);
140 defaults->update("AFIREWIRE_IN_PORT", afirewire_in_port);
141 defaults->update("AFIREWIRE_IN_CHANNEL", afirewire_in_channel);
142 defaults->update("OSS_IN_DEVICE", oss_in_device);
143 defaults->update("OSS_IN_CHANNELS", oss_in_channels);
144 defaults->update("OSS_IN_BITS", oss_in_bits);
145 defaults->update("ESOUND_IN_SERVER", esound_in_server);
146 defaults->update("PULSE_IN_SERVER", pulse_in_server);
147 defaults->update("ESOUND_IN_PORT", esound_in_port);
149 defaults->update("AUDIO_OUT_DRIVER", audio_out_driver);
150 defaults->update("AUDIO_DUPLEX_DRIVER", audio_duplex_driver);
151 defaults->update("OSS_OUT_DEVICE", oss_out_device);
152 defaults->update("OUT_CHANNELS", oss_out_channels);
153 defaults->update("OUT_BITS", oss_out_bits);
154 defaults->update("ESOUND_OUT_SERVER", esound_out_server);
155 defaults->update("PULSE_OUT_SERVER", pulse_out_server);
156 defaults->update("ESOUND_OUT_PORT", esound_out_port);
158 defaults->update("AUDIO_DUPLEX_DRIVER", audio_duplex_driver);
159 defaults->update("OSS_DUPLEX_DEVICE", oss_duplex_device);
160 defaults->update("OSS_DUPLEX_CHANNELS", oss_duplex_channels);
161 defaults->update("OSS_DUPLEX_BITS", oss_duplex_bits);
162 defaults->update("ESOUND_DUPLEX_SERVER", esound_duplex_server);
163 defaults->update("ESOUND_DUPLEX_PORT", esound_duplex_port);