[xiph-cvs] cvs commit: ao/src ao_alsa.c ao_oss.c ao_wav.c audio_out.c

Jack Moffitt jack at xiph.org
Tue Sep 26 23:11:55 PDT 2000



jack        00/09/26 23:11:55

  Modified:    include/ao ao.h
               src      ao_alsa.c ao_oss.c ao_wav.c audio_out.c
  Log:
  brought up to date with postbeta2

Revision  Changes    Path
1.2       +5 -7      ao/include/ao/ao.h

Index: ao.h
===================================================================
RCS file: /usr/local/cvsroot/ao/include/ao/ao.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ao.h	2000/09/03 09:56:05	1.1
+++ ao.h	2000/09/27 06:11:54	1.2
@@ -1,6 +1,6 @@
 /*
  *
- *  ao.h 
+ *  audio_out.h 
  *    
  *	Original Copyright (C) Aaron Holtzman - May 1999
  *      Modifications Copyright (C) Stan Seibert - July 2000
@@ -24,13 +24,10 @@
  *
  */
 
-#ifndef __AO_H__
-#define __AO_H__
-
 #include <stdlib.h>
 
-/* Type sizes */
-#include <ao/os_types.h>
+// Type sizes
+#include "config.h"
 
 /* --- Structures --- */
 
@@ -90,6 +87,7 @@
 /* Total number of drivers */
 #define AO_DRIVERS 12
 
+
 /* --- Functions --- */
 
 int ao_get_driver_id (const char *short_name);
@@ -108,4 +106,4 @@
 
 void ao_free_options (ao_option_t* options);
 
-#endif  /* __AO_H__ */
+int ao_is_big_endian();

1.2       +3 -2      ao/src/ao_alsa.c

Index: ao_alsa.c
===================================================================
RCS file: /usr/local/cvsroot/ao/src/ao_alsa.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ao_alsa.c	2000/09/03 09:56:05	1.1
+++ ao_alsa.c	2000/09/27 06:11:54	1.2
@@ -31,7 +31,7 @@
 #include <string.h>
 
 #include <sys/asoundlib.h>
-#include <ao/ao.h>
+#include "audio_out.h"
 
 #define AO_ALSA_BUF_SIZE 32768
 
@@ -91,7 +91,8 @@
         {
         case 8  : param.format.format = SND_PCM_SFMT_S8;
                   break;
-	case 16 : param.format.format = SND_PCM_SFMT_S16_LE;
+        case 16 : param.format.format = ao_is_big_endian() ?
+		    SND_PCM_SFMT_S16_BE : SND_PCM_SFMT_S16_LE;
                   break;
         default : return NULL;
         }

1.2       +3 -3      ao/src/ao_oss.c

Index: ao_oss.c
===================================================================
RCS file: /usr/local/cvsroot/ao/src/ao_oss.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ao_oss.c	2000/09/03 09:56:05	1.1
+++ ao_oss.c	2000/09/27 06:11:54	1.2
@@ -39,7 +39,7 @@
 #endif
 #include <sys/ioctl.h>
 
