static int init(int rate_hz, int channels, int format, int flags)
{
	int err;
	int frag_spec;

	if( (err=arts_init()) ) {
		mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ARTS_CantInit, arts_error_text(err));
		return 0;
	}
	mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_ARTS_ServerConnect);

	/*
	 * arts supports 8bit unsigned and 16bit signed sample formats
	 * (16bit apparently in little endian format, even in the case
	 * when artsd runs on a big endian cpu).
	 *
	 * Unsupported formats are translated to one of these two formats
	 * using mplayer's audio filters.
	 */
	switch (format) {
	case AF_FORMAT_U8:
	case AF_FORMAT_S8:
	    format = AF_FORMAT_U8;
	    break;
	default:
	    format = AF_FORMAT_S16_LE;    /* artsd always expects little endian?*/
	    break;
	}

	ao_data.format = format;
	ao_data.channels = channels;
	ao_data.samplerate = rate_hz;
	ao_data.bps = (rate_hz*channels);

	if(format != AF_FORMAT_U8 && format != AF_FORMAT_S8)
		ao_data.bps*=2;

	stream=arts_play_stream(rate_hz, OBTAIN_BITRATE(format), channels, "MPlayer");

	if(stream == NULL) {
		mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_ARTS_CantOpenStream);
		arts_free();
		return 0;
	}

	/* Set the stream to blocking: it will not block anyway, but it seems */
	/* to be working better */
	arts_stream_set(stream, ARTS_P_BLOCKING, 1);
	frag_spec = ARTS_PACKET_SIZE_LOG2 | ARTS_PACKETS << 16;
	arts_stream_set(stream, ARTS_P_PACKET_SETTINGS, frag_spec);
	ao_data.buffersize = arts_stream_get(stream, ARTS_P_BUFFER_SIZE);
	mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_ARTS_StreamOpen);

	mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_ARTS_BufferSize,
	    ao_data.buffersize);
	mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_ARTS_BufferSize,
	    arts_stream_get(stream, ARTS_P_PACKET_SIZE));

	return 1;
}
Exemple #2
0
static int output_data(char *buf, int32 nbytes)
{
    int n;

    if (stream == 0) return -1;

    while(nbytes > 0)
    {
	if((n = arts_write(stream, buf, nbytes)) < 0)
	{
	    ctl->cmsg(CMSG_WARNING, VERB_VERBOSE,
		      "%s: %s", dpm.name, arts_error_text(n));
	    if(errno == EWOULDBLOCK)
	    {
		/* It is possible to come here because of bug of the
		 * sound driver.
		 */
		continue;
	    }
	    return -1;
	}
	output_count += n;
	buf += n;
	nbytes -= n;
    }

    return 0;
}
     static gboolean gst_artsdsink_open_audio (GstArtsdsink * sink)
{
  const char connname[] = "gstreamer";
  int errcode;

  /* Name used by aRtsd for this connection. */
  if (sink->connect_name != NULL)
    connname = sink->connect_name;

  /* FIXME: this should only ever happen once per process. */
  /* Really, artsc needs to be made thread safe to fix this (and other related */
  /* problems). */
  errcode = arts_init ();
  if (errcode < 0) {
    fprintf (stderr, "arts_init error: %s\n", arts_error_text (errcode));
    return FALSE;
  }

  GST_DEBUG ("artsdsink: attempting to open connection to aRtsd server");
  sink->stream = arts_play_stream (sink->frequency, sink->depth,
      sink->channels, connname);
  /* FIXME: check connection */
  /*   GST_DEBUG ("artsdsink: can't open connection to aRtsd server"); */

  GST_OBJECT_FLAG_SET (sink, GST_ARTSDSINK_OPEN);
  sink->connected = TRUE;

  return TRUE;
}
Exemple #4
0
/* initialize the sound card or connect to aRts server */
void audio_init(audio_dev_handle* handle, int rate, int latency, int try_arts)
{
#ifdef HAS_ARTS
    int artserr = 0;

    handle->arts_handle = NULL;
    handle->use_arts    = 0;
#endif
    handle->alsa_handle = NULL;
    handle->channels    = 1;  /* mono */
    handle->format      = SND_PCM_FORMAT_U8;
    handle->rate        = rate;
    handle->latency     = latency; /* in ms */

#ifdef HAS_ARTS    
    if( try_arts )
    {
        artserr = arts_init();
        if( artserr < 0 )
        {
            fprintf(stderr, "Error initializing aRts: %s\n", arts_error_text(artserr));
            exit(-1);
        }
        handle->arts_handle = arts_play_stream( *rate, 8, handle->channels, "arts-whitenoise" );
        arts_stream_set(handle->arts_handle, ARTS_P_BUFFER_TIME, *latency);
        handle->use_arts = 1;
    }
    else
#endif
    {
        alsa_init(handle);
    }
}
Exemple #5
0
static int arts_dsp_write(struct sysdep_dsp_struct *dsp, unsigned char *data,
   int count)
{
   int result;
   struct arts_dsp_priv_data *priv = dsp->_priv;

   result = arts_write(priv->stream, data, count *
      arts_dsp_bytes_per_sample[dsp->hw_info.type]);
      
   if (result < 0)
   {
      fprintf(stderr,
         "arts_write error: %s\n", arts_error_text(result));
      return -1;
   }
      
   return result / arts_dsp_bytes_per_sample[dsp->hw_info.type];
}
static void
gst_artsdsink_chain (GstPad * pad, GstData * _data)
{
  GstBuffer *buf = GST_BUFFER (_data);
  GstArtsdsink *artsdsink;

  g_return_if_fail (pad != NULL);
  g_return_if_fail (GST_IS_PAD (pad));
  g_return_if_fail (buf != NULL);

  artsdsink = GST_ARTSDSINK (gst_pad_get_parent (pad));

  if (GST_BUFFER_DATA (buf) != NULL) {
    gst_trace_add_entry (NULL, 0, GPOINTER_TO_INT (buf),
        "artsdsink: writing to server");
    if (!artsdsink->mute && artsdsink->connected) {
      int bytes;
      void *bufptr = GST_BUFFER_DATA (buf);
      int bufsize = GST_BUFFER_SIZE (buf);

      GST_DEBUG ("artsdsink: stream=%p data=%p size=%d",
          artsdsink->stream, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf));

      do {
        bytes = arts_write (artsdsink->stream, bufptr, bufsize);
        if (bytes < 0) {
          fprintf (stderr, "arts_write error: %s\n", arts_error_text (bytes));
          gst_buffer_unref (buf);
          return;
        }
        bufptr += bytes;
        bufsize -= bytes;
      } while (bufsize > 0);
    }
  }
  gst_buffer_unref (buf);
}
Exemple #7
0
static int open_output(void)
{
    int i, include_enc, exclude_enc;
    int sample_width, channels;

    include_enc = 0;
    exclude_enc = PE_ULAW|PE_ALAW|PE_BYTESWAP; /* They can't mean these */
    if(dpm.encoding & PE_16BIT)
	include_enc |= PE_SIGNED;
    else
	exclude_enc |= PE_SIGNED;
    dpm.encoding = validate_encoding(dpm.encoding, include_enc, exclude_enc);
    sample_width = (dpm.encoding & PE_16BIT) ? 16 : 8;
    channels = (dpm.encoding & PE_MONO) ? 1 : 2;

    /* Open the audio device */
    switch (arts_init_state) {
    case 0:
	if((i = arts_init()) != 0)
	{
	    ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: %s",
		      dpm.name, arts_error_text(i));
	    return -1;
	}
	arts_init_state = 1;
	break;
    case 2:
	ctl->cmsg(CMSG_ERROR, VERB_NORMAL, 
	    "TiMidity aRts bug: open_output() after close_output() not supported");
	return -1;
    }
    stream = arts_play_stream(dpm.rate,
			      LE_LONG(sample_width),
			      channels,
			      "timidity");
    if(stream == NULL)
    {
	ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: %s",
		  dpm.name, strerror(errno));
	return -1;
    }
    arts_stream_set(stream, ARTS_P_BLOCKING, 1);

    server_buffer = arts_stream_get(stream, ARTS_P_SERVER_LATENCY) * dpm.rate * (sample_width/8) * channels / 1000;
    output_count = 0;
    return 0;
    /* "this aRts function isnot yet implemented"
     *
    if (dpm.extra_param[0]) {
        i = arts_stream_set(stream,
            ARTS_P_PACKET_COUNT,
            dpm.extra_param[0]);
	if (i < 0) {
            ctl->cmsg(CMSG_ERROR, VERB_NORMAL, "%s: %s",
              dpm.name, arts_error_text(i));
	    return 1;
        }
    }
    return 0;
     *
     */
}
Exemple #8
0
/* public methods (static but exported through the sysdep_dsp or plugin
   struct) */
