Пример #1
0
int audriv_write(char *buff, int n)
/* audio に buff を n バイト分流し込みます.
 * audriv_set_noblock_write() で非ブロック・モードが設定された
 * 場合は,この関数の呼び出しは即座に処理が返ります.
 * 返り値は実際に流し込まれたバイト数であり,非ブロック・モードが設定
 * されている場合は,引数 n より少ない場合があります.
 * 失敗すると -1 を返し,成功すると,実際に流し込まれたバイト数を返します.
 */
{
    n /= play_frame_width;

    if(audio_write_noblocking)
    {
	int size;
	size = alGetFillable(out);
	if(size < n)
	    n = size;
    }

    add_sample_counter(n);

    if(play_encoding != AENC_G711_ULAW)
    {
	alWriteFrames(out, buff, n);
	return n * play_frame_width;
    }
    else
    {
	/* AENC_G711_ULAW */
	int i, m, ret;
	short samps[BUFSIZ];

	n *= play_frame_width;
	ret = n;
	while(n > 0)
	{
	    m = n;
	    if(m > BUFSIZ)
		m = BUFSIZ;
	    for(i = 0; i < m; i++)
		samps[i] = AUDIO_U2S(buff[i]);
	    alWriteFrames(out, samps, m / play_frame_width);
	    buff += m;
	    n    -= m;
	}
	return ret;
    }
}
Пример #2
0
void WritePlay(
	       struct FFTSound *fftsound,
	       void *port,double **buffer,int size
	       ){
  struct Sgiplay *sgiplay=(struct Sgiplay *)port;
  alWriteFrames(sgiplay->out_port,  buffer, size);
}
Пример #3
0
  void
  ALAudioDevice::update() {
    ADR_GUARD("ALAudioDevice::update");

    // how much data can we write?
    const int filled = alGetFilled(m_port);
    int can_write = 5000 - filled;  // empty portion of the buffer

    // write 1024 frames at a time
    static const int BUFFER_SIZE = 1024;
    u8 buffer[BUFFER_SIZE * 4];
    while (can_write > 0) {
      int transfer_count = std::min(can_write, BUFFER_SIZE);

      ADR_LOG("reading");

      read(transfer_count, buffer);

      ADR_LOG("writing");

      alWriteFrames(m_port, buffer, transfer_count);
      can_write -= transfer_count;
    }

    usleep(50000);  // 50 milliseconds
  }
