<commit_before>// ------------------------------------------------------------------------
// audioio-oss.cpp: OSS (/dev/dsp) input/output.
// Copyright (C) 1999-2002 <NAME> (<EMAIL>)
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
// ------------------------------------------------------------------------

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <string>
#include <cstring>
#include <cstdio>
#include <errno.h>

#include <kvu_dbc.h>
#include <kvu_message_item.h>
#include <kvu_numtostr.h>

#include "audioio-oss_impl.h"
#include "audioio-oss.h"

#include "eca-error.h"
#include "eca-logger.h"

OSSDEVICE::OSSDEVICE(const std::string& name,
		     bool precise_sample_rates) 
{
  set_label(name);
  precise_srate_mode = precise_sample_rates;
}

OSSDEVICE::~OSSDEVICE(void)
{
  if (is_open() == true && is_running()) stop();

  if (is_open() == true) {
    close();
  }
}

OSSDEVICE* OSSDEVICE::clone(void) const
{
  OSSDEVICE* target = new OSSDEVICE(label(), precise_srate_mode);
  return(target);
}

void OSSDEVICE::open(void) throw(AUDIO_IO::SETUP_ERROR &)
{
  if (io_mode() == io_read) {
    if ((audio_fd = ::open(label().c_str(), O_RDONLY, 0)) == -1) {
      throw(SETUP_ERROR(SETUP_ERROR::io_mode, 
			"AUDIOIO-OSS: unable to open OSS-device to O_RDONLY (" +
			  kvu_numtostr(errno) + ")"));
    }
  }
  else if (io_mode() == io_write) {
    if ((audio_fd = ::open(label().c_str(), O_WRONLY, 0)) == -1) {
      // Opening device failed
      perror("(eca-oss)");
      throw(SETUP_ERROR(SETUP_ERROR::io_mode, 
			"AUDIOIO-OSS: unable to open OSS-device to O_RWONLY (" +
 			  kvu_numtostr(errno) + ")"));
    }
  }
  else {
      throw(SETUP_ERROR(SETUP_ERROR::io_mode, "AUDIOIO-OSS: Simultanious intput/output not supported."));
  }

  // -------------------------------------------------------------------
  // Check capabilities

  if (ioctl(audio_fd, SNDCTL_DSP_GETCAPS, &oss_caps) == -1)
    throw(SETUP_ERROR(SETUP_ERROR::unexpected, "AUDIOIO-OSS: OSS-device doesn't support SNDCTL_DSP_GETCAPS"));
<commit_msg>Only warn if DSP_GETCAPS is not supported.<commit_after>// ------------------------------------------------------------------------
// audioio-oss.cpp: OSS (/dev/dsp) input/output.
// Copyright (C) 1999-2003 <NAME> (<EMAIL>)
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
// ------------------------------------------------------------------------

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <string>
#include <cstring>
#include <cstdio>
#include <errno.h>

#include <kvu_dbc.h>
#include <kvu_message_item.h>
#include <kvu_numtostr.h>

#include "audioio-oss_impl.h"
#include "audioio-oss.h"

#include "eca-error.h"
#include "eca-logger.h"

OSSDEVICE::OSSDEVICE(const std::string& name,
		     bool precise_sample_rates) 
{
  set_label(name);
  precise_srate_mode = precise_sample_rates;
}

OSSDEVICE::~OSSDEVICE(void)
{
  if (is_open() == true && is_running()) stop();

  if (is_open() == true) {
    close();
  }
}

OSSDEVICE* OSSDEVICE::clone(void) const
{
  OSSDEVICE* target = new OSSDEVICE(label(), precise_srate_mode);
  return(target);
}

void OSSDEVICE::open(void) throw(AUDIO_IO::SETUP_ERROR &)
{
  if (io_mode() == io_read) {
    if ((audio_fd = ::open(label().c_str(), O_RDONLY, 0)) == -1) {
      throw(SETUP_ERROR(SETUP_ERROR::io_mode, 
			"AUDIOIO-OSS: unable to open OSS-device to O_RDONLY (" +
			  kvu_numtostr(errno) + ")"));
    }
  }
  else if (io_mode() == io_write) {
    if ((audio_fd = ::open(label().c_str(), O_WRONLY, 0)) == -1) {
      // Opening device failed
      perror("(eca-oss)");
      throw(SETUP_ERROR(SETUP_ERROR::io_mode, 
			"AUDIOIO-OSS: unable to open OSS-device to O_RWONLY (" +
 			  kvu_numtostr(errno) + ")"));
    }
  }
  else {
      throw(SETUP_ERROR(SETUP_ERROR::io_mode, "AUDIOIO-OSS: Simultanious intput/output not supported."));
  }

  // -------------------------------------------------------------------
  // Check capabilities

  if (ioctl(audio_fd, SNDCTL_DSP_GETCAPS, &oss_caps) == -1) {
    oss_caps = 0;
    ECA_LOG_MSG(ECA_LOGGER::info, "(audioio-oss) Warning! OSS-device doesn't support SNDCTL_DSP_GETCAPS."); 
  }

{'fraction_non_alphanumeric': 0.20821917808219179, 'fraction_numerical': 0.010410958904109589, 'mean_word_length': 2.710027100271003, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4122299', 'n_tokens_mistral': 1890, 'n_tokens_neox': 1793, 'n_words': 491}