4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 1990-2001 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <AudioStream.h>
32 // class AudioStream methods
38 const char *path
): // pathname
39 Audio(path
), length(AUDIO_UNKNOWN_TIME
)
43 // Set the header structure, even if it is already set
44 AudioError
AudioStream::
46 const AudioHdr
& h
) // new header to set
50 // Validate the header before stuffing it in
52 if (err
!= AUDIO_SUCCESS
)
53 return (RaiseError(err
));
55 // Copy in the new header
57 return (AUDIO_SUCCESS
);
60 // Set the header structure
61 AudioError
AudioStream::
63 const AudioHdr
& h
) // new header to set
65 // Once the header is set and the file is open, it cannot be changed
66 // XXX - hdrset test might be redundant?
67 if (hdrset() && opened())
68 return (RaiseError(AUDIO_ERR_NOEFFECT
));
70 return (updateheader(h
));
73 // Check the endian nature of the data, and change if necessary.
74 AudioError
AudioStream::
75 coerceEndian(unsigned char *buf
, size_t len
,
78 // If the stream isn't endian sensitive, don't bother.
79 if (! isEndianSensitive())
80 return (AUDIO_SUCCESS
);
82 if (hdr
.endian
== endian
) {
84 AUDIO_DEBUG((1, "AudioStream: endian swap not needed, byte"
87 return (AUDIO_SUCCESS
);
90 // The endians don't match, lets swap bytes.
92 for (int i
= 0; i
< len
- 1; i
+= 2) {
99 AUDIO_DEBUG((1, "AudioStream: converting endian.\n"));
100 // printf("AudioStream: converting endian.\n");
102 return (AUDIO_SUCCESS
);
105 // This routine knows if the current format is endian sensitive.
106 Boolean
AudioStream::isEndianSensitive() const
109 // Only these encodings have endian problems.
110 if (hdr
.encoding
== LINEAR
|| hdr
.encoding
== FLOAT
)