PaError PaHost_CloseStream( internalPortAudioStream *past ) { PaHostSoundControl *pahsc; if( past == NULL ) return paBadStreamPtr; pahsc = (PaHostSoundControl *) past->past_DeviceData; if( pahsc == NULL ) return paNoError; DSW_Term( &pahsc->pahsc_DSoundWrapper ); if( pahsc->pahsc_NativeBuffer ) { PaHost_FreeFastMemory( pahsc->pahsc_NativeBuffer, pahsc->pahsc_BytesPerBuffer ); /* MEM */ pahsc->pahsc_NativeBuffer = NULL; } PaHost_FreeFastMemory( pahsc, sizeof(PaHostSoundControl) ); /* MEM */ past->past_DeviceData = NULL; return paNoError; }
PaError PaHost_Term( void ) { /* Free all of the linked devices. */ internalPortAudioDevice *pad, *nextPad; pad = sDeviceList; while( pad != NULL ) { nextPad = pad->pad_Next; DBUG(("PaHost_Term: freeing %s\n", pad->pad_DeviceName )); PaHost_FreeFastMemory( pad, sizeof(internalPortAudioDevice) ); pad = nextPad; } sDeviceList = NULL; return 0; }
PaError PaHost_Term( void ) { int i; /* Free names allocated during enumeration. */ for( i=0; i<sNumDevices; i++ ) { if( sDevices[i].pad_Info.name != NULL ) { free( (void *) sDevices[i].pad_Info.name ); sDevices[i].pad_Info.name = NULL; } } if( sDevices != NULL ) { PaHost_FreeFastMemory( sDevices, sNumDevices * sizeof(internalPortAudioDevice) ); /* MEM */ sDevices = NULL; sNumDevices = 0; } return 0; }
/* Build linked a list with all the available audio devices on this SGI machine (only 1 for now). */ PaError PaHost_Init(void) /* Called by Pa_Initialize() from pa_lib.c. */ { internalPortAudioDevice* pad; PaError r = paNoError; int audioLibFileID; /* To test for the presence of audio. */ if (sDeviceList) /* Allow re-init, only warn, no error. */ { ERR_RPT(("Warning: PaHost_Init() did not really re-init PA.\n")); return r; } /*------------- ADD THE SGI DEFAULT DEVICE TO THE LIST: ---------------------------------------*/ audioLibFileID = open("/dev/hdsp/hdsp0master", O_RDONLY); /* Try to open Indigo style audio */ if (audioLibFileID < 0) /* IO port. On failure, machine */ { /* has no audio ability. */ ERR_RPT(("PaHost_Init(): This machine has no (Indigo-style) audio abilities.\n")); return paHostError; } close(audioLibFileID); /* Allocate fast mem to hold device info. */ pad = PaHost_AllocateFastMemory(sizeof(internalPortAudioDevice)); if (pad == NULL) return paInsufficientMemory; memset(pad, 0, sizeof(internalPortAudioDevice)); /* "pad->pad_Next = NULL" is more elegant. */ r = Pa_sgiQueryDevice(AL_DEFAULT_DEVICE, /* Set AL device num (AL_DEFAULT_DEVICE). */ Pa_GetDefaultOutputDeviceID(),/* Set PA device num (or InputDeviceID()). */ "AL default", /* A suitable name. */ pad); /* Write args and queried info into pad. */ if (r != paNoError) { ERR_RPT(("Pa_QueryDevice for '%s' returned: %d\n", pad->pad_DeviceName, r)); PaHost_FreeFastMemory(pad, sizeof(internalPortAudioDevice)); /* sDeviceList still NULL ! */ } else sDeviceList = pad; /* First element in linked list. pad->pad_Next already NULL. */ /*------------- QUERY AND ADD MORE POSSIBLE SGI DEVICES TO THE LINKED LIST: -------------------*/ /*---------------------------------------------------------------------------------------------*/ return r; }
/********************************************************************* * Determines the number of available devices by trying to open * each "/dev/dsp#" or "/dsp/audio#" in order until it fails. * Add each working device to a singly linked list of devices. */ PaError Pa_QueryDevices( void ) { internalPortAudioDevice *pad, *lastPad; int go = 1; int numDevices = 0; PaError testResult; PaError result = paNoError; char *envdev; sDefaultInputDeviceID = paNoDevice; sDefaultOutputDeviceID = paNoDevice; lastPad = NULL; while( go ) { /* Allocate structure to hold device info. */ pad = (internalPortAudioDevice *) PaHost_AllocateFastMemory( sizeof(internalPortAudioDevice) ); if( pad == NULL ) return paInsufficientMemory; memset( pad, 0, sizeof(internalPortAudioDevice) ); /* Build name for device. */ if( numDevices == 0 ) { sprintf( pad->pad_DeviceName, DEVICE_NAME_BASE); } else { sprintf( pad->pad_DeviceName, DEVICE_NAME_BASE "%d", numDevices ); } DBUG(("Try device %s\n", pad->pad_DeviceName )); testResult = Pa_QueryDevice( pad->pad_DeviceName, pad ); DBUG(("Pa_QueryDevice returned %d\n", testResult )); if( testResult != paNoError ) { if( lastPad == NULL ) { result = testResult; /* No good devices! */ } go = 0; PaHost_FreeFastMemory( pad, sizeof(internalPortAudioDevice) ); } else { numDevices += 1; /* Add to linked list of devices. */ if( lastPad ) { lastPad->pad_Next = pad; } else { sDeviceList = pad; /* First element in linked list. */ } lastPad = pad; } } /* I'm sitting at a SunRay1 and I neither have /dev/audio# nor /dev/dsp#. Instead, the correct audio device is stored in the environment variable AUDIODEV and/or UTAUDIODEV, so check these devices as well if we haven't checked them yet above - MR */ DBUG(("Checking for AUDIODEV and UTAUDIODEV\n")); envdev = getenv("AUDIODEV"); if (envdev != NULL && !strstr(envdev, DEVICE_NAME_BASE)) { result = paNoError; /* Allocate structure to hold device info. */ pad = (internalPortAudioDevice *) PaHost_AllocateFastMemory( sizeof(internalPortAudioDevice) ); if( pad == NULL ) return paInsufficientMemory; memset( pad, 0, sizeof(internalPortAudioDevice) ); /* Build name for device. */ strcpy(pad->pad_DeviceName, envdev); DBUG(("Try device %s\n", pad->pad_DeviceName )); testResult = Pa_QueryDevice( pad->pad_DeviceName, pad ); DBUG(("Pa_QueryDevice returned %d\n", testResult )); if( testResult != paNoError ) { if( lastPad == NULL ) { result = testResult; /* No good devices! */ } PaHost_FreeFastMemory( pad, sizeof(internalPortAudioDevice) ); } else { numDevices += 1; /* Add to linked list of devices. */ if( lastPad ) { lastPad->pad_Next = pad; } else { sDeviceList = pad; /* First element in linked list. */ } lastPad = pad; } } envdev = getenv("UTAUDIODEV"); if (envdev != NULL && !strstr(envdev, DEVICE_NAME_BASE) && getenv("AUDIODEV") != NULL && strcmp(envdev, getenv("AUDIODEV"))) { result = paNoError; /* Allocate structure to hold device info. */ pad = (internalPortAudioDevice *) PaHost_AllocateFastMemory( sizeof(internalPortAudioDevice) ); if( pad == NULL ) return paInsufficientMemory; memset( pad, 0, sizeof(internalPortAudioDevice) ); /* Build name for device. */ strcpy(pad->pad_DeviceName, envdev); DBUG(("Try device %s\n", pad->pad_DeviceName )); testResult = Pa_QueryDevice( pad->pad_DeviceName, pad ); DBUG(("Pa_QueryDevice returned %d\n", testResult )); if( testResult != paNoError ) { if( lastPad == NULL ) { result = testResult; /* No good devices! */ } PaHost_FreeFastMemory( pad, sizeof(internalPortAudioDevice) ); } else { numDevices += 1; /* Add to linked list of devices. */ if( lastPad ) { lastPad->pad_Next = pad; } else { sDeviceList = pad; /* First element in linked list. */ } lastPad = pad; } } return result; }