コード例 #1
0
ファイル: sound.c プロジェクト: JackieXie168/movgrab
int SoundOpenOutput(char *Dev, TAudioInfo *Info)
{
int fd=-1;

#ifdef HAVE_LIBESD
esd_format_t esd_format;

if ((StrLen(Dev)==0) || (strncmp(Dev,"esd:",4)==0))
{
esd_format=ESD_STREAM | ESD_PLAY;

if (Info->Channels==2) esd_format |= ESD_STEREO;
else esd_format |= ESD_MONO;

if (Info->SampleSize==2) esd_format |= ESD_BITS16;
else esd_format |= ESD_BITS8;

if (StrLen(Dev) > 4) setenv("ESPEAKER",Dev+4,TRUE);
else setenv("ESPEAKER","localhost",TRUE);
fd=esd_play_stream(esd_format, Info->SampleRate, NULL, "testing");
}

#endif

#ifdef HAVE_OSS
if (fd < 0) fd=OpenOSSOutput(Dev, Info);
#endif

return(fd);
}
コード例 #2
0
ファイル: sound_esd.c プロジェクト: eswartz/emul
static int
setup_sound(void)
{
	server_fd = esd_open_sound(hostname);
	if (server_fd < 0) {
		module_logger(&esdSound, _L|LOG_ERROR|LOG_USER, _("could not open audio (%s)\n"),
			   strerror(errno));
		soundblksize = 512;
	} else {
		/*
		soundblksize = esd_get_latency(server_fd);
		// 16-bit, mono
		soundblksize *= 2;
*/
		soundblksize = 512;
	}

	sound_fd = esd_play_stream(
					ESD_BITS16|ESD_MONO|ESD_STREAM|ESD_PLAY,
					soundhz,
					hostname,
					"V9t9 sndESD module");
	if (sound_fd < 0) {
		module_logger(&esdSound, _L|LOG_ERROR|LOG_USER, _("could not open stream (%s)\n"),
			   strerror(errno));
		return 0;
	}

	module_logger(&esdSound, _L|LOG_USER, _("\nwarning, this module is not optimal and\n"
		   "sound can be delayed up to a second.\n"
		   "Consider killing esd and using native OSS or ALSA sound.\n\n"));
	return 1;
}
コード例 #3
0
//_______________________________________________
//
//
//_______________________________________________
uint8_t esdAudioDevice::init(uint8_t channels, uint32_t fq) 
{
esd_format_t format;
_channels = channels;

    format=ESD_STREAM | ESD_PLAY | ESD_BITS16;
    if(channels==1) format|=ESD_MONO;
        else format|=ESD_STEREO;

    printf("\n ESD  : %lu Hz, %lu channels", fq, channels);
    esdDevice=esd_play_stream(format,fq,NULL,"avidemux");
    if(esdDevice<=0) 
    {
        printf("Esd open failed\n");
        return 0;
    }
    printf("Esd open succeedeed\n");
    /*
#ifdef ADM_BIG_ENDIAN    
    int fmt = AFMT_S16_BE;
#else
    int fmt = AFMT_S16_LE;
#endif    
*/
    return 1;
}
コード例 #4
0
ファイル: xvesd.c プロジェクト: tdoris/xvoice
int AudioStartPlayback (void)
{
  if (audio.playsock == -1) {
    audio.playsock = esd_play_stream(audio.format, audio.rate, NULL, NULL);
    if (audio.playsock < 0) {
        return -1;
    }
  }
  return 0;
}
コード例 #5
0
ファイル: oa_esd.c プロジェクト: Jheengut/gmerlin
static int start_esd(void * p)
  {
  esd_t * e = p;
  e->esd_socket = esd_play_stream(e->esd_format,
                                  e->samplerate,
                                  e->hostname,
                                  "gmerlin output");
  if(e->esd_socket < 0)
    return 0;
  return 1;
  }
