Ejemplo n.º 1
0
static int
parse_sound (Lisp_Object sound, Lisp_Object *attrs)
{
  /* SOUND must be a list starting with the symbol `sound'.  */
  if (!CONSP (sound) || !EQ (XCAR (sound), Qsound))
    return 0;

  sound = XCDR (sound);
  attrs[SOUND_FILE] = Fplist_get (sound, QCfile);
  attrs[SOUND_DATA] = Fplist_get (sound, QCdata);
  attrs[SOUND_DEVICE] = Fplist_get (sound, QCdevice);
  attrs[SOUND_VOLUME] = Fplist_get (sound, QCvolume);

#ifndef WINDOWSNT
  /* File name or data must be specified.  */
  if (!STRINGP (attrs[SOUND_FILE])
      && !STRINGP (attrs[SOUND_DATA]))
    return 0;
#else /* WINDOWSNT */
  /*
    Data is not supported in Windows.  Therefore a
    File name MUST be supplied.
  */
  if (!STRINGP (attrs[SOUND_FILE]))
    {
      return 0;
    }
#endif /* WINDOWSNT */

  /* Volume must be in the range 0..100 or unspecified.  */
  if (!NILP (attrs[SOUND_VOLUME]))
    {
      if (INTEGERP (attrs[SOUND_VOLUME]))
	{
	  if (XINT (attrs[SOUND_VOLUME]) < 0
	      || XINT (attrs[SOUND_VOLUME]) > 100)
	    return 0;
	}
      else if (FLOATP (attrs[SOUND_VOLUME]))
	{
	  if (XFLOAT_DATA (attrs[SOUND_VOLUME]) < 0
	      || XFLOAT_DATA (attrs[SOUND_VOLUME]) > 1)
	    return 0;
	}
      else
	return 0;
    }

#ifndef WINDOWSNT
  /* Device must be a string or unspecified.  */
  if (!NILP (attrs[SOUND_DEVICE])
      && !STRINGP (attrs[SOUND_DEVICE]))
    return 0;
#endif  /* WINDOWSNT */
  /*
    Since device is ignored in Windows, it does not matter
    what it is.
   */
  return 1;
}
Ejemplo n.º 2
0
static ad_device_data *
sound_ao_create(Lisp_Object ao_options)
{
	int driver;
	ao_device *device;
	ao_option *options;
	ao_sample_format *fmt;
	/* result */
	sound_ao_data_t *aod;
	/* option keywords */
	Lisp_Object opt_driver;
	char *optext_driver = NULL;

	/* parse options */
	opt_driver = Fplist_get(ao_options, intern(":driver"), Qnil);
	if (!NILP(opt_driver) && !STRINGP(opt_driver)) {
		wrong_type_argument(Qstringp, opt_driver);
		return NULL;
	} else if (STRINGP(opt_driver))
		optext_driver = (char*)XSTRING_DATA(opt_driver);

	/* -- initialise -- */
	ao_initialize();
	fmt = xmalloc(sizeof(ao_sample_format));

	/* -- Setup for driver -- */
	if (optext_driver != NULL)
		driver = ao_driver_id(optext_driver);
	else
		driver = ao_default_driver_id();

	/* just some generics */
	fmt->channels = 2;
	fmt->rate = 44100;
	fmt->bits = 16;
	fmt->byte_format = AO_FMT_LITTLE;

	options = NULL;

	/* -- Open driver -- */
	device = ao_open_live(driver, fmt, options);
	if (device == NULL) {
		message(GETTEXT("audio-ao: Unsupported driver."));
		xfree(fmt);
		aod = NULL;
	} else {
		aod = xnew_and_zero(sound_ao_data_t);

		aod->ad = device;
		aod->options = NULL;
		aod->fmt = fmt;
		aod->driver_id = driver;
	}

	return aod;
}
Ejemplo n.º 3
0
static int
plist_get_margin (Lisp_Object plist, Lisp_Object prop, int mm_p)
{
  Lisp_Object val =
    Fplist_get (plist, prop, make_fixnum (mswindows_get_default_margin (prop)));
  if (!FIXNUMP (val))
    invalid_argument ("Margin value must be an integer", val);

  return MulDiv (XFIXNUM (val), mm_p ? 254 : 100, 144);
}
Ejemplo n.º 4
0
static ad_device_data *
sound_nas_create(Lisp_Object nas_options)
{
	sound_nas_data_t *snd;
	char *server[6] = {NULL, NULL, NULL, NULL, NULL, NULL};
	int i, server_cnt = 0;
	AuServer *aud = NULL;
	Lisp_Object opt_server = Qnil;

	/* parse options */
	opt_server = Fplist_get(nas_options, intern(":server"), Qnil);
	if (!NILP(opt_server) && !STRINGP(opt_server) && !DEVICEP(opt_server)) {
		wrong_type_argument(Qstringp, opt_server);
		return NULL;
	}

	if (NILP(opt_server))
		nas_setup_defaults(server, &server_cnt);
	else if (STRINGP(opt_server))
		server[server_cnt++] = (char*)XSTRING_DATA(opt_server);
#ifdef HAVE_X_WINDOWS
	else if (DEVICEP(opt_server) && DEVICE_X_P(XDEVICE(opt_server)))
		server[server_cnt++] =
			(char*)XSTRING_DATA(
				DEVICE_CONNECTION(XDEVICE(opt_server)));
#endif

	NAS_DEBUG("trying %d connections\n", server_cnt);
	for (i = 0; i<server_cnt; i++)
		if ((aud = nas_try_connection(server[i])))
			break;

	if (!aud) {
		NAS_DEBUG_C("cannot contact any NAS server\n");
		warn_when_safe(Qnas, Qwarning,
			       GETTEXT("No NAS servers in sight.\n"));
		return NULL; /* Could not contact NAS server */
	}


	/* -- initialise -- */
	snd = xnew_and_zero(sound_nas_data_t);
	snd->aud = aud;

	/* round up SOUND_MAX_AUDIO_FRAME_SIZE to multiple of NAS_FRAG_SIZE
	 * divide by 3 first because of 2:1 split */
	snd->proposed_buffer_size =
		(SOUND_MAX_AUDIO_FRAME_SIZE/3 + NAS_FRAG_SIZE-1)
		& ~(NAS_FRAG_SIZE-1);
	NAS_DEBUG_C("proposed buffer size: %u\n", snd->proposed_buffer_size);

	NAS_DEBUG_C("created: 0x%x\n", (unsigned int)snd);

	return snd;
}
Ejemplo n.º 5
0
static ad_device_data *
sound_oss_create(Lisp_Object oss_options)
{
	/* result */
	sound_oss_data_t *sod = NULL;
	int keep_open = 0;
	/* option keywords */
	Lisp_Object opt_device;
	Lisp_Object opt_keepopen;

	/* parse options */
	opt_device = Fplist_get(oss_options, Q_device, Qnil);
	if (!NILP(opt_device) && !STRINGP(opt_device)) {
		wrong_type_argument(Qstringp, opt_device);
		return NULL;
	}

	opt_keepopen = Fplist_get(oss_options, Q_keep_open, Qnil);
	if (!NILP(opt_keepopen))
		keep_open = 1;

	/* initialise and fill */
	sod = xnew_and_zero(sound_oss_data_t);
	sod->device = opt_device;
	sod->keep_open = keep_open;
	sod->device_fd = -1;
	SXE_MUTEX_INIT(&sod->mtx);

	/* Open the device */


	if (!keep_open) {
		sod->device_fd = -1;
	}

	return (ad_device_data*)sod;
}