Exemple #1
0
FileDescriptor InitAudio(ALport *alpp) {
	/* initialize audio driver 
 	   for 16-bit 44100kHz monophonic sample source to DACs */
	ALconfig alc; 
 	alc = ALnewconfig();
	ALsetwidth (alc, AL_SAMPLE_16);
	ALsetqueuesize (alc, OUTPUTQUEUESIZE);
	ALsetchannels(alc, (long)1);
	*alpp = ALopenport("obuf", "w", alc);
	{
         	long pvbuf[2];
		long pvlen=2;
  	 	 
		pvbuf[0] = AL_OUTPUT_RATE;
		pvbuf[1] = AL_RATE_44100; 
		ALsetparams(AL_DEFAULT_DEVICE, pvbuf, pvlen);
		the_sample_rate = 44100.0f;
	}

	/* obtain a file descriptor associated with sound output port */
	return ALgetfd(*alpp);
}
Exemple #2
0
int esd_audio_open()
{
    ALconfig audioconfig;
    audioconfig = ALnewconfig();
  
	rate_params[1] = esd_audio_rate;
	rate_params[3] = esd_audio_rate;

    if (!audioconfig) {
	printf( "Couldn't initialize new audio config\n" );
	esd_audio_fd = -1;
	return esd_audio_fd;
    } else {
	long pvbuf[] = { AL_OUTPUT_COUNT, 0, 
			 AL_MONITOR_CTL, 0, 
			 AL_OUTPUT_RATE, 0 };
    
	if (ALgetparams(AL_DEFAULT_DEVICE, pvbuf, 6) < 0)
	    if (oserror() == AL_BAD_DEVICE_ACCESS) {
		esd_audio_fd = -1;
		return esd_audio_fd;
	    }
    
	if (pvbuf[1] == 0 && pvbuf[3] == AL_MONITOR_OFF) {
	    ALsetparams(AL_DEFAULT_DEVICE, rate_params, 2);
	} else
	    if (pvbuf[5] != esd_audio_rate) {
		printf("audio device is already in use with wrong sample output rate\n");
		esd_audio_fd = -1;
		return esd_audio_fd;
	
	    }
    
	/* ALsetsampfmt(audioconfig, AL_SAMPFMT_TWOSCOMP); this is the default */
	/* ALsetwidth(audioconfig, AL_SAMPLE_16); this is the default */
    
	if ( (esd_audio_format & ESD_MASK_CHAN) == ESD_MONO)
	    ALsetchannels(audioconfig, AL_MONO);
	/* else ALsetchannels(audioconfig, AL_STEREO); this is the default */

	ALsetqueuesize(audioconfig, ESD_BUF_SIZE * 2);
    
	outaudioport = ALopenport("esd", "w", audioconfig);
	if (outaudioport == (ALport) 0) {
	    switch (oserror()) {
	    case AL_BAD_NO_PORTS:
		printf( "system is out of ports\n");
		esd_audio_fd = -1;
		return esd_audio_fd;
		break;
	
	    case AL_BAD_DEVICE_ACCESS:
		printf("couldn't access audio device\n");
		esd_audio_fd = -1;
		return esd_audio_fd;
		break;
	
	    case AL_BAD_OUT_OF_MEM:
		printf("out of memory\n");
		esd_audio_fd = -1;
		return esd_audio_fd;
		break;
	    }
	    /* don't know how we got here, but it must be bad */
	    esd_audio_fd = -1;
	    return esd_audio_fd;
	}
	ALsetfillpoint(outaudioport, ESD_BUF_SIZE);

	esd_audio_fd = ALgetfd(outaudioport);

	/*
	 * If we are recording, open a second port to read from
	 * and return that fd instead
	 */
	if ( (esd_audio_format & ESD_MASK_FUNC) == ESD_RECORD ) {
	    inaudioport = ALopenport("esd", "r", audioconfig);
	    if (inaudioport == (ALport) 0) {
		switch (oserror()) {
		case AL_BAD_NO_PORTS:
		    printf( "system is out of ports\n");
		    esd_audio_fd = -1;
		    return esd_audio_fd;
		    break;
	
		case AL_BAD_DEVICE_ACCESS:
		    printf("couldn't access audio device\n");
		    esd_audio_fd = -1;
		    return esd_audio_fd;
		    break;
	
		case AL_BAD_OUT_OF_MEM:
		    printf("out of memory\n");
		    esd_audio_fd = -1;
		    return esd_audio_fd;
		    break;
		default:
		    printf( "Unknown error opening port\n" );
		}
				/* don't know how we got here, but it must be bad */
		esd_audio_fd = -1;
		return esd_audio_fd;
	    }
	    ALsetfillpoint(inaudioport, ESD_BUF_SIZE);
	    ALsetparams(AL_DEFAULT_DEVICE, (rate_params + 2), 2);

	    esd_audio_fd = ALgetfd(inaudioport);
	}

    }
    return esd_audio_fd;
}
Exemple #3
0
Error SoundCardPMO::Init(OutputInfo * info)
{
   ALconfig config = ALnewconfig();
   long pvbuffer[2];

   m_properlyInitialized = false;

   if (!info)
   {
      info = myInfo;
   }
   else
   {
      m_iDataSize = info->max_buffer_size;
   }

   pvbuffer[0] = AL_OUTPUT_RATE;
   pvbuffer[1] = info->samples_per_second;

   if (ALsetparams(AL_DEFAULT_DEVICE, pvbuffer, 2) < 0)
   {
      ReportError("Cannot set the soundcard's sampling speed.");
      return (Error) pmoError_IOCTL_SNDCTL_DSP_SPEED;
   }

   int ret = -1;
   if (info->bits_per_sample > 8)
       ret = ALsetwidth(config, AL_SAMPLE_16);
   else
       ret = ALsetwidth(config, AL_SAMPLE_8);

   if (ret < 0)
   {
      ReportError("The soundcard does not support 16 bit sample size.");
      return (Error) pmoError_IOCTL_SNDCTL_DSP_SAMPLESIZE;
   }

   ret = -1;
   if (info->number_of_channels == 2)
       ret = ALsetchannels(config, AL_STEREO);
   else
       ret = ALsetchannels(config, AL_MONO);
   if (ret < 0)
   {
      ReportError("Cannot set the soundcard to stereo.");
      return (Error) pmoError_IOCTL_SNDCTL_DSP_STEREO;
   }

   ALsetqueuesize(config, m_iDataSize);

   outaudioport = ALopenport("freeamp", "w", config);

   if (outaudioport == (ALport)0)
   {
       ReportError("Couldn't open port.");
       return (Error) pmoError_IOCTL_SNDCTL_DSP_STEREO;
   }

   audio_fd = ALgetfd(outaudioport);

   channels = info->number_of_channels;

   // configure the device:
   int       play_precision = info->bits_per_sample;
   int       play_stereo = channels - 1;
   int       play_sample_rate = info->samples_per_second;

   memcpy(myInfo, info, sizeof(OutputInfo));
   m_properlyInitialized = true;

   // PORTING: The GETOSPACE ioctl determines how much space the kernel's
   // output buffer has. Your OS may not have this.

   m_iTotalFragments = 2048; /* arbitrary blah */
   m_iOutputBufferSize = play_precision * m_iTotalFragments;
   m_iBytesPerSample = info->number_of_channels * (info->bits_per_sample / 8);

   return kError_NoErr;
}
int
sgi_audio_open(audio_desc_t ad, audio_format* ifmt, audio_format *ofmt)
{
	ALconfig	c;
	long		cmd[8];

        if (audio_fd != -1) {
                sgi_audio_close(ad);
        }

        if (ifmt->encoding != DEV_S16) return FALSE;

	if ((c = ALnewconfig()) == NULL) {
		fprintf(stderr, "ALnewconfig error\n");
		exit(1);
	}

        switch(ifmt->channels) {
        case 1:
                ALsetchannels(c, AL_MONO); break;
        case 2:
                ALsetchannels(c, AL_STEREO); break;
        default:
                sgi_audio_close(ad);
        }

	ALsetwidth(c, AL_SAMPLE_16);
	ALsetqueuesize(c, QSIZE);
	ALsetsampfmt(c, AL_SAMPFMT_TWOSCOMP);

	if ((wp = ALopenport("RAT write", "w", c)) == NULL) {
		fprintf(stderr, "ALopenport (write) error\n");
                sgi_audio_close(ad);
                return FALSE;
        }

	if ((rp = ALopenport("RAT read", "r", c)) == NULL) {
		fprintf(stderr, "ALopenport (read) error\n");
                sgi_audio_close(ad);
                return FALSE;
        }

	cmd[0] = AL_OUTPUT_RATE;
	cmd[1] = ofmt->sample_rate;
	cmd[2] = AL_INPUT_RATE;
	cmd[3] = ifmt->sample_rate;
	cmd[4] = AL_MONITOR_CTL;
	cmd[5] = AL_MONITOR_OFF;
	/*cmd[6] = AL_INPUT_SOURCE;*/
	/*cmd[7] = AL_INPUT_MIC;*/

	if (ALsetparams(AL_DEFAULT_DEVICE, cmd, 6L/*was 8L*/) == -1) {
		fprintf(stderr, "audio_open/ALsetparams error\n");
                sgi_audio_close(ad);
        }

	/* Get the file descriptor to use in select */
	audio_fd = ALgetfd(rp);

	if (ALsetfillpoint(rp, ifmt->bytes_per_block) < 0) {
                debug_msg("ALsetfillpoint failed (%d samples)\n", ifmt->bytes_per_block);
        }
        bytes_per_block = ifmt->bytes_per_block;
        
	/* We probably should free the config here... */
        
	return TRUE;
}