Esempio n. 1
0
PcmDevice *
openPcmDevice (int errorLevel, const char *device) {
#ifdef HAVE_HPUX_AUDIO
  PcmDevice *pcm;
  if ((pcm = malloc(sizeof(*pcm)))) {
    long status;
    AudioAttrMask mask = 0;
    AudioAttributes attributes;
    SSPlayParams parameters;
  
    if (!audioServer) {
      char *server = "";
      audioServer = AOpenAudio(server, &status);
      if (status != AENoError) {
        logAudioError(errorLevel, status, "AOpenAudio");
        audioServer = NULL;
        goto noServer;
      }
      logMessage(LOG_DEBUG, "connected to audio server: %s", AAudioString(audioServer));
  
      ASetCloseDownMode(audioServer, AKeepTransactions, &status);
      if (status != AENoError) {
        logAudioError(errorLevel, status, "ASetCloseDownMode");
      }
    }
  
    memset(&attributes, 0, sizeof(attributes));
  
    parameters.gain_matrix = *ASimplePlayer(audioServer);
    parameters.play_volume = AUnityGain;
    parameters.priority = APriorityUrgent;
    parameters.event_mask = 0;
  
    pcm->transaction = APlaySStream(audioServer, mask, &attributes, &parameters, &pcm->stream, &status);
    if (status == AENoError) {
      if ((pcm->socket = socket(AF_INET, SOCK_STREAM, 0)) != -1) {
        if (connect(pcm->socket, (struct sockaddr *)&pcm->stream.tcp_sockaddr, sizeof(pcm->stream.tcp_sockaddr)) != -1) {
          return pcm;
        } else {
          logSystemError("PCM socket connection");
        }
        close(pcm->socket);
      } else {
        logSystemError("PCM socket creation");
      }
    } else {
      logAudioError(errorLevel, status, "APlaySStream");
    }

  noServer:
    free(pcm);
  } else {
    logSystemError("PCM device allocation");
  }
#endif /* HAVE_HPUX_AUDIO */
  return NULL;
}
Esempio n. 2
0
// Initialize Sound Card ------------------------------------------------------
static  int     Sound_Init_SoundCard (void)
{
  int            i;
  AUDIOINFO      Audio_Infos;

  ConsolePrintf (Msg_Get (MSG_Sound_Init_Soundcard), Sound.SampleRate);
  ConsolePrint ("\n");

  Audio_Infos.nDeviceId = Sound.SoundCard;
  Audio_Infos.wFormat = AUDIO_FORMAT_16BITS | AUDIO_FORMAT_STEREO; // FIXME: Stereo ?
  Audio_Infos.nSampleRate = audio_sample_rate = Sound.SampleRate;

  if (AOpenAudio(&Audio_Infos) != AUDIO_ERROR_NONE)
     {
     Quit_Msg ("%s", Msg_Get (MSG_Sound_Init_Error_Audio));
     return (MEKA_ERR_FAIL);
     }
  // FIXME: original sound engine was trying different sample rate on failure

  // Unused
  // Maybe it was intended to check out number of channels there ?
  // AGetAudioCaps (Audio_Infos.nDeviceId, &Audio_Caps);

  // Open voices
  if (AOpenVoices(Sound.Voices_Max) != AUDIO_ERROR_NONE)
     {
     Quit_Msg ("%s", Msg_Get (MSG_Sound_Init_Error_Voices));
     return (MEKA_ERR_FAIL);
     }

  ASetAudioMixerValue (AUDIO_MIXER_MASTER_VOLUME, 256);

  // Allocate voices and waveforms
  Sound.Voices = Memory_Alloc (sizeof (t_voice) * Sound.Voices_Max);
  for (i = 0; i < Sound.Voices_Max; i++)
     {
     if (ACreateAudioVoice(&Sound.Voices[i].hVoice) != AUDIO_ERROR_NONE)
        {
        Quit_Msg (Msg_Get (MSG_Sound_Init_Error_Voice_N), i);
        return (MEKA_ERR_FAIL);
        }
     ASetVoicePanning(Sound.Voices[i].hVoice, 128); // Center voice
     Sound.Voices[i].lpWave  = NULL;
     Sound.Voices[i].playing = FALSE;
     }

  // FIXME: is this needed ?
  AUpdateAudio ();

  // FIXME: is this needed ?
  // Check frame sample rate
  audio_sample_rate = nominal_sample_rate = Audio_Infos.nSampleRate;

  return (MEKA_ERR_OK);
}
Esempio n. 3
0
int main(void)
{
    AUDIOINFO info;
    AUDIOCAPS caps;
    UINT rc, nDevId;

    /* initialize audio library */
    AInitialize();

    /* show registered device drivers */
    printf("List of registered devices:\n");
    for (nDevId = 0; nDevId < AGetAudioNumDevs(); nDevId++) {
        AGetAudioDevCaps(nDevId, &caps);
        printf("  %2d. %s\n", nDevId, caps.szProductName);
    }
    printf("\n");

    /*
     * NOTE: Here we can use any of the above devices, or we can
     * use the virtual device AUDIO_DEVICE_MAPPER for detection.
     */

    /* open audio device */
    info.nDeviceId = AUDIO_DEVICE_MAPPER;
    info.wFormat = AUDIO_FORMAT_16BITS | AUDIO_FORMAT_STEREO;
    info.nSampleRate = 44100;
    if ((rc = AOpenAudio(&info)) != AUDIO_ERROR_NONE) {
        CHAR szText[80];
        AGetErrorText(rc, szText, sizeof(szText) - 1);
        printf("ERROR: %s\n", szText);
        exit(1);
    }

    /*
     * NOTE: Since the audio device may not support the playback
     * format and sampling frequency, the audio system uses the
     * closest configuration which is then returned to the user
     * in the AUDIOINFO structure.
     *
     */

    /* print information */
    AGetAudioDevCaps(info.nDeviceId, &caps);
    printf("%s at %d-bit %s %u Hz detected\n",
        caps.szProductName,
        info.wFormat & AUDIO_FORMAT_16BITS ? 16 : 8,
        info.wFormat & AUDIO_FORMAT_STEREO ? "stereo" : "mono",
        info.nSampleRate);


    /* close audio device */
    ACloseAudio();
    return 0;
}
Esempio n. 4
0
int main(void)
{
    AUDIOINFO info;
    LPAUDIOMODULE lpModule;
    LPAUDIOWAVE lpWave;
    HAC hVoice;
    BOOL stopped;

    /* initialize audio library */
    AInitialize();

    /* open audio device */
    info.nDeviceId = AUDIO_DEVICE_MAPPER;
    info.wFormat = AUDIO_FORMAT_16BITS | AUDIO_FORMAT_STEREO;
    info.nSampleRate = 44100;
    AOpenAudio(&info);

    /* load module and waveform file */
    ALoadModuleFile("test.s3m", &lpModule, 0);
    ALoadWaveFile("test.wav", &lpWave, 0);

    /* open voices for module and waveform */
    AOpenVoices(lpModule->nTracks + 1);

    /* play the module file */
    APlayModule(lpModule);
    ASetModuleVolume(64);

    /* play the waveform through a voice */
    ACreateAudioVoice(&hVoice);
    APlayVoice(hVoice, lpWave);
    ASetVoiceVolume(hVoice, 48);
    ASetVoicePanning(hVoice, 128);

    /* program main execution loop */
    printf("Playing module and waveform, press any key to stop.\n");
    while (!kbhit()) {
        /* update audio system */
        AUpdateAudio();

        /* restart waveform if stopped */
        AGetVoiceStatus(hVoice, &stopped);
        if (stopped) APlayVoice(hVoice, lpWave);

        /* check if the module is stopped */
        AGetModuleStatus(&stopped);
        if (stopped) break;
    }

    /* stop playing the waveform */
    AStopVoice(hVoice);
    ADestroyAudioVoice(hVoice);

    /* stop playing the module */
    AStopModule();
    ACloseVoices();

    /* release the waveform & module */
    AFreeWaveFile(lpWave);
    AFreeModuleFile(lpModule);

    /* close audio device */
    ACloseAudio();
    return 0;
}
Esempio n. 5
0
int msdos_init_sound(int *rate, int card)
{
  int i;

  seal_sample_rate = *rate;
  seal_sound_card  = card;

  if (AInitialize() != AUDIO_ERROR_NONE)
    return 1;

  /* Ask the user if no sound card was chosen */
  if (seal_sound_card == -1)
  {
    unsigned int k;

    printf("\n SELECT YOUR AUDIO DEVICE :\n\n"
            " AWE32/64 playback requires onboard DRAM,\n"
            " Sound Blaster playback is the most compatible & better for emulation\n\n");

    for (k = 0;k < AGetAudioNumDevs();k++)
    {
      if (AGetAudioDevCaps(k,&caps) == AUDIO_ERROR_NONE)
        printf("  %2d. %s\n",k,caps.szProductName);
    }
    printf("\n");

    if (k < 10)
    {
      i = getch();
      seal_sound_card = i - '0';
    }
    else
      scanf("%d",&seal_sound_card);
  }

  /* initialize SEAL audio library */
  if (seal_sound_card == 0)     /* silence */
  {
    /* update the Machine structure to show that sound is disabled */
    seal_sample_rate = 0;
    exit(0);
    return 0;
  }

  /* open audio device */
  /* info.nDeviceId = AUDIO_DEVICE_MAPPER;*/
  info.nDeviceId = seal_sound_card;
  /* always use 16 bit mixing if possible - better quality and same speed of 8 bit */
  info.wFormat = AUDIO_FORMAT_16BITS | AUDIO_FORMAT_STEREO | AUDIO_FORMAT_RAW_SAMPLE;

  info.nSampleRate = seal_sample_rate;
  if (AOpenAudio(&info) != AUDIO_ERROR_NONE)
  {
    return (1);
  }

  AGetAudioDevCaps(info.nDeviceId,&caps);
  printf("Using `%s' at %d-bit %s %u Hz\n",
  caps.szProductName,
  info.wFormat & AUDIO_FORMAT_16BITS ? 16 : 8,
  info.wFormat & AUDIO_FORMAT_STEREO ? "stereo" : "mono",
  info.nSampleRate);

  /* open and allocate voices, allocate waveforms */
  if (AOpenVoices(NUMVOICES) != AUDIO_ERROR_NONE)
  {
    printf("voices initialization failed\n");
    return 1;
  }

  for (i = 0; i < NUMVOICES; i++)
  {
    if (ACreateAudioVoice(&hVoice[i]) != AUDIO_ERROR_NONE)
    {
      printf("voice #%d creation failed\n",i);
      return 1;
    }

    ASetVoicePanning(hVoice[i],128);

    lpWave[i] = 0;
  }

  /* update the Machine structure to reflect the actual sample rate */
  *rate = seal_sample_rate = info.nSampleRate;

  {
    uclock_t a,b;
    LONG start,end;


    if ((lpWave[0] = (LPAUDIOWAVE)malloc(sizeof(AUDIOWAVE))) == 0)
      return 1;

    lpWave[0]->wFormat = AUDIO_FORMAT_8BITS | AUDIO_FORMAT_MONO;
    lpWave[0]->nSampleRate = seal_sample_rate;
    lpWave[0]->dwLength = 3*seal_sample_rate;
    lpWave[0]->dwLoopStart = 0;
    lpWave[0]->dwLoopEnd = 3*seal_sample_rate;
    if (ACreateAudioData(lpWave[0]) != AUDIO_ERROR_NONE)
    {
      free(lpWave[0]);
      lpWave[0] = 0;

      return 1;
    }

    memset(lpWave[0]->lpData,0,3*seal_sample_rate);
    /* upload the data to the audio DRAM local memory */
    AWriteAudioData(lpWave[0],0,3*seal_sample_rate);
    APrimeVoice(hVoice[0],lpWave[0]);
    ASetVoiceFrequency(hVoice[0],seal_sample_rate);
    ASetVoiceVolume(hVoice[0],0);
    AStartVoice(hVoice[0]);

    a = uclock();
    /* wait some time to let everything stabilize */
    do
    {
      osd_update_audio();
      b = uclock();
    } while (b-a < UCLOCKS_PER_SEC/10);

    a = uclock();
    AGetVoicePosition(hVoice[0],&start);
    do
    {
      osd_update_audio();
      b = uclock();
    } while (b-a < UCLOCKS_PER_SEC);
    AGetVoicePosition(hVoice[0],&end);

    nominal_sample_rate = seal_sample_rate;
    seal_sample_rate = end - start;

    AStopVoice(hVoice[0]);
    ADestroyAudioData(lpWave[0]);
    free(lpWave[0]);
    lpWave[0] = 0;
  }

  osd_set_mastervolume(0);    /* start at maximum volume */

  return 0;
}
Esempio n. 6
0
File: alib.c Progetto: 5py/libmpg123
/* return on error leaves stuff dirty here... */
static int open_alib(audio_output_t *ao)
{
	AudioAttributes Attribs;
	AudioAttrMask   AttribsMask;
	AGainEntry      gainEntry[4];
	SSPlayParams    playParams;
	SStream	  audioStream;
	AErrorHandler   prevHandler;
	char		  server[1];
	int		  i;
	long            status;
	
	if (audioServer) {
		error("openAudio: audio already open");
		return -1;
	}
	
	prevHandler = ASetErrorHandler(myHandler);
	
	server[0] = '\0';
	audioServer = AOpenAudio( server, NULL );
	if (audioServer==NULL) {
		error("Error: could not open audio\n");
		return -1;
	}
	
	ao->fn = socket( AF_INET, SOCK_STREAM, 0 );
	if(ao->fn<0) {
		error("Socket creation failed");
		return -1;
	}
	
	Attribs.type = ATSampled;
	Attribs.attr.sampled_attr.sampling_rate = ao->rate;
	Attribs.attr.sampled_attr.channels	  = ao->channels;
	Attribs.attr.sampled_attr.data_format	  = ADFLin16;
	AttribsMask = ASSamplingRateMask | ASChannelsMask  | ASDataFormatMask;
	
	gainEntry[0].gain = AUnityGain;
	gainEntry[0].u.o.out_ch  = AOCTMono;
	gainEntry[0].u.o.out_dst = AODTDefaultOutput;
	
	playParams.gain_matrix.type = AGMTOutput;  /* gain matrix */
	playParams.gain_matrix.num_entries = 1;
	playParams.gain_matrix.gain_entries = gainEntry;
	playParams.play_volume = AUnityGain;       /* play volume */
	playParams.priority = APriorityNormal;     /* normal priority */
	playParams.event_mask = 0;                 /* don't solicit any events */
	
	xid=APlaySStream(audioServer,AttribsMask,&Attribs,
	&playParams,&audioStream,NULL);
	
	status=connect(ao->fn,
	(struct sockaddr *) &audioStream.tcp_sockaddr,
	sizeof(struct sockaddr_in) );
	if (status<0) {
		error("Connect failed");
		return -1;
	}
	
	i=-1;
	tcpProtocolEntry=getprotobyname("tcp");
	setsockopt(ao->fn,tcpProtocolEntry->p_proto,TCP_NODELAY,&i,sizeof(i));
	
	return ao->fn;
}
Esempio n. 7
0
int main(void)
{
    AUDIOINFO info;
    LPAUDIOWAVE lpWave;
    HAC hVoice[NUMVOICES];
    BOOL stopped;
    UINT n, m;

    /* initialize audio library */
    AInitialize();

    /* open audio device */
    info.nDeviceId = AUDIO_DEVICE_MAPPER;
    info.wFormat = AUDIO_FORMAT_16BITS | AUDIO_FORMAT_STEREO;
    info.nSampleRate = 44100;
    AOpenAudio(&info);

    /* load waveform file */
    ALoadWaveFile("test.wav", &lpWave, 0);

    /* open and allocate voices */
    AOpenVoices(NUMVOICES);
    for (n = 0; n < NUMVOICES; n++) {
        ACreateAudioVoice(&hVoice[n]);
        ASetVoiceVolume(hVoice[n], 64);
        ASetVoicePanning(hVoice[n], n & 1 ? 0 : 255);
    }

    /* program main execution loop */
    printf("Playing waveform, press any key to stop.\n");
    for (n = m = 0; !kbhit() && n < 48 - 7; n++) {
        /* play chord C-E-G */
        APlayVoice(hVoice[m+0], lpWave);
        APlayVoice(hVoice[m+1], lpWave);
        APlayVoice(hVoice[m+2], lpWave);
        ASetVoiceFrequency(hVoice[m+0], FREQ(aPeriodTable[n+0]));
        ASetVoiceFrequency(hVoice[m+1], FREQ(aPeriodTable[n+4]));
        ASetVoiceFrequency(hVoice[m+2], FREQ(aPeriodTable[n+7]));
        m = (m + 3) % NUMVOICES;

        /* wait until note finishes */
        do {
            /* update audio system */
            AUpdateAudio();
            AGetVoiceStatus(hVoice[0], &stopped);
        } while (!stopped);
    }

    /* stop and release voices */
    for (n = 0; n < NUMVOICES; n++) {
        AStopVoice(hVoice[n]);
        ADestroyAudioVoice(hVoice[n]);
    }
    ACloseVoices();

    /* release the waveform file */
    AFreeWaveFile(lpWave);

    /* close audio device */
    ACloseAudio();
    return 0;
}
Esempio n. 8
0
int msdos_init_sound(void)
{
#ifdef USE_SEAL
	int i;

	/* Ask the user if no soundcard was chosen */
	if (soundcard == -1)
	{
		unsigned int k;

		printf("\nSelect the audio device:\n");

		for (k = 0;k < AGetAudioNumDevs();k++)
		{
			/* don't show the AWE32, it's too slow, users must choose Sound Blaster */
			if (AGetAudioDevCaps(k,&caps) == AUDIO_ERROR_NONE &&
					strcmp(caps.szProductName,"Sound Blaster AWE32"))
				printf("  %2d. %s\n",k,caps.szProductName);
		}
		printf("\n");

		if (k < 10)
		{
			i = getch();
			soundcard = i - '0';
		}
		else
			scanf("%d",&soundcard);
	}

	/* initialize SEAL audio library */
	if (soundcard == 0)     /* silence */
	{
		/* update the Machine structure to show that sound is disabled */
		Machine->sample_rate = 0;
		return 0;
	}

	/* open audio device */
	/*                              info.nDeviceId = AUDIO_DEVICE_MAPPER;*/
	info.nDeviceId = soundcard;
	/* always use 16 bit mixing if possible - better quality and same speed of 8 bit */
	info.wFormat = AUDIO_FORMAT_16BITS | AUDIO_FORMAT_MONO | AUDIO_FORMAT_RAW_SAMPLE;

	/* use stereo output if supported */
	if (usestereo)
	{
		if (Machine->drv->sound_attributes & SOUND_SUPPORTS_STEREO)
			info.wFormat = AUDIO_FORMAT_16BITS | AUDIO_FORMAT_STEREO | AUDIO_FORMAT_RAW_SAMPLE;
	}

	info.nSampleRate = Machine->sample_rate;
	if (AOpenAudio(&info) != AUDIO_ERROR_NONE)
	{
		printf("audio initialization failed\n");
		return 1;
	}

	AGetAudioDevCaps(info.nDeviceId,&caps);
	logerror("Using %s at %d-bit %s %u Hz\n",
			caps.szProductName,
			info.wFormat & AUDIO_FORMAT_16BITS ? 16 : 8,
			info.wFormat & AUDIO_FORMAT_STEREO ? "stereo" : "mono",
			info.nSampleRate);

	/* open and allocate voices, allocate waveforms */
	if (AOpenVoices(SOUND_CHANNELS) != AUDIO_ERROR_NONE)
	{
		printf("voices initialization failed\n");
		return 1;
	}

	for (i = 0; i < SOUND_CHANNELS; i++)
	{
		lpWave[i] = 0;
	}

	stream_playing = 0;
	stream_cache_data = 0;
	stream_cache_len = 0;
	stream_cache_stereo = 0;

	/* update the Machine structure to reflect the actual sample rate */
	Machine->sample_rate = info.nSampleRate;

	logerror("set sample rate: %d\n",Machine->sample_rate);
	if (sampleratedetect)
	{
		TICKER a,b;
		LONG start,end;


		if (ACreateAudioVoice(&hVoice[0]) != AUDIO_ERROR_NONE)
			return 1;

		if ((lpWave[0] = (LPAUDIOWAVE)malloc(sizeof(AUDIOWAVE))) == 0)
		{
			ADestroyAudioVoice(hVoice[0]);
			return 1;
		}

		lpWave[0]->wFormat = AUDIO_FORMAT_8BITS | AUDIO_FORMAT_MONO;
		lpWave[0]->nSampleRate = Machine->sample_rate;
		lpWave[0]->dwLength = 3*Machine->sample_rate;
		lpWave[0]->dwLoopStart = 0;
		lpWave[0]->dwLoopEnd = 3*Machine->sample_rate;
		if (ACreateAudioData(lpWave[0]) != AUDIO_ERROR_NONE)
		{
			free(lpWave[0]);
			lpWave[0] = 0;

			return 1;
		}

		memset(lpWave[0]->lpData,0,3*Machine->sample_rate);
		/* upload the data to the audio DRAM local memory */
		AWriteAudioData(lpWave[0],0,3*Machine->sample_rate);
		APrimeVoice(hVoice[0],lpWave[0]);
		ASetVoiceFrequency(hVoice[0],Machine->sample_rate);
		ASetVoiceVolume(hVoice[0],0);
		AStartVoice(hVoice[0]);

		a = ticker();
		/* wait some time to let everything stabilize */
		do
		{
			AUpdateAudioEx(Machine->sample_rate / Machine->drv->frames_per_second);
			b = ticker();
		} while (b-a < TICKS_PER_SEC/10);

		a = ticker();
		AGetVoicePosition(hVoice[0],&start);
		do
		{
			AUpdateAudioEx(Machine->sample_rate / Machine->drv->frames_per_second);
			b = ticker();
		} while (b-a < TICKS_PER_SEC);
		AGetVoicePosition(hVoice[0],&end);
		nominal_sample_rate = Machine->sample_rate;
		Machine->sample_rate = end - start;
		logerror("actual sample rate: %d\n",Machine->sample_rate);

		AStopVoice(hVoice[0]);
		ADestroyAudioData(lpWave[0]);
		free(lpWave[0]);
		lpWave[0] = 0;
		ADestroyAudioVoice(hVoice[0]);
	}
	else
		nominal_sample_rate = Machine->sample_rate;

#if 0
	{
		char *blaster_env;
		/* Get Soundblaster base address from environment variabler BLASTER   */
		/* Soundblaster OPL base port, at some compatibles this must be 0x388 */

		if(!getenv("BLASTER"))
		{
			printf("\nBLASTER variable not found, disabling fm sound!\n");
                        No_OPL = options.no_fm = 1;
		}
		else
		{
			blaster_env = getenv("BLASTER");
			BaseSb = i = 0;
			while ((blaster_env[i] & 0x5f) != 0x41) i++;        /* Look for 'A' char */
			while (blaster_env[++i] != 0x20) {
				BaseSb = (BaseSb << 4) + (blaster_env[i]-0x30);
			}
		}
	}
#endif

#endif

#ifdef USE_ALLEGRO
	reserve_voices(1,0);
	if (install_sound(DIGI_AUTODETECT,MIDI_NONE,0) != 0)
	{
		logerror("Allegro install_sound error: %s\n",allegro_error);
		return 1;
	}

	nominal_sample_rate = Machine->sample_rate;
#endif

	num_used_opl = 0;

	osd_set_mastervolume(attenuation);	/* set the startup volume */

	return 0;
}