Example #1
0
/* this will open a connection to the AF sound server.  If you are porting
   to a different sound format, this should do all the setup, so when we
   go to play the sample we can just do something like AFPlaySamples() or
   write(dev_audio_file_descriptor, data);
                                     */
Bool SetupSound() {
	AFSetACAttributes attributes;
	int device;
	char *server;

	device = SPEAKER;
	attributes.preempt = Mix;
	attributes.start_timeout = 0;
	attributes.end_silence = 0;
	attributes.play_gain = 0;
	attributes.rec_gain =  0;
	server=(char *)getenv("AUDIOFILE");
	if (server==NULL) server=":0";
	aud  =AFOpenAudioConn(server);
	if (aud==NULL) return FALSE;
	ac   =AFCreateAC(aud, device, ACPlayGain, &attributes);
	atime=AFGetTime(ac);
	return TRUE;
	}
Example #2
0
int init_sound (void)
{
    AFSetACAttributes   attributes;
    AFDeviceDescriptor *aDev;
    int                 device;
    
    aud = AFOpenAudioConn(NULL);
    have_sound = !(aud == NULL);
    if (!have_sound) {
	return 0;
    }
    
    for(device = 0; device < ANumberOfAudioDevices(aud); device++) {
	aDev = AAudioDeviceDescriptor(aud, device);
	rate = aDev->playSampleFreq;
	sndbufsize = (rate / 8) * 4;
	if(aDev->inputsFromPhone == 0
	   && aDev->outputsToPhone == 0
	   && aDev->playNchannels == 1)
	    break;
    }
    if (device == ANumberOfAudioDevices(aud)) {
	return 0;
    }
    
    attributes.type = LIN16;
    ac = AFCreateAC(aud, device, ACEncodingType, &attributes);
    aftime = AFGetTime(ac);

    init_sound_table16 ();
    sample_handler = sample16_handler;
    sample_evtime = (long)MAXHPOS_PAL * MAXVPOS_PAL * VBLANK_HZ_PAL / rate;

    sndbufpt = sndbuffer;
    sound_available = 1;
    printf ("Sound driver found and configured for %d bits at %d Hz, buffer is %d bytes\n", 16, rate, sndbufsize);
    return 1;
}