Esempio n. 1
0
/* This is the audio processing callback. */
OSStatus coreaudiowrite( void *inRefCon,
                         AudioUnitRenderActionFlags *ioActionFlags,
                         const AudioTimeStamp *inTimeStamp,
                         UInt32 inBusNumber,
                         UInt32 inNumberFrames,                       
                         AudioBufferList *ioData )
{
  int f;
  int len = deviceFormat.mBytesPerFrame * inNumberFrames;
  uint8_t* out = ioData->mBuffers[0].mData;

  /* Try to only read an even number of bytes so as not to fragment a sample */
  len = MIN( len, sfifo_used( &sound_fifo ) );
  len &= sound_stereo ? 0xfffc : 0xfffe;

  /* Read input_size bytes from fifo into sound stream */
  while( ( f = sfifo_read( &sound_fifo, out, len ) ) > 0 ) {
    out += f;
    len -= f;
  }

  /* If we ran out of sound, make do with silence :( */
  if( f < 0 ) {
    for( f=0; f<len; f++ ) {
      *out++ = 0;
    }
  }

  return noErr;
}
Esempio n. 2
0
static int n2s_sender_thread(void *data)
{
	char buf[N2S_SEND_FRAGMENT];
	REAL_EB_socket *rs = (REAL_EB_socket *)data;
	while(!rs->closed && !rs->status)
	{
		int count;
		SDL_Delay(rs->pollperiod);
		count = sfifo_used(&rs->fifo);
		if(!count)
			continue;
		while(count)
		{
			int res;
			int n = count;
			if(n > N2S_SEND_FRAGMENT)
				n = N2S_SEND_FRAGMENT;
			sfifo_read(&rs->fifo, buf, n);
			res = NET2_TCPSend(rs->n2socket, buf, n);
			if(res < 0)
			{
				rs->status = EEL_XDEVICEWRITE;
				break;
			}
			count -= n;
		}
	}
	// Detach from the EEL wrapper object
	rs->sender = NULL;
	return 0;
}
Esempio n. 3
0
/*
 * This is where buffered asynchronous commands are
 * processed. Some of them turn directly into timestamped
 * events right here.
 */
static void _run_commands(void)
{
	int d = hold_until - get_time();
	if(labs(d) > 1000)
		hold_until = get_time();
	else if(d > 0)
		return;

	while(sfifo_used(&commands) >= sizeof(command_t))
	{
		command_t cmd;
		if(sfifo_read(&commands, &cmd, (unsigned)sizeof(cmd)) < 0)
		{
			log_printf(ELOG, "audio.c: Engine failure!\n");
			_audio_running = 0;
			return;
		}
		switch(cmd.action)
		{
		  case CMD_STOP:
			DBG2(log_printf(D3LOG, "%d: CMD_STOP\n", get_time());)
			(void)ce_stop(channeltab + cmd.cid, 0, cmd.tag, 32768);
			break;
		  case CMD_STOP_ALL:
			DBG2(log_printf(D3LOG, "%d: CMD_STOP_ALL\n", get_time());)
			channel_stop_all();
			break;
		  case CMD_PLAY:
			DBG2(log_printf(D3LOG, "%d: CMD_PLAY\n", get_time());)
Esempio n. 4
0
static void
sound_dmacallback( void )
{
  if( sfifo_used( &sound_fifo ) < 128) return;
  
  dmalen = MIN( BUFSIZE, sfifo_used( &sound_fifo ) );
  sfifo_read( &sound_fifo, dmabuf, dmalen );
  DCFlushRange( dmabuf, dmalen );
  AUDIO_InitDMA( (u32)dmabuf, dmalen );
  AUDIO_StartDMA();
}
Esempio n. 5
0
static OSStatus playProc(AudioConverterRef inAudioConverter,
						 UInt32 *ioNumberDataPackets,
                         AudioBufferList *outOutputData,
                         AudioStreamPacketDescription **outDataPacketDescription,
                         void* inClientData)
{
	mpg123_coreaudio_t *ca = (mpg123_coreaudio_t *)inClientData;
	long n;
	
	
	if(ca->last_buffer) {
		ca->play_done = 1;
		return noErr;
	}
	
	for(n = 0; n < outOutputData->mNumberBuffers; n++)
	{
		unsigned int wanted = *ioNumberDataPackets * ca->channels * ca->bps;
		unsigned char *dest;
		unsigned int read;
		if(ca->buffer_size < wanted) {
			debug1("Allocating %d byte sample conversion buffer", wanted);
			ca->buffer = realloc( ca->buffer, wanted);
			ca->buffer_size = wanted;
		}
		dest = ca->buffer;
		
		/* Only play if we have data left */
		if ( sfifo_used( &ca->fifo ) < (int)wanted ) {
			if(!ca->decode_done) {
				warning("Didn't have any audio data in callback (buffer underflow)");
				return -1;
			}
			wanted = sfifo_used( &ca->fifo );
			ca->last_buffer = 1;
		}
		
		/* Read audio from FIFO to SDL's buffer */
		read = sfifo_read( &ca->fifo, dest, wanted );
		
		if (wanted!=read)
			warning2("Error reading from the ring buffer (wanted=%u, read=%u).\n", wanted, read);
		
		outOutputData->mBuffers[n].mDataByteSize = read;
		outOutputData->mBuffers[n].mData = dest;
	}
	
	return noErr; 
}
Esempio n. 6
0
/* The audio function callback takes the following parameters:
       stream:  A pointer to the audio buffer to be filled
       len:     The length (in bytes) of the audio buffer
*/
static void audio_callback_sdl(void *udata, Uint8 *stream, int len)
{
	out123_handle *ao = (out123_handle*)udata;
	sfifo_t *fifo = (sfifo_t*)ao->userptr;
	int bytes_read;
	int bytes_avail;

	bytes_avail = sfifo_used(fifo);
	if(bytes_avail < len) len = bytes_avail;

	/* Read audio from FIFO to SDL's buffer */
	bytes_read = sfifo_read( fifo, stream, len );

	if (len!=bytes_read)
	warning2("Error reading from the FIFO (wanted=%u, bytes_read=%u).\n", len, bytes_read);
}
Esempio n. 7
0
static OSStatus playProc(AudioConverterRef inAudioConverter,
                         UInt32 *ioNumberDataPackets,
                         AudioBufferList *outOutputData,
                         AudioStreamPacketDescription
                         **outDataPacketDescription,
                         void* inClientData)
{
    mpg123_coreaudio_t *ca = (mpg123_coreaudio_t *)inClientData;
    long n;


    if(ca->last_buffer) {
        ca->play_done = 1;
        return noErr;
    }

    for(n = 0; n < outOutputData->mNumberBuffers; n++)
    {
        unsigned int wanted = *ioNumberDataPackets * ca->channels * ca->bps;
        unsigned char *dest;
        unsigned int read;
        if(ca->buffer_size < wanted) {
            ca->buffer = realloc( ca->buffer, wanted);
            ca->buffer_size = wanted;
        }
        dest = ca->buffer;

        /* Only play if we have data left */
        if ( sfifo_used( &ca->fifo ) < wanted ) {
            if(!ca->decode_done) {
                return -1;
            }
            wanted = sfifo_used( &ca->fifo );
            ca->last_buffer = 1;
        }

        /* Read audio from FIFO to SDL's buffer */
        read = sfifo_read( &ca->fifo, dest, wanted );

        outOutputData->mBuffers[n].mDataByteSize = read;
        outOutputData->mBuffers[n].mData = dest;
    }

    return noErr;
}