Beispiel #1
0
static void *gx_audio_init(const char *device, unsigned rate, unsigned latency)
{
   gx_audio_t *wa = (gx_audio_t*)memalign(32, sizeof(*wa));
   if (!wa)
      return NULL;

   gx_audio_data = wa;

   memset(wa, 0, sizeof(*wa));

   AUDIO_Init(NULL);
   AUDIO_RegisterDMACallback(dma_callback);

   if (rate < 33000)
   {
      AUDIO_SetDSPSampleRate(AI_SAMPLERATE_32KHZ);
      g_settings.audio.out_rate = 32000;
   }
   else
   {
      AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ);
      g_settings.audio.out_rate = 48000;
   }

   LWP_InitQueue(&wa->cond);

   wa->dma_write = BLOCKS - 1;
   DCFlushRange(wa->data, sizeof(wa->data));
   AUDIO_InitDMA((uint32_t)wa->data[wa->dma_next], CHUNK_SIZE);
   AUDIO_StartDMA();

   return wa;
}
Beispiel #2
0
static int init(int rate, int channels, int format, int flags)
{
	AUDIO_StopDMA();

	if(rate>32000) quality = AI_SAMPLERATE_48KHZ; 
	else quality = AI_SAMPLERATE_32KHZ;
	ao_data.samplerate = (quality==AI_SAMPLERATE_48KHZ) ? 48000 : 32000;
	ao_data.channels = clamp(channels, 2, 6);
	ao_data.format = AF_FORMAT_S16_NE;
	ao_data.bps = ao_data.channels * ao_data.samplerate * sizeof(s16);
	request_mult = (float)ao_data.channels / HW_CHANNELS;
	request_size = BUFFER_SIZE * request_mult;
	ao_data.buffersize = request_size * BUFFER_COUNT;
	ao_data.outburst = request_size;
	
	for (int counter = 0; counter < BUFFER_COUNT; counter++)
	{
		memset(buffers[counter], 0, BUFFER_SIZE);
		DCFlushRange(buffers[counter], BUFFER_SIZE);
	}

	memset(silence, 0, BUFFER_SIZE);
	DCFlushRange(silence, BUFFER_SIZE);

	buffer_fill = 0;
	buffer_play = 0;
	buffered = 0;

	playing = false;

	AUDIO_SetDSPSampleRate(quality);
	AUDIO_RegisterDMACallback(switch_buffers);

	return CONTROL_TRUE;
}
Beispiel #3
0
int
sound_lowlevel_init( const char *device, int *freqptr, int *stereoptr )
{
  switch(*freqptr) {
  case 32000:
    samplerate = AI_SAMPLERATE_32KHZ;
    break;
  case 48000:
    samplerate = AI_SAMPLERATE_48KHZ;
    break;
  default:
    printf("Sample rate %d not supported on Wii\n", *freqptr);
    return 1;
  }

  sfifo_init( &sound_fifo, BUFSIZE );
  *stereoptr = 1;
  
  AUDIO_Init( NULL );
  AUDIO_SetDSPSampleRate( samplerate );

#ifndef DISPLAY_AUDIO
  AUDIO_RegisterDMACallback( sound_dmacallback );
  memset( dmabuf, 0, BUFSIZE );
  AUDIO_InitDMA( (u32)dmabuf, BUFSIZE );
  DCFlushRange( dmabuf, dmalen );
  AUDIO_StartDMA();
#endif
  
  return 0;
}
Beispiel #4
0
EXPORT void CALL
AiDacrateChanged( int SystemType )
{
	// Taken from mupen_audio
	freq = 32000; //default to 32khz incase we get a bad systemtype
	switch (SystemType){
	      case SYSTEM_NTSC:
		freq = 48681812 / (*AudioInfo.AI_DACRATE_REG + 1);
		break;
	      case SYSTEM_PAL:
		freq = 49656530 / (*AudioInfo.AI_DACRATE_REG + 1);
		break;
	      case SYSTEM_MPAL:
		freq = 48628316 / (*AudioInfo.AI_DACRATE_REG + 1);
		break;
	}

	// Calculate the absolute differences from 32 and 48khz
	int diff32 = freq - 32000;
	int diff48 = freq - 48000;
	diff32 = diff32 > 0 ? diff32 : -diff32;
	diff48 = diff48 > 0 ? diff48 : -diff48;
	// Choose the closest real frequency
	real_freq = (diff32 < diff48) ? 32000 : 48000;
	freq_ratio = (float)freq / real_freq;

	if( real_freq == 32000 ){
		AUDIO_SetDSPSampleRate(AI_SAMPLERATE_32KHZ);
		buffer_size = (SystemType != SYSTEM_PAL) ?
		               BUFFER_SIZE_32_60 : BUFFER_SIZE_32_50;
	} else if( real_freq == 48000 ){
		AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ);
		buffer_size = (SystemType != SYSTEM_PAL) ?
		               BUFFER_SIZE_48_60 : BUFFER_SIZE_48_50;
	}
