summaryrefslogtreecommitdiff
blob: d25b79cff81ed89f88ae55f45e5d4848011b119c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
--- sfconvert.c.orig	2004-04-04 23:39:56.000000000 -0700
+++ sfconvert.c	2004-04-05 00:00:25.000000000 -0700
@@ -66,12 +66,14 @@
 
 	AFfilehandle	infile, outfile;
 	AFfilesetup	outfilesetup;
-	int		sampleFormat, sampleWidth, channelCount;
-	double		sampleRate;
+	int		sampleFormat, sampleWidth, channelCount, byteOrder;
+	double		sampleRate, outSampleRate;
+	int		outSampleRateInt = -1;
 	int		outSampleFormat = -1, outSampleWidth = -1,
-			outChannelCount = -1;
+			outChannelCount = -1, outByteOrder = -1;
 	double		outMaxAmp = 1.0;
 
+
 	AFframecount	totalFrames;
 
 	if (argc < 3)
@@ -88,7 +90,10 @@
 		{
 			if (i + 1 >= argc)
 				usageerror();
-			if (!strcmp(argv[i+1], "aiff"))
+
+			if (!strcmp(argv[i+1], "raw"))
+				outFileFormat = AF_FILE_RAWDATA;
+			else if (!strcmp(argv[i+1], "aiff"))
 				outFileFormat = AF_FILE_AIFF;
 			else if (!strcmp(argv[i+1], "aifc"))
 				outFileFormat = AF_FILE_AIFFC;
@@ -98,6 +103,12 @@
 				outFileFormat = AF_FILE_NEXTSND;
 			else if (!strcmp(argv[i+1], "bics"))
 				outFileFormat = AF_FILE_BICSF;
+			else if (!strcmp(argv[i+1], "avr"))
+				outFileFormat = AF_FILE_AVR;
+			else if (!strcmp(argv[i+1], "iff"))
+				outFileFormat = AF_FILE_IFF_8SVX;
+			else if (!strcmp(argv[i+1], "nist"))
+				outFileFormat = AF_FILE_NIST_SPHERE;
 			else
 			{
 				fprintf(stderr, "sfconvert: Unknown format %s.\n", argv[i+1]);
@@ -107,6 +118,22 @@
 			/* Increment for argument. */
 			i++;
 		}
+		else if (!strcmp(argv[i], "byteorder"))
+		{
+			if (i + 1 >= argc)
+				usageerror();
+
+			if(!strcmp("big", argv[i+1])) {
+				outByteOrder = AF_BYTEORDER_BIGENDIAN;
+			} else if(!strcmp("little", argv[i+1])) {
+				outByteOrder = AF_BYTEORDER_LITTLEENDIAN;
+			} else {
+				usageerror();
+			}
+
+			/* Increment for argument. */
+			i++;
+		}
 		else if (!strcmp(argv[i], "channels"))
 		{
 			if (i + 1 >= argc)
@@ -119,6 +146,20 @@
 			/* Increment for argument. */
 			i++;
 		}
+		else if (!strcmp(argv[i], "rate"))
+		{
+			if (i + 1 >= argc)
+				usageerror();
+
+			outSampleRateInt = atoi(argv[i+1]);
+			if (outSampleRateInt <= 0)
+				usageerror();
+
+			outSampleRate = (double)outSampleRateInt;
+
+			/* Increment for argument. */
+			i++;
+		}
 		else if (!strcmp(argv[i], "float"))
 		{
 			if (i + 1 >= argc)
@@ -170,6 +211,7 @@
 	totalFrames = afGetFrameCount(infile, AF_DEFAULT_TRACK);
 	channelCount = afGetChannels(infile, AF_DEFAULT_TRACK);
 	sampleRate = afGetRate(infile, AF_DEFAULT_TRACK);
+        byteOrder = afGetByteOrder(infile, AF_DEFAULT_TRACK);
 	afGetSampleFormat(infile, AF_DEFAULT_TRACK, &sampleFormat, &sampleWidth);
 
 	/* Initialize output audio format parameters. */
@@ -184,14 +226,21 @@
 		outSampleWidth = sampleWidth;
 	}
 
+	if (outByteOrder == -1)
+		outByteOrder = byteOrder;
+
 	if (outChannelCount == -1)
 		outChannelCount = channelCount;
 
+	if (outSampleRateInt == -1)
+		outSampleRate = sampleRate;
+
 	afInitFileFormat(outfilesetup, outFileFormat);
 	afInitSampleFormat(outfilesetup, AF_DEFAULT_TRACK, outSampleFormat,
 		outSampleWidth);
 	afInitChannels(outfilesetup, AF_DEFAULT_TRACK, outChannelCount);
-	afInitRate(outfilesetup, AF_DEFAULT_TRACK, sampleRate);
+	afInitRate(outfilesetup, AF_DEFAULT_TRACK, outSampleRate);
+        afInitByteOrder(outfilesetup, AF_DEFAULT_TRACK, outByteOrder);
 
 	outfile = afOpenFile(outfilename, "w", outfilesetup);
 	if (outfile == AF_NULL_FILEHANDLE)
@@ -228,6 +277,7 @@
 	printf("\n");
 
 	printf("Where keywords specify format of input or output soundfile:\n");
+	printf("    rate n         sample rate (22050, 44100, 48000, etc.)\n");
 	printf("    byteorder e    endian (e is big or little)\n");
 	printf("    channels n     n-channel file (1 or 2)\n");
 	printf("    format f       file format f (see below)\n");
@@ -239,11 +289,15 @@
 
 	printf("Currently supported formats are:\n");
 	printf("\n");
+	printf("    raw     \n");
 	printf("    aiff    Audio Interchange File Format\n");
 	printf("    aifc    AIFF-C File Format\n");
 	printf("    next    NeXT/Sun Format\n");
 	printf("    wave    MS RIFF WAVE Format\n");
 	printf("    bics    Berkeley/IRCAM/CARL Sound File Format\n");
+	printf("    avr     Audio Visual Research File Format\n");
+	printf("    iff     Amiga IFF/8SVX Sound File Format\n");
+	printf("    nist    NIST SPHERE File Format\n");
 	printf("\n");
 
 	exit(EXIT_FAILURE);