Example #1
0
static int audriv_al_set_width(ALconfig c, int encoding)
{
    if(encoding == AENC_G711_ULAW)
	return alSetWidth(c, 2);
    else
	return alSetWidth(c, AENC_SAMPW(encoding));
}
Example #2
0
/*
	Set the sample width of an audio configuration.
*/
void setwidth (ALconfig config, int sampleWidth)
{
	if (sampleWidth <= 8)
	{
		printf("setting width to 8\n");
		alSetWidth(config, AL_SAMPLE_8);
	}
	else if (sampleWidth <= 16)
	{
		printf("setting width to 16\n");
		alSetWidth(config, AL_SAMPLE_16);
	}
	else if (sampleWidth <= 24)
	{
		printf("setting width to 24\n");
		alSetWidth(config, AL_SAMPLE_24);
	}
}
Example #3
0
File: sgi.c Project: 5py/libmpg123
static int set_format(audio_output_t *ao, ALconfig config)
{
	if (alSetSampFmt(config,AL_SAMPFMT_TWOSCOMP) < 0)
		error1("set_format : %s",alGetErrorString(oserror()));
	
	if (alSetWidth(config,AL_SAMPLE_16) < 0)
		error1("set_format : %s",alGetErrorString(oserror()));
	
	return 0;
}
Example #4
0
static int audio_set_format(struct audio_info_struct *ai, ALconfig config)
{
  if (alSetSampFmt(config,AL_SAMPFMT_TWOSCOMP) < 0)
    fprintf(stderr,"audio_set_format : %s\n",alGetErrorString(oserror()));
  
  if (alSetWidth(config,AL_SAMPLE_16) < 0)
    fprintf(stderr,"audio_set_format : %s\n",alGetErrorString(oserror()));
  
  return 0;
}
Example #5
0
static int set_format(audio_output_t *ao, ALconfig config)
{
	if(ao->format == MPG123_ENC_FLOAT_32)
	{
		if(alSetSampFmt(config, AL_SAMPFMT_FLOAT) < 0)
		{
			error1("SetSampFmt: %s", alGetErrorString(oserror()));
			return -1;
		}
	} else
	{
		if(alSetSampFmt(config, AL_SAMPFMT_TWOSCOMP) < 0)
		{
			error1("SetSampFmt: %s", alGetErrorString(oserror()));
			return -1;
		}
		if(alSetWidth(config, AL_SAMPLE_16) < 0)
		{
			error1("SetWidth: %s", alGetErrorString(oserror()));
			return -1;
		}
	}
	return 0;
}
Example #6
0
static int AL_OpenAudio(_THIS, SDL_AudioSpec *spec)
{
	ALconfig audio_config;
#ifdef OLD_IRIX_AUDIO
	long audio_param[2];
#else
	ALpv audio_param;
#endif
	int width;

	/* Determine the audio parameters from the AudioSpec */
	switch ( spec->format & 0xFF ) {

		case 8: { /* Signed 8 bit audio data */
			spec->format = AUDIO_S8;
			width = AL_SAMPLE_8;
		}
		break;

		case 16: { /* Signed 16 bit audio data */
			spec->format = AUDIO_S16MSB;
			width = AL_SAMPLE_16;
		}
		break;

		default: {
			SDL_SetError("Unsupported audio format");
			return(-1);
		}
	}

	/* Update the fragment size as size in bytes */
	SDL_CalculateAudioSpec(spec);

	/* Set output frequency */
#ifdef OLD_IRIX_AUDIO
	audio_param[0] = AL_OUTPUT_RATE;
	audio_param[1] = spec->freq;
	if( ALsetparams(AL_DEFAULT_DEVICE, audio_param, 2) < 0 ) {
#else
	audio_param.param = AL_RATE;
	audio_param.value.i = spec->freq;
	if( alSetParams(AL_DEFAULT_OUTPUT, &audio_param, 1) < 0 ) {
#endif
		SDL_SetError("alSetParams failed");
		return(-1);
	}

	/* Open the audio port with the requested frequency */
	audio_port = NULL;
	audio_config = alNewConfig();
	if ( audio_config &&
	     (alSetSampFmt(audio_config, AL_SAMPFMT_TWOSCOMP) >= 0) &&
	     (alSetWidth(audio_config, width) >= 0) &&
	     (alSetQueueSize(audio_config, spec->samples*2) >= 0) &&
	     (alSetChannels(audio_config, spec->channels) >= 0) ) {
		audio_port = alOpenPort("SDL audio", "w", audio_config);
	}
	alFreeConfig(audio_config);
	if( audio_port == NULL ) {
		SDL_SetError("Unable to open audio port");
		return(-1);
	}

	/* Allocate mixing buffer */
	mixbuf = (Uint8 *)SDL_AllocAudioMem(spec->size);
	if ( mixbuf == NULL ) {
		SDL_OutOfMemory();
		return(-1);
	}
	memset(mixbuf, spec->silence, spec->size);

	/* We're ready to rock and roll. :-) */
	return(0);
}
Example #7
0
BOOL
wave_out_set_format(WAVEFORMATEX * pwfx)
{
	int channels;
	int frameSize, channelCount;
	ALpv params;

#if (defined(IRIX_DEBUG))
	fprintf(stderr, "wave_out_set_format: init...\n");
#endif

	g_swapaudio = False;
	if (pwfx->wBitsPerSample == 8)
		width = AL_SAMPLE_8;
	else if (pwfx->wBitsPerSample == 16)
	{
		width = AL_SAMPLE_16;
		/* Do we need to swap the 16bit values? (Are we BigEndian) */
#if (defined(B_ENDIAN))
		g_swapaudio = 1;
#else
		g_swapaudio = 0;
#endif
	}

	/* Limited support to configure an opened audio port in IRIX.  The
	   number of channels is a static setting and can not be changed after
	   a port is opened.  So if the number of channels remains the same, we
	   can configure other settings; otherwise we have to reopen the audio
	   port, using same config. */

	channels = pwfx->nChannels;
	g_snd_rate = pwfx->nSamplesPerSec;

	alSetSampFmt(audioconfig, AL_SAMPFMT_TWOSCOMP);
	alSetWidth(audioconfig, width);
	if (channels != alGetChannels(audioconfig))
	{
		alClosePort(output_port);
		alSetChannels(audioconfig, channels);
		output_port = alOpenPort("rdpsnd", "w", audioconfig);

		if (output_port == (ALport) 0)
		{
			fprintf(stderr, "wave_out_set_format: alOpenPort failed: %s\n",
				alGetErrorString(oserror()));
			return False;
		}

	}

	resource = alGetResource(output_port);
	maxFillable = alGetFillable(output_port);
	channelCount = alGetChannels(audioconfig);
	frameSize = alGetWidth(audioconfig);

	if (frameSize == 0 || channelCount == 0)
	{
		fprintf(stderr, "wave_out_set_format: bad frameSize or channelCount\n");
		return False;
	}
	combinedFrameSize = frameSize * channelCount;

	params.param = AL_RATE;
	params.value.ll = (long long) g_snd_rate << 32;

	if (alSetParams(resource, &params, 1) < 0)
	{
		fprintf(stderr, "wave_set_format: alSetParams failed: %s\n",
			alGetErrorString(oserror()));
		return False;
	}
	if (params.sizeOut < 0)
	{
		fprintf(stderr, "wave_set_format: invalid rate %d\n", g_snd_rate);
		return False;
	}

#if (defined(IRIX_DEBUG))
	fprintf(stderr, "wave_out_set_format: returning...\n");
#endif
	return True;
}
Example #8
0
qboolean SNDDMA_Init(void)
{
    ALconfig	ac = NULL;
    ALpv	pvbuf[2];

    s_loadas8bit = Cvar_Get("s_loadas8bit", "16", CVAR_ARCHIVE);
    if ((int)s_loadas8bit->value)
	dma.samplebits = 8;
    else
	dma.samplebits = 16;

    if (dma.samplebits != 16) {
	Com_Printf("Don't currently support %i-bit data.  Forcing 16-bit.\n",
		   dma.samplebits);
	dma.samplebits = 16;
	Cvar_SetValue( "s_loadas8bit", false );
    }

    s_khz = Cvar_Get("s_khz", "0", CVAR_ARCHIVE);
    switch ((int)s_khz->value) {
    case 48:
	dma.speed = AL_RATE_48000;
	break;
    case 44:
	dma.speed = AL_RATE_44100;
	break;
    case 32:
	dma.speed = AL_RATE_32000;
	break;
    case 22:
	dma.speed = AL_RATE_22050;
	break;
    case 16:
	dma.speed = AL_RATE_16000;
	break;
    case 11:
	dma.speed = AL_RATE_11025;
	break;
    case 8:
	dma.speed = AL_RATE_8000;
	break;
    default:
	dma.speed = AL_RATE_22050;
	Com_Printf("Don't currently support %i kHz sample rate.  Using %i.\n",
		   (int)s_khz->value, (int)(dma.speed/1000));
    }
    
    sndchannels = Cvar_Get("sndchannels", "2", CVAR_ARCHIVE);
    dma.channels = (int)sndchannels->value;
    if (dma.channels != 2)
	Com_Printf("Don't currently support %i sound channels.  Try 2.\n",
		   sndchannels);

    /***********************/

    ac = alNewConfig();
    alSetChannels( ac, AL_STEREO );
    alSetSampFmt( ac, AL_SAMPFMT_TWOSCOMP );
    alSetQueueSize( ac, QSND_BUFFER_FRAMES );
    if (dma.samplebits == 8)
	alSetWidth( ac, AL_SAMPLE_8 );
    else
	alSetWidth( ac, AL_SAMPLE_16 );

    sgisnd_aport = alOpenPort( "Quake", "w", ac );
    if (!sgisnd_aport)
    {
	printf( "failed to open audio port!\n" );
    }

    // set desired sample rate
    pvbuf[0].param = AL_MASTER_CLOCK;
    pvbuf[0].value.i = AL_CRYSTAL_MCLK_TYPE;
    pvbuf[1].param = AL_RATE;
    pvbuf[1].value.ll = alIntToFixed( dma.speed );
    alSetParams( alGetResource( sgisnd_aport ), pvbuf, 2 );
    if (pvbuf[1].sizeOut < 0)
	printf( "illegal sample rate %d\n", dma.speed );

    sgisnd_frames_per_ns = dma.speed * 1.0e-9;

    dma.samples = sizeof(dma_buffer)/(dma.samplebits/8);
    dma.submission_chunk = 1;

    dma.buffer = (unsigned char *)dma_buffer;

    dma.samplepos = 0;

    alFreeConfig( ac );
    return true;
}
// open & setup audio device
// return: 1=success 0=fail
static int init(int rate, int channels, int format, int flags) {

  int smpwidth, smpfmt;
  int rv = AL_DEFAULT_OUTPUT;

  smpfmt = fmt2sgial(&format, &smpwidth);

  mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_SGI_InitInfo, rate, (channels > 1) ? "Stereo" : "Mono", af_fmt2str_short(format));

  { /* from /usr/share/src/dmedia/audio/setrate.c */

    double frate, realrate;
    ALpv x[2];

    if(ao_subdevice) {
      rv = alGetResourceByName(AL_SYSTEM, ao_subdevice, AL_OUTPUT_DEVICE_TYPE);
      if (!rv) {
	mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_SGI_InvalidDevice);
	return 0;
      }
    }

    frate = rate;

    x[0].param = AL_RATE;
    x[0].value.ll = alDoubleToFixed(rate);
    x[1].param = AL_MASTER_CLOCK;
    x[1].value.i = AL_CRYSTAL_MCLK_TYPE;

    if (alSetParams(rv,x, 2)<0) {
      mp_msg(MSGT_AO, MSGL_WARN, MSGTR_AO_SGI_CantSetParms_Samplerate, alGetErrorString(oserror()));
    }

    if (x[0].sizeOut < 0) {
      mp_msg(MSGT_AO, MSGL_WARN, MSGTR_AO_SGI_CantSetAlRate);
    }

    if (alGetParams(rv,x, 1)<0) {
      mp_msg(MSGT_AO, MSGL_WARN, MSGTR_AO_SGI_CantGetParms, alGetErrorString(oserror()));
    }

    realrate = alFixedToDouble(x[0].value.ll);
    if (frate != realrate) {
      mp_msg(MSGT_AO, MSGL_INFO, MSGTR_AO_SGI_SampleRateInfo, realrate, frate);
    }
    sample_rate = (int)realrate;
  }

  bytes_per_frame = channels * smpwidth;

  ao_data.samplerate = sample_rate;
  ao_data.channels = channels;
  ao_data.format = format;
  ao_data.bps = sample_rate * bytes_per_frame;
  ao_data.buffersize=131072;
  ao_data.outburst = ao_data.buffersize/16;

  ao_config = alNewConfig();

  if (!ao_config) {
    mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_SGI_InitConfigError, alGetErrorString(oserror()));
    return 0;
  }

  if(alSetChannels(ao_config, channels) < 0 ||
     alSetWidth(ao_config, smpwidth) < 0 ||
     alSetSampFmt(ao_config, smpfmt) < 0 ||
     alSetQueueSize(ao_config, sample_rate) < 0 ||
     alSetDevice(ao_config, rv) < 0) {
    mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_SGI_InitConfigError, alGetErrorString(oserror()));
    return 0;
  }

  ao_port = alOpenPort("mplayer", "w", ao_config);

  if (!ao_port) {
    mp_msg(MSGT_AO, MSGL_ERR, MSGTR_AO_SGI_InitOpenAudioFailed, alGetErrorString(oserror()));
    return 0;
  }

  // printf("ao_sgi, init: port %d config %d\n", ao_port, ao_config);
  queue_size = alGetQueueSize(ao_config);
  return 1;

}
Example #10
0
// open & setup audio device
// return: 1=success 0=fail
static int init(int rate, int channels, int format, int flags) {

  int smpwidth, smpfmt;
  int rv = AL_DEFAULT_OUTPUT;

  smpfmt = fmt2sgial(&format, &smpwidth);

  mp_tmsg(MSGT_AO, MSGL_INFO, "[AO SGI] init: Samplerate: %iHz Channels: %s Format %s\n", rate, (channels > 1) ? "Stereo" : "Mono", af_fmt2str_short(format));

  { /* from /usr/share/src/dmedia/audio/setrate.c */

    double frate, realrate;
    ALpv x[2];

    if(ao_subdevice) {
      rv = alGetResourceByName(AL_SYSTEM, ao_subdevice, AL_OUTPUT_DEVICE_TYPE);
      if (!rv) {
	mp_tmsg(MSGT_AO, MSGL_ERR, "[AO SGI] play: invalid device.\n");
	return 0;
      }
    }

    frate = rate;

    x[0].param = AL_RATE;
    x[0].value.ll = alDoubleToFixed(rate);
    x[1].param = AL_MASTER_CLOCK;
    x[1].value.i = AL_CRYSTAL_MCLK_TYPE;

    if (alSetParams(rv,x, 2)<0) {
      mp_tmsg(MSGT_AO, MSGL_WARN, "[AO SGI] init: setparams failed: %s\nCould not set desired samplerate.\n", alGetErrorString(oserror()));
    }

    if (x[0].sizeOut < 0) {
      mp_tmsg(MSGT_AO, MSGL_WARN, "[AO SGI] init: AL_RATE was not accepted on the given resource.\n");
    }

    if (alGetParams(rv,x, 1)<0) {
      mp_tmsg(MSGT_AO, MSGL_WARN, "[AO SGI] init: getparams failed: %s\n", alGetErrorString(oserror()));
    }

    realrate = alFixedToDouble(x[0].value.ll);
    if (frate != realrate) {
      mp_tmsg(MSGT_AO, MSGL_INFO, "[AO SGI] init: samplerate is now %f (desired rate is %f)\n", realrate, frate);
    }
    sample_rate = (int)realrate;
  }

  bytes_per_frame = channels * smpwidth;

  ao_data.samplerate = sample_rate;
  ao_data.channels = channels;
  ao_data.format = format;
  ao_data.bps = sample_rate * bytes_per_frame;
  ao_data.buffersize=131072;
  ao_data.outburst = ao_data.buffersize/16;

  ao_config = alNewConfig();

  if (!ao_config) {
    mp_tmsg(MSGT_AO, MSGL_ERR, "[AO SGI] init: %s\n", alGetErrorString(oserror()));
    return 0;
  }

  if(alSetChannels(ao_config, channels) < 0 ||
     alSetWidth(ao_config, smpwidth) < 0 ||
     alSetSampFmt(ao_config, smpfmt) < 0 ||
     alSetQueueSize(ao_config, sample_rate) < 0 ||
     alSetDevice(ao_config, rv) < 0) {
    mp_tmsg(MSGT_AO, MSGL_ERR, "[AO SGI] init: %s\n", alGetErrorString(oserror()));
    return 0;
  }

  ao_port = alOpenPort("mplayer", "w", ao_config);

  if (!ao_port) {
    mp_tmsg(MSGT_AO, MSGL_ERR, "[AO SGI] init: Unable to open audio channel: %s\n", alGetErrorString(oserror()));
    return 0;
  }

  // printf("ao_sgi, init: port %d config %d\n", ao_port, ao_config);
  queue_size = alGetQueueSize(ao_config);
  return 1;

}
Example #11
0
static int
IRIXAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
{
    SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
    long width = 0;
    long fmt = 0;
    int valid = 0;

    /* !!! FIXME: Handle multiple devices and capture? */

    /* Initialize all variables that we clean on shutdown */
    this->hidden = (struct SDL_PrivateAudioData *)
        SDL_malloc((sizeof *this->hidden));
    if (this->hidden == NULL) {
        SDL_OutOfMemory();
        return 0;
    }
    SDL_memset(this->hidden, 0, (sizeof *this->hidden));

#ifdef OLD_IRIX_AUDIO
    {
        long audio_param[2];
        audio_param[0] = AL_OUTPUT_RATE;
        audio_param[1] = this->spec.freq;
        valid = (ALsetparams(AL_DEFAULT_DEVICE, audio_param, 2) < 0);
    }
#else
    {
        ALpv audio_param;
        audio_param.param = AL_RATE;
        audio_param.value.i = this->spec.freq;
        valid = (alSetParams(AL_DEFAULT_OUTPUT, &audio_param, 1) < 0);
    }
#endif

    while ((!valid) && (test_format)) {
        valid = 1;
        this->spec.format = test_format;

        switch (test_format) {
        case AUDIO_S8:
            width = AL_SAMPLE_8;
            fmt = AL_SAMPFMT_TWOSCOMP;
            break;

        case AUDIO_S16SYS:
            width = AL_SAMPLE_16;
            fmt = AL_SAMPFMT_TWOSCOMP;
            break;

        case AUDIO_F32SYS:
            width = 0;          /* not used here... */
            fmt = AL_SAMPFMT_FLOAT;
            break;

            /* Docs say there is int24, but not int32.... */

        default:
            valid = 0;
            test_format = SDL_NextAudioFormat();
            break;
        }

        if (valid) {
            ALconfig audio_config = alNewConfig();
            valid = 0;
            if (audio_config) {
                if (alSetChannels(audio_config, this->spec.channels) < 0) {
                    if (this->spec.channels > 2) {      /* can't handle > stereo? */
                        this->spec.channels = 2;        /* try again below. */
                    }
                }

                if ((alSetSampFmt(audio_config, fmt) >= 0) &&
                    ((!width) || (alSetWidth(audio_config, width) >= 0)) &&
                    (alSetQueueSize(audio_config, this->spec.samples * 2) >=
                     0)
                    && (alSetChannels(audio_config, this->spec.channels) >=
                        0)) {

                    this->hidden->audio_port = alOpenPort("SDL audio", "w",
                                                          audio_config);
                    if (this->hidden->audio_port == NULL) {
                        /* docs say AL_BAD_CHANNELS happens here, too. */
                        int err = oserror();
                        if (err == AL_BAD_CHANNELS) {
                            this->spec.channels = 2;
                            alSetChannels(audio_config, this->spec.channels);
                            this->hidden->audio_port =
                                alOpenPort("SDL audio", "w", audio_config);
                        }
                    }

                    if (this->hidden->audio_port != NULL) {
                        valid = 1;
                    }
                }

                alFreeConfig(audio_config);
            }
        }
    }

    if (!valid) {
        IRIXAUDIO_CloseDevice(this);
        SDL_SetError("Unsupported audio format");
        return 0;
    }

    /* Update the fragment size as size in bytes */
    SDL_CalculateAudioSpec(&this->spec);

    /* Allocate mixing buffer */
    this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->spec.size);
    if (this->hidden->mixbuf == NULL) {
        IRIXAUDIO_CloseDevice(this);
        SDL_OutOfMemory();
        return 0;
    }
    SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);

    /* We're ready to rock and roll. :-) */
    return 1;
}
Example #12
0
File: sgi.c Project: 5py/libmpg123
static int open_sgi(audio_output_t *ao)
{
	int dev = AL_DEFAULT_OUTPUT;
	ALconfig config = alNewConfig();
	ALport port = NULL;
	
	/* Test for correct completion */
	if (config == 0) {
		error1("open_sgi: %s",alGetErrorString(oserror()));
		return -1;
	}
	
	/* Set port parameters */
	if(ao->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 ao structure, use the default four output */
	if ((ao->device) != NULL) {
		char *dev_name;
		
		dev_name=malloc((strlen(ao->device) + strlen(analog_output_res_name) + 1) *
		  sizeof(char));
		
		strcpy(dev_name,ao->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) {
			error2("Invalid audio resource: %s (%s)",dev_name, alGetErrorString(oserror()));
			return -1;
		}
	}
	
	/* Set the device */
	if (alSetDevice(config,dev) < 0)
	{
		error1("open_sgi: %s",alGetErrorString(oserror()));
		return -1;
	}
	
	/* Open the audio port */
	port = alOpenPort("mpg123-VSC", "w", config);
	if(port == NULL) {
		error1("Unable to open audio channel: %s", alGetErrorString(oserror()));
		return -1;
	}
	
	ao->userptr = (void*)port;
	
	
	set_format(ao, config);
	set_channels(ao, config);
	set_rate(ao, config);
	
	
	alFreeConfig(config);
	
	return 1;
}
Example #13
0
static int AL_OpenAudio(_THIS, SDL_AudioSpec * spec)
{
	Uint16 test_format = SDL_FirstAudioFormat(spec->format);
	long width = 0;
	long fmt = 0;
	int valid = 0;

#ifdef OLD_IRIX_AUDIO
	{
		long audio_param[2];
		audio_param[0] = AL_OUTPUT_RATE;
		audio_param[1] = spec->freq;
		valid = (ALsetparams(AL_DEFAULT_DEVICE, audio_param, 2) < 0);
	}
#else
	{
		ALpv audio_param;
		audio_param.param = AL_RATE;
		audio_param.value.i = spec->freq;
		valid = (alSetParams(AL_DEFAULT_OUTPUT, &audio_param, 1) < 0);
	}
#endif

	while ((!valid) && (test_format)) {
		valid = 1;
		spec->format = test_format;

		switch (test_format) {
			case AUDIO_S8:
				width = AL_SAMPLE_8;
				fmt = AL_SAMPFMT_TWOSCOMP;
				break;

			case AUDIO_S16SYS:
				width = AL_SAMPLE_16;
				fmt = AL_SAMPFMT_TWOSCOMP;
				break;

			default:
				valid = 0;
				test_format = SDL_NextAudioFormat();
				break;
		}

		if (valid) {
			ALconfig audio_config = alNewConfig();
			valid = 0;
			if (audio_config) {
				if (alSetChannels(audio_config, spec->channels) < 0) {
					if (spec->channels > 2) {  /* can't handle > stereo? */
						spec->channels = 2;  /* try again below. */
					}
				}

				if ((alSetSampFmt(audio_config, fmt) >= 0) &&
				    ((!width) || (alSetWidth(audio_config, width) >= 0)) &&
				    (alSetQueueSize(audio_config, spec->samples * 2) >= 0) &&
				    (alSetChannels(audio_config, spec->channels) >= 0)) {

					audio_port = alOpenPort("SDL audio", "w", audio_config);
					if (audio_port == NULL) {
						/* docs say AL_BAD_CHANNELS happens here, too. */
						int err = oserror();
						if (err == AL_BAD_CHANNELS) {
							spec->channels = 2;
							alSetChannels(audio_config, spec->channels);
							audio_port = alOpenPort("SDL audio", "w",
							                        audio_config);
						}
					}

					if (audio_port != NULL) {
						valid = 1;
					}
				}

				alFreeConfig(audio_config);
			}
		}
	}

	if (!valid) {
		SDL_SetError("Unsupported audio format");
		return (-1);
	}

	/* Update the fragment size as size in bytes */
	SDL_CalculateAudioSpec(spec);

	/* Allocate mixing buffer */
	mixbuf = (Uint8 *) SDL_AllocAudioMem(spec->size);
	if (mixbuf == NULL) {
		SDL_OutOfMemory();
		return (-1);
	}
	SDL_memset(mixbuf, spec->silence, spec->size);

	/* We're ready to rock and roll. :-) */
	return (0);
}
Example #14
0
/*
 * public methods (static but exported through the sysdep_dsp or plugin struct)
 */
static void *
irix_dsp_create(const void *flags)
{
   ALpv pvs[4];
   long tempbits, tempchan;
   int oldrate;
   struct irix_dsp_priv_data *priv = NULL;
   struct sysdep_dsp_struct *dsp = NULL;
   const struct sysdep_dsp_create_params *params = flags;
   ALconfig devAudioConfig;	
   
   /* 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;
   }
   
   /* allocate private data */
   if(!(priv = calloc(1, sizeof(struct irix_dsp_priv_data))))
   {
      fprintf(stderr, "Error: malloc failed for struct irix_dsp_priv_data\n");
      free(dsp);
      return NULL;
   }
   
   /* fill in the functions and some data */
   priv->port_status = -1;
   dsp->_priv = priv;
   dsp->get_freespace = irix_dsp_get_freespace;
   dsp->write = irix_dsp_write;
   dsp->destroy = irix_dsp_destroy;
   dsp->hw_info.type = params->type;
   dsp->hw_info.samplerate = params->samplerate;

   tempchan = (dsp->hw_info.type & SYSDEP_DSP_STEREO) ? 2 : 1;
   tempbits = (dsp->hw_info.type & SYSDEP_DSP_16BIT) ? 2 : 1;

#ifdef IRIX_DEBUG
   fprintf(stderr, "Source Format is %dHz, %d bit, %s, with bufsize %f\n",
           dsp->hw_info.samplerate, 
           tempbits * 8, (tempchan == 2) ? "stereo" : "mono",
           params->bufsize);
#endif

   /*
    * Since AL wants signed data in either case, and 8-bit data from
    * core xmame is unsigned, let the core xmame convert everything
    * to 16-bit signed.
    */
   if (tempbits == 1)
   {
      dsp->hw_info.type |= SYSDEP_DSP_16BIT;
      tempbits = 2;
   }

   /*
    * Get the current hardware sampling rate
    */
   pvs[0].param = AL_RATE;
   if (alGetParams(AL_DEFAULT_OUTPUT, pvs, 1) < 0)
   {
      fprintf(stderr, "alGetParams failed: %s\n", alGetErrorString(oserror()));
      irix_dsp_destroy(dsp);
      return NULL;
   }

   oldrate = pvs[0].value.i;

   /*
    * If requested samplerate is different than current hardware rate,
    * set it.
    */
   if (oldrate != dsp->hw_info.samplerate)
   {
      int audioHardwareRate = oldrate;

      fprintf(stderr, "System sample rate was %dHz, forcing %dHz instead.\n",
              oldrate, dsp->hw_info.samplerate);

      /*
       * If the desired rate is unsupported, most devices (such as RAD) will
       * force the device rate to be as close as possible to the desired rate.
       * Since close isn't going to help us here, we avoid the call entirely,
       * and let core xmame audio convert to our rate.
       */
      if (RateSupported(AL_DEFAULT_OUTPUT, (float) dsp->hw_info.samplerate))
      {
         /* Set desired sample rate */
         pvs[0].param = AL_MASTER_CLOCK;
         pvs[0].value.i = AL_CRYSTAL_MCLK_TYPE;
         pvs[1].param = AL_RATE;
         pvs[1].value.i = dsp->hw_info.samplerate;
         alSetParams(AL_DEFAULT_OUTPUT, pvs, 2);

         /* Get the new sample rate */
         pvs[0].param = AL_RATE;
         if (alGetParams(AL_DEFAULT_OUTPUT, pvs, 1) < 0)
         {
            fprintf(stderr, "alGetParams failed: %s\n",
                    alGetErrorString(oserror()));
            irix_dsp_destroy(dsp);
            return NULL;
         }

         audioHardwareRate = pvs[0].value.i;
      }

      if (audioHardwareRate != dsp->hw_info.samplerate)
      {
         fprintf(stderr, "Requested rate of %dHz is not supported by "
                 "the audio hardware, so forcing\n"
                 "playback at %dHz.\n",
                 dsp->hw_info.samplerate, audioHardwareRate);
         dsp->hw_info.samplerate = audioHardwareRate;
      }
   }

   /* create a config descriptor */
   devAudioConfig = alNewConfig();
   if (devAudioConfig == NULL) {
      fprintf(stderr, "Cannot get a Descriptor. Exiting..\n");
      irix_dsp_destroy(dsp);
      return NULL;
   }

#ifdef FORCEMONO
   dsp->hw_info.type &= ~SYSDEP_DSP_STEREO;
   tempchan = 1;
#endif

   priv->buffer_samples = dsp->hw_info.samplerate * params->bufsize;

   priv->buffer_samples *= tempchan;

   priv->sampwidth = tempbits;
   priv->sampchan = tempchan;

   fprintf(stderr, "Setting sound to %dHz, %d bit, %s\n",
           dsp->hw_info.samplerate,
           tempbits * 8, (tempchan == 2) ? "stereo" : "mono");

   /* source specific audio parameters */
   alSetChannels(devAudioConfig, tempchan);
   alSetQueueSize(devAudioConfig, priv->buffer_samples);
   alSetWidth(devAudioConfig, tempbits);
   alSetSampFmt(devAudioConfig, AL_SAMPFMT_TWOSCOMP);

   /* Open the audio port with the parameters we setup */
   priv->devAudio = alOpenPort("audio_fd", "w", devAudioConfig);
   if (priv->devAudio == NULL)
   {
       fprintf(stderr, "Error: Cannot get an audio channel descriptor.\n");
       irix_dsp_destroy(dsp);
       return NULL;
   }

   alFreeConfig(devAudioConfig);

   /*
    * Since we don't use FD's with AL, we use this to inform us
    * of success
    */
   priv->port_status = 0;

   return dsp;
}