/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 1992-2002 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #ifndef _MULTIMEDIA_AUDIO_H #define _MULTIMEDIA_AUDIO_H #include #include #include #ifdef __cplusplus extern "C" { #endif // Error-handling function declaration class Audio; typedef Boolean (*AudioErrfunc)(const Audio*, AudioError, AudioSeverity, const char *); // Data transfer subcodes. // Returned from ReadData(), WriteData(), AsyncCopy(), Copy() in err.sys enum AudioCopyFlag { AUDIO_COPY_SHORT_INPUT = 100, // AUDIO_SUCCESS: input would block AUDIO_COPY_ZERO_LIMIT = 101, // AUDIO_SUCCESS: length was zero AUDIO_COPY_SHORT_OUTPUT = 102, // AUDIO_SUCCESS: only partial output AUDIO_COPY_INPUT_EOF = 103, // AUDIO_EOF: eof on input AUDIO_COPY_OUTPUT_EOF = 104 // AUDIO_EOF: eof on output }; // This is the abstract base class from which all audio data types derive. // It is invalid to create an object of type Audio. class Audio { private: static int idctr; // id seed value int id; // object id number int refcnt; // reference count char *name; // name Double readpos; // current read position ptr Double writepos; // current write position ptr AudioErrfunc errorfunc; // address of error function protected: void SetName(const char *str); // Set name string // Set position Double setpos( Double& pos, // position field to update Double newpos, // new position Whence w = Absolute); // Absolute || Relative // XXX - should these be protected? public: int getid() const; // Get id value // Raise error code virtual AudioError RaiseError( AudioError code, // error code AudioSeverity sev = Error, // error severity const char *msg = "unknown error") const; // error message // Raise error msg virtual void PrintMsg( char *msg, // error code AudioSeverity sev = Message) const; // error severity public: Audio(const char *str = ""); // Constructor virtual ~Audio(); // Destructor void Reference(); // Increment ref count void Dereference(); // Decrement ref count Boolean isReferenced() const; // TRUE if referenced virtual char *GetName() const; // Get name string // Set user error func virtual void SetErrorFunction( AudioErrfunc func); // return TRUE if non-fatal virtual Double ReadPosition() const; // Get read position virtual Double WritePosition() const; // Get write position // Set read position virtual Double SetReadPosition( Double pos, // new position Whence w = Absolute); // Absolute || Relative // Set write position virtual Double SetWritePosition( Double pos, // new position Whence w = Absolute); // Absolute || Relative // Read from current pos virtual AudioError Read( void* buf, // buffer to fill size_t& len); // buffer length (updated) // Write to current pos virtual AudioError Write( void* buf, // buffer to copy size_t& len); // buffer length (updated) // XXX - no Append() method for now because of name clashes // methods specialized by inherited classes virtual AudioHdr GetHeader() = 0; // Get header virtual AudioHdr GetDHeader(Double); // Get header at pos virtual Double GetLength() const = 0; // Get length, in secs // Read from position virtual AudioError ReadData( void* buf, // buffer to fill size_t& len, // buffer length (updated) Double& pos) = 0; // start position (updated) // Write at position virtual AudioError WriteData( void* buf, // buffer to copy size_t& len, // buffer length (updated) Double& pos) = 0; // start position (updated) // Write and extend virtual AudioError AppendData( void* buf, // buffer to copy size_t& len, // buffer length (updated) Double& pos); // start position (updated) // copy to another audio obj. virtual AudioError Copy( Audio* ap); // dest audio object // copy to another audio obj. virtual AudioError Copy( Audio* ap, // dest audio object Double& frompos, Double& topos, Double& limit); // copy to another audio obj. virtual AudioError AsyncCopy( Audio* ap, // dest audio object Double& frompos, Double& topos, Double& limit); // Define default classification routines // The appropriate routine should be specialized by each leaf class. virtual Boolean isFile() const { return (FALSE); } virtual Boolean isDevice() const { return (FALSE); } virtual Boolean isDevicectl() const { return (FALSE); } virtual Boolean isPipe() const { return (FALSE); } virtual Boolean isBuffer() const { return (FALSE); } virtual Boolean isExtent() const { return (FALSE); } virtual Boolean isList() const { return (FALSE); } }; #include #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_AUDIO_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1992-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_AUDIOBUFFER_H #define _MULTIMEDIA_AUDIOBUFFER_H #include #ifdef __cplusplus extern "C" { #endif // This is the class describing a mapped buffer of audio data. // In addition to the standard Read and Write methods, the address // of the buffer may be obtained and the data accessed directly. class AudioBuffer : public AudioStream { private: Double buflen; // buffer size, in seconds int zflag; // malloc'd with zmalloc? protected: size_t bufsize; // buffer size, in bytes void* bufaddr; // buffer address // class AudioStream methods specialized here virtual Boolean opened() const; // TRUE, if open virtual AudioError alloc(); // Allocate buffer public: // Constructor AudioBuffer( double len = 0., // buffer size, in seconds const char *name = "(buffer)"); // name ~AudioBuffer(); // Destructor virtual void* GetAddress() const; // Get buffer address virtual void* GetAddress(Double) const; // Get address at offset virtual AudioError SetSize(Double len); // Change buffer size virtual Double GetSize() const; // Get buffer size virtual size_t GetByteCount() const; // Get size, in bytes // class AudioStream methods specialized here // Set header virtual AudioError SetHeader( const AudioHdr& h); // header to copy // Set data length virtual void SetLength( Double len); // new length, in secs // class Audio methods specialized here // Read from position virtual AudioError ReadData( void* buf, // buffer to fill size_t& len, // buffer length (updated) Double& pos); // start position (updated) // Write at position virtual AudioError WriteData( void* buf, // buffer to copy size_t& len, // buffer length (updated) Double& pos); // start position (updated) // Append at position virtual AudioError AppendData( void* buf, // buffer to copy size_t& len, // buffer length (updated) Double& pos); // start position (updated) // copy to another audio obj. virtual AudioError AsyncCopy( Audio* to, // dest audio object Double& frompos, Double& topos, Double& limit); virtual Boolean isBuffer() const { return (TRUE); } }; #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_AUDIOBUFFER_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1992-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_AUDIODEBUG_H #define _MULTIMEDIA_AUDIODEBUG_H #include #include #ifdef __cplusplus extern "C" { #endif // Declare default message printing routine Boolean AudioStderrMsg(const Audio *, AudioError, AudioSeverity, const char *); #ifdef DEBUG EXTERN_FUNCTION(void AudioDebugMsg, (int, char *fmt, DOTDOTDOT)); #endif EXTERN_FUNCTION(void SetDebug, (int)); EXTERN_FUNCTION(int GetDebug, ()); #ifdef DEBUG #define AUDIO_DEBUG(args) AudioDebugMsg args #else #define AUDIO_DEBUG(args) #endif /* !DEBUG */ #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_AUDIODEBUG_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #ifndef _MULTIMEDIA_AUDIOERROR_H #define _MULTIMEDIA_AUDIOERROR_H #include #include #include /* to get enum for error codes */ #ifdef __cplusplus extern "C" { #endif #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */ #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */ #endif #define _MGET_(str) (char *)dgettext(TEXT_DOMAIN, str) #define _GETTEXT_(str) (char *)gettext(str) // The AudioError class allows various interesting automatic conversions class AudioError { private: audioerror_t code; // error code public: int sys; // system error code AudioError(const AudioError&) = default; inline AudioError(audioerror_t val = AUDIO_SUCCESS): // Constructor code(val), sys(0) { if (code == AUDIO_UNIXERROR) sys = errno; } inline AudioError(int val): // Constructor from int code((audioerror_t)val), sys(0) { if (code == AUDIO_UNIXERROR) sys = errno; } inline AudioError operator = (AudioError val) // Assignment { code = val.code; sys = val.sys; return (*this); } inline operator int() // Cast to integer { return (code); } inline int operator == (audioerror_t e) // Compare { return (code == e); } inline int operator != (audioerror_t e) // Compare { return (code != e); } inline int operator == (AudioError e) // Compare { return ((code == e.code) && (sys == e.sys)); } inline int operator != (AudioError e) // Compare { return ((code != e.code) || (sys != e.sys)); } char *msg(); // Return error string }; #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_AUDIOERROR_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1990-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_AUDIOEXTENT_H #define _MULTIMEDIA_AUDIOEXTENT_H #include #include #ifdef __cplusplus extern "C" { #endif // This class defines an extent of a referenced audio class class AudioExtent : public Audio { private: Audio* ref; // reference to audio object Double start; // start time Double end; // end time AudioExtent operator=(AudioExtent); // Assignment is illegal public: // Constructor AudioExtent( Audio* obj, // audio object double s = 0., // start time double e = AUDIO_UNKNOWN_TIME); // end time virtual ~AudioExtent(); // Destructor Audio* GetRef() const; // Get audio obj void SetRef(Audio* r); // Set audio obj Double GetStart() const; // Get start time void SetStart(Double s); // Set start time Double GetEnd() const; // Get end time void SetEnd(Double e); // Set end time // class Audio methods specialized here virtual Double GetLength() const; // Get length, in secs virtual char *GetName() const; // Get name string virtual AudioHdr GetHeader(); // Get header virtual AudioHdr GetHeader(Double pos); // Get header at pos // Read from position virtual AudioError ReadData( void* buf, // buffer to fill size_t& len, // buffer length (updated) Double& pos); // start position (updated) // Write is prohibited virtual AudioError WriteData( void* buf, // buffer to copy size_t& len, // buffer length (updated) Double& pos); // start position (updated) virtual Boolean isExtent() const { return (TRUE); } }; #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_AUDIOEXTENT_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1992-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_AUDIOFILE_H #define _MULTIMEDIA_AUDIOFILE_H #ifdef NO_EXTERN_C #ifdef __cplusplus extern "C" { #endif #endif /* NO_EXTERN_C */ #include #include #include // A 'primitive type' for memory mapped file access types enum vmaccess_t { NormalAccess = 0, RandomAccess = 1, SequentialAccess = 2 }; class VMAccess { private: vmaccess_t type; // combined mode public: VMAccess(vmaccess_t x = NormalAccess): type(x) { } // Constructor inline operator vmaccess_t() // Cast to enum { return (type); } inline operator int() { // Cast to integer switch (type) { case RandomAccess: return (MADV_RANDOM); case SequentialAccess: return (MADV_SEQUENTIAL); case NormalAccess: default: return (MADV_NORMAL); } } }; // This is the 'base' class for regular files containing audio data class AudioFile : public AudioUnixfile { private: static const FileAccess defmode; // Default access mode static const char *AUDIO_PATH; // Default path env name off_t hdrsize; // length of file header off_t seekpos; // current system file pointer Double origlen; // initial length of file caddr_t mapaddr; // for mmaping RO files off_t maplen; // length of mmaped region VMAccess vmaccess; // vm (mmap) access type AudioFile operator=(AudioFile); // Assignment is illegal protected: // Open named file virtual AudioError tryopen( const char *, int); // Create named file virtual AudioError createfile( const char *path); // filename // class AudioUnixfile methods specialized here // Seek in input stream virtual AudioError seekread( Double pos, // position to seek to off_t& offset); // returned byte offset // Seek in output stream virtual AudioError seekwrite( Double pos, // position to seek to off_t& offset); // returned byte offset public: AudioFile(); // Constructor w/no args // Constructor with path AudioFile( const char *path, // filename const FileAccess acc = defmode); // access mode virtual ~AudioFile(); // Destructor // Set tmpfile location static AudioError SetTempPath( const char *path); // directory path // class AudioUnixfile methods specialized here virtual void SetBlocking(Boolean) { } // No-op for files // front end to madvise AudioError SetAccessType( VMAccess vmacc); // (normal, random, seq access) inline VMAccess GetAccessType() const { // get vm access type return (vmaccess); } virtual AudioError Create(); // Create file virtual AudioError Open(); // Open file // ... with search path virtual AudioError OpenPath( const char *path = AUDIO_PATH); virtual AudioError Close(); // Close file // Read from position virtual AudioError ReadData( void* buf, // buffer to fill size_t& len, // buffer length (updated) Double& pos); // start position (updated) // Write at position virtual AudioError WriteData( void* buf, // buffer to copy size_t& len, // buffer length (updated) Double& pos); // start position (updated) // copy to another audio obj. virtual AudioError AsyncCopy( Audio* ap, // dest audio object Double& frompos, Double& topos, Double& limit); // class Audio methods specialized here virtual Boolean isFile() const { return (TRUE); } }; #ifdef NO_EXTERN_C #ifdef __cplusplus } #endif #endif /* NO_EXTERN_C */ #endif /* !_MULTIMEDIA_AUDIOFILE_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1993-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_AUDIOGAIN_H #define _MULTIMEDIA_AUDIOGAIN_H #include #ifdef __cplusplus extern "C" { #endif // Class to handle gain calculations // Define bits for AudioGain::Process() type argument #define AUDIO_GAIN_INSTANT (1) // Gain for level meter #define AUDIO_GAIN_WEIGHTED (2) // Gain for agc class AudioGain { protected: static const double LoSigInstantRange; // normalization constants static const double HiSigInstantRange; static const double NoSigWeight; static const double LoSigWeightRange; static const double HiSigWeightRange; static const double PeakSig; static const double DCtimeconstant; // DC offset time constant AudioTypePcm float_convert; // used in signal processing unsigned clipcnt; // clip counter Double DCaverage; // weighted DC offset Double instant_gain; // current (instantaneous) gain Double weighted_peaksum; // peak weighted sum Double weighted_sum; // running sum of squares Double weighted_avgsum; // accumulated sums to averages unsigned weighted_cnt; // number of sums to average double *gain_cache; // weighted gains Double gain_cache_size; // number of cached gains protected: // Internal processing methods // filter DC bias virtual void process_dcfilter( AudioBuffer*); // calculate instant gain virtual void process_instant( AudioBuffer*); // calculate weighted gain virtual void process_weighted( AudioBuffer*); public: AudioGain(); // Constructor virtual ~AudioGain(); // Destructor // TRUE if conversion ok virtual Boolean CanConvert( const AudioHdr&) const; // type to check against // Process new audio data virtual AudioError Process( AudioBuffer*, int); // buffer destroyed if not referenced! virtual double InstantGain(); // Get most recent gain virtual double WeightedGain(); // Get current weighted gain virtual double WeightedPeak(); // Get peak weighted gain virtual Boolean Clipped(); // TRUE if peak since last check virtual void Flush(); // Reset state }; #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_AUDIOGAIN_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1992-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_AUDIOHDR_H #define _MULTIMEDIA_AUDIOHDR_H #ifdef NO_EXTERN_C #ifdef __cplusplus extern "C" { #endif #endif /* NO_EXTERN_C */ #include #include #include // Required for the use of MAXSHORT #include // Required by htons() and other network services. #include #include // Define an in-core audio data header. // // This is different than the on-disk file header. // // // The audio header contains the following fields: // // sample_rate Number of samples per second (per channel). // // samples_per_unit This field describes the number of samples // represented by each sample unit (which, by // definition, are aligned on byte boundaries). // Audio samples may be stored individually // or, in the case of compressed formats // (e.g., ADPCM), grouped in algorithm- // specific ways. If the data is bit-packed, // this field tells the number of samples // needed to get to a byte boundary. // // bytes_per_unit Number of bytes stored for each sample unit // // channels Number of interleaved sample units. // For any given time quantum, the set // consisting of 'channels' sample units // is called a sample frame. Seeks in // the data should be aligned to the start // of the nearest sample frame. // // encoding Data encoding format. // // // The first four values are used to compute the byte offset given a // particular time, and vice versa. Specifically: // // seconds = offset / C // offset = seconds * C // where: // C = (channels * bytes_per_unit * sample_rate) / samples_per_unit // Define the possible encoding types. // XXX - As long as audio_hdr.h exists, these values should match the // corresponding fields in audio_hdr.h since the cast operator // copies them blindly. This implies that the values should // match any of the encodings that appear in also. // XXX - How can encoding types be added dynamically? enum AudioEncoding { NONE = 0, // no encoding type set ULAW = 1, // ISDN u-law ALAW = 2, // ISDN A-law LINEAR = 3, // PCM 2's-complement (0-center) FLOAT = 100, // IEEE float (-1. <-> +1.) G721 = 101, // CCITT G.721 ADPCM G722 = 102, // CCITT G.722 ADPCM G723 = 103, // CCITT G.723 ADPCM DVI = 104 // DVI ADPCM }; // The byte order of the data. This is only applicable if the data // is 16-bit. All variables of this type will have the prefix "endian". enum AudioEndian { BIG_ENDIAN = 0, // Sun and network byte order LITTLE_ENDIAN = 1, // Intel byte order SWITCH_ENDIAN = 2, // Flag to switch to the opposite endian, used // by coerceEndian(). UNDEFINED_ENDIAN = -1 }; // Define a public data header structure. // Clients must be able to modify multiple fields inbetween validity checking. class AudioHdr { public: unsigned int sample_rate; // samples per second unsigned int samples_per_unit; // samples per unit unsigned int bytes_per_unit; // bytes per sample unit unsigned int channels; // # of interleaved channels AudioEncoding encoding; // data encoding format AudioEndian endian; // byte order AudioHdr(): // Constructor sample_rate(0), samples_per_unit(0), bytes_per_unit(0), channels(0), encoding(NONE) { // The default for files is BIG, but this is // set in the AudioUnixfile class. endian = localByteOrder(); } AudioHdr(Audio_hdr hdr): // Constructor from C struct sample_rate(hdr.sample_rate), samples_per_unit(hdr.samples_per_unit), bytes_per_unit(hdr.bytes_per_unit), channels(hdr.channels), encoding((AudioEncoding)hdr.encoding) { // The default for files is BIG, but this is // set in the AudioUnixfile class. endian = localByteOrder(); } // Determines the local byte order, otherwise know as the endian // nature of the current machine. AudioEndian localByteOrder() const; virtual void Clear(); // Init header virtual AudioError Validate() const; // Check hdr validity // Conversion between time (in seconds) and byte offsets virtual Double Bytes_to_Time(off_t cnt) const; virtual off_t Time_to_Bytes(Double sec) const; // Round down a byte count to a sample frame boundary virtual off_t Bytes_to_Bytes(off_t& cnt) const; virtual size_t Bytes_to_Bytes(size_t& cnt) const; // Conversion between time (in seconds) and sample frames virtual Double Samples_to_Time(unsigned long cnt) const; virtual unsigned long Time_to_Samples(Double sec) const; // Return the number of bytes in a sample frame for the audio encoding. virtual unsigned int FrameLength() const; // Return some meaningful strings. The returned char pointers // must be deleted when the caller is through with them. virtual char *RateString() const; // eg "44.1kHz" virtual char *ChannelString() const; // eg "stereo" virtual char *EncodingString() const; // eg "3-bit G.723" virtual char *FormatString() const; // eg "4-bit G.721, 8 kHz, mono" // Parse strings and set corresponding header fields. virtual AudioError RateParse(char *); virtual AudioError ChannelParse(char *); virtual AudioError EncodingParse(char *); virtual AudioError FormatParse(char *); // for casting to C Audio_hdr struct operator Audio_hdr() { Audio_hdr hdr; hdr.sample_rate = sample_rate; hdr.samples_per_unit = samples_per_unit; hdr.bytes_per_unit = bytes_per_unit; hdr.channels = channels; hdr.encoding = encoding; hdr.endian = endian; return (hdr); }; // compare two AudioHdr objects int operator == (const AudioHdr& tst) { return ((sample_rate == tst.sample_rate) && (samples_per_unit == tst.samples_per_unit) && (bytes_per_unit == tst.bytes_per_unit) && (channels == tst.channels) && // Audioconvert uses this method to see if a conversion should take // place, but doesn't know how to convert between endian formats. // This makes it ignore endian differences. // (endian = tst.endian) && (encoding == tst.encoding)); } int operator != (const AudioHdr& tst) { return (! (*this == tst)); } }; #ifdef NO_EXTERN_C #ifdef __cplusplus } #endif #endif /* NO_EXTERN_C */ #endif /* !_MULTIMEDIA_AUDIOHDR_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1990-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_AUDIOLIB_H #define _MULTIMEDIA_AUDIOLIB_H #ifdef NO_EXTERN_C #ifdef __cplusplus extern "C" { #endif #endif /* NO_EXTERN_C */ #include // Declarations for global functions // Copy entire stream AudioError AudioCopy( Audio* from, // input source Audio* to); // output sink // Copy data AudioError AudioCopy( Audio* from, // input source Audio* to, // output sink Double& frompos, // input position (updated) Double& topos, // output position (updated) Double& limit); // amount to copy (updated) // Copy one data segment AudioError AudioAsyncCopy( Audio* from, // input source Audio* to, // output sink Double& frompos, // input position (updated) Double& topos, // output position (updated) Double& limit); // amount to copy (updated) // Filename->AudioList AudioError Audio_OpenInputFile( const char *path, // input filename Audio*& ap); // returned AudioList ptr // Copy to output file AudioError Audio_WriteOutputFile( const char *path, // output filename const AudioHdr& hdr, // output data header Audio* input); // input data stream #ifdef NO_EXTERN_C #ifdef __cplusplus } #endif #endif /* NO_EXTERN_C */ #endif /* !_MULTIMEDIA_AUDIOLIB_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1990-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_AUDIOLIST_H #define _MULTIMEDIA_AUDIOLIST_H #include #ifdef __cplusplus extern "C" { #endif // This is the 'base' class for a list of extents of audio objects class AudioList : public Audio { // Define a linked list nested class class AudioListEntry { private: void operator=(AudioListEntry); // Assignment is illegal public: Audio* aptr; // pointer to audio object AudioListEntry* next; // pointer to next in list AudioListEntry* prev; // pointer to previous // Constructor w/obj AudioListEntry( Audio* obj); // referenced audio object ~AudioListEntry(); // Destructor void newptr(Audio* newa); // Reset extent // Link in new extent void link( AudioListEntry* after); // link after this one // Split an extent void split( Double pos); // split at offset }; private: AudioListEntry head; // list head AudioListEntry* first() const; // Return first extent // Locate extent/offset virtual Boolean getposition( Double& pos, // target position (updated) AudioListEntry*& ep) const; // returned entry pointer AudioList operator=(AudioList); // Assignment is illegal public: AudioList(const char *name = "[list]"); // Constructor virtual ~AudioList(); // Destructor // class Audio methods specialized here virtual Double GetLength() const; // Get length, in secs virtual char *GetName() const; // Get name string virtual AudioHdr GetHeader(); // Get header virtual AudioHdr GetHeader(Double pos); // Get header at pos // Read from position virtual AudioError ReadData( void* buf, // buffer to fill size_t& len, // buffer length (updated) Double& pos); // start position (updated) // Write is prohibited virtual AudioError WriteData( void* buf, // buffer to copy size_t& len, // buffer length (updated) Double& pos); // start position (updated) virtual Boolean isList() const { return (TRUE); } // list manipulation methods // Insert an entry virtual AudioError Insert( Audio* obj); // object to insert // Insert an entry virtual AudioError Insert( Audio* obj, // object to insert Double pos); // insertion offset, in seconds // Append an entry virtual AudioError Append( Audio* obj); // object to append // copy to another audio obj. virtual AudioError AsyncCopy( Audio* ap, // dest audio object Double& frompos, Double& topos, Double& limit); }; #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_AUDIOLIST_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1990-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_AUDIOPIPE_H #define _MULTIMEDIA_AUDIOPIPE_H #include #ifdef __cplusplus extern "C" { #endif // This is the 'base' class for pipes (such as stdin) containing audio data class AudioPipe : public AudioUnixfile { private: AudioPipe(); // Constructor w/no args AudioPipe operator=(AudioPipe); // Assignment is illegal public: // Constructor with path AudioPipe( const int desc, // file descriptor const FileAccess acc, // access mode const char *name = "(pipe)"); // name // class AudioUnixfile methods specialized here virtual AudioError Create(); // Create file virtual AudioError Open(); // Open file // Read from position virtual AudioError ReadData( void* buf, // buffer to fill size_t& len, // buffer length (updated) Double& pos); // start position (updated) // Write at position virtual AudioError WriteData( void* buf, // buffer to copy size_t& len, // buffer length (updated) Double& pos); // start position (updated) // class Audio methods specialized here virtual Boolean isPipe() const { return (TRUE); } }; #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_AUDIOPIPE_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1991-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_AUDIORAWPIPE_H #define _MULTIMEDIA_AUDIORAWPIPE_H #include #ifdef __cplusplus extern "C" { #endif // This is a specialization of an AudioPipe for raw audio data class AudioRawPipe : public AudioPipe { private: Boolean isopened; off_t offset; /* offset to start read/write */ public: // Constructor with path AudioRawPipe( const int desc, // file descriptor const FileAccess acc, // access mode const AudioHdr& hdr, // header describing raw data const char *name = "(raw pipe)", // name const off_t offset = 0 ); // class AudioPipe methods specialized here virtual AudioError Create(); // Create file virtual AudioError Open(); // Open file virtual Boolean opened() const; // TRUE of opened AudioError SetOffset(off_t val); // set offset off_t GetOffset() const; // set offset }; #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_AUDIORAWPIPE_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1990-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_AUDIOSTREAM_H #define _MULTIMEDIA_AUDIOSTREAM_H #include #include #include #include #ifdef __cplusplus extern "C" { #endif // This is the abstract base class for all audio data sources/sinks. // It is invalid to create an object of type AudioStream. class AudioStream : public Audio { private: AudioHdr hdr; // data encoding info Double length; // length of data, in secs protected: Boolean hdrset() const; // TRUE if header valid // Set header (always) AudioError updateheader( const AudioHdr& h); // header to copy // Set data length void setlength( Double len); // new length, in secs virtual Boolean opened() const = 0; // TRUE if stream 'open' public: AudioStream(const char *path = ""); // Constructor // Set header virtual AudioError SetHeader( const AudioHdr& h); // header to copy // Set data length virtual void SetLength( Double len); // new length, in secs // XXX - is this needed? do we need time->sample frames? virtual size_t GetByteCount() const; // Get length, in bytes // class Audio methods specialized here virtual AudioHdr GetHeader(); // Get header virtual Double GetLength() const; // Get length, in secs // Make sure endian of the data matches the current processor. AudioError coerceEndian(unsigned char *buf, size_t len, AudioEndian en); virtual Boolean isEndianSensitive() const; AudioEndian localByteOrder() const { return (hdr.localByteOrder()); } }; #include #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_AUDIOSTREAM_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1990-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_AUDIOSTREAM_INLINE_H #define _MULTIMEDIA_AUDIOSTREAM_INLINE_H #ifdef __cplusplus extern "C" { #endif // Inline routines for class AudioStream // Return TRUE if the current AudioHdr is valid inline Boolean AudioStream:: hdrset() const { return (hdr.Validate() == AUDIO_SUCCESS); } // Return the current AudioHdr inline AudioHdr AudioStream:: GetHeader() { return (hdr); } // Set the length parameter inline void AudioStream:: setlength( Double len) // new length, in secs { length = len; } // Set the length parameter, if possible inline void AudioStream:: SetLength( Double len) // new length, in secs { // This may be used to set the expected length of a write-only stream if (!opened()) length = len; } inline Double AudioStream:: GetLength() const { return (length); } inline size_t AudioStream:: GetByteCount() const { return (hdr.Time_to_Bytes(length)); } #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_AUDIOSTREAM_INLINE_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1992-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_AUDIOTYPECHANNEL_H #define _MULTIMEDIA_AUDIOTYPECHANNEL_H #include #include #ifdef __cplusplus extern "C" { #endif // This is the class doing channel (mono->stereo) conversion class AudioTypeChannel : public AudioTypeConvert { protected: public: AudioTypeChannel(); // Constructor ~AudioTypeChannel(); // Destructor // Class AudioTypeConvert methods specialized here // TRUE if conversion ok virtual Boolean CanConvert( AudioHdr h) const; // type to check against // Convert buffer to the specified type // Either the input or output type must be handled by this class // Convert to new type virtual AudioError Convert( AudioBuffer*& inbuf, // data buffer to process AudioHdr outhdr); // target header virtual AudioError Flush(AudioBuffer*& buf); }; #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_AUDIOTYPECHANNEL_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1990-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_AUDIOTYPECONVERT_H #define _MULTIMEDIA_AUDIOTYPECONVERT_H #include #ifdef __cplusplus extern "C" { #endif // This is the abstract base class for an audio type conversion module class AudioTypeConvert { protected: AudioHdr hdr; // contains type information public: AudioTypeConvert() {}; // Constructor virtual ~AudioTypeConvert() {}; // Destructor virtual AudioHdr DataType() const // Return type { return (hdr); } // class methods specialized by subclasses // TRUE if conversion ok virtual Boolean CanConvert( AudioHdr h) const = 0; // type to check against // Convert buffer to the specified type // Either the input or output type must be handled by this class // Convert to new type virtual AudioError Convert( AudioBuffer*& inbuf, // data buffer to process AudioHdr outhdr) = 0; // target header virtual AudioError Flush(AudioBuffer*& buf) = 0; // flush any remaining // data that may exist }; #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_AUDIOTYPECONVERT_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1992-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_AUDIOTYPEG72X_H #define _MULTIMEDIA_AUDIOTYPEG72X_H #include #include #ifdef __cplusplus extern "C" { #endif // This is the class for CCITT G.72X compress/decompress class AudioTypeG72X : public AudioTypeConvert { private: struct audio_g72x_state g72x_state; Boolean initialized; protected: public: AudioTypeG72X(); // Constructor ~AudioTypeG72X(); // Destructor // Class AudioTypeConvert methods specialized here // TRUE if conversion ok virtual Boolean CanConvert( AudioHdr h) const; // type to check against // Convert buffer to the specified type // Either the input or output type must be handled by this class // Convert to new type virtual AudioError Convert( AudioBuffer*& inbuf, // data buffer to process AudioHdr outhdr); // target header virtual AudioError Flush(AudioBuffer*& buf); }; #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_AUDIOTYPEG72X_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1992-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_AUDIOTYPEMUX_H #define _MULTIMEDIA_AUDIOTYPEMUX_H #include #ifdef __cplusplus extern "C" { #endif // This is the class doing channel multiplex/demultiplex class AudioTypeMux : public AudioTypeConvert { protected: public: AudioTypeMux(); // Constructor ~AudioTypeMux(); // Destructor // Class AudioTypeConvert methods specialized here // TRUE if conversion ok virtual Boolean CanConvert( AudioHdr h) const; // type to check against // Convert buffer to the specified type // Either the input or output type must be handled by this class // Convert to new type virtual AudioError Convert( AudioBuffer*& inbuf, // data buffer to process AudioHdr outhdr); // target header virtual AudioError Flush(AudioBuffer*& buf); }; #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_AUDIOTYPEMUX_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1990-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_AUDIOTYPEPCM_H #define _MULTIMEDIA_AUDIOTYPEPCM_H #include #ifdef __cplusplus extern "C" { #endif // This is the class for a linear PCM conversion module class AudioTypePcm : public AudioTypeConvert { protected: typedef unsigned char ulaw; typedef unsigned char alaw; // Conversion routines inline'd in the source file double char2dbl(char); double short2dbl(short); double long2dbl(long); long dbl2long(double, long); void char2short(char *&, short *&); void char2long(char *&, long *&); void char2float(char *&, float *&); void char2double(char *&, double *&); void char2ulaw(char *&, ulaw *&); void char2alaw(char *&, alaw *&); void short2char(short *&, char *&); void short2long(short *&, long *&); void short2float(short *&, float *&); void short2double(short *&, double *&); void short2ulaw(short *&, ulaw *&); void short2alaw(short *&, alaw *&); void long2char(long *&, char *&); void long2short(long *&, short *&); void long2float(long *&, float *&); void long2double(long *&, double *&); void long2ulaw(long *&, ulaw *&); void long2alaw(long *&, alaw *&); void float2char(float *&, char *&); void float2short(float *&, short *&); void float2long(float *&, long *&); void float2double(float *&, double *&); void float2ulaw(float *&, ulaw *&); void float2alaw(float *&, alaw *&); void double2char(double *&, char *&); void double2short(double *&, short *&); void double2long(double *&, long *&); void double2float(double *&, float *&); void double2ulaw(double *&, ulaw *&); void double2alaw(double *&, alaw *&); void ulaw2char(ulaw *&, char *&); void ulaw2short(ulaw*&, short *&); void ulaw2long(ulaw*&, long *&); void ulaw2float(ulaw *&, float *&); void ulaw2double(ulaw *&, double *&); void ulaw2alaw(ulaw *&, alaw *&); void alaw2ulaw(alaw *&, ulaw *&); void alaw2char(alaw *&, char *&); void alaw2short(alaw *&, short *&); void alaw2long(alaw *&, long *&); void alaw2float(alaw *&, float *&); void alaw2double(alaw *&, double *&); public: AudioTypePcm(); // Constructor // Class AudioTypeConvert methods specialized here // TRUE if conversion ok virtual Boolean CanConvert( AudioHdr h) const; // type to check against // Convert buffer to the specified type // Either the input or output type must be handled by this class // Convert to new type virtual AudioError Convert( AudioBuffer*& inbuf, // data buffer to process AudioHdr outhdr); // target header virtual AudioError Flush(AudioBuffer*& buf); }; #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_AUDIOTYPEPCM_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1992-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_AUDIOTYPESAMPLERATE_H #define _MULTIMEDIA_AUDIOTYPESAMPLERATE_H #include #include #ifdef __cplusplus extern "C" { #endif // This is the class doing Sample Rate conversion class AudioTypeSampleRate : public AudioTypeConvert { private: ResampleFilter resampler; int input_rate; int output_rate; protected: public: AudioTypeSampleRate(int inrate, int outrate); // Constructor ~AudioTypeSampleRate(); // Destructor // Class AudioTypeConvert methods specialized here // TRUE if conversion ok virtual Boolean CanConvert( AudioHdr h) const; // type to check against // Convert buffer to the specified type // Either the input or output type must be handled by this class // Convert to new type virtual AudioError Convert( AudioBuffer*& inbuf, // data buffer to process AudioHdr outhdr); // target header virtual AudioError Flush(AudioBuffer*& buf); // flush remains }; #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_AUDIOTYPESAMPLERATE_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1992-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_AUDIOTYPES_H #define _MULTIMEDIA_AUDIOTYPES_H #ifdef NO_EXTERN_C #ifdef __cplusplus extern "C" { #endif #endif /* NO_EXTERN_C */ #include #include #include #include #include #include #include // Types used in the audio API // Values used for indeterminate size (e.g., data passed through a pipe) const double AUDIO_UNKNOWN_TIME = DBL_MAX; // Error severity enum AudioSeverity { InitMessage, // debugging message from constructor InitFatal, // fatal error from constructor Message, // debugging message Warning, // non-fatal error Error, // potentially severe error Consistency, // internal consistency warning Fatal // fatal internal error }; // Used in SetPosition methods enum Whence { Absolute = 0, Relative = 1, Relative_eof = 2}; // XXX - classes that ought to be defined elsewhere // A Boolean 'primitive type' with values TRUE and FALSE // undefine these in case they're defined elsewhere #undef TRUE #undef FALSE // use bool_t 'cause boolean_t is already used under 5.0 // Since 4/93 can't use bool_t cause rpc/types.h typedefs it // so use aud_bool_t enum aud_bool_t {FALSE = 0, TRUE = 1}; class Boolean { private: aud_bool_t value; // value is TRUE or FALSE public: inline Boolean(aud_bool_t x = FALSE): value(x) // Constructor { } inline Boolean(int x) // Constructor from int { value = (x == 0) ? FALSE : TRUE; } inline Boolean operator=(int x) // Assignment from int { return (value = (x == 0) ? FALSE : TRUE); } inline operator int() // Cast to integer { return ((value == TRUE) ? 1 : 0); } inline Boolean operator!() // Logical not { return ((value == TRUE) ? FALSE : TRUE); } }; // A 'primitive type' for file access modes enum fileaccess_t { NoAccess = 0, ReadOnly = 1, WriteOnly = 2, ReadWrite = 3, AppendOnly = 6, ReadAppend = 7 }; class FileAccess { private: fileaccess_t mode; // combined mode public: FileAccess(fileaccess_t x = NoAccess): mode(x) { } // Constructor inline operator fileaccess_t() // Cast to enum { return (mode); } inline operator int() { // Cast to integer switch (mode) { case ReadOnly: return (O_RDONLY); case WriteOnly: return (O_WRONLY); case ReadWrite: return (O_RDWR); case AppendOnly: return (O_WRONLY | O_APPEND); case ReadAppend: return (O_RDWR | O_APPEND); case NoAccess: default: return (-1); } } // These tests depend on the actual enum values inline Boolean Readable() const // TRUE if readable { return ((int)mode & 1); } inline Boolean Writeable() const // TRUE if writeable { return ((int)mode & 2); } inline Boolean Append() const // TRUE if append only { return ((int)mode & 4); } }; // Define a small number corresponding to minor floating-point bit errors const double AUDIO_MINFLOAT = .00000001; // Define a 'double' class that allows some leeway in magnitude checking // to try to correct for small errors due to floating-point imprecision class Double { private: double val; public: Double(double x = 0.): val(x) { } Double(const Double &x): val(x.val) { } inline int Undefined() const { return (val == AUDIO_UNKNOWN_TIME); } inline operator double() const { return (val); } inline Double& operator += (double y) { val += y; return (*this); } inline Double& operator -= (double y) { val -= y; return (*this); } Double& operator=(const Double&) = default; }; // inline double fabs(double x) // { return ((x >= 0.) ? x : -x); } inline double min(const Double& x, const Double& y) { return (((double)x < (double)y) ? (double)x : (double)y); } inline double min(const Double& x, double y) { return (((double)x < (double)y) ? (double)x : (double)y); } inline double min(double x, const Double& y) { return (((double)x < (double)y) ? (double)x : (double)y); } inline double max(const Double& x, const Double& y) { return (((double)x > (double)y) ? (double)x : (double)y); } inline double max(const Double& x, double y) { return (((double)x > (double)y) ? (double)x : (double)y); } inline double max(double x, const Double& y) { return (((double)x > (double)y) ? (double)x : (double)y); } inline int operator == (const Double &x, const Double &y) { return (fabs((double)x - (double)y) <= AUDIO_MINFLOAT); } inline int operator == (const Double &x, double y) { return (fabs((double)x - (double)y) <= AUDIO_MINFLOAT); } inline int operator == (double x, const Double &y) { return (fabs((double)x - (double)y) <= AUDIO_MINFLOAT); } inline int operator != (const Double &x, const Double &y) { return (!(x == y)); } inline int operator != (const Double &x, double y) { return (!(x == y)); } inline int operator != (double x, const Double &y) { return (!(x == y)); } inline int operator <= (const Double &x, const Double &y) { return (((double)x < (double)y) || (x == y)); } inline int operator <= (const Double &x, double y) { return (((double)x < (double)y) || (x == y)); } inline int operator <= (double x, const Double &y) { return (((double)x < (double)y) || (x == y)); } inline int operator >= (const Double &x, const Double &y) { return (((double)x > (double)y) || (x == y)); } inline int operator >= (const Double &x, double y) { return (((double)x > (double)y) || (x == y)); } inline int operator >= (double x, const Double &y) { return (((double)x > (double)y) || (x == y)); } inline int operator < (const Double &x, const Double &y) { return (!(x >= y)); } inline int operator < (const Double &x, double y) { return (!(x >= y)); } inline int operator < (double x, const Double &y) { return (!(x >= y)); } inline int operator > (const Double &x, const Double &y) { return (!(x <= y)); } inline int operator > (const Double &x, double y) { return (!(x <= y)); } inline int operator > (double x, const Double &y) { return (!(x <= y)); } inline Double& operator += (Double &x, const Double &y) { return (x += (double)y); } inline double operator += (double &x, const Double &y) { return (x += (double)y); } inline Double& operator -= (Double &x, const Double &y) { return (x -= (double)y); } inline double operator -= (double &x, const Double &y) { return (x -= (double)y); } inline int Undefined(const Double &x) { return (x.Undefined()); } inline int Undefined(double x) { return (x == AUDIO_UNKNOWN_TIME); } #ifdef NO_EXTERN_C #ifdef __cplusplus } #endif #endif /* NO_EXTERN_C */ #endif /* !_MULTIMEDIA_AUDIOTYPES_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1992-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_AUDIOUNIXFILE_H #define _MULTIMEDIA_AUDIOUNIXFILE_H #include #ifdef __cplusplus extern "C" { #endif // This is the abstract base class for all file descriptor based audio i/o. // It is invalid to create an object of type AudioUnixfile. class AudioUnixfile : public AudioStream { private: FileAccess mode; // access mode Boolean block; // FALSE if fd set non-blocking Boolean filehdrset; // TRUE if file hdr read/written int fd; // file descriptor char *infostring; // Info string from header unsigned int infolength; // Info string length AudioUnixfile() {} // Constructor w/no args protected: // Constructor AudioUnixfile( const char *path, // pathname const FileAccess acc); // access mode int getfd() const; // Return descriptor void setfd(int d); // Set descriptor virtual AudioError decode_filehdr(); // Get header from file virtual AudioError encode_filehdr(); // Write file header // Seek in input stream virtual AudioError seekread( Double pos, // position to seek to off_t& offset); // returned byte offset // Seek in output stream virtual AudioError seekwrite( Double pos, // position to seek to off_t& offset); // returned byte offset virtual Boolean isfdset() const; // TRUE if fd is valid virtual Boolean isfilehdrset() const; // TRUE if file hdr r/w // class AudioStream methods specialized here virtual Boolean opened() const; // TRUE, if open public: virtual ~AudioUnixfile(); // Destructor virtual FileAccess GetAccess() const; // Get mode virtual Boolean GetBlocking() const; // TRUE, if blocking i/o virtual void SetBlocking(Boolean b); // Set block/non-block virtual AudioError Create() = 0; // Create file virtual AudioError Open() = 0; // Open file // ... with search path virtual AudioError OpenPath( const char *path = 0); virtual AudioError Close(); // Close file // Methods specific to the audio file format // Get info string virtual char *GetInfostring( int& len) const; // return length // Set info string virtual void SetInfostring( const char *str, // ptr to info data int len = -1); // optional length // class Audio methods specialized here // Read from position virtual AudioError ReadData( void* buf, // buffer to fill size_t& len, // buffer length (updated) Double& pos); // start position (updated) // Write at position virtual AudioError WriteData( void* buf, // buffer to copy size_t& len, // buffer length (updated) Double& pos); // start position (updated) }; #include #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_AUDIOUNIXFILE_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1990-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_AUDIOUNIXFILE_INLINE_H #define _MULTIMEDIA_AUDIOUNIXFILE_INLINE_H #ifdef __cplusplus extern "C" { #endif // Inline routines for class AudioUnixfile // Return the file descriptor inline int AudioUnixfile:: getfd() const { return (fd); } // Set the file descriptor inline void AudioUnixfile:: setfd( int newfd) // new file descriptor { fd = newfd; } // Return TRUE if fd is valid inline Boolean AudioUnixfile:: isfdset() const { return (fd >= 0); } // Return TRUE if file hdr read/written inline Boolean AudioUnixfile:: isfilehdrset() const { return (filehdrset); } // Return TRUE if stream is open inline Boolean AudioUnixfile:: opened() const { return (isfdset() && isfilehdrset()); } // Return the access mode inline FileAccess AudioUnixfile:: GetAccess() const { return (mode); } // Return the blocking i/o mode inline Boolean AudioUnixfile:: GetBlocking() const { return (block); } #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_AUDIOUNIXFILE_INLINE_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1990-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_AUDIO_INLINE_H #define _MULTIMEDIA_AUDIO_INLINE_H #ifdef __cplusplus extern "C" { #endif // Inline routines for class Audio // Return object id inline int Audio:: getid() const { return (id); } // Return TRUE if the object is referenced inline Boolean Audio:: isReferenced() const { return (refcnt > 0); } // Access routine for retrieving the current read position pointer inline Double Audio:: ReadPosition() const { return (readpos); } // Access routine for retrieving the current write position pointer inline Double Audio:: WritePosition() const { return (writepos); } // Return the name of an audio object inline char *Audio:: GetName() const { return (name); } // Set the error function callback address inline void Audio:: SetErrorFunction( AudioErrfunc func) // function address { errorfunc = func; } // Default get header at position routine does a normal GetHeader inline AudioHdr Audio:: GetDHeader( Double) { return (GetHeader()); } #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_AUDIO_INLINE_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1992-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_FIR_H #define _MULTIMEDIA_FIR_H #ifdef __cplusplus extern "C" { #endif /* * Finite Impulse Response (FIR) filter object * * For every input sample, the FIR filter generates an output sample: * output = coef[0] * input + * coef[1] * state[order - 1] + * coef[2] * state[order - 2] + * ... * coef[order] * state[0] * * and the filter states are updated: * state[0] = state[1] * state[1] = state[2] * ... * state[order - 2] = state[order - 1] * state[order - 1] = input */ class Fir { protected: int order; // filter order, # taps = order + 1 double *coef; // (order + 1) filter coeffs. double *state; // "order" filter states int delay; // actual delay between output & input virtual void updateState(double *data, int size); virtual void update_short(short *data, int size); virtual int flush(short *out); public: virtual void resetState(void); // reset states to zero Fir(void); Fir(int order_in); ~Fir(); virtual int getOrder(void); // get filter order value virtual int getNumCoefs(void); // get number of coefficients virtual void putCoef(double *coef_in); // put coef_in in filter coef virtual void getCoef(double *coef_out); // get filter coef // filter "size" input samples for "size" output samples virtual int filter_noadjust(short *in, int size, short *out); /* * filter "size" input samples. Output sample sequence is offset by * group delay samples to align with the input sample sequence. * the first call of this routine returns "size - group_delay" * output samples. Call this routine with size = 0 * to fill the output buffer such that the total number of output * samples is equal to the number of input samples. */ virtual int getFlushSize(void); // size of out[] for the last call virtual int filter(short *in, int size, short *out); }; #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_FIR_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1992-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_RESAMPLE_H #define _MULTIMEDIA_RESAMPLE_H /* * To convert the sampling rate of fi of input signal to fo of output signal, * the least common multiple fm = L * fi = M * fo needs to be derived first. * Then the input signal is * 1) up-sampled to fm by inserting (L - 1) zero-valued samples after each * input sample, * 2) low-pass filtered to half of the lower of fi and fo, and * 3) down-sampled to fo by saving one out of every M samples. * * The low-pass filter is implemented with an FIR filter which is a truncated * ideal low pass filter whose order is dependent on its bandwidth. * * Refer to Fir.h for explanations of filter() and flush(). * */ #include #ifdef __cplusplus extern "C" { #endif class ResampleFilter : public Fir { int num_state; // interpolation requires less states int up; // upsampling ratio int down; // down sampling ratio int down_offset; // 0 <= index in down-sampling < down int up_offset; // -up < index in up_sampling <= 0 void updateState(double *in, int size); // if fi is a multiple of fo, LP filtering followed by down_sampling int decimate_noadjust(short *in, int size, short *out); int decimate_flush(short *); int decimate(short *in, int size, short *out); // if fo is a multiple of fi, up-sampling followed by LP filtering int interpolate_noadjust(short *in, int size, short *out); int interpolate_flush(short *); int interpolate(short *in, int size, short *out); int flush(short *out); public: ResampleFilter(int rate_in, int rate_out); virtual int filter_noadjust(short *in, int size, short *out); virtual int filter(short *in, int size, short *out); virtual int getFlushSize(void); }; #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_RESAMPLE_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2004 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* * This header file defines the .aiff audio file format. */ #ifndef _AIFF_H #define _AIFF_H #include #ifdef __cplusplus extern "C" { #endif /* * Define the on-disk audio file header for the aiff file format. * By definition .aiff files are big endian. Macros are provided * to make the conversion easier. * * As many file formats, .aiff is composed of "chunks" of data grouped * together. The aiff specification states that chunks may be in any * order. Thus it is not possible to create a condensed header structure * as is possible with .aif or .wav. * * The first chunk is always a FORM chunk. All other chunks have the * following form: * * Chunk ID * Chunk Data Size * Data * * AIFF files must have FORM, COMM, and SSND chunks. All other chunks * can be ignored. When a chunk with an unknown ID is found then the * application should read the next integer to get the size and then * seek past the unknown chunk to the next chunk. * * When building a .aiff header the size of the data isn't always known. * The following define is used for that situation. */ #define AUDIO_AIFF_UNKNOWN_SIZE (~0) struct aiff_hdr_chunk { uint32_t aiff_hdr_ID; /* initial chunk ID */ uint32_t aiff_hdr_size; /* file_size - aiff_hdr_chunk */ uint32_t aiff_hdr_data_type; /* file data type */ }; typedef struct aiff_hdr_chunk aiff_hdr_chunk_t; /* define for aiff_hdr_chunk.aiff_hdr_ID */ #define AUDIO_AIFF_HDR_CHUNK_ID ((uint32_t)0x464f524d) /* 'FORM' */ /* define for audio form type */ #define AUDIO_AIFF_HDR_FORM_AIFF ((uint32_t)0x41494646) /* 'AIFF' */ /* * The COMMon chunk definitions. Due to an unfortunate layout, the integer * aiff_comm_frames is not on a 4 byte boundary, which most compilers pad to * put back onto an integer boundary. Thus it is implemented as 4 chars which * gets around this. There are convenience macros to aid in getting and setting * the value. Also, some compilers will pad the end of the data structure to * place it on a 4 byte boundary, thus sizeof (aiff_comm_chunk_t) is off by * 2 bytes. Use AIFF_COMM_CHUNK_SIZE instead. */ #define AUDIO_AIFF_COMM_SR_SIZE 10 #define AUDIO_AIFF_COMM_CHUNK_SIZE 26 struct aiff_comm_chunk { uint32_t aiff_comm_ID; /* chunk ID */ uint32_t aiff_comm_size; /* size without _ID and _size */ uint16_t aiff_comm_channels; /* number of channels */ uint8_t aiff_comm_frames[4]; /* sample frames */ int16_t aiff_comm_sample_size; /* bits in each sample */ uint8_t aiff_comm_sample_rate[AUDIO_AIFF_COMM_SR_SIZE]; /* SR in float */ }; typedef struct aiff_comm_chunk aiff_comm_chunk_t; /* define for aiff_comm_chunk.aiff_comm_ID */ #define AUDIO_AIFF_COMM_ID ((uint32_t)0x434f4d4d) /* 'COMM' */ /* define for aiff_comm_chunk.aiff_comm_size */ #define AUDIO_AIFF_COMM_SIZE 18 /* define for aiff_comm_chunk.aiff_comm_channels */ #define AUDIO_AIFF_COMM_CHANNELS_MONO 1 #define AUDIO_AIFF_COMM_CHANNELS_STEREO 2 /* defines to get and set the frame count */ #define AUDIO_AIFF_COMM_FRAMES2INT(X) \ (((X)[0] << 24) | ((X)[1] << 16) | ((X)[2] << 8) | (X)[3]) #define AUDIO_AIFF_COMM_INT2FRAMES(X, D) \ (X)[0] = (D) >> 24; (X)[1] = (D) >> 16; (X)[2] = (D) >> 8; (X)[3] = (D); /* define for aiff_comm_chunk.aiff_comm_sample_size */ #define AUDIO_AIFF_COMM_8_BIT_SAMPLE_SIZE 8 #define AUDIO_AIFF_COMM_16_BIT_SAMPLE_SIZE 16 /* * The SSND chunk definitions. Sound data immediately follows this data * structure. Use aiff_ssnd_block_size to move past the data. The size of * audio is aiff_ssnd_size - 8. */ struct aiff_ssnd_chunk { uint32_t aiff_ssnd_ID; /* chunk ID */ uint32_t aiff_ssnd_size; /* size without _id and _size */ uint32_t aiff_ssnd_offset; /* offset to frame beginning */ uint32_t aiff_ssnd_block_size; /* block size */ }; typedef struct aiff_ssnd_chunk aiff_ssnd_chunk_t; /* define for aiff_ssnd_chunk.aiff_ssnd_ID */ #define AUDIO_AIFF_SSND_ID ((uint32_t)0x53534e44) /* 'SSND' */ /* byte swapping macros */ #if defined(__BIG_ENDIAN) #define AUDIO_AIFF_FILE2HOST_INT(from, to) \ *((int *)(to)) = *((int *)(from)) #define AUDIO_AIFF_FILE2HOST_SHORT(from, to) \ *((short *)(to)) = *((short *)(from)) #define AUDIO_AIFF_HOST2FILE_INT(from, to) \ *((int *)(to)) = *((int *)(from)) #define AUDIO_AIFF_HOST2FILE_SHORT(from, to) \ *((short *)(to)) = *((short *)(from)) #elif defined(_LITTLE_ENDIAN) #define AUDIO_AIFF_FILE2HOST_INT(from, to) \ (*to) = ((((*from) >> 24) & 0xff) | (((*from) & 0xff) << 24) | \ (((*from) >> 8) & 0xff00) | (((*from) & 0xff00) << 8)) #define AUDIO_AIFF_FILE2HOST_SHORT(from, to) \ (*to) = ((((*from) >> 8) & 0xff) | (((*from) & 0xff) << 8)) #define AUDIO_AIFF_HOST2FILE_INT(from, to) \ AUDIO_AIFF_FILE2HOST_INT((from), (to)) #define AUDIO_AIFF_HOST2FILE_SHORT(from, to) \ AUDIO_AIFF_FILE2HOST_SHORT((from), (to)) #else #error unknown machine type; #endif /* byte swapping */ #ifdef __cplusplus } #endif #endif /* _AIFF_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1992-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_ARCHDEP_H #define _MULTIMEDIA_ARCHDEP_H #ifdef __cplusplus extern "C" { #endif /* * Machine-dependent and implementation-dependent definitions * are placed here so that source code can be portable among a wide * variety of machines. */ /* * The following macros are used to generate architecture-specific * code for handling byte-ordering correctly. * * Note that these macros *do not* work for in-place transformations. */ #if defined(_BIG_ENDIAN) #define DECODE_SHORT(from, to) *((short *)(to)) = *((short *)(from)) #define DECODE_LONG(from, to) *((long *)(to)) = *((long *)(from)) #define DECODE_FLOAT(from, to) *((float *)(to)) = *((float *)(from)) #define DECODE_DOUBLE(from, to) *((double *)(to)) = *((double *)(from)) #elif defined(_LITTLE_ENDIAN) #define DECODE_SHORT(from, to) \ ((char *)(to))[0] = ((char *)(from))[1]; \ ((char *)(to))[1] = ((char *)(from))[0]; #define DECODE_LONG(from, to) \ ((char *)(to))[0] = ((char *)(from))[3]; \ ((char *)(to))[1] = ((char *)(from))[2]; \ ((char *)(to))[2] = ((char *)(from))[1]; \ ((char *)(to))[3] = ((char *)(from))[0]; #define DECODE_FLOAT(from, to) DECODE_LONG((to), (from)) #define DECODE_DOUBLE(from, to) \ ((char *)(to))[0] = ((char *)(from))[7]; \ ((char *)(to))[1] = ((char *)(from))[6]; \ ((char *)(to))[2] = ((char *)(from))[5]; \ ((char *)(to))[3] = ((char *)(from))[4]; \ ((char *)(to))[4] = ((char *)(from))[3]; \ ((char *)(to))[5] = ((char *)(from))[2]; \ ((char *)(to))[6] = ((char *)(from))[1]; \ ((char *)(to))[7] = ((char *)(from))[0]; #else /* little-endian */ #error Unknown machine endianness #endif #define ENCODE_SHORT(from, to) DECODE_SHORT((from), (to)) #define ENCODE_LONG(from, to) DECODE_LONG((from), (to)) #define ENCODE_FLOAT(from, to) DECODE_FLOAT((from), (to)) #define ENCODE_DOUBLE(from, to) DECODE_DOUBLE((from), (to)) #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_ARCHDEP_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1992-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_AUDIO_DEVICE_H #define _MULTIMEDIA_AUDIO_DEVICE_H #ifdef __cplusplus extern "C" { #endif #include #include #include typedef audio_info_t Audio_info; /* * The following macros read the current audio device configuration * and convert the data encoding format into an Audio_hdr. * 'F' is an open audio file descriptor. * 'H' is a pointer to an Audio_hdr. * The structure '*H' is updated after the device state has been read. */ #define audio_get_play_config(F, H) \ audio__setplayhdr((F), (H), AUDIO__PLAY) #define audio_get_record_config(F, H) \ audio__setplayhdr((F), (H), AUDIO__RECORD) /* * The following macros attempt to reconfigure the audio device so that * it operates on data encoded according to a given Audio_hdr. * 'F' is an open audio file descriptor. * 'H' is a pointer to an Audio_hdr describing the desired encoding. * The structure '*H' is updated after the device state has been read * to reflect the actual state of the device. * * AUDIO_SUCCESS is returned if the device configuration matches the * requested encoding. AUDIO_ERR_NOEFFECT is returned if it does not. */ #define audio_set_play_config(F, H) \ audio__setplayhdr((F), (H), AUDIO__SET|AUDIO__PLAY) #define audio_set_record_config(F, H) \ audio__setplayhdr((F), (H), AUDIO__SET|AUDIO__RECORD) /* * The following macros pause or resume the audio play and/or record channels. * Note that requests to pause a channel that is not open will have no effect. * In such cases, AUDIO_ERR_NOEFFECT is returned. */ #define audio_pause(F) \ audio__setpause((F), AUDIO__PLAYREC|AUDIO__PAUSE) #define audio_pause_play(F) \ audio__setpause((F), AUDIO__PLAY|AUDIO__PAUSE) #define audio_pause_record(F) \ audio__setpause((F), AUDIO__RECORD|AUDIO__PAUSE) #define audio_resume(F) \ audio__setpause((F), AUDIO__PLAYREC|AUDIO__RESUME) #define audio_resume_play(F) \ audio__setpause((F), AUDIO__PLAY|AUDIO__RESUME) #define audio_resume_record(F) \ audio__setpause((F), AUDIO__RECORD|AUDIO__RESUME) /* * The following macros get individual state values. * 'F' is an open audio file descriptor. * 'V' is a pointer to an unsigned int. * The value '*V' is updated after the device state has been read. */ #define audio_get_play_port(F, V) \ audio__setval((F), (V), AUDIO__PLAY|AUDIO__PORT) #define audio_get_record_port(F, V) \ audio__setval((F), (V), AUDIO__RECORD|AUDIO__PORT) #define audio_get_play_balance(F, V) \ audio__setval((F), (V), AUDIO__PLAY|AUDIO__BALANCE) #define audio_get_record_balance(F, V) \ audio__setval((F), (V), AUDIO__RECORD|AUDIO__BALANCE) #define audio_get_play_samples(F, V) \ audio__setval((F), (V), AUDIO__PLAY|AUDIO__SAMPLES) #define audio_get_record_samples(F, V) \ audio__setval((F), (V), AUDIO__RECORD|AUDIO__SAMPLES) #define audio_get_play_error(F, V) \ audio__setval((F), (V), AUDIO__PLAY|AUDIO__ERROR) #define audio_get_record_error(F, V) \ audio__setval((F), (V), AUDIO__RECORD|AUDIO__ERROR) #define audio_get_play_eof(F, V) \ audio__setval((F), (V), AUDIO__PLAY|AUDIO__EOF) #define audio_get_play_open(F, V) \ audio__setval((F), (V), AUDIO__PLAY|AUDIO__OPEN) #define audio_get_record_open(F, V) \ audio__setval((F), (V), AUDIO__RECORD|AUDIO__OPEN) #define audio_get_play_active(F, V) \ audio__setval((F), (V), AUDIO__PLAY|AUDIO__ACTIVE) #define audio_get_record_active(F, V) \ audio__setval((F), (V), AUDIO__RECORD|AUDIO__ACTIVE) #define audio_get_play_waiting(F, V) \ audio__setval((F), (V), AUDIO__PLAY|AUDIO__WAITING) #define audio_get_record_waiting(F, V) \ audio__setval((F), (V), AUDIO__RECORD|AUDIO__WAITING) /* * The following macros set individual state values. * 'F' is an open audio file descriptor. * 'V' is a pointer to an unsigned int. * The value '*V' is updated after the device state has been read. */ #define audio_set_play_port(F, V) \ audio__setval((F), (V), AUDIO__SET|AUDIO__PLAY|AUDIO__PORT) #define audio_set_record_port(F, V) \ audio__setval((F), (V), AUDIO__SET|AUDIO__RECORD|AUDIO__PORT) /* * The value returned for these is the value *before* the state was changed. * This allows you to atomically read and reset their values. */ #define audio_set_play_balance(F, V) \ audio__setval((F), (V), AUDIO__SET|AUDIO__PLAY|AUDIO__BALANCE) #define audio_set_record_balance(F, V) \ audio__setval((F), (V), AUDIO__SET|AUDIO__RECORD|AUDIO__BALANCE) #define audio_set_play_samples(F, V) \ audio__setval((F), (V), AUDIO__SET|AUDIO__PLAY|AUDIO__SAMPLES) #define audio_set_record_samples(F, V) \ audio__setval((F), (V), AUDIO__SET|AUDIO__RECORD|AUDIO__SAMPLES) #define audio_set_play_error(F, V) \ audio__setval((F), (V), AUDIO__SET|AUDIO__PLAY|AUDIO__ERROR) #define audio_set_record_error(F, V) \ audio__setval((F), (V), AUDIO__SET|AUDIO__RECORD|AUDIO__ERROR) #define audio_set_play_eof(F, V) \ audio__setval((F), (V), AUDIO__SET|AUDIO__PLAY|AUDIO__EOF) /* The value can only be set to one. It is reset to zero on close(). */ #define audio_set_play_waiting(F, V) \ audio__setval((F), (V), AUDIO__SET|AUDIO__PLAY|AUDIO__WAITING) #define audio_set_record_waiting(F, V) \ audio__setval((F), (V), AUDIO__SET|AUDIO__RECORD|AUDIO__WAITING) /* * Gain routines take double values, mapping the valid range of gains * to a floating-point value between zero and one, inclusive. * The value returned will likely be slightly different than the value set. * This is because the value is quantized by the device. * * Make sure that 'V' is a (double *)! */ #define audio_get_play_gain(F, V) \ audio__setgain((F), (V), AUDIO__PLAY|AUDIO__GAIN) #define audio_get_record_gain(F, V) \ audio__setgain((F), (V), AUDIO__RECORD|AUDIO__GAIN) #define audio_get_monitor_gain(F, V) \ audio__setgain((F), (V), AUDIO__MONGAIN) #define audio_set_play_gain(F, V) \ audio__setgain((F), (V), AUDIO__SET|AUDIO__PLAY|AUDIO__GAIN) #define audio_set_record_gain(F, V) \ audio__setgain((F), (V), AUDIO__SET|AUDIO__RECORD|AUDIO__GAIN) #define audio_set_monitor_gain(F, V) \ audio__setgain((F), (V), AUDIO__SET|AUDIO__MONGAIN) /* * The following macros flush the audio play and/or record queues. * Note that requests to flush a channel that is not open will have no effect. */ #define audio_flush(F) \ audio__flush((F), AUDIO__PLAYREC) #define audio_flush_play(F) \ audio__flush((F), AUDIO__PLAY) #define audio_flush_record(F) \ audio__flush((F), AUDIO__RECORD) /* The following is used for 'which' arguments to get/set info routines */ #define AUDIO__PLAY (0x10000) #define AUDIO__RECORD (0x20000) #define AUDIO__PLAYREC (AUDIO__PLAY | AUDIO__RECORD) #define AUDIO__PORT (1) #define AUDIO__SAMPLES (2) #define AUDIO__ERROR (3) #define AUDIO__EOF (4) #define AUDIO__OPEN (5) #define AUDIO__ACTIVE (6) #define AUDIO__WAITING (7) #define AUDIO__GAIN (8) #define AUDIO__MONGAIN (9) #define AUDIO__PAUSE (10) #define AUDIO__RESUME (11) #define AUDIO__BALANCE (12) #define AUDIO__SET (0x80000000) #define AUDIO__SETVAL_MASK (0xff) #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_AUDIO_DEVICE_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1992-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_AUDIO_ENCODE_H #define _MULTIMEDIA_AUDIO_ENCODE_H #ifdef __cplusplus extern "C" { #endif #include #include /* * audio_encode.h * * u-law, A-law and linear PCM conversion tables and macros. */ /* PCM linear <-> a-law conversion tables */ extern short _alaw2linear[]; /* 8-bit a-law to 16-bit PCM */ extern unsigned char *_linear2alaw; /* 13-bit PCM to 8-bit a-law */ /* PCM linear <-> u-law conversion tables */ extern short _ulaw2linear[]; /* 8-bit u-law to 16-bit PCM */ extern unsigned char *_linear2ulaw; /* 14-bit PCM to 8-bit u-law */ /* A-law <-> u-law conversion tables */ extern unsigned char _alaw2ulaw[]; /* 8-bit A-law to 8-bit u-law */ extern unsigned char _ulaw2alaw[]; /* 8-bit u-law to 8-bit A-law */ /* PCM linear <-> a-law conversion macros */ /* a-law to 8,16,32-bit linear */ #define audio_a2c(X) ((char)(_alaw2linear[(unsigned char) (X)] >> 8)) #define audio_a2s(X) (_alaw2linear[(unsigned char) (X)]) #define audio_a2l(X) (((long)_alaw2linear[(unsigned char) (X)]) << 16) /* 8,16,32-bit linear to a-law */ #define audio_c2a(X) (_linear2alaw[((short)(X)) << 5]) #define audio_s2a(X) (_linear2alaw[((short)(X)) >> 3]) #define audio_l2a(X) (_linear2alaw[((long)(X)) >> 19]) /* PCM linear <-> u-law conversion macros */ /* u-law to 8,16,32-bit linear */ #define audio_u2c(X) ((char)(_ulaw2linear[(unsigned char) (X)] >> 8)) #define audio_u2s(X) (_ulaw2linear[(unsigned char) (X)]) #define audio_u2l(X) (((long)_ulaw2linear[(unsigned char) (X)]) << 16) /* 8,16,32-bit linear to u-law */ #define audio_c2u(X) (_linear2ulaw[((short)(X)) << 6]) #define audio_s2u(X) (_linear2ulaw[((short)(X)) >> 2]) #define audio_l2u(X) (_linear2ulaw[((long)(X)) >> 18]) /* A-law <-> u-law conversion macros */ #define audio_a2u(X) (_alaw2ulaw[(unsigned char)(X)]) #define audio_u2a(X) (_ulaw2alaw[(unsigned char)(X)]) /* * external declarations, type definitions and * macro definitions for use with the G.721 routines. */ /* * The following is the definition of the state structure * used by the G.721/G.723 encoder and decoder to preserve their internal * state between successive calls. The meanings of the majority * of the state structure fields are explained in detail in the * CCITT Recommendation G.721. The field names are essentially indentical * to variable names in the bit level description of the coding algorithm * included in this Recommendation. */ struct audio_g72x_state { long yl; /* Locked or steady state step size multiplier. */ short yu; /* Unlocked or non-steady state step size multiplier. */ short dms; /* Short term energy estimate. */ short dml; /* Long term energy estimate. */ short ap; /* Linear weighting coefficient of 'yl' and 'yu'. */ short a[2]; /* Coefficients of pole portion of prediction filter. */ short b[6]; /* Coefficients of zero portion of prediction filter. */ short pk[2]; /* * Signs of previous two samples of a partially * reconstructed signal. */ short dq[6]; /* * Previous 6 samples of the quantized difference * signal represented in an internal floating point * format. */ short sr[2]; /* * Previous 2 samples of the quantized difference * signal represented in an internal floating point * format. */ char td; /* delayed tone detect, new in 1988 version */ unsigned char leftover[8]; /* * This array is used to store the last unpackable * code bits in the event that the number of code bits * which must be packed into a byte stream is not a * multiple of the sample unit size. */ char leftover_cnt; /* * Flag indicating the number of bits stored in * 'leftover'. Reset to 0 upon packing of 'leftover'. */ }; /* External tables. */ /* Look-up table for performing fast log based 2. */ extern unsigned char _fmultanexp[]; /* Look-up table for perfoming fast 6bit by 6bit multiplication. */ extern unsigned char _fmultwanmant[]; /* * Look-up table for performing fast quantization of the step size * scale factor normalized log magnitude of the difference signal. */ extern unsigned char _quani[]; /* External function definitions. */ EXTERN_FUNCTION(void g721_init_state, (struct audio_g72x_state *state_ptr)); EXTERN_FUNCTION(int g721_encode, ( void *in_buf, int data_size, Audio_hdr *in_header, unsigned char *out_buf, int *out_size, struct audio_g72x_state *state_ptr)); EXTERN_FUNCTION(int g721_decode, ( unsigned char *in_buf, int data_size, Audio_hdr *out_header, void *out_buf, int *out_size, struct audio_g72x_state *state_ptr)); /* * Look-up table for performing fast quantization of the step size * scale factor normalized log magnitude of the difference signal. */ extern unsigned char _g723quani[]; /* External function definitions. */ EXTERN_FUNCTION(void g723_init_state, (struct audio_g72x_state *state_ptr)); EXTERN_FUNCTION(int g723_encode, ( void *in_buf, int data_size, Audio_hdr *out_header, unsigned char *out_buf, int *out_size, struct audio_g72x_state *state_ptr)); EXTERN_FUNCTION(int g723_decode, ( unsigned char *in_buf, int data_size, Audio_hdr *out_header, void *out_buf, int *out_size, struct audio_g72x_state *state_ptr)); #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_AUDIO_ENCODE_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 1992-2003 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #ifndef _MULTIMEDIA_AUDIO_ERRNO_H #define _MULTIMEDIA_AUDIO_ERRNO_H #ifdef __cplusplus extern "C" { #endif /* * libaudio error codes */ /* XXX - error returns and exception handling need to be worked out */ enum audioerror_t { AUDIO_SUCCESS = 0, /* no error */ AUDIO_NOERROR = -2, /* no error, no message */ AUDIO_UNIXERROR = -1, /* check errno for error code */ AUDIO_ERR_BADHDR = 1, /* bad audio header structure */ AUDIO_ERR_BADFILEHDR = 2, /* bad file header format */ AUDIO_ERR_BADARG = 3, /* bad subroutine argument */ AUDIO_ERR_NOEFFECT = 4, /* device control ignored */ AUDIO_ERR_ENCODING = 5, /* unknown encoding format */ AUDIO_ERR_INTERRUPTED = 6, /* operation was interrupted */ AUDIO_EOF = 7, /* end-of-file */ AUDIO_ERR_HDRINVAL = 8, /* unsupported data format */ AUDIO_ERR_PRECISION = 9, /* unsupported data precision */ AUDIO_ERR_NOTDEVICE = 10, /* not an audio device */ AUDIO_ERR_DEVICEBUSY = 11, /* audio device is busy */ AUDIO_ERR_BADFRAME = 12, /* partial sample frame */ AUDIO_ERR_FORMATLOCK = 13, /* audio format cannot be changed */ AUDIO_ERR_DEVOVERFLOW = 14, /* device overflow error */ AUDIO_ERR_BADFILETYPE = 15 /* bad audio header type */ }; #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_AUDIO_ERRNO_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 1992-2003 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #ifndef _MULTIMEDIA_AUDIO_HDR_H #define _MULTIMEDIA_AUDIO_HDR_H #ifdef __cplusplus extern "C" { #endif /* * Define an in-core audio data header. * * This is different that the on-disk file header. * The fields defined here are preliminary at best. */ /* * The audio header contains the following fields: * * endian Byte order of 16-bit or greater PCM, * and possibly floating point data. * * sample_rate Number of samples per second (per channel). * * samples_per_unit This field describes the number of samples * represented by each sample unit (which, by * definition, are aligned on byte boundaries). * Audio samples may be stored individually * or, in the case of compressed formats * (e.g., ADPCM), grouped in algorithm- * specific ways. If the data is bit-packed, * this field tells the number of samples * needed to get to a byte boundary. * * bytes_per_unit Number of bytes stored for each sample unit * * channels Number of interleaved sample units. * For any given time quantum, the set * consisting of 'channels' sample units * is called a sample frame. Seeks in * the data should be aligned to the start * of the nearest sample frame. * * encoding Data encoding format. * * data_size Number of bytes in the data. * This value is advisory only, and may * be set to the value AUDIO_UNKNOWN_SIZE * if the data size is unknown (for * instance, if the data is being * recorded or generated and piped * to another process). * * The first four values are used to compute the byte offset given a * particular time, and vice versa. Specifically: * * seconds = offset / C * offset = seconds * C * where: * C = (channels * bytes_per_unit * sample_rate) / samples_per_unit * * */ typedef struct { unsigned sample_rate; /* samples per second */ unsigned samples_per_unit; /* samples per unit */ unsigned bytes_per_unit; /* bytes per sample unit */ unsigned channels; /* # of interleaved channels */ unsigned encoding; /* data encoding format */ unsigned endian; /* byte order */ unsigned data_size; /* length of data (optional) */ } Audio_hdr; /* * Define the possible encoding types. * Note that the names that overlap the encodings in * must have the same values. */ #define AUDIO_ENCODING_NONE (0) /* No encoding specified ... */ #define AUDIO_ENCODING_ULAW (1) /* ISDN u-law */ #define AUDIO_ENCODING_ALAW (2) /* ISDN A-law */ #define AUDIO_ENCODING_LINEAR (3) /* PCM 2's-complement (0-center) */ #define AUDIO_ENCODING_FLOAT (100) /* IEEE float (-1. <-> +1.) */ #define AUDIO_ENCODING_G721 (101) /* CCITT g.721 ADPCM */ #define AUDIO_ENCODING_G722 (102) /* CCITT g.722 ADPCM */ #define AUDIO_ENCODING_G723 (103) /* CCITT g.723 ADPCM */ #define AUDIO_ENCODING_DVI (104) /* DVI ADPCM */ /* * Define the possible endian types. */ #define AUDIO_ENDIAN_BIG 0 /* SPARC, 68000, etc. */ #define AUDIO_ENDIAN_SMALL 1 /* Intel */ #define AUDIO_ENDIAN_UNKNOWN 2 /* Unknown endian */ /* Value used for indeterminate size (e.g., data passed through a pipe) */ #define AUDIO_UNKNOWN_SIZE ((unsigned)(~0)) /* Define conversion macros for integer<->floating-point conversions */ /* double to 8,16,32-bit linear */ #define audio_d2c(X) ((X) >= 1. ? 127 : (X) <= -1. ? -127 : \ (char)(rint((X) * 127.))) #define audio_d2s(X) ((X) >= 1. ? 32767 : (X) <= -1. ? -32767 :\ (short)(rint((X) * 32767.))) #define audio_d2l(X) ((X) >= 1. ? 2147483647 : (X) <= -1. ? \ -2147483647 : \ (long)(rint((X) * 2147483647.))) /* 8,16,32-bit linear to double */ #define audio_c2d(X) (((unsigned char)(X)) == 0x80 ? -1. : \ ((double)((char)(X))) / 127.) #define audio_s2d(X) (((unsigned short)(X)) == 0x8000 ? -1. :\ ((double)((short)(X))) / 32767.) #define audio_l2d(X) (((unsigned long)(X)) == 0x80000000 ? -1. :\ ((double)((long)(X))) / 2147483647.) #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_AUDIO_HDR_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1993-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _AUDIO_I18N_H #define _AUDIO_I18N_H #ifdef __cplusplus extern "C" { #endif #include extern char *ds_expand_pathname(const char *, char *); #define DGET(labels, str) (char *)dgettext(labels, str) #ifdef __cplusplus } #endif #endif /* !_AUDIO_I18N_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright (c) 1992-2001 by Sun Microsystems, Inc. * All rights reserved. */ #ifndef _MULTIMEDIA_AUDIO_TYPES_H #define _MULTIMEDIA_AUDIO_TYPES_H #ifdef __cplusplus extern "C" { #endif /* * NOTE: The following is the contents of c_varieties.h. We'll use the * _C_VARIETIES_H header guard so there's no conflict if c_varieties.h * is also included. The C_VARIETIES_H header guard is in */ #ifndef _C_VARIETIES_H #define _C_VARIETIES_H #ifndef C_VARIETIES_H #define C_VARIETIES_H /* * This file defines some macros that are used to make code * portable among the major C dialects currently in use at * Sun. As of 12/90, these include Sun C (a lot like K&R C), * ANSI C, and C++. * * external functions: * To declare an external function, invoke the EXTERN_FUNCTION * macro; the macro's first parameter should be the function's * return type and function name, and the second macro parameter * should be the parenthesized list of function arguments (or an * ellipsis - DOTDOTDOT macro should be used to indicate the * ellipsis as explained later in this file - if the arguments are * unspecified or of varying number or type, or the uppercase word * "_VOID_" if the function takes no arguments). Some examples: * * EXTERN_FUNCTION( void printf, (char *, DOTDOTDOT) ); * EXTERN_FUNCTION( int fread, (char*, int, int, FILE*) ); * EXTERN_FUNCTION( int getpid, (_VOID_) ); * * Note that to be ANSI-C conformant, one should put "," at the end * first argument of printf() declaration. * * structure tags: * In order to handle cases where a structure tag has the same name * as a type, the STRUCT_TAG macro makes the tag disappear in C++. * An example (from ): * * typedef struct STRUCT_TAG(fd_set) { ... } fd_set; * * enum bitfields: * In K&R C as interpreted at UCB, bitfields may be declared to * be of an enumerated type. Neither ANSI C nor C++ permit this, * so the ENUM_BITFIELD macro replaces the enum declaration with * "unsigned". An example (from ): * * struct { * ENUM_BITFIELD( Attr_pkg ) pkg : 8; * unsigned ordinal : 8; * ENUM_BITFIELD( Attr_list_type ) list_type : 8; * ... * }; * * enum type specifier: * In K&R C, it is OK to use "enum xyz" as return type but in C++, * one should use "xyz". ENUM_TYPE macro is used to handle this. * * ENUM_TYPE(enum, xyz) (*func) (...); * * "struct s s;": * C++ does not allow this sort of name conflict, since struct tags are * in the same namespace as variables. In this case, we use the * NAME_CONFLICT macro to prepend (for C++) an underscore to the * variable (or struct member) name. E.g. from : * * typedef struct pixrect { * struct pixrectops *pr_ops; * struct pr_size NAME_CONFLICT(pr_size); * } Pixrect; * #define pr_height NAME_CONFLICT(pr_size).y * #define pr_width NAME_CONFLICT(pr_size).x * * Note that no spaces are allowed within the parentheses in the * invocation of NAME_CONFLICT. * * Pointers to functions declared as struct members: * Instead of getting picky about the types expected by struct * members which are pointers to functions, we use DOTDOTDOT to * tell C++ not to be so uptight: * * struct pixrectops { * int (*pro_rop)( DOTDOTDOT ); * int (*pro_stencil)( DOTDOTDOT ); * int (*pro_batchrop)( DOTDOTDOT ); * . . . * }; * */ /* Which type of C/C++ compiler are we using? */ #if defined(__cplusplus) /* * Definitions for C++ 2.0 and later require extern "C" { decl; } */ #define EXTERN_FUNCTION(rtn, args) extern "C" { rtn args; } #define STRUCT_TAG(tag_name) /* the tag disappears */ #define ENUM_BITFIELD(enum_type) unsigned #define ENUM_TYPE(enum_sp, enum_ty) enum_ty #if defined(__STDC__) || defined(__cplusplus) || defined(c_plusplus) #define NAME_CONFLICT(name) _##name #else #define NAME_CONFLICT(name) _**name #endif #define DOTDOTDOT ... #define _VOID_ /* anachronism */ #define CONST const /* * This is not necessary for 2.0 since 2.0 has corrected the void (*) () problem */ typedef void (*_PFV_)(); typedef int (*_PFI_)(); #elif defined(c_plusplus) /* * Definitions for C++ 1.2 */ #define EXTERN_FUNCTION(rtn, args) rtn args #define STRUCT_TAG(tag_name) /* the tag disappears */ #define ENUM_BITFIELD(enum_type) unsigned #define ENUM_TYPE(enum_sp, enum_ty) enum_ty #define NAME_CONFLICT(name) _**name #define DOTDOTDOT ... #define _VOID_ /* anachronism */ #define CONST const typedef void (*_PFV_)(); typedef int (*_PFI_)(); #elif defined(__STDC__) /* * Definitions for ANSI C */ #define EXTERN_FUNCTION(rtn, args) rtn args #define STRUCT_TAG(tag_name) tag_name #define ENUM_BITFIELD(enum_type) unsigned #define ENUM_TYPE(enum_sp, enum_ty) enum_sp enum_ty #define NAME_CONFLICT(name) name #define DOTDOTDOT ... #define _VOID_ void #define CONST #else /* * Definitions for Sun/K&R C -- ignore function prototypes, * but preserve tag names and enum bitfield declarations. */ #define EXTERN_FUNCTION(rtn, args) rtn() #define STRUCT_TAG(tag_name) tag_name #define ENUM_BITFIELD(enum_type) enum_type #define ENUM_TYPE(enum_sp, enum_ty) enum_sp enum_ty #define NAME_CONFLICT(name) name #define DOTDOTDOT #define _VOID_ /* VOID is only used where it disappears anyway */ #define CONST #endif /* Which type of C/C++ compiler are we using? */ #endif /* !C_VARIETIES_H */ #endif /* !_C_VARIETIES_H */ #ifdef __cplusplus } #endif #endif /* !_MULTIMEDIA_AUDIO_TYPES_H */ /* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 1992-2003 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #ifndef _MULTIMEDIA_LIBAUDIO_H #define _MULTIMEDIA_LIBAUDIO_H #include #include #include #include #include #include