📄 sound.h
字号:
/** Create a sound channel. Create a reference to the sound drivers for the platform. */ PSoundChannel( const PString & device, /// Name of sound driver/device Directions dir, /// Sound I/O direction unsigned numChannels = 1, /// Number of channels eg mono/stereo unsigned sampleRate = 8000, /// Samples per second unsigned bitsPerSample = 16 /// Number of bits per sample ); // ~PSoundChannel(); // Destroy and close the sound driver //@} /**@name Open functions */ //@{ /**Get all of the names for sound devices/drivers that are available on this platform. Note that a named device may not necessarily do both playing and recording so the arrays returned with the #dir# parameter in each value is not necessarily the same. @return An array of platform dependent strings for each sound player/recorder. */ static PStringArray GetDeviceNames( Directions dir // Sound I/O direction ); /**Get the name for the default sound devices/driver that is on this platform. Note that a named device may not necessarily do both playing and recording so the arrays returned with the #dir# parameter in each value is not necessarily the same. @return A platform dependent string for the sound player/recorder. */ static PString GetDefaultDevice( Directions dir // Sound I/O direction ); /**Open the specified device for playing or recording. The device name is platform specific and is as returned in the GetDevices() function. @return TRUE if the sound device is valid for playing/recording. */ BOOL Open( const PString & device, /// Name of sound driver/device Directions dir, /// Sound I/O direction unsigned numChannels = 1, /// Number of channels eg mono/stereo unsigned sampleRate = 8000, /// Samples per second unsigned bitsPerSample = 16 /// Number of bits per sample ); /**Abort the background playing/recording of the sound channel. @return TRUE if the sound has successfully been aborted. */ BOOL Abort(); //@} /**@name Channel set up functions */ //@{ /**Set the format for play/record. Note that linear PCM data is the only one supported at this time. Note that if the PlayFile() function is used, this may be overridden by information in the file being played. @return TRUE if the format is valid. */ BOOL SetFormat( unsigned numChannels = 1, /// Number of channels eg mono/stereo unsigned sampleRate = 8000, /// Samples per second unsigned bitsPerSample = 16 /// Number of bits per sample ); /**Set the internal buffers for the sound channel I/O. Note that with Linux OSS, the size is always rounded up to the nearest power of two, so 20000 => 32768. @return TRUE if the sound device is valid for playing/recording. */ BOOL SetBuffers( PINDEX size, /// Size of each buffer PINDEX count = 2 /// Number of buffers ); /**Get the internal buffers for the sound channel I/O. @return TRUE if the buffer size were obtained. */ BOOL GetBuffers( PINDEX & size, // Size of each buffer PINDEX & count // Number of buffers ); //@} /**@name Play functions */ //@{ /**Play a sound to the open device. If the #wait# parameter is TRUE then the function does not return until the file has been played. If FALSE then the sound play is begun asynchronously and the function returns immediately. Note if the driver is closed of the object destroyed then the sound play is aborted. Also note that not all possible sounds and sound files are playable by this library. No format conversions between sound object and driver are performed. @return TRUE if the sound is playing or has played. */ BOOL PlaySound( const PSound & sound, /// Sound to play. BOOL wait = TRUE /// Flag to play sound synchronously. ); /**Play a sound file to the open device. If the #wait# parameter is TRUE then the function does not return until the file has been played. If FALSE then the sound play is begun asynchronously and the function returns immediately. Note if the driver is closed of the object destroyed then the sound play is aborted. Also note that not all possible sounds and sound files are playable by this library. No format conversions between sound object and driver are performed. @return TRUE if the sound is playing or has played. */ BOOL PlayFile( const PFilePath & file, /// Sound file to play. BOOL wait = TRUE /// Flag to play sound synchronously. ); /**Indicate if the sound play begun with PlayBuffer() or PlayFile() has completed. @return TRUE if the sound has completed playing. */ BOOL HasPlayCompleted(); /**Block the thread until the sound play begun with PlayBuffer() or PlayFile() has completed. @return TRUE if the sound has successfully completed playing. */ BOOL WaitForPlayCompletion(); //@} /**@name Record functions */ //@{ /**Record into the sound object all of the buffer's of sound data. Use the SetBuffers() function to determine how long the recording will be made. For the Win32 platform, the most efficient way to record a PSound is to use the SetBuffers() function to set a single buffer of the desired size and then do the recording. For Linux OSS this can cause problems as the buffers are rounded up to a power of two, so to gain more accuracy you need a number of smaller buffers. Note that this function will block until all of the data is buffered. If you wish to do this asynchronously, use StartRecording() and AreAllrecordBuffersFull() to determine when you can call RecordSound() without blocking. @return TRUE if the sound has been recorded. */ BOOL RecordSound( PSound & sound /// Sound recorded ); /**Record into the platform dependent sound file all of the buffer's of sound data. Use the SetBuffers() function to determine how long the recording will be made. Note that this function will block until all of the data is buffered. If you wish to do this asynchronously, use StartRecording() and AreAllrecordBuffersFull() to determine when you can call RecordSound() without blocking. @return TRUE if the sound has been recorded. */ BOOL RecordFile( const PFilePath & file /// Sound file recorded ); /**Start filling record buffers. The first call to Read() will also initiate the recording. @return TRUE if the sound driver has successfully started recording. */ BOOL StartRecording(); /**Determine if a record buffer has been filled, so that the next Read() call will not block. Provided that the amount of data read is less than the buffer size. @return TRUE if the sound driver has filled a buffer. */ BOOL IsRecordBufferFull(); /**Determine if all of the record buffer allocated has been filled. There is an implicit Abort() of the recording if this occurs and recording is stopped. The channel may need to be closed and opened again to start a new recording. @return TRUE if the sound driver has filled a buffer. */ BOOL AreAllRecordBuffersFull(); /**Block the thread until a record buffer has been filled, so that the next Read() call will not block. Provided that the amount of data read is less than the buffer size. @return TRUE if the sound driver has filled a buffer. */ BOOL WaitForRecordBufferFull(); /**Block the thread until all of the record buffer allocated has been filled. There is an implicit Abort() of the recording if this occurs and recording is stopped. The channel may need to be closed and opened again to start a new recording. @return TRUE if the sound driver has filled a buffer. */ BOOL WaitForAllRecordBuffersFull(); //@} private: void Construct();#ifdef DOC_PLUS_PLUS};#endif// Class declaration continued in platform specific header file ///////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -