Beispiel #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;
	}
Beispiel #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;
}
Beispiel #3
0
/* To change for nonAF-sound, change SetupSound() and the last part
   of this function.  Change LoadFile only if you need more data stored
   when loading. (maybe sample rate, stereo on/off, etc)
                                     */
void PlaySoundFile(char *filename, int forked) {
	static int sound_is_setup=FALSE;
	struct Sound *sound;
	
	DEBUG(D_CALLS) printf("PlaySoundFile: %s\n",filename);
	if (!sound_is_setup || forked) {
		DEBUG(D_CHECKP) printf("PSF: Connecting to AF server\n");
		Zero(&InMemList, sizeof(InMemList));
		if (!SetupSound()) {
			printf("Could not connect to sound server.\n");
			return;
			}
		sound_is_setup=TRUE;
		}
	sound=(struct Sound *) LoadFile(filename);
	DEBUG(D_CHECKP) printf("PSF: Loaded %s into %d\n",filename, sound);
	if (sound==NULL) return;

	/* this part is sound-device dependant */
	DEBUG(D_CHECKP) printf("PSF: Actually playing now!\n");
	atime=AFGetTime(ac);
	AFPlaySamples(ac, atime+PLAY_DELAY, sound->size, (unsigned char *)sound->data);
	}