#ifdef SHOW_DEBUG
	sprintf(txtbuffer, "Initializing frequency: %d (resampling ratio %f)",
	        real_freq, freq_ratio);
	DEBUG_print(txtbuffer,DBG_AUDIOINFO);
#endif
}
Beispiel #5
0
static void *gx_audio_init(const char *device, unsigned rate, unsigned latency)
{
   if (g_audio)
      return g_audio;

   AUDIO_Init(NULL);
   AUDIO_RegisterDMACallback(dma_callback);

   if (rate < 33000)
   {
      AUDIO_SetDSPSampleRate(AI_SAMPLERATE_32KHZ);
      g_settings.audio.out_rate = 32000;
   }
   else
   {
      AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ);
      g_settings.audio.out_rate = 48000;
   }

   if (!g_audio)
   {
      g_audio = memalign(32, sizeof(*g_audio));
      memset(g_audio, 0, sizeof(*g_audio));
      LWP_InitQueue(&g_audio->cond);
   }
   else
   {
      memset(g_audio->data, 0, sizeof(g_audio->data));
      g_audio->dma_busy = g_audio->dma_next = 0;
      g_audio->write_ptr = 0;
      g_audio->nonblock = false;
   }

   g_audio->dma_write = BLOCKS - 1;
   DCFlushRange(g_audio->data, sizeof(g_audio->data));
   AUDIO_InitDMA((u32)g_audio->data[g_audio->dma_next], CHUNK_SIZE);
   AUDIO_StartDMA();

   return g_audio;
}
Beispiel #6
0
int SNDWiiInit()
{
    AUDIO_Init(NULL);
    AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ);

    soundpos = 0;
    soundlen = 44100 / 60; // 60 for NTSC or 50 for PAL. Initially assume it's going to be NTSC.
    soundtruelen = 48000 / 60;
    truesoundoffset = stereodata16[0];

    memset(stereodata16, 0, SOUNDBUFSIZE);

    issoundmuted = 0;

    AUDIO_RegisterDMACallback(StartDMA);
    AUDIO_InitDMA((u32)stereodata16[soundpos], soundlen * 4);
    DCFlushRange((void *)stereodata16[soundpos], soundlen * 4);
    AUDIO_StartDMA();

    return 0;
}
Beispiel #7
0
void OSystem_Wii::initSfx() {
	_mixer = new Audio::MixerImpl(this, 48000);

	sfx_thread_running = false;
	sfx_thread_quit = false;

	sfx_stack = (u8 *) memalign(32, SFX_THREAD_STACKSIZE);

	if (sfx_stack) {
		memset(sfx_stack, 0, SFX_THREAD_STACKSIZE);

		LWP_InitQueue(&sfx_queue);

		s32 res = LWP_CreateThread(&sfx_thread, sfx_thread_func, _mixer, sfx_stack,
									SFX_THREAD_STACKSIZE, SFX_THREAD_PRIO);

		if (res) {
			printf("ERROR creating sfx thread: %d\n", res);
			LWP_CloseQueue(sfx_queue);
			return;
		}

		sfx_thread_running = true;
	}

	for (u32 i = 0; i < SFX_BUFFERS; ++i) {
		sound_buffer[i] = (u8 *) memalign(32, SFX_THREAD_FRAG_SIZE);
		memset(sound_buffer[i], 0, SFX_THREAD_FRAG_SIZE);
		DCFlushRange(sound_buffer[i], SFX_THREAD_FRAG_SIZE);
	}

	_mixer->setReady(true);

	sb_hw = 0;

	AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ);
	AUDIO_RegisterDMACallback(audio_switch_buffers);
	AUDIO_InitDMA((u32) sound_buffer[sb_hw], SFX_THREAD_FRAG_SIZE);
	AUDIO_StartDMA();
}
Beispiel #8
0
qboolean SNDDMA_Init(void)
{
	// Set up Quake's audio.
	shm = &sn;
	shm->channels			= 2;
	shm->samplebits			= 16;
	shm->speed				= 32000;
	shm->soundalive			= TRUE;
	shm->splitbuffer		= FALSE;
	shm->samples			= samples_per_mix_buffer * shm->channels;
	shm->samplepos			= 0;
	shm->submission_chunk	= 1;
	shm->buffer				= (unsigned char*)(&mix_buffer[0]);

	// Initialise the audio system.
	AUDIO_Init(0);
	AUDIO_SetDSPSampleRate(AI_SAMPLERATE_32KHZ);
	AUDIO_RegisterDMACallback(play_more_audio);

	// Start the first chunk of audio playing.
	play_more_audio();

	return TRUE;
}
Beispiel #9
0
static int
wii_audio_start(audio_mode_t *am, audio_fifo_t *af)
{
  audio_buf_t *ab;
  int tbuf = 0, i;
  uint32_t level;
  int64_t pts;
  media_pipe_t *mp;

  prop_sub_t *s_vol;

  s_vol =
    prop_subscribe(PROP_SUB_DIRECT_UPDATE,
		   PROP_TAG_CALLBACK_FLOAT, set_mastervol, NULL,
		   PROP_TAG_ROOT, prop_mastervol,
		   NULL);

  LWP_InitQueue(&audio_queue);

  AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ);
  AUDIO_RegisterDMACallback(switch_buffers);

  AUDIO_StartDMA();

  while(1) {
    
    level = IRQ_Disable();
    while(tbuf == cur_buffer)
      LWP_ThreadSleep(audio_queue);
    tbuf = cur_buffer;
    IRQ_Restore(level);

    ab = af_deq(af, 0);
    
    if(am != audio_mode_current) {
      /* We're not the selected audio output anymore, return. */
      if(ab != NULL)
	ab_free(ab);
      break;
    }

    if(ab != NULL) {
      const int16_t *src = (const int16_t *)ab->ab_data;
      int16_t *dst = (int16_t *)buffer[!tbuf];
      for(i = 0; i < ADMA_BUFFER_SIZE / 2; i++)
	*dst++ = (*src++ * audio_vol) >> 16;

      /* PTS is the time of the first frame of this audio packet */

      if((pts = ab->ab_pts) != AV_NOPTS_VALUE && ab->ab_mp != NULL) {

#if 0
	/* Convert the frame delay into micro seconds */

	d = (fr * 1000 / aam->aam_sample_rate) * 1000;

	/* Subtract it from our timestamp, this will yield
	   the PTS for the sample currently played */

	pts -= d;

	/* Offset with user configure delay */
#endif

	pts += am->am_audio_delay * 1000;

	mp = ab->ab_mp;

	hts_mutex_lock(&mp->mp_clock_mutex);
	mp->mp_audio_clock = pts;
	mp->mp_audio_clock_realtime = showtime_get_ts();
	mp->mp_audio_clock_epoch = ab->ab_epoch;

	hts_mutex_unlock(&mp->mp_clock_mutex);

      }
      ab_free(ab);

    } else {
      memset(buffer[!tbuf], 0, ADMA_BUFFER_SIZE);
    }
    DCFlushRange(buffer[!tbuf], ADMA_BUFFER_SIZE);

  }