[ Previous | Next | Contents | Glossary | Home | Search ]
Ultimedia Services Version 2 for AIX: Programmer's Guide and Reference

UMSAudioFile Object

The UMSAudioFile object is a base class. Specific audio file implementations inherit their interface from this class. Objects, such as the UMSAudioPlayer, and applications can achieve audio file-type independence by accessing audio file data through the methods of the base class. This allows the application to transparently support any audio file types for which a UMSAudioFile object is provided without knowing the specific object implementation being used.

A metaclass is provided with a method to construct a specific audio file based on a user specified path name to an audio file, a Detector alias, and data in the configuration file. The construction method in the metaclass invokes the series of detectors specified by the Detector alias. If the file type is recognized by one of the detectors, the corresponding specific audio file object is instantiated and returned. This allows applications to be extended to support new audio file types by adding new audio file objects and corresponding detectors.

Note that this is the preferred construction technique for applications. Alternatively, a specific audio file object can be constructed using the ObjectNameNew method.

The object presents the paradigm that the file consists of a length of audio data. The file position can be set by seeking to an offset within the data where the offset is specified as bytes, samples, or milliseconds. Specific implementations may have an underlying structure that allows storing of attributes, such as sample rate and format. These implementations respond with True to the has_attributes query. Implementations that have attributes initialize the object attributes based on data that is in an existing file or save the attribute settings to files that are being created.

To learn more about the UMSAudioFile object, see:

For introductory information, see Formatted File Access Objects.

Enumeration Lists

To avoid name collision on defines, integer values have been captured as enumerated lists. The set of valid values from an enumerated list may vary with the application. The detailed method descriptions describe the valid or possible values for the specific use. The enumerated lists that are defined for this object are listed as follows:

enum ReturnCode { 
   Success, 
   Failure, 
   InvalidTimeFormat, 
   FormatChange,
   EndOfFile, 
   UnsupportedFormat, 
   MemoryError,
   OutOfRange,
   InsufficientBufferLength, 
   };

The UMSAudioFile object also uses the following enumerated list defined in UMSAudioTypes.idl.

enum TimeFormat { 
   Msecs, 
   Bytes, 
   Samples 
   };

Method Descriptions

ReturnCode open(in string path, in long oflag, in long filemode)

Description

This method opens a file. If the file does not exist and the proper oflags are specified then the file will be created. If the file exists then it is opened. If the specific file implementation supports storage of audio parameters, the objects audio parameters are initialized based on the contents of the file. The file position is set to the beginning of the audio data. The preferred method of opening existing files is via the metaclass make_by_pathname method which constructs the specific UMSAudioFile object and returns the object with the file opened. The preferred method of opening a new file is to construct the specific object using the metaclass make_by_alias method and then use the open method with appropriate flags to create the file.

Arguments
in string path The pathname of the file to open is provided in the string parameter.
in long oflag Standard UNIX O_flags defined in <fcntl.h>.
in long filemode Standard UNIX filemode flags defined in <sys/mode.h>.
Return Values
Success
Failure

ReturnCode close()

Description

All data and headers are written to the file and the file is closed.

Return Values
Success
Failure

ReturnCode status_ok()

Description

This method checks the status of the last file operation. If the operation was successful, then Success is returned, otherwise, Failure is returned.

Return Values
Success
Failure

ReturnCode seek(in long position, in UMSAudioTypes::TimeFormat tformat)

Description

This method seeks to a location specified by position. The position is interpreted based on the value of the tformat parameter to be Msecs, Bytes, or Samples. The seek position is relative to the start of the audio data in the file.

Arguments
in long position The requested seek position in units of the specified time format.
in UMSAudioTypes::TimeFormat tformat The specified time units of Msecs, Bytes, or Samples.
Return Values
Success
Failure
InvalidTimeFormat
OutOfRange  

ReturnCode get_position(in UMSAudioTypes::TimeFormat tformat, inout long pos)