コード例 #6
0
ファイル: sndesd.cpp プロジェクト: nealey/vera
wxSoundStreamESD::wxSoundStreamESD(const wxString& hostname)
{
#ifndef HAVE_ESD_H
    m_snderror = wxSOUND_INVDEV;
    return;
#else
    wxSoundFormatPcm pcm_default;

    // First, we make some basic test: is there ESD on this computer ?
    m_esd_ok = false;

    if (hostname.IsNull())
        m_fd_output = esd_play_stream(ESD_PLAY | ESD_STREAM, 22050,
                                      hostname.mb_str(), MY_ESD_NAME);
    else
        m_fd_output = esd_play_stream(ESD_PLAY | ESD_STREAM, 22050,
                                      NULL, MY_ESD_NAME);
    if (m_fd_output == -1) {
        // Answer: no. We return with an error.
        m_snderror = wxSOUND_INVDEV;
        return;
    }

    // Close this unuseful stream.
    esd_close(m_fd_output);

    m_hostname = hostname;

    // Set the default audio format
    SetSoundFormat(pcm_default);

    // Initialize some variable
    m_snderror = wxSOUND_NOERROR;
    m_esd_stop = true;
    m_q_filled = true;
    m_esd_ok   = true;
    m_fd_output= -1;
    m_fd_input = -1;
#endif // defined HAVE_ESD_H
}
コード例 #7
0
ファイル: esd.c プロジェクト: Aye1/RVProject
void *grab_write_esd(void) {
	esd_format_t fmt;
	int socket;
	const char *esdkey = genesdkey();
	const char *espeaker = getenv("ESPEAKER");
	int esd;

	esd = esd_open_sound(espeaker);
	if(esd < 0) {
		fprintf(stderr, "esd open sound failed.\n");
		return NULL;
	}

	fmt = ESD_STREAM | ESD_PLAY;

	switch(DEF_CHANNELS) {
		case 1: fmt |= ESD_MONO; break;
		case 2: fmt |= ESD_STEREO; break;
		default: break;
	}

	switch(_al_formatbits(DEF_FORMAT)) {
		case 8:  fmt |= ESD_BITS8; break;
		case 16: fmt |= ESD_BITS16; break;
		default: break;
	}

	socket = esd_play_stream(fmt, DEF_SPEED, espeaker, esdkey);

	if(socket < 0) {
		fprintf(stderr, "esd play stream failed.\n");
		return NULL;
	}

	_alBlitBuffer = esd_blitbuffer;

	fprintf(stderr, "esd grab audio ok\n");

	_alDebug(ALD_CONTEXT, __FILE__, __LINE__,
		"esd grab audio ok");

	esd_info.speed     = DEF_SPEED;
	esd_info.fmt       = fmt;
	esd_info.socket    = socket;
	esd_info.espeaker  = espeaker;
	esd_info.paused    = AL_FALSE;
	esd_info.esdhandle = esd;

	strncpy(esd_info.name, esdkey, ESD_NAMELEN);

        return &esd_info;
}
コード例 #8
0
ファイル: sndesd.cpp プロジェクト: nealey/vera
// --------------------------------------------------------------------------
// StartProduction(): see wxSoundStream
// --------------------------------------------------------------------------
bool wxSoundStreamESD::StartProduction(int evt)
{
#ifndef HAVE_ESD_H
    m_snderror = wxSOUND_INVDEV;
    return false;
#else
    wxSoundFormatPcm *pcm;
    int flag = 0;

    if (!m_esd_ok) {
        m_snderror = wxSOUND_INVDEV;
        return false;
    }

    if (!m_esd_stop)
        StopProduction();

    pcm = (wxSoundFormatPcm *)m_sndformat;

    flag |= (pcm->GetBPS() == 16) ? ESD_BITS16 : ESD_BITS8;
    flag |= (pcm->GetChannels() == 2) ? ESD_STEREO : ESD_MONO;

    if ((evt & wxSOUND_OUTPUT) != 0) {
        flag |= ESD_PLAY | ESD_STREAM;
        m_fd_output = esd_play_stream(flag, pcm->GetSampleRate(), NULL,
                                      MY_ESD_NAME);
    }

    if ((evt & wxSOUND_INPUT) != 0) {
        flag |= ESD_RECORD | ESD_STREAM;
        m_fd_input = esd_record_stream(flag, pcm->GetSampleRate(), NULL,
                                       MY_ESD_NAME);
    }

#ifdef __WXGTK__
    if ((evt & wxSOUND_OUTPUT) != 0) {
        m_tag_output = gdk_input_add(m_fd_output, GDK_INPUT_WRITE,
                                     _wxSound_OSS_CBack, (gpointer)this);
    }
    if ((evt & wxSOUND_INPUT) != 0) {
        m_tag_input = gdk_input_add(m_fd_input, GDK_INPUT_READ,
                                    _wxSound_OSS_CBack, (gpointer)this);
    }
#endif

    m_esd_stop = false;
    m_q_filled = false;

    return true;
#endif // defined HAVE_ESD_H
}
コード例 #9
0
ファイル: lnxaudio.cpp プロジェクト: alilloyd/livecode
int X11Audio::play(int1 * p_sample, uint4 p_samplesize, uint p_rate)
{
	if ( isinit() ) 
	{
		uint t_func = ESD_PLAY | ESD_STREAM | m_flags; 
		
		int chan ;
		chan = esd_play_stream(t_func, p_rate, NULL, NULL);
		
		uint t_bytes_written ;
		t_bytes_written = write(chan, p_sample, p_samplesize);
		
		esd_close(chan);
		
		return t_bytes_written ;
	}
}
コード例 #10
0
ファイル: esd.c プロジェクト: Aye1/RVProject
ALboolean set_write_esd(UNUSED(void *handle),
		  UNUSED(ALuint *bufsiz),
		  ALenum *fmt,
		  ALuint *speed) {
	esd_openal_info_t *eh;
	int socket;
	ALuint chans = _al_ALCHANNELS(*fmt);

	if(handle == NULL) {
		return AL_FALSE;
	}

	eh = (esd_openal_info_t *) handle;

	close(eh->socket);

	eh->fmt = ESD_STREAM | ESD_PLAY;

	switch(chans) {
		case 1: eh->fmt |= ESD_MONO; break;
		case 2: eh->fmt |= ESD_STEREO; break;
		default: break;
	}

	switch(_al_formatbits(*fmt)) {
		case 8:  eh->fmt |= ESD_BITS8; break;
		case 16: eh->fmt |= ESD_BITS16; break;
		default: break;
	}

	eh->speed = *speed;

	socket = esd_play_stream(eh->fmt,
				 eh->speed,
				 eh->espeaker,
				 eh->name);
	if(socket < 0) {
		return AL_FALSE;
	}

	eh->socket = socket;
	eh->paused = AL_FALSE;

        return AL_TRUE;
}
コード例 #11
0
int ao_plugin_open(ao_device *device, ao_sample_format *format)
{
	ao_esd_internal *internal = (ao_esd_internal *) device->internal;
	int esd_bits;
	int esd_channels;
	int esd_mode = ESD_STREAM;
	int esd_func = ESD_PLAY;
	int esd_format;

	switch (format->bits)
	{
	case 8  :
          esd_bits = ESD_BITS8;
          internal->bits = 8;
          break;
	case 16 :
          esd_bits = ESD_BITS16;
          internal->bits = 16;
          break;
	default :
          return 0;
	}
	switch (device->output_channels)
	{
	case 1 : esd_channels = ESD_MONO;
		 break;
	case 2 : esd_channels = ESD_STEREO;
		 break;
	default: return 0;
	}

	esd_format = esd_bits | esd_channels | esd_mode | esd_func;

	internal->sock = esd_play_stream(esd_format, format->rate,
					 internal->host,
					 internal->client_name == NULL ?
                                         "libao output" : internal->client_name);
	if (internal->sock < 0)
		return 0; /* Could not contact ESD server */

	device->driver_byte_format = AO_FMT_NATIVE;

	return 1;
}
コード例 #12
0
static int init(struct xmp_context *ctx)
{
	int format, rate = ESD_DEFAULT_RATE;
	int bits = ESD_BITS16, channels = ESD_STEREO;
	int mode = ESD_STREAM, func = ESD_PLAY;
	struct xmp_options *o = &ctx->o;

	if (o->resol == 8)
		bits = ESD_BITS8;
	if (o->outfmt & XMP_FMT_MONO)
		channels = ESD_MONO;
	rate = o->freq;
	format = bits | channels | mode | func;

	printf("opening socket, format = 0x%08x at %d Hz\n", format, rate);

	/* Number of arguments fixed by Terry Glass <*****@*****.**> */
	if ((audio_fd = esd_play_stream(format, rate, NULL, "xmp")) <= 0) {
		fprintf(stderr, "drv_esd: unable to connect to server\n");
		return XMP_ERR_DINIT;
	}

	return xmp_smix_on(ctx);
}
コード例 #13
0
ファイル: esdsink.c プロジェクト: JJCG/gst-plugins-good
static gboolean
gst_esdsink_prepare (GstAudioSink * asink, GstRingBufferSpec * spec)
{
  GstEsdSink *esdsink = GST_ESDSINK (asink);
  esd_format_t esdformat;

  /* Name used by esound for this connection. */
  const char connname[] = "GStreamer";

  GST_DEBUG_OBJECT (esdsink, "prepare");

  /* Bitmap describing audio format. */
  esdformat = ESD_STREAM | ESD_PLAY;

  switch (spec->depth) {
    case 8:
      esdformat |= ESD_BITS8;
      break;
    case 16:
      esdformat |= ESD_BITS16;
      break;
    default:
      goto unsupported_depth;
  }

  switch (spec->channels) {
    case 1:
      esdformat |= ESD_MONO;
      break;
    case 2:
      esdformat |= ESD_STEREO;
      break;
    default:
      goto unsupported_channels;
  }

  GST_INFO_OBJECT (esdsink,
      "attempting to open data connection to esound server");

  esdsink->fd =
      esd_play_stream (esdformat, spec->rate, esdsink->host, connname);

  if ((esdsink->fd < 0) || (esdsink->ctrl_fd < 0))
    goto cannot_open;

  esdsink->rate = spec->rate;

  spec->segsize = ESD_BUF_SIZE;
  spec->segtotal = (ESD_MAX_WRITE_SIZE / spec->segsize);

  /* FIXME: this is wrong for signed ints (and the
   * audioringbuffers should do it for us anyway) */
  spec->silence_sample[0] = 0;
  spec->silence_sample[1] = 0;
  spec->silence_sample[2] = 0;
  spec->silence_sample[3] = 0;

  GST_INFO_OBJECT (esdsink, "successfully opened connection to esound server");

  return TRUE;

  /* ERRORS */
unsupported_depth:
  {
    GST_ELEMENT_ERROR (esdsink, STREAM, WRONG_TYPE, (NULL),
        ("can't handle sample depth of %d, only 8 or 16 supported",
            spec->depth));
    return FALSE;
  }
unsupported_channels:
  {
    GST_ELEMENT_ERROR (esdsink, STREAM, WRONG_TYPE, (NULL),
        ("can't handle %d channels, only 1 or 2 supported", spec->channels));
    return FALSE;
  }
cannot_open:
  {
    GST_ELEMENT_ERROR (esdsink, RESOURCE, OPEN_WRITE,
        (_("Could not establish connection to sound server")),
        ("can't open connection to esound server"));
    return FALSE;
  }
}
コード例 #14
0
/*
 * connect to esd
 */