-#include <ao/ao.h>
+#include "audio_out.h"
 
 static ao_info_t ao_oss_info =
 {
@@ -120,8 +120,8 @@
         {
         case 8: tmp = AFMT_S8;
                 break;
-	case 16: tmp = AFMT_S16_LE;
-		break;
+        case 16: tmp = ao_is_big_endian() ? AFMT_S16_BE : AFMT_S16_LE;
+	        break;
         default:fprintf(stderr,"libao - Unsupported number of bits: %d.",
                         bits);
                 goto ERR;

1.2       +49 -3     ao/src/ao_wav.c

Index: ao_wav.c
===================================================================
RCS file: /usr/local/cvsroot/ao/src/ao_wav.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ao_wav.c	2000/09/03 09:56:05	1.1
+++ ao_wav.c	2000/09/27 06:11:55	1.2
@@ -32,7 +32,7 @@
 #include <fcntl.h>
 #include <signal.h>
 
-#include <ao/ao.h>
+#include "audio_out.h"
 
 #define WAVE_FORMAT_PCM  0x0001
 #define FORMAT_MULAW     0x0101
@@ -49,6 +49,8 @@
 #define WRITE_U16(buf, x) *(buf)     = (unsigned char)(x&0xff);\
                                                   *((buf)+1) = (unsigned char)((x>>8)&0xff);
 
+#define DEFAULT_SWAP_BUFFER_SIZE 2048
+
 struct riff_struct 
 {
   unsigned char id[4];   /* RIFF */
@@ -94,6 +96,9 @@
 {
         char *output_file;
         int fd;
+	int byte_swap;
+	char *swap_buffer;
+	int buffer_size;
         struct wave_header wave;
 } ao_wav_internal_t;
 
@@ -147,7 +152,19 @@
 
         // Grab options here
         ao_wav_parse_options(state, options);
-
+	state->byte_swap = (bits == 16) && (ao_is_big_endian());
+	if (state->byte_swap)
+	{
+		state->buffer_size = DEFAULT_SWAP_BUFFER_SIZE;
+		state->swap_buffer = calloc(sizeof(char), state->buffer_size);
+	       
+		if (state->swap_buffer == NULL)
+		{
+			fprintf(stderr, "ao_wav: Could not allocate byte-swapping buffer.\n");
+			goto ERR;
+		}
+	}
+		
         state->fd=open(state->output_file,O_WRONLY | O_TRUNC | O_CREAT, 0644);
 
         if(state->fd < 0) 
@@ -201,7 +218,36 @@
 static void
 ao_wav_play(ao_internal_t *state, void *output_samples, uint_32 num_bytes)
 {
-  	write( ((ao_wav_internal_t *) state)->fd, output_samples, num_bytes );
+	int i;
+	ao_wav_internal_t *s = (ao_wav_internal_t *) state;
+
+	/* Swap all of the bytes if things are not little_endian */
+	if (s->byte_swap)
+	{
+		/* Resize buffer larger if needed */
+		if (num_bytes > s->buffer_size)
+		{
+			s->swap_buffer = realloc(s->swap_buffer, sizeof(char)*num_bytes);
+			if (s->swap_buffer == NULL) {
+				fprintf(stderr, "ao_wav: Could not resize swap buffer.\n");
+				return;
+			}
+			else
+				s->buffer_size = num_bytes;
+		}
+
+		/* Swap the bytes into the swap buffer (so we don't
+		 mess up the output_samples buffer) */
+		for(i = 0; i < num_bytes/2; i+=2)
+		{
+			s->swap_buffer[i]   = ((char *) output_samples)[i+1];
+			s->swap_buffer[i+1] = ((char *) output_samples)[i];
+		}
+
+		write(s->fd, s->swap_buffer, num_bytes );
+	}
+	else    /* Otherwise just write the output buffer directly */
+		write(s->fd, output_samples, num_bytes );
 }
 
 

1.2       +12 -1     ao/src/audio_out.c

Index: audio_out.c
===================================================================
RCS file: /usr/local/cvsroot/ao/src/audio_out.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- audio_out.c	2000/09/03 09:56:05	1.1
+++ audio_out.c	2000/09/27 06:11:55	1.2
@@ -27,7 +27,8 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
-#include <ao/ao.h>
+#include <assert.h>
+#include "audio_out.h"
 
 /* --- Function Tables --- */
 
@@ -267,4 +268,14 @@
                 free(options);
                 options = rest;
         }
+}
+
+/* Helper function lifted from lib/vorbisfile.c */
+int ao_is_big_endian() {
+	uint_16 pattern = 0xbabe;
+	unsigned char *bytewise = (unsigned char *)&pattern;
+	if (bytewise[0] == 0xba) return 1;
+	
+	assert(bytewise[0] == 0xbe);
+	return 0;
 }

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list