Description

The current file position is returned in the position parameter in the time units specified by the tformat parameter.

Arguments
in UMSAudioTypes::TimeFormat tformat The specified time units of Msecs, Bytes, or Samples.
inout long pos The requested seek position in units of the specified time format.
Return Values
Success
Failure
InvalidTimeFormat

ReturnCode get_length(in UMSAudioTypes::TimeFormat tformat, inout long length)

Description

The file length is returned in the length parameter in the time units specified by the tformat parameter. Length is presented as the length of audio data contained in the file.

Arguments
in UMSAudioTypes::TimeFormat tformat The specified time units of Msecs, Bytes, or Samples.
inout long length The file length in units of the specified time format.
Return Values
Success
Failure
InvalidTimeFormat

ReturnCode read(inout sequence<octet> buf, in long samples, inout long samples_read)

Description

This method returns audio data in the buffer sequence provided. The data returned is from the current file position and of the length reported in the samples_read parameter. The samples_requested parameter input specifies the desired number of samples to read. The length is specified in samples to enforce sample bounded access to the data. If an end of file condition occurs prior to the requested samples being read, the read is terminated, a ReturnCode value of EndOfFile is returned, and samples_read is set to the actual number of samples returned. For stereo data a sample includes the data for both the left and right channel. The current file position is advanced by the number of samples read. A file object can support midstream format changes by returning data up to the format change and setting ReturnCode to FormatChange. No further data should be returned until the application queries the changed attributes.

Arguments
inout sequence<octet> buf This sequence provides the buffer to receive the requested data. buffer._maximum must indicate that the buffer at buffer._buffer is of sufficient size to receive the requested data or the read will be truncated to the maximum buffer size. buffer._length will be set to the length of the returned data in bytes.
in long samples The number of samples requested is provided as input.
inout long samples_read The number of samples actually read is returned.
Return Values
Success
Failure
InsufficientBufferLength
FormatChange
EndOfFile

ReturnCode write(in sequence<octet> buf, in long samples, inout long samples_written)

Description

This method writes the audio data provided in the buffer to the file. The data written is inserted at the current file position and of the length reported in the samples_written parameter. The samples_to_write parameter specifies the desired number of samples to write. The length is specified in samples to enforce sample bounded access to the data. For stereo data a sample includes the data for both the left and right channel. The current file position is advanced by the number of samples written.

Arguments
in sequence<octet> buf This sequence provides a buffer containing the data to be written. buffer._length must specify a length sufficient to contain the specified samples_to_write or the write will be truncated to the buffer._length size. The data to be written must be provided at the address specified by buffer._buffer.
in long samples The number or samples to write is specified on input.
inout long samples_written The number of samples actually written is returned.
Return Values
Success
Failure
MemoryError

ReturnCode get_file_type(out string file_alias)

Description

The filetype alias is returned as a string. The specific UMSAudioDevice class should be registered under this alias in the configuration file.

Arguments
out string file_alias A string containing the filetype alias.
Return Values
Success
Failure
MemoryError

ReturnCode has_attributes(inout boolean attributes)

Description

Specific UMSAudioFile implementations may or may not support storage of audio attributes in the file format. This method is provided to query whether the object supports attribute storage.

Arguments
inout boolean attributes Returned with a TRUE value if attributes are supported.
Return Values
Success
Failure

ReturnCode set_byte_order(in string byte_order)

Description

This method allows the user to specify the byte order for data received on read or supplied on write. The format that the data is actually stored in the file may be different than this. For example, by convention WAVE files always use MSB byte order and SND files always use LSB order. In these cases a user specified byte order that conflicts with the file standard simply causes the data to/from the user to be converted.

Arguments
in string byte_order A string specifying the desired byte order. Supported values are MSB and LSB for Big Endian and Little Endian respectively.
Return Values
Success
Failure

ReturnCode get_byte_order(out string byte_order)

Description

