Movatterモバイル変換


[0]ホーム

URL:


Up one LevelPython Library ReferenceContentsModule IndexIndex


35.1.1 Audio Device Objects

The audio device objects are returned byopen() define thefollowing methods (exceptcontrol objects which only providegetinfo(),setinfo(),fileno(), anddrain()):

close()
This method explicitly closes the device. It is useful in situationswhere deleting the object does not immediately close it since thereare other references to it. A closed device should not be used again.

fileno()
Returns the file descriptor associated with the device. This can beused to set upSIGPOLL notification, as described below.

drain()
This method waits until all pending output is processed and then returns.Calling this method is often not necessary: destroying the object willautomatically close the audio device and this will do an implicit drain.

flush()
This method discards all pending output. It can be used avoid theslow response to a user's stop request (due to buffering of up to onesecond of sound).

getinfo()
This method retrieves status information like input and output volume,etc. and returns it in the form ofan audio status object. This object has no methods but it contains anumber of attributes describing the current device status. The namesand meanings of the attributes are described in<sun/audioio.h> and in theaudio(7I)manual page. Member namesare slightly different from their C counterparts: a status object isonly a single structure. Members of theplay substructure have"o_" prepended to their name and members of therecordstructure have "i_". So, the C memberplay.sample_rate isaccessed aso_sample_rate,record.gain asi_gainandmonitor_gain plainly asmonitor_gain.

ibufcount()
This method returns the number of samples that are buffered on therecording side, i.e. the program will not block on aread() call of so many samples.

obufcount()
This method returns the number of samples buffered on the playbackside. Unfortunately, this number cannot be used to determine a numberof samples that can be written without blocking since the kerneloutput queue length seems to be variable.

read(size)
This method readssize samples from the audio input and returnsthem as a Python string. The function blocks until enough data is available.

setinfo(status)
This method sets the audio device status parameters. Thestatusparameter is an device status object as returned bygetinfo() andpossibly modified by the program.

write(samples)
Write is passed a Python string containing audio samples to be played.If there is enough buffer space free it will immediately return,otherwise it will block.

The audio device supports asynchronous notification of various events,through the SIGPOLL signal. Here's an example of how you might enablethis in Python:

def handle_sigpoll(signum, frame):    print 'I got a SIGPOLL update'import fcntl, signal, STROPTSsignal.signal(signal.SIGPOLL, handle_sigpoll)fcntl.ioctl(audio_obj.fileno(), STROPTS.I_SETSIG, STROPTS.S_MSG)


Up one LevelPython Library ReferenceContentsModule IndexIndex

Release 2.5.2, documentation updated on 21st February, 2008.
SeeAbout this document... for information on suggesting changes.
[8]ページ先頭

©2009-2025 Movatter.jp