1 #include "audioconfig.h"
2 #include "audiodevice.h"
3 #include "audioesound.h"
4 #include "playbackconfig.h"
5 #include "preferences.h"
6 #include "recordconfig.h"
12 AudioESound::AudioESound(AudioDevice *device) : AudioLowLevel(device)
14 esd_in = esd_out = esd_duplex = 0;
15 esd_in_fd = esd_out_fd = esd_duplex_fd = 0;
18 AudioESound::~AudioESound()
23 int AudioESound::get_bit_flag(int bits)
41 // No more than 2 channels in ESD
42 int AudioESound::get_channels_flag(int channels)
60 char* AudioESound::translate_device_string(char *server, int port)
63 if(port > 0 && strlen(server))
64 sprintf(device_string, "%s:%d", server, port);
66 sprintf(device_string, "");
70 int AudioESound::open_input()
72 esd_format_t format = ESD_STREAM | ESD_RECORD;
74 device->in_channels = 2;
77 format |= get_channels_flag(device->in_channels);
78 format |= get_bit_flag(device->in_bits);
80 if((esd_in = esd_open_sound(translate_device_string(device->in_config->esound_in_server, device->in_config->esound_in_port))) <= 0)
82 fprintf(stderr, "AudioESound::open_input: open failed\n");
85 esd_in_fd = esd_record_stream_fallback(format, device->in_samplerate,
86 translate_device_string(device->out_config->esound_out_server, device->out_config->esound_out_port),
91 int AudioESound::open_output()
93 esd_format_t format = ESD_STREAM | ESD_PLAY;
95 device->out_channels = 2;
96 device->out_bits = 16;
98 format |= get_channels_flag(device->out_channels);
99 format |= get_bit_flag(device->out_bits);
101 if((esd_out = esd_open_sound(translate_device_string(device->out_config->esound_out_server, device->out_config->esound_out_port))) <= 0)
103 fprintf(stderr, "AudioESound::open_output: open failed\n");
106 esd_out_fd = esd_play_stream_fallback(format, device->out_samplerate,
107 translate_device_string(device->out_config->esound_out_server, device->out_config->esound_out_port),
110 device->device_buffer = esd_get_latency(esd_out);
111 device->device_buffer *= device->out_bits / 8 * device->out_channels;
115 // Open both input and output in ESD
116 int AudioESound::open_duplex()
118 device->duplex_channels = 2;
119 device->duplex_bits = 16;
125 int AudioESound::close_all()
127 if(device->r || device->d)
133 if(device->w || device->d)
140 // No position on ESD
141 int64_t AudioESound::device_position()
146 int AudioESound::read_buffer(char *buffer, int size)
149 return read(esd_in_fd, buffer, size);
154 int AudioESound::write_buffer(char *buffer, int size)
157 return write(esd_out_fd, buffer, size);
162 // No flushing in ESD
163 int AudioESound::flush_device()
168 // No interrupting ESD
169 int AudioESound::interrupt_playback()
174 #endif // HAVE_ESOUND
178 // c-file-style: "linux"