8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / audio / utilities / AudioLib.cc
blobd8d80854e3857a220887741aacbb17112926416f
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 <Audio.h>
30 #include <AudioFile.h>
31 #include <AudioList.h>
32 #include <AudioLib.h>
34 // Generic Audio functions
37 // Open an audio file readonly, and return an AudioList referencing it.
38 AudioError
39 Audio_OpenInputFile(
40 const char *path, // input filename
41 Audio*& ap) // returned AudioList pointer
43 AudioFile* inf;
44 AudioList* lp;
45 AudioError err;
47 // Open file and decode the header
48 inf = new AudioFile(path, (FileAccess)ReadOnly);
49 if (inf == 0)
50 return (AUDIO_UNIXERROR);
51 err = inf->Open();
52 if (err) {
53 delete inf;
54 return (err);
57 // Create a list object and set it up to reference the file
58 lp = new AudioList;
59 if (lp == 0) {
60 delete inf;
61 return (AUDIO_UNIXERROR);
63 lp->Insert(inf);
64 ap = lp;
65 return (AUDIO_SUCCESS);
69 // Create an output file and copy an input stream to it.
70 // If an error occurs during output, leave a partially written file.
71 AudioError
72 Audio_WriteOutputFile(
73 const char *path, // output filename
74 const AudioHdr& hdr, // output data header
75 Audio* input) // input data stream
77 AudioFile* outf;
78 AudioError err;
80 // Create output file object
81 outf = new AudioFile(path, (FileAccess)WriteOnly);
82 if (outf == 0)
83 return (AUDIO_UNIXERROR);
85 // Set audio file header and create file
86 if ((err = outf->SetHeader(hdr)) || (err = outf->Create())) {
87 delete outf;
88 return (err);
91 // Copy data to file
92 err = AudioCopy(input, outf);
94 // Close output file and clean up. If error, leave partial file.
95 delete outf;
96 return (err);