dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / audio / utilities / AudioStream.cc
blobbdde212b9ead9d925c98270b7a6f7c3bbd8e2748
1 /*
2 * CDDL HEADER START
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
7 * with the License.
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]
20 * CDDL HEADER END
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>
30 #include <string.h>
32 // class AudioStream methods
35 // Constructor
36 AudioStream::
37 AudioStream(
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::
45 updateheader(
46 const AudioHdr& h) // new header to set
48 AudioError err;
50 // Validate the header before stuffing it in
51 err = h.Validate();
52 if (err != AUDIO_SUCCESS)
53 return (RaiseError(err));
55 // Copy in the new header
56 hdr = h;
57 return (AUDIO_SUCCESS);
60 // Set the header structure
61 AudioError AudioStream::
62 SetHeader(
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,
76 AudioEndian endian)
78 // If the stream isn't endian sensitive, don't bother.
79 if (! isEndianSensitive())
80 return (AUDIO_SUCCESS);
82 if (hdr.endian == endian) {
83 #ifdef DEBUG
84 AUDIO_DEBUG((1, "AudioStream: endian swap not needed, byte"
85 "order OK.\n"));
86 #endif
87 return (AUDIO_SUCCESS);
90 // The endians don't match, lets swap bytes.
91 unsigned char chTemp;
92 for (int i = 0; i < len - 1; i += 2) {
93 chTemp = buf[i];
94 buf[i] = buf[i + 1];
95 buf[i+1] = chTemp;
98 #ifdef DEBUG
99 AUDIO_DEBUG((1, "AudioStream: converting endian.\n"));
100 // printf("AudioStream: converting endian.\n");
101 #endif
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)
111 return (TRUE);
113 return (FALSE);