static int ao_esd_open(ao_driver_t *this_gen,
		       uint32_t bits, uint32_t rate, int mode)
{
  esd_driver_t *this = (esd_driver_t *) this_gen;
  esd_format_t     format;

  xprintf (this->xine, XINE_VERBOSITY_DEBUG,
	   "audio_esd_out: ao_open bits=%d rate=%d, mode=%d\n", bits, rate, mode);

  if ( (mode & this->capabilities) == 0 ) {
    xprintf (this->xine, XINE_VERBOSITY_DEBUG, "audio_esd_out: unsupported mode %08x\n", mode);
    return 0;
  }

  if (this->audio_fd>=0) {

    if ( (mode == this->mode) && (rate == this->input_sample_rate) )
      return this->output_sample_rate;

    esd_close (this->audio_fd);
  }

  this->mode                   = mode;
  this->input_sample_rate      = rate;
  this->output_sample_rate     = rate;
  this->bytes_in_buffer        = 0;
  this->start_time.tv_sec      = 0;

  /*
   * open stream to ESD server
   */

  format = ESD_STREAM | ESD_PLAY | ESD_BITS16;
  switch (mode) {
  case AO_CAP_MODE_MONO:
    format |= ESD_MONO;
    this->num_channels = 1;
    break;
  case AO_CAP_MODE_STEREO:
    format |= ESD_STEREO;
    this->num_channels = 2;
    break;
  }
  xprintf (this->xine, XINE_VERBOSITY_DEBUG, "audio_esd_out: %d channels output\n",this->num_channels);

  this->bytes_per_frame=(bits*this->num_channels)/8;

#if ESD_RESAMPLE
  /* esd resamples (only for sample rates < the esd server's sample rate) */
  if (this->output_sample_rate > this->server_sample_rate)
    this->output_sample_rate = this->server_sample_rate;
#else
  /* use xine's resample code */
  this->output_sample_rate = this->server_sample_rate;
#endif
  this->output_sample_k_rate = this->output_sample_rate / 1000;

  this->audio_fd = esd_play_stream(format, this->output_sample_rate, NULL, this->pname);
  if (this->audio_fd < 0) {
    char *server = getenv("ESPEAKER");
    xprintf(this->xine, XINE_VERBOSITY_LOG,
	    _("audio_esd_out: connecting to ESD server %s: %s\n"),
	    server ? server : "<default>", strerror(errno));
    return 0;
  }

  return this->output_sample_rate;
}
コード例 #15
0
ファイル: esd.c プロジェクト: kenny-thomas/xemacs
int
esd_play_sound_data (Binbyte *data, size_t length, int UNUSED (vol))
{                              /* #### FIXME: vol is ignored */
  size_t         (*parsesndfile)(void **dayta,size_t *sz,void **outbuf);
  size_t         (*sndcnv)(void **dayta,size_t *sz,void **);
  fmtType        ffmt;
  int            fmt,speed,tracks;
  unsigned char *pptr,*optr,*cptr,*sptr;
  Bytecount      wrtn, crtn;
  size_t         prtn;
  int flags, sock;

  /* analyze_format needs at least this many bytes to work with */
  if (length < HEADERSZ)
    return 0;

  ffmt = analyze_format(data,&fmt,&speed,&tracks,&parsesndfile);

  if (ffmt != fmtRaw && ffmt != fmtSunAudio && ffmt != fmtWave) {
    sound_warn("Unsupported file format (neither RAW, nor Sun/DECAudio, nor WAVE)");
      return 0;
  }

  /* convert header information into ESD flags */
  flags = ESD_STREAM|ESD_PLAY;
  sndcnv = sndcnvnop;
  switch (fmt)
    {
    case AFMT_MU_LAW:
      sndcnv = sndcnvULaw_2linear;
      flags |= ESD_BITS8;
      break;
    case AFMT_S8:
      sndcnv = sndcnv2unsigned;        /* ESD needs unsigned bytes */
    case AFMT_U8:
      flags |= ESD_BITS8;
      break;
    case AFMT_S16_BE:
      sndcnv = sndcnv16swap;   /* ESD wants little endian */
    case AFMT_S16_LE:
      flags |= ESD_BITS16;
      break;
    default:
      {
	Extbyte warn_buf[255];
	sprintf (warn_buf, "byte format %d unimplemented", fmt);
	sound_warn (warn_buf);
	return 0;
      }
    }
  switch (tracks)
    {
    case 1: flags |= ESD_MONO; break;
    case 2: flags |= ESD_STEREO; break;
    default:
      {
	Extbyte warn_buf[255];
	sprintf (warn_buf, "%d channels - only 1 or 2 supported", tracks);
	sound_warn (warn_buf);
	return 0;
      }
    }

  sock = esd_play_stream(flags, speed, NULL, "xemacs");
  if (sock < 0)
    return 0;

  reset_parsestate();

  for (pptr = data; (prtn = parsesndfile((void **)&pptr,&length,
                                        (void **)&optr)) > 0; )
    for (cptr = optr; (crtn = sndcnv((void **)&cptr,&prtn,
                                    (void **)&sptr)) > 0; )
      {
	if ((wrtn = write(sock,sptr,crtn)) < 0)
	  {
	    sound_perror ("write error");
	    goto END_OF_PLAY;
	  }
	if (wrtn != crtn)
	  {
	    Extbyte warn_buf[255];
	    sprintf (warn_buf, "only wrote %ld of %ld bytes", wrtn, crtn);
	    sound_warn (warn_buf);
	    goto END_OF_PLAY;
	  }
      }

  if (ffmt == fmtWave)
    parse_wave_complete();

END_OF_PLAY:
  /* Now cleanup all used resources */

  close(sock);
  return 1;
}