sun.c
上传用户:xiejiait
上传日期:2007-01-06
资源大小:881k
文件大小:2k
- /* @(#)sun.c 1.2 99/12/19 Copyright 1998,1999 Heiko Eissfeldt */
- #ifndef lint
- static char sccsid[] =
- "@(#)sun.c 1.2 99/12/19 Copyright 1998,1999 Heiko Eissfeldt";
- #endif
- /***
- * CopyPolicy: GNU Public License 2 applies
- * Copyright (C) by Heiko Eissfeldt
- *
- *
- * ---------------------------------------------------------------------
- * definitions for sun pcm output
- * ---------------------------------------------------------------------
- */
- #include "config.h"
- #include "mytype.h"
- #include <stdio.h>
- #if defined (HAVE_UNISTD_H) && (HAVE_UNISTD_H == 1)
- #include <sys/types.h>
- #include <unistd.h>
- #endif
- #include "byteorder.h"
- #include "sndfile.h"
- typedef struct SUNHDR {
- unsigned int magic; /* dns. a la .snd */
- unsigned int data_location; /* offset to data */
- unsigned int size; /* # of data bytes */
- unsigned int format; /* format code */
- unsigned int sample_rate; /* in Hertz */
- unsigned int channelcount; /* 1 for mono, 2 for stereo */
- char info[8]; /* comments */
- } SUNHDR;
- static SUNHDR sunHdr;
- static int InitSound __PR(( int audio, long channels, unsigned long rate, long nBitsPerSample, unsigned long expected_bytes ));
- static int InitSound ( audio, channels, rate, nBitsPerSample, expected_bytes)
- int audio;
- long channels;
- unsigned long rate;
- long nBitsPerSample;
- unsigned long expected_bytes;
- {
- unsigned long format = nBitsPerSample > 8 ? 0x03 : 0x02;
- sunHdr.magic = cpu_to_le32(UINT4_C(0x646e732e));
- sunHdr.data_location = cpu_to_be32(0x20);
- sunHdr.size = cpu_to_be32(expected_bytes);
- sunHdr.format = cpu_to_be32(format);
- sunHdr.sample_rate = cpu_to_be32(rate);
- sunHdr.channelcount = cpu_to_be32(channels);
- return write (audio, &sunHdr, sizeof (sunHdr));
- }
- static int ExitSound __PR(( int audio, unsigned long nBytesDone ));
- static int ExitSound ( audio, nBytesDone )
- int audio;
- unsigned long nBytesDone;
- {
- sunHdr.size = cpu_to_be32(nBytesDone);
- /* goto beginning */
- if (lseek(audio, 0L, SEEK_SET) == -1) {
- return 0;
- }
- return write (audio, &sunHdr, sizeof (sunHdr));
- }
- static unsigned long GetHdrSize __PR(( void ));
- static unsigned long GetHdrSize( )
- {
- return sizeof( sunHdr );
- }
- struct soundfile sunsound =
- {
- InitSound, /* init header method */
- ExitSound, /* exit header method */
- GetHdrSize, /* report header size method */
- 1 /* needs big endian samples */
- };