2 * This file has been modified for the cdrkit suite.
4 * The behaviour and appearence of the program code below can differ to a major
5 * extent from the version distributed by the original author(s).
7 * For details, see Changelog file distributed with the cdrkit package. If you
8 * received this file from another source then ask the distributing person for
9 * a log of modifications.
13 /* @(#)sun.c 1.4 01/10/27 Copyright 1998,1999 Heiko Eissfeldt */
15 * CopyPolicy: GNU Public License 2 applies
16 * Copyright (C) by Heiko Eissfeldt
19 * ---------------------------------------------------------------------
20 * definitions for sun pcm output
21 * ---------------------------------------------------------------------
28 #include "byteorder.h"
31 typedef struct SUNHDR {
32 unsigned int magic; /* dns. a la .snd */
33 unsigned int data_location; /* offset to data */
34 unsigned int size; /* # of data bytes */
35 unsigned int format; /* format code */
36 unsigned int sample_rate; /* in Hertz */
37 unsigned int channelcount; /* 1 for mono, 2 for stereo */
38 char info[8]; /* comments */
43 static int InitSound(int audio, long channels, unsigned long rate,
44 long nBitsPerSample, unsigned long expected_bytes);
46 static int InitSound(int audio, long channels, unsigned long rate,
47 long nBitsPerSample, unsigned long expected_bytes)
49 unsigned long format = nBitsPerSample > 8 ? 0x03 : 0x02;
51 sunHdr.magic = cpu_to_le32(UINT4_C(0x646e732e));
52 sunHdr.data_location = cpu_to_be32(0x20);
53 sunHdr.size = cpu_to_be32(expected_bytes);
54 sunHdr.format = cpu_to_be32(format);
55 sunHdr.sample_rate = cpu_to_be32(rate);
56 sunHdr.channelcount = cpu_to_be32(channels);
58 return write (audio, &sunHdr, sizeof (sunHdr));
61 static int ExitSound(int audio, unsigned long nBytesDone);
63 static int ExitSound(int audio, unsigned long nBytesDone)
65 sunHdr.size = cpu_to_be32(nBytesDone);
68 if (lseek(audio, 0L, SEEK_SET) == -1) {
71 return write (audio, &sunHdr, sizeof (sunHdr));
74 static unsigned long GetHdrSize(void);
76 static unsigned long GetHdrSize()
78 return sizeof( sunHdr );
81 static unsigned long InSizeToOutSize(unsigned long BytesToDo);
83 static unsigned long InSizeToOutSize(unsigned long BytesToDo)
88 struct soundfile sunsound =
90 InitSound, /* init header method */
91 ExitSound, /* exit header method */
92 GetHdrSize, /* report header size method */
93 /* get sound samples out */
94 (int (*)(int audio, unsigned char *buf, unsigned long BytesToDo)) write,
95 InSizeToOutSize, /* compressed? output file size */
96 1 /* needs big endian samples */