static PyObject *Snd_SPBCloseDevice(PyObject *_self, PyObject *_args) { PyObject *_res = NULL; OSErr _err; long inRefNum; if (!PyArg_ParseTuple(_args, "l", &inRefNum)) return NULL; _err = SPBCloseDevice(inRefNum); if (_err != noErr) return PyMac_Error(_err); Py_INCREF(Py_None); _res = Py_None; return _res; }
int audio_close(snd_node *n) { buffer_state *data = (buffer_state *)n->u.audio.descriptor; OSErr err; if (data->recording) { SPBStopRecording(data->refnum); SPBCloseDevice(data->refnum); if (data->starved) { data->starved = 0; } #ifndef TARGET_CARBON DisposeRoutineDescriptor(data->params.interruptRoutine); #endif free((void *)data->recBuffer); } else { data->finished = 1; SndCallBackUPP callBack = data->chan->callBack; err = SndDisposeChannel(data->chan, true // quiets the channel now ); #ifndef TARGET_CARBON DisposeRoutineDescriptor(callBack); #endif free((void *)data->buffer); free((void *)data->nextBuffer); } free((void *)data); return SND_SUCCESS; }
/************************************************************************* ** TestSettingDeviceInfo() ** Query information about a named input device. */ static int TestSettingDeviceInfo( const unsigned char *deviceName ) { OSErr err; long mRefNum = 0; long tempL; short tempS; Fixed tempF; err = SPBOpenDevice( deviceName, siWritePermission, &mRefNum); if (err) { PRINT(("Cound not open device!\n")); return -1; } /* Define macros for printing out device info. */ #define PrintDeviceInfo(selector,var) \ err = SPBGetDeviceInfo(mRefNum, selector, (Ptr) &var); \ if (err) { \ PRINT(("query %s failed\n", #selector )); \ }\ else { \ PRINT(("query %s = 0x%x\n", #selector, var )); \ } PrintDeviceInfo( siContinuous, tempS ); PrintDeviceInfo( siAsync, tempS ); PrintDeviceInfo( siNumberChannels, tempS ); PrintDeviceInfo( siSampleSize, tempS ); PrintDeviceInfo( siSampleRate, tempF ); PrintDeviceInfo( siChannelAvailable, tempS ); PrintDeviceInfo( siActiveChannels, tempL ); PrintDeviceInfo( siDeviceBufferInfo, tempL ); #if USE_POINTER /* Continuous Mode ---------- */ PRINT(("Attempt to set siContinuous to 1 using pointer method.\n")); tempS = 1; err = SPBSetDeviceInfo(mRefNum, siContinuous, (Ptr) &tempS); if (err) PRINT(("setting siContinuous using pointer failed\n")); PrintDeviceInfo( siContinuous, tempS ); PRINT(("Attempt to set siContinuous to 0 using pointer method.\n")); tempS = 1; err = SPBSetDeviceInfo(mRefNum, siContinuous, (Ptr) &tempS); if (err) PRINT(("setting siContinuous using pointer failed\n")); PrintDeviceInfo( siContinuous, tempS ); #else PRINT(("Attempt to set siContinuous to 1 using direct method.\n")); err = SPBSetDeviceInfo(mRefNum, siContinuous, (Ptr) 1); if (err) PRINT(("setting siContinuous using direct failed\n")); PrintDeviceInfo( siContinuous, tempS ); PRINT(("Attempt to set siContinuous to 0 using direct method.\n")); err = SPBSetDeviceInfo(mRefNum, siContinuous, (Ptr) 0); if (err) PRINT(("setting siContinuous using direct failed\n")); PrintDeviceInfo( siContinuous, tempS ); #endif /* Sample rate ----------- */ #if USE_POINTER PRINT(("Attempt to set siSampleRate to 44100 using pointer method.\n")); tempF = ((unsigned long)44100) << 16; err = SPBSetDeviceInfo(mRefNum, siSampleRate, (Ptr) &tempF); if (err) PRINT(("setting siSampleRate using pointer failed\n")); tempF = 0; PrintDeviceInfo( siSampleRate, tempF ); PRINT(("Attempt to set siSampleRate to 22050 using pointer method.\n")); tempF = ((unsigned long)22050) << 16; err = SPBSetDeviceInfo(mRefNum, siSampleRate, (Ptr) &tempF); if (err) PRINT(("setting siSampleRate using pointer failed\n")); tempF = 0; PrintDeviceInfo( siSampleRate, tempF ); #else PRINT(("Attempt to set siSampleRate to 44100 using direct method.\n")); err = SPBSetDeviceInfo(mRefNum, siSampleRate, (Ptr) (((unsigned long)44100) << 16)); if (err) PRINT(("setting siSampleRate using direct failed\n")); PrintDeviceInfo( siSampleRate, tempF ); PRINT(("Attempt to set siSampleRate to 22050 using direct method.\n")); err = SPBSetDeviceInfo(mRefNum, siSampleRate, (Ptr) (((unsigned long)44100) << 16)); if (err) PRINT(("setting siSampleRate using direct failed\n")); PrintDeviceInfo( siSampleRate, tempF ); #endif /* All done so close up device. */ if( mRefNum ) SPBCloseDevice(mRefNum); return 0; error: if( mRefNum ) SPBCloseDevice(mRefNum); return -1; }