comparison src/nas.c @ 442:abe6d1db359e r21-2-36

Import from CVS: tag r21-2-36
author cvs
date Mon, 13 Aug 2007 11:35:02 +0200
parents 8de8e3f6228a
children 183866b06e0b
comparison
equal deleted inserted replaced
441:72a7cfa4a488 442:abe6d1db359e
66 66
67 #ifdef HAVE_UNISTD_H 67 #ifdef HAVE_UNISTD_H
68 #include <unistd.h> 68 #include <unistd.h>
69 #endif 69 #endif
70 70
71 71 /* NAS <= 1.2p5 defines {BIG,LITTLE}_ENDIAN in <audio/fileutil.h>,
72 conflicting with GNU libc (at least); newer versions avoid this
73 name space pollution.
74
75 DO NOT USE THOSE MACROS in this file. Use NAS_{BIG,LITTLE}_ENDIAN.
76
77 It would be slightly more reliable to do this via configure, but that
78 seems unnecessarily complex.
79 */
72 #undef LITTLE_ENDIAN 80 #undef LITTLE_ENDIAN
73 #undef BIG_ENDIAN 81 #undef BIG_ENDIAN
82
74 #include <audio/audiolib.h> 83 #include <audio/audiolib.h>
75 #include <audio/soundlib.h> 84 #include <audio/soundlib.h>
76 #include <audio/snd.h> 85 #include <audio/snd.h>
77 #include <audio/wave.h> 86 #include <audio/wave.h>
78 #include <audio/fileutil.h> 87 #include <audio/fileutil.h>
79 88
89 /* NAS <= 1.2p5 <audio/fileutil.h> doesn't define the NAS_ versions */
90 #ifndef NAS_LITTLE_ENDIAN
91 #define NAS_LITTLE_ENDIAN LITTLE_ENDIAN
92 #define NAS_BIG_ENDIAN BIG_ENDIAN
93 #endif
94
80 #ifdef emacs 95 #ifdef emacs
81 96
82 # define XTOOLKIT 97 # define XTOOLKIT
83 # define XTEVENTS 98 # define XTEVENTS
84 # define ROBUST_PLAY 99 # define ROBUST_PLAY
106 # define init_play nas_init_play 121 # define init_play nas_init_play
107 # define close_down_play nas_close_down_play 122 # define close_down_play nas_close_down_play
108 123
109 #else /* !emacs */ 124 #else /* !emacs */
110 # define warn(str) fprintf (stderr, "%s\n", (str)) 125 # define warn(str) fprintf (stderr, "%s\n", (str))
111 # define CONST const
112 #endif /* emacs */ 126 #endif /* emacs */
113 127
114 #ifdef XTOOLKIT 128 #ifdef XTOOLKIT
115 # include <X11/Intrinsic.h> 129 # include <X11/Intrinsic.h>
116 # include <audio/Xtutil.h> 130 # include <audio/Xtutil.h>
622 \********************************************************************/ 636 \********************************************************************/
623 637
624 /* Create a name from the sound. */ 638 /* Create a name from the sound. */
625 639
626 static char * 640 static char *
627 NameFromData (CONST char *buf, 641 NameFromData (const char *buf,
628 int len) 642 int len)
629 643
630 { 644 {
631 char name[9]; 645 char name[9];
632 int i; 646 int i;
666 /* Code to do a pseudo-open on a data buffer. Only for snd files at the 680 /* Code to do a pseudo-open on a data buffer. Only for snd files at the
667 moment. 681 moment.
668 */ 682 */
669 683
670 static SndInfo * 684 static SndInfo *
671 SndOpenDataForReading (CONST char *data, 685 SndOpenDataForReading (const char *data,
672 int length) 686 int length)
673 687
674 { 688 {
675 SndInfo *si; 689 SndInfo *si;
676 int size; 690 int size;
681 si->comment = NULL; 695 si->comment = NULL;
682 si->writing = 0; 696 si->writing = 0;
683 697
684 memcpy (&si->h, data, sizeof (SndHeader)); 698 memcpy (&si->h, data, sizeof (SndHeader));
685 699
686 if (LITTLE_ENDIAN) 700 if (NAS_LITTLE_ENDIAN)
687 { 701 {
688 char n; 702 char n;
689 703
690 swapl (&si->h.magic, n); 704 swapl (&si->h.magic, n);
691 swapl (&si->h.dataOffset, n); 705 swapl (&si->h.dataOffset, n);
742 /* The "file" position */ 756 /* The "file" position */
743 static size_t file_posn; 757 static size_t file_posn;
744 /* The length of the "file" */ 758 /* The length of the "file" */
745 static size_t file_len; 759 static size_t file_len;
746 /* The actual "file" data. */ 760 /* The actual "file" data. */
747 static CONST void* file_data; 761 static const void* file_data;
748 762
749 /* Like fopen, but for a buffer in memory */ 763 /* Like fopen, but for a buffer in memory */
750 static void 764 static void
751 dopen (CONST void* data, size_t length) 765 dopen (const void* data, size_t length)
752 { 766 {
753 file_data = data; 767 file_data = data;
754 file_len = length; 768 file_len = length;
755 file_posn = 0; 769 file_posn = 0;
756 } 770 }
833 { 847 {
834 int status; 848 int status;
835 char n; 849 char n;
836 850
837 if ((status = dread(c, sizeof(RiffChunk), 1))) 851 if ((status = dread(c, sizeof(RiffChunk), 1)))
838 if (BIG_ENDIAN) 852 if (NAS_BIG_ENDIAN)
839 swapl(&c->ckSize, n); 853 swapl(&c->ckSize, n);
840 854
841 return status; 855 return status;
842 } 856 }
843 857
844 /* A very straight-forward translation of WaveOpenFileForReading to 858 /* A very straight-forward translation of WaveOpenFileForReading to
845 read the wave data from a buffer in memory. */ 859 read the wave data from a buffer in memory. */
846 860
847 static WaveInfo * 861 static WaveInfo *
848 WaveOpenDataForReading (CONST char *data, 862 WaveOpenDataForReading (const char *data,
849 int length) 863 int length)
850 { 864 {
851 RiffChunk ck; 865 RiffChunk ck;
852 RIFF_FOURCC fourcc; 866 RIFF_FOURCC fourcc;
853 AuInt32 fileSize; 867 AuInt32 fileSize;
919 /* wave format chunk */ 933 /* wave format chunk */
920 else if (!cmpID(&ck.ckID, RIFF_WaveFmtID) && !wi->format) 934 else if (!cmpID(&ck.ckID, RIFF_WaveFmtID) && !wi->format)
921 { 935 {
922 AuInt32 dummy; 936 AuInt32 dummy;
923 937
924 wi->format = DataReadS(BIG_ENDIAN); 938 wi->format = DataReadS(NAS_BIG_ENDIAN);
925 wi->channels = DataReadS(BIG_ENDIAN); 939 wi->channels = DataReadS(NAS_BIG_ENDIAN);
926 wi->sampleRate = DataReadL(BIG_ENDIAN); 940 wi->sampleRate = DataReadL(NAS_BIG_ENDIAN);
927 941
928 /* we don't care about the next two fields */ 942 /* we don't care about the next two fields */
929 dummy = DataReadL(BIG_ENDIAN); 943 dummy = DataReadL(NAS_BIG_ENDIAN);
930 dummy = DataReadS(BIG_ENDIAN); 944 dummy = DataReadS(NAS_BIG_ENDIAN);
931 945
932 if (wi->format != RIFF_WAVE_FORMAT_PCM) 946 if (wi->format != RIFF_WAVE_FORMAT_PCM)
933 Err(); 947 Err();
934 948
935 wi->bitsPerSample = DataReadS(BIG_ENDIAN); 949 wi->bitsPerSample = DataReadS(NAS_BIG_ENDIAN);
936 950
937 /* skip any other format specific fields */ 951 /* skip any other format specific fields */
938 dseek(PAD2(ck.ckSize - 16), 1); 952 dseek(PAD2(ck.ckSize - 16), 1);
939 } 953 }
940 /* wave data chunk */ 954 /* wave data chunk */