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.
24 This file contains routines for writing to Berkeley/IRCAM/CARL
37 #include "afinternal.h"
38 #include "audiofile.h"
40 #include "byteorder.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
)
63 uint8_t zeros
[SIZEOF_BSD_HEADER
];
67 bool isSwapped
, isLittleEndian
;
69 assert(handle
->fileFormat
== AF_FILE_IRCAM
);
71 if (_af_filesetup_make_handle(setup
, handle
) == 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
;
88 magic
= _af_ircam_vax_magic
;
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);
101 else if (track
->f
.sampleFormat
== AF_SAMPFMT_FLOAT
)
103 assert(track
->f
.sampleWidth
== 32);
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
);
120 status
_af_ircam_update (AFfilehandle file
)