The current setting of byte order is returned.

Arguments
out string byte_order string specifying the desired byte order. Supported values are MSB and LSB for Big Endian and Little Endian respectively.
Return Values
Success
Failure

ReturnCode set_number_format(in string nfs)

Description

This method sets the number format to the value specified by the number_format_string parameter. If this is different than data in the file a ReturnCode value of UnsupportedFormat is returned. It is a convention to use signed for 8-bit data and twos complement for 16-bit data.

Arguments
in string nfs A string specifying the number format for the audio data. Possible values are unsigned, signed, and twos complement.
Return Values
Success
Failure
UnsupportedFormat
MemoryError

ReturnCode get_number_format(out string number_format)

Description

This method returns a string indicating the current number format for audio data.

Arguments
out string number_format A string specifying the number format for the audio data. Possible values are unsigned, signed and twos complement.
Return Values
Success
Failure
MemoryError

ReturnCode set_audio_format_type(in string afs)

Description

This method sets the audio format to the value specified by the audio_format_string parameter. If this is different than data in the file a ReturnCode value of UnsupportedFormat is returned. Possible values for WAV and SND audio file objects are PCM, A-law, and mu-law. The list of file formats supported by a file object is contained in the configuration file under the audio_formats_alias for the file object. This method selects the audio format to use by specifying one of the properties of the audio_formats_alias.

Arguments
in string afs A string specifying the audio format for the audio data.
Return Values
Success
Failure
UnsupportedFormat
MemoryError

ReturnCode get_audio_format_type(out string format)

Description

This method returns a string indicating the current format for audio data. Possible values for WAV and SND audio file objects are PCM, A-law, and mu-law. The list of file formats supported by a file object is contained in the configuration file under the audio_formats_alias for the file object.

Arguments
out string format A string specifying the number format for the audio data.
Return Values
Success
Failure
MemoryError

ReturnCode set_samples_per_second(in long sps)

Description

The method sets the sample rate for audio data. This overrides an attribute value extracted from the file. If the setting is different than the file data, the file may be corrupted at close. In general, this method should not be used on file objects that support attributes unless the file is being created.

Arguments
in long sps The specified sample rate in samples per second.
Return Values
Success
Failure

ReturnCode get_samples_per_second(inout long sps)

Description

The current sample rate is returned in the samples_per_second parameter.

Arguments
inout long sps The current sample rate in samples per second.
Return Values
Success
Failure

ReturnCode set_bits_per_sample(in long bps)

Description

The method sets the bits per sample attribute for audio data. This overrides an attribute value extracted from the file. Since the object provides file creation/modification capability the setting specified should match the data content of the file. In general, this method should not be used on file objects that support attributes unless the file is being created.

Arguments
in long bps The specified bits per sample attribute for audio data.
Return Values
Success
Failure

ReturnCode get_bits_per_sample(inout long bps)

Description

The number of bits per sample of audio data is returned in the bits_per_sample parameter. Even though sample boundaries for stereo data includes data for the left and right channel, the number of bits per sample reports the bits in only 1 channel (for example, 8-bit mu-law data is 8 bits per sample regardless of whether it is mono or stereo).

Arguments
inout long bps The number of bits per sample of audio data.
Return Values
Success
Failure

ReturnCode set_number_of_channels(in long chan)

Description

The method sets the number of channels for audio data. This overrides an attribute value extracted from the file. If the setting is different than the file data, the file may be corrupted at close. In general, this method should not be used on file objects that support attributes unless the file is being created.

Arguments
in long chan The specified value for the number of channels attribute for audio data.
Return Values
Success
Failure

ReturnCode get_number_of_channels(inout long chan)

Description

The value of the number of channels attribute is returned.

Arguments
inout long chan The current channels value for the audio data is returned.
Return Values
Success
Failure

For introductory information, see Formatted File Access Objects.


[ Previous | Next | Contents | Glossary | Home | Search ]