Exemplo n.º 1
0
int audio_get_formats()
{
  int fmt = 0;
  int r = rate;
  int c = channels;
  int i;

  static int fmts[] = { 
	AUDIO_FORMAT_ULAW_8 , AUDIO_FORMAT_SIGNED_16 ,
	AUDIO_FORMAT_UNSIGNED_8 , AUDIO_FORMAT_SIGNED_8 ,
	AUDIO_FORMAT_UNSIGNED_16 , AUDIO_FORMAT_ALAW_8 };
	
  for(i=0;i<6;i++) {
	format = fmts[i];
	if(audio_set_format() < 0) {
		continue;
        }
	channels = c;
	if(audio_set_channels() < 0) {
		continue;
	}
	rate = r;
	if(audio_rate_best_match() < 0) {
		continue;
	}
	if( (rate*100 > r*(100-AUDIO_RATE_TOLERANCE)) && (rate*100 < r*(100+AUDIO_RATE_TOLERANCE)) ) {
		fmt |= fmts[i];
	}
  }

  return fmt;
}
Exemplo n.º 2
0
int audio_reset_parameters(struct audio_info_struct *ai)
{
	audio_set_format(ai);
	audio_set_channels(ai);
	audio_set_rate(ai);

	return 0;
}
Exemplo n.º 3
0
/* !!! pamiêtaæ o zainicjowaniu parametrów !!! */
int outputInit()
{
	int ret;
	filedevice = open( SOUNDDEVICE, O_WRONLY );
	if ( filedevice == -1 )
		return -1;
	ret = ioctl( filedevice, SNDCTL_DSP_RESET, NULL );
	if(ret < 0)
	{
		fprintf(stderr,"Can't reset audio!\n");
		return -1;
	}
	if ( audio_set_format() < 0 )
		return -1;
	if ( audio_set_rate() < 0 )
		return -1;
	if ( audio_set_channels() < 0 )
		return -1;
	return 0;
}
Exemplo n.º 4
0
int audio_open(struct audio_info_struct *ai)
{
  int dev = AL_DEFAULT_OUTPUT;
  ALconfig config = alNewConfig();
  ALport port = NULL;
  
  /* Test for correct completion */
  if (config == 0) {
    fprintf(stderr,"audio_open : %s\n",alGetErrorString(oserror()));
    return -1;
  }
  
  /* Set port parameters */
  if(ai->channels == 2)
    alSetChannels(config, AL_STEREO);
  else
    alSetChannels(config, AL_MONO);

  alSetWidth(config, AL_SAMPLE_16);
  alSetSampFmt(config,AL_SAMPFMT_TWOSCOMP);
  alSetQueueSize(config, 131069);

  /* Setup output device to specified module. If there is no module
     specified in ai structure, use the default four output */
  if ((ai->device) != NULL) {
    
    char *dev_name;
    
    dev_name=malloc((strlen(ai->device) + strlen(analog_output_res_name) + 1) *
                  sizeof(char));
    
    strcpy(dev_name,ai->device);
    strcat(dev_name,analog_output_res_name);
    
    /* Find the asked device resource */
    dev=alGetResourceByName(AL_SYSTEM,dev_name,AL_DEVICE_TYPE);

    /* Free allocated space */
    free(dev_name);

    if (!dev) {
      fprintf(stderr,"Invalid audio resource: %s (%s)\n",dev_name,
            alGetErrorString(oserror()));
      return -1;
    }
  }
  
  /* Set the device */
  if (alSetDevice(config,dev) < 0)
    {
      fprintf(stderr,"audio_open : %s\n",alGetErrorString(oserror()));
      return -1;
    }
  
  /* Open the audio port */
  port = alOpenPort("mpg123-VSC", "w", config);
  if(port == NULL) {
    fprintf(stderr, "Unable to open audio channel: %s\n",
          alGetErrorString(oserror()));
    return -1;
  }
  
  ai->handle = (void*)port;
  
  
  audio_set_format(ai, config);
  audio_set_channels(ai, config);
  audio_set_rate(ai, config);
    

  alFreeConfig(config);
 
  return 1;
}