Пример #4
0
static void AL_PlayAudio(_THIS)
{
	/* Write the audio data out */
	if ( alWriteFrames(audio_port, mixbuf, this->spec.samples) < 0 ) {
		/* Assume fatal error, for now */
		this->enabled = 0;
	}
}
Пример #5
0
static void
IRIXAUDIO_PlayDevice(_THIS)
{
    /* Write the audio data out */
    ALport port = this->hidden->audio_port;
    Uint8 *mixbuf = this->hidden->mixbuf;
    if (alWriteFrames(port, mixbuf, this->spec.samples) < 0) {
        /* Assume fatal error, for now */
        this->enabled = 0;
    }
}
Пример #6
0
static int
irix_dsp_write(struct sysdep_dsp_struct *dsp, unsigned char *data, int count)
{
   struct irix_dsp_priv_data *priv = dsp->_priv;
   int playcnt;
   int maxsize;

   /*
    * We write as many samples as possible (up to count) without blocking
    */
   maxsize = alGetFillable(priv->devAudio);

   playcnt = (count <= maxsize) ? count : maxsize;

   alWriteFrames(priv->devAudio, data, playcnt);

   return playcnt;
}
Пример #7
0
void SNDDMA_Submit(void)
{
    int nFillable, nFilled, nPos;
    int nFrames, nFramesLeft;
    unsigned endtime;

    if (!sgisnd_aport) return;

    nFillable = alGetFillable( sgisnd_aport );
    nFilled = QSND_BUFFER_FRAMES - nFillable;

    nFrames = dma.samples >> (dma.channels - 1);

    if (paintedtime - soundtime < nFrames)
	nFrames = paintedtime - soundtime;

    if (nFrames <= QSND_SKID) return;

    nPos = UST_TO_BUFFPOS( sgisnd_startframe );

    // dump re-written contents of the buffer
    if (sgisnd_lastframewritten > sgisnd_startframe)
    {
	alDiscardFrames( sgisnd_aport, sgisnd_lastframewritten - sgisnd_startframe );
    }
    else if ((int)(sgisnd_startframe - sgisnd_lastframewritten) >= QSND_BUFFER_FRAMES)
    {
	// blow away everything if we've underflowed
	alDiscardFrames( sgisnd_aport, QSND_BUFFER_FRAMES );
    }

    // don't block
    if (nFrames > nFillable) nFrames = nFillable;

    // account for stereo
    nFramesLeft = nFrames;
    if (nPos + nFrames * dma.channels > QSND_BUFFER_SIZE)
    {
	int nFramesAtEnd = (QSND_BUFFER_SIZE - nPos) >> (dma.channels - 1);
	
	alWriteFrames( sgisnd_aport, &dma_buffer[nPos], nFramesAtEnd );
	nPos = 0;
	nFramesLeft -= nFramesAtEnd;
    }
Пример #8
0
void
sgi_play(void)
{
	struct audio_packet *packet;
	ssize_t len;
	unsigned int i;
	STREAM out;
	int gf;

	while (1)
	{
		if (rdpsnd_queue_empty())
			return;

		packet = rdpsnd_queue_current_packet();
		out = &packet->s;

		len = out->end - out->p;

		alWriteFrames(output_port, out->p, len / combinedFrameSize);

		out->p += len;
		if (out->p == out->end)
		{
			gf = alGetFilled(output_port);
			if (gf < (4 * maxFillable / 10))
			{
				rdpsnd_queue_next(0);
			}
			else
			{
#if (defined(IRIX_DEBUG))
/*  				fprintf(stderr,"Busy playing...\n"); */
#endif
				usleep(10);
				return;
			}
		}
	}
}
Пример #9
0
main (int argc, char **argv)
{
	AFfilehandle	file;
	AFframecount	count, frameCount;
	int		channelCount, sampleFormat, sampleWidth;
	float		frameSize;
	void		*buffer;
	double		sampleRate;

	ALport		outport;
	ALconfig	outportconfig;

	if (argc < 2)
		usage();

	file = afOpenFile(argv[1], "r", NULL);
	if (file == AF_NULL_FILEHANDLE)
	{
		fprintf(stderr, "Could not open file %s.\n", argv[1]);
		exit(EXIT_FAILURE);
	}

	frameCount = afGetFrameCount(file, AF_DEFAULT_TRACK);
	frameSize = afGetVirtualFrameSize(file, AF_DEFAULT_TRACK, 1);
	channelCount = afGetVirtualChannels(file, AF_DEFAULT_TRACK);
	sampleRate = afGetRate(file, AF_DEFAULT_TRACK);
	afGetVirtualSampleFormat(file, AF_DEFAULT_TRACK, &sampleFormat,
		&sampleWidth);

	if (sampleFormat == AF_SAMPFMT_UNSIGNED)
	{
		afSetVirtualSampleFormat(file, AF_DEFAULT_TRACK,
			AF_SAMPFMT_TWOSCOMP, sampleWidth);
	}

	printf("frame count: %lld\n", frameCount);
	printf("frame size: %d bytes\n", (int) frameSize);
	printf("channel count: %d\n", channelCount);
	printf("sample rate: %.2f Hz\n", sampleRate);
	buffer = malloc(BUFFERED_FRAME_COUNT * frameSize);

	outportconfig = alNewConfig();
	setwidth(outportconfig, sampleWidth);
	setsampleformat(outportconfig, sampleFormat);
	alSetChannels(outportconfig, channelCount);

	count = afReadFrames(file, AF_DEFAULT_TRACK, buffer, BUFFERED_FRAME_COUNT);

	outport = alOpenPort("irixread", "w", outportconfig);
	setrate(outport, sampleRate);

	do
	{
		printf("count = %lld\n", count);
		alWriteFrames(outport, buffer, count);

		count = afReadFrames(file, AF_DEFAULT_TRACK, buffer,
			BUFFERED_FRAME_COUNT);
	} while (count > 0);

	waitport(outport);

	alClosePort(outport);
	alFreeConfig(outportconfig);

	afCloseFile(file);
}
Пример #10
0
void
wave_out_play(void)
{
	struct audio_packet *packet;
	ssize_t len;
	unsigned int i;
	uint8 swap;
	STREAM out;
	static BOOL swapped = False;
	int gf;

	while (1)
	{
		if (queue_lo == queue_hi)
		{
			This->dsp_bu = False;
			return;
		}

		packet = &packet_queue[queue_lo];
		out = &packet->s;

		/* Swap the current packet, but only once */
		if (g_swapaudio && !swapped)
		{
			for (i = 0; i < out->end - out->p; i += 2)
			{
				swap = *(out->p + i);
				*(out->p + i) = *(out->p + i + 1);
				*(out->p + i + 1) = swap;
			}
			swapped = True;
		}

		len = out->end - out->p;

		alWriteFrames(output_port, out->p, len / combinedFrameSize);

		out->p += len;
		if (out->p == out->end)
		{
			gf = alGetFilled(output_port);
			if (gf < (4 * maxFillable / 10))
			{
				rdpsnd_send_completion(packet->tick, packet->index);
				free(out->data);
				queue_lo = (queue_lo + 1) % MAX_QUEUE;
				swapped = False;
			}
			else
			{
#if (defined(IRIX_DEBUG))
/*  				fprintf(stderr,"Busy playing...\n"); */
#endif
				This->dsp_bu = True;
				usleep(10);
				return;
			}
		}
	}
}
Пример #11
0
static int al_play (ao_instance_t * _instance, int flags, sample_t * _samples)
{
    al_instance_t * instance = (al_instance_t *) _instance;
    int16_t int16_samples[256*6];
    int chans = -1;

#ifdef LIBDTS_DOUBLE
    convert_t samples[256 * 6];
    int i;

    for (i = 0; i < 256 * 6; i++)
	samples[i] = _samples[i];
#else
    convert_t * samples = _samples;
#endif

    chans = channels_multi (flags);
    flags &= DTS_CHANNEL_MASK | DTS_LFE;

    if (instance->set_params) {
	ALconfig config;
	ALpv params[2];

	config = alNewConfig ();
	if (!config) {
	    fprintf (stderr, "alNewConfig failed\n");
	    return 1;
	}
	if (alSetChannels (config, chans)) {
	    fprintf (stderr, "alSetChannels failed\n");
	    return 1;
	}
	if (alSetConfig (instance->port, config)) {
	    fprintf (stderr, "alSetConfig failed\n");
	    return 1;
	}
	alFreeConfig (config);

	params[0].param = AL_MASTER_CLOCK;
	params[0].value.i = AL_CRYSTAL_MCLK_TYPE;
	params[1].param = AL_RATE;
	params[1].value.ll = alIntToFixed (instance->sample_rate);
	if (alSetParams (alGetResource (instance->port), params, 2) < 0) {
	    fprintf (stderr, "alSetParams failed\n");
	    return 1;
	}

	instance->flags = flags;
	instance->set_params = 0;
    } else if ((flags == DTS_DOLBY) && (instance->flags == DTS_STEREO)) {
	fprintf (stderr, "Switching from stereo to dolby surround\n");
	instance->flags = DTS_DOLBY;
    } else if ((flags == DTS_STEREO) && (instance->flags == DTS_DOLBY)) {
	fprintf (stderr, "Switching from dolby surround to stereo\n");
	instance->flags = DTS_STEREO;
    } else if (flags != instance->flags)
	return 1;

    convert2s16_multi (samples, int16_samples, flags);
    alWriteFrames (instance->port, int16_samples, 256);

    return 0;
}
Пример #12
0
main() 
{
  LS_DATA ls_data;
  FILE *fp;
  double gains[MAX_CHANNELS];
  int azimuth=-10;
  int elevation=14;
  double *gainptr,  gain;
  short *inptr,*outptr;
  short out[BUFFER_LENGTH][MAX_CHANNELS];
  ALconfig c;
  AFfilehandle fh;
  ALport p;

  short *in;
  long frames;

  int i,j,k;
  int numchannels = 8; /* change this according your output device*/
  int ls_set_dim = 3;
  int ls_num = 8;
  int ls_dirs[MAX_FIELD_AM]={-30,0,  30,0, -45,45,  45,45,  -90,0, 
			     90,0,  180,0,  180,45};
  /* change these according to your loudspeaker positioning*/
  

  /* defining loudspeaker data */
  define_loudspeakers(&ls_data, ls_set_dim, ls_num, ls_dirs);
     /* ls_data is a struct containing matrices etc
     ls_set_dim  is 2 if loudspeakers are on a (horizontal) plane
     ls_set_dim  is 3 if also elevated or descended loudpeakers exist
     ls_num is the number of loudspeakers
     ls_dirs is an array containing the angular directions of loudsp*/

  
  /* gain factors for virtual source in direction
     (int azimuth, int elevation) */
  vbap(gains, &ls_data, azimuth, elevation);  
     /* panning monophonic stream  float *in 
     to multiple outputs           float *out[]
     with gain factors             float *gains  */
  

  /* input audio*/
  if((fh=afOpenFile("myaiff.aiff","r",0))==NULL){
    fprintf(stderr, "Could not open file myaiff.aiff\n");
    exit(-1);
  }
  frames=AFgetframecnt(fh,AF_DEFAULT_TRACK);
  if(afGetChannels(fh, AF_DEFAULT_TRACK) != 1){
    fprintf(stderr, "Supports only mono aiff-files\n");
    exit(-1);
  }
  in= malloc(frames*sizeof(short)*2);
  afReadFrames(fh,AF_DEFAULT_TRACK,in,frames);


  /*opening the audio port*/
  c = alNewConfig();
  if (!c) {
    printf("Couldn't create ALconfig:%s\n", alGetErrorString(oserror()));
    exit(-1);
  }
  alSetChannels(c,numchannels);
  ALsetqueuesize(c,BUFFER_LENGTH);
  p = alOpenPort("alVBAP example","w",c);
  if (!p) {
    printf("port open failed:%s\n", alGetErrorString(oserror()));
    exit(-1);
  }
  


  fprintf(stderr,"\nPanning audio");
  for(j=0;j<(frames/BUFFER_LENGTH);j++){
    inptr = &(in[j*BUFFER_LENGTH]); /* audio to be panned  */
    outptr= out[0];         

    for (i=0; i<BUFFER_LENGTH; i++){    /* panning */ 
      gainptr=gains;
      for (k=0; k<numchannels; k++){
	*outptr++ = (short) ((double) *inptr * *gainptr++); 
      }
      inptr++;
    }
    alWriteFrames(p, out, BUFFER_LENGTH); /* write frames */
    fprintf(stderr,".");
  }

  /*write rest samples out*/

  inptr = &(in[j*BUFFER_LENGTH]); /* partial buffer  */
  outptr= out[0];
  for (i=0; i<(frames-BUFFER_LENGTH*j); i++){    /* panning */ 
    gainptr=gains;
    for (k=0; k<numchannels; k++){
      *outptr++ = (short) ((double) *inptr * *gainptr++); 
    }
    inptr++;
  }
  for (;i<BUFFER_LENGTH; i++){    /* zeros  */ 
    for (k=0; k<numchannels; k++){
      *outptr++ = 0; 
    }
  }

  alWriteFrames(p, out, BUFFER_LENGTH); /* write frames */
  fprintf(stderr,".");

  printf("\n\nDone!\n\n");
}