static void *arts_dsp_create(const void *flags)
{
   int i, j, result, bits, channels, block;
   struct arts_dsp_priv_data *priv = NULL;
   struct sysdep_dsp_struct *dsp = NULL;
   const struct sysdep_dsp_create_params *params = flags;
   
   /* allocate the dsp struct */
   if (!(dsp = calloc(1, sizeof(struct sysdep_dsp_struct))))
   {
      fprintf(stderr,
         "error malloc failed for struct sysdep_dsp_struct\n");
      return NULL;
   }
   
   /* alloc private data */
   if(!(priv = calloc(1, sizeof(struct arts_dsp_priv_data))))
   {
      fprintf(stderr,
         "error malloc failed for struct arts_dsp_priv_data\n");
      arts_dsp_destroy(dsp);
      return NULL;
   }
   
   /* fill in the functions and some data */
   priv->stream = NULL;
   dsp->_priv = priv;
   dsp->write = arts_dsp_write;
   dsp->destroy = arts_dsp_destroy;
   dsp->hw_info.type = params->type;
   dsp->hw_info.samplerate = params->samplerate;

   result = arts_init();
   if (result < 0)
   {
      fprintf(stderr,
         "arts_init error: %s\n", arts_error_text(result));
      arts_dsp_destroy(dsp);
      return NULL;
   }

   bits = (dsp->hw_info.type & SYSDEP_DSP_16BIT) ? 16 : 8;
   channels = (dsp->hw_info.type & SYSDEP_DSP_STEREO) ? 2 : 1;
   priv->stream = arts_play_stream(dsp->hw_info.samplerate, bits, channels,
      "xmame arts");

   block = (params->flags & SYSDEP_DSP_O_NONBLOCK) ? 0 : 1;
   result = arts_stream_set(priv->stream, ARTS_P_BLOCKING, block);
   if (result < 0)
   {
      fprintf(stderr,
         "arts_stream_set error: %s\n", arts_error_text(result));
      arts_dsp_destroy(dsp);
      return NULL;
   }
   else 
   {
      if (result != block)
      {
         fprintf(stderr,
            "arts_stream_set ARTS_P_BLOCKING to %d failed\n", block);
         arts_dsp_destroy(dsp);
         return NULL;
      }
   }

   /* calculate fragsize & number of frags */
   /* fragsize (as power of 2) */
   i = 7;
   if (dsp->hw_info.type & SYSDEP_DSP_16BIT) i++;
   if (dsp->hw_info.type & SYSDEP_DSP_STEREO) i++;
   i += dsp->hw_info.samplerate / 22050;
 
   /* number of frags */
   j = ((dsp->hw_info.samplerate * arts_dsp_bytes_per_sample[dsp->hw_info.type] * params->bufsize) / (0x01 << i)) + 1;

   arts_stream_set(priv->stream, ARTS_P_BUFFER_SIZE, (0x01<<i)*j);

#ifdef ARTS_DEBUG
   /* print some info messages ;) */
   fprintf(stderr, "info: aRts buffer size    : %d\n", 
      arts_stream_get(priv->stream, ARTS_P_BUFFER_SIZE));
   fprintf(stderr, "info: aRts buffer time    : %d\n",
      arts_stream_get(priv->stream, ARTS_P_BUFFER_TIME));
   fprintf(stderr, "info: aRts server latency : %d\n",
      arts_stream_get(priv->stream, ARTS_P_SERVER_LATENCY));
   fprintf(stderr, "info: aRts total latency  : %d\n",
      arts_stream_get(priv->stream, ARTS_P_TOTAL_LATENCY));
   fprintf(stderr, "info: aRts blocking       : %s\n",
      arts_stream_get(priv->stream, ARTS_P_BLOCKING) ? "yes" : "no");
#endif /* ifdef ARTS_DEBUG */

   return dsp;
}