(Metux) autogen.sh: not running ./configure anymore (breaks certain distro builders)
[mirror-ossqm-audiofile.git] / libaudiofile / ircamwrite.c
blobc92f11991b616d3ea588474e0ab04e5cbec2b27f
1 /*
2 Audio File Library
3 Copyright (C) 2001, Silicon Graphics, Inc.
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307 USA.
22 ircamwrite.c
24 This file contains routines for writing to Berkeley/IRCAM/CARL
25 format files.
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
32 #include <assert.h>
33 #include <stdint.h>
34 #include <stdio.h>
35 #include <string.h>
37 #include "afinternal.h"
38 #include "audiofile.h"
39 #include "util.h"
40 #include "byteorder.h"
41 #include "setup.h"
42 #include "track.h"
43 #include "marker.h"
45 #include "ircam.h"
48 Here ircam_mips_magic refers to little-endian MIPS, not SGI IRIX,
49 which uses big-endian MIPS.
51 extern const uint8_t _af_ircam_vax_magic[4], _af_ircam_sun_magic[4],
52 _af_ircam_mips_magic[4], _af_ircam_next_magic[4];
54 /* We write IRCAM files using the native byte order. */
55 status _af_ircam_write_init (AFfilesetup setup, AFfilehandle handle)
57 _Track *track;
58 const uint8_t *magic;
59 float rate;
60 uint32_t channels;
61 uint32_t packMode;
62 uint32_t dataOffset;
63 uint8_t zeros[SIZEOF_BSD_HEADER];
65 float maxAmp = 1.0;
67 bool isSwapped, isLittleEndian;
69 assert(handle->fileFormat == AF_FILE_IRCAM);
71 if (_af_filesetup_make_handle(setup, handle) == AF_FAIL)
72 return AF_FAIL;
74 dataOffset = SIZEOF_BSD_HEADER;
76 track = &handle->tracks[0];
77 track->totalfframes = 0;
78 track->fpos_first_frame = dataOffset;
79 track->nextfframe = 0;
80 track->fpos_next_frame = track->fpos_first_frame;
82 handle->formatSpecific = NULL;
84 /* Choose the magic number appropriate for the byte order. */
85 #ifdef WORDS_BIGENDIAN
86 magic = _af_ircam_sun_magic;
87 #else
88 magic = _af_ircam_vax_magic;
89 #endif
91 channels = track->f.channelCount;
92 rate = track->f.sampleRate;
94 assert(track->f.compressionType == AF_COMPRESSION_NONE);
96 if (track->f.sampleFormat == AF_SAMPFMT_TWOSCOMP)
98 assert(track->f.sampleWidth == 16);
99 packMode = SF_SHORT;
101 else if (track->f.sampleFormat == AF_SAMPFMT_FLOAT)
103 assert(track->f.sampleWidth == 32);
104 packMode = SF_FLOAT;
107 af_fseek(handle->fh, 0, SEEK_SET);
108 af_fwrite(magic, 4, 1, handle->fh);
109 af_fwrite(&rate, 4, 1, handle->fh);
110 af_fwrite(&channels, 4, 1, handle->fh);
111 af_fwrite(&packMode, 4, 1, handle->fh);
113 /* Zero the entire description block. */
114 memset(zeros, 0, SIZEOF_BSD_HEADER);
115 af_fwrite(zeros, SIZEOF_BSD_HEADER - 4*4, 1, handle->fh);
117 return AF_SUCCEED;
120 status _af_ircam_update (AFfilehandle file)
122 return AF_SUCCEED;