~ubuntu-branches/ubuntu/natty/ecasound2.2/natty

« back to all changes in this revision

Viewing changes to libecasound/audioio-oss.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Junichi Uekawa
  • Date: 2008-09-26 09:58:52 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20080926095852-k3v9ewhmxpaltusw
Tags: 2.5.2-3
yodl 2.13.1 removed --unique-output option. Remove --unique-output
accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
// ------------------------------------------------------------------------
2
2
// audioio-oss.cpp: OSS (/dev/dsp) input/output.
3
 
// Copyright (C) 1999-2004 Kai Vehmanen
 
3
// Copyright (C) 1999-2004,2008 Kai Vehmanen
 
4
//
 
5
// Attributes:
 
6
//     eca-style-version: 3 (see Ecasound Programmer's Guide)
4
7
//
5
8
// This program is free software; you can redistribute it and/or modify
6
9
// it under the terms of the GNU General Public License as published by
55
58
OSSDEVICE* OSSDEVICE::clone(void) const
56
59
{
57
60
  OSSDEVICE* target = new OSSDEVICE(label(), precise_srate_mode);
58
 
  return(target);
 
61
  return target;
59
62
}
60
63
 
61
64
void OSSDEVICE::open(void) throw(AUDIO_IO::SETUP_ERROR &)
85
88
 
86
89
  if (ioctl(audio_fd, SNDCTL_DSP_GETCAPS, &oss_caps) == -1) {
87
90
    oss_caps = 0;
88
 
    ECA_LOG_MSG(ECA_LOGGER::info, "(audioio-oss) WARNING: OSS-device doesn't support SNDCTL_DSP_GETCAPS."); 
 
91
    ECA_LOG_MSG(ECA_LOGGER::info, "WARNING: OSS-device doesn't support SNDCTL_DSP_GETCAPS."); 
89
92
  }
90
93
 
91
94
  // -------------------------------------------------------------------
125
128
    fragment_count = 3;
126
129
    
127
130
  ECA_LOG_MSG(ECA_LOGGER::user_objects, 
128
 
                "(audioio-oss) Setting OSS fragment size according to " + kvu_numtostr(buffersize()) + ".");
 
131
                "Setting OSS fragment size according to " + kvu_numtostr(buffersize()) + ".");
129
132
 
130
133
  // fr_size == 4  -> the minimum fragment size: 2^4 = 16 bytes
131
134
  unsigned short int fr_size = 4;
138
141
    ECA_LOG_MSG(ECA_LOGGER::info, "WARNING: OSS-device doesn't support SNDCTL_DSP_SETFRAGMENT!");
139
142
 
140
143
  ECA_LOG_MSG(ECA_LOGGER::user_objects, 
141
 
                "(audioio-oss) set OSS fragment size to (2^x) " +
 
144
                "set OSS fragment size to (2^x) " +
142
145
                kvu_numtostr(fr_size) + ".");
143
146
    
144
147
  // -------------------------------------------------------------------
176
179
 
177
180
  int t = stereo;
178
181
  if (::ioctl(audio_fd, SNDCTL_DSP_STEREO, &t)==-1)
179
 
    ECA_LOG_MSG(ECA_LOGGER::info, "(audioio-oss) WARNING: Error when setting sample rate."); 
 
182
    ECA_LOG_MSG(ECA_LOGGER::info, "WARNING: Error when setting sample rate."); 
180
183
 
181
184
  if (stereo != t)
182
185
    throw(SETUP_ERROR(SETUP_ERROR::channels, "AUDIOIO-OSS: audio format not supported SNDCTL_DSP_STEREO"));
193
196
      throw(SETUP_ERROR(SETUP_ERROR::unexpected, "AUDIOIO-OSS: Requested sample rate is not supported. Audio device suggests sample rate of " + kvu_numtostr(speed) + ". Disable precise-sample-rate mode to ignore the difference."));
194
197
    }
195
198
    else {
196
 
      ECA_LOG_MSG(ECA_LOGGER::info, "(audioio-oss) WARNING: Requested sample rate is not supported. Ignoring the the difference between requested (" + kvu_numtostr(samples_per_second()) + ") and suggested (" + kvu_numtostr(speed) + ") sample rates."); 
 
199
      ECA_LOG_MSG(ECA_LOGGER::info, "WARNING: Requested sample rate is not supported. Ignoring the the difference between requested (" + kvu_numtostr(samples_per_second()) + ") and suggested (" + kvu_numtostr(speed) + ") sample rates."); 
197
200
    }
198
201
  }
199
202
 
201
204
  // Get fragment size.
202
205
 
203
206
  if (::ioctl(audio_fd, SNDCTL_DSP_GETBLKSIZE, &fragment_size) == -1)
204
 
      ECA_LOG_MSG(ECA_LOGGER::info, "(audioio-oss) WARNING: SNDCTL_DSP_GETBLKSIZE ioctl failed. Might affect OSS audio input/output."); 
 
207
      ECA_LOG_MSG(ECA_LOGGER::info, "WARNING: SNDCTL_DSP_GETBLKSIZE ioctl failed. Might affect OSS audio input/output."); 
205
208
 
206
 
  ECA_LOG_MSG(ECA_LOGGER::user_objects, "(audioio-oss) OSS set to use fragment size of " + 
 
209
  ECA_LOG_MSG(ECA_LOGGER::user_objects, "OSS set to use fragment size of " + 
207
210
                   kvu_numtostr(fragment_size) + ".");
208
211
 
209
212
  /* SNDCTL_DSP_GET[IO]PTR report offset since device was opened */
218
221
  //        won't work properly (see OSS adv.prog.guide)
219
222
 
220
223
  ::ioctl(audio_fd, SNDCTL_DSP_POST, 0);
221
 
  ECA_LOG_MSG(ECA_LOGGER::user_objects,"(audioio-oss) Audio device \"" + label() + "\" disabled.");
 
224
  ECA_LOG_MSG(ECA_LOGGER::user_objects,"Audio device \"" + label() + "\" disabled.");
222
225
 
223
226
  AUDIO_IO_DEVICE::stop();
224
227
}
234
237
 
235
238
void OSSDEVICE::start(void)
236
239
{
237
 
  ECA_LOG_MSG(ECA_LOGGER::user_objects,"(audioio-oss) Audio device \"" + label() + "\" started.");
 
240
  ECA_LOG_MSG(ECA_LOGGER::user_objects,"Audio device \"" + label() + "\" started.");
238
241
#ifndef ECA_DISABLE_OSS_TRIGGER
239
242
  if ((oss_caps & DSP_CAP_TRIGGER) == DSP_CAP_TRIGGER) {
240
243
    int enable_bits;
279
282
    }
280
283
  }
281
284
  DBC_CHECK(delay >= 0);
282
 
  return(delay);
 
285
  return delay;
283
286
}
284
287
 
285
288
long int OSSDEVICE::read_samples(void* target_buffer, 
286
289
                                 long int samples)
287
290
{
288
 
  return(::read(audio_fd,target_buffer, frame_size() * samples) / frame_size());
 
291
  return ::read(audio_fd,target_buffer, frame_size() * samples) / frame_size();
289
292
}
290
293
 
291
294
void OSSDEVICE::write_samples(void* target_buffer, long int samples)