[prev in list] [next in list] [prev in thread] [next in thread] 

List:       alsaplayer-devel
Subject:    [Alsaplayer-devel] A patch for alsa cvs versions
From:       jeremy <jerwin () osf1 ! gmu ! edu>
Date:       2000-07-16 11:46:40
[Download RAW message or body]


I don't know if any one will find much use for the following patch, but it
will allow one to compile the alsa output module while using cvs versions
of alsa. However, it does not produce correct output: the sound files are
played at one fourth speed. Perhaps someone may be able to fix this bug: I
really don't understand fragmentation. 


Jeremy

--- alsa-old.c	Fri Jul 14 17:14:18 2000
+++ alsa.c	Fri Jul 14 20:54:10 2000
@@ -28,14 +28,14 @@
 
 static snd_pcm_t *sound_handle;
 static snd_pcm_format_t format;
-static snd_pcm_channel_info_t pinfo;
-static int direction = SND_PCM_OPEN_PLAYBACK;
-static int mode = SND_PCM_MODE_BLOCK;
-static int channel = SND_PCM_CHANNEL_PLAYBACK;
-static int frag_size = -1;
-static int frag_count = -1;
-static int output_rate = 44000;
-
+static snd_pcm_info_t pinfo;
+static int stream = SND_PCM_STREAM_PLAYBACK;
+static int mode = SND_PCM_MODE_FRAME;
+static int frag_length = 125; 
+static int buffer_length = 500;
+static int min_avail =  50;
+static int output_rate = 44100;
+static int buffer_size = -1;
 static int alsa_init()
 {
 	// Always return ok for now
@@ -48,12 +48,12 @@
 {
 	int err;
 
-	if ((err = snd_pcm_open(&sound_handle, card, device, direction)) < 0) {
+	if ((err = snd_pcm_hw_open(&sound_handle, card, device, stream, mode)) <
0) {
 		fprintf(stderr, "ALSA->open(): %s\n", snd_strerror(err));
 		return 0;
 	}
 	memset(&pinfo, 0, sizeof(pinfo));
-	if ((err = snd_pcm_channel_info(sound_handle, &pinfo)) < 0) {
+	if ((err = snd_pcm_info(sound_handle, &pinfo)) < 0) {
 		fprintf(stderr, "ALSA->open(): %s\n", snd_strerror(err));
 		return 0;
 	}		
@@ -69,24 +69,24 @@
 
 static int alsa_write(void *data, int count)
 {
-	snd_pcm_channel_status_t status;
+	snd_pcm_status_t status;
 		                
 	snd_pcm_write(sound_handle, data, count);
 	memset(&status, 0, sizeof(status));
-	if (snd_pcm_channel_status(sound_handle, &status) < 0) {
+	if (snd_pcm_status(sound_handle, &status) < 0) {
 		fprintf(stderr, "ALSA: could not get channel status\n");
 		return 0;
 	}       
-	if (status.underrun) {
+	if (status.state==SND_PCM_STATE_XRUN) {
 		fprintf(stderr, "ALSA: underrun. resetting channel\n");
-		snd_pcm_channel_flush(sound_handle, channel);
+		snd_pcm_flush(sound_handle);
 		snd_pcm_playback_prepare(sound_handle);
 		snd_pcm_write(sound_handle, data, count);
-		if (snd_pcm_channel_status(sound_handle, &status) < 0) {
+		if (snd_pcm_status(sound_handle, &status) < 0) {
 			fprintf(stderr, "ALSA: could not get channel status. giving up\n");
 			return 0;
 		}
-		if (status.underrun) {
+		if (status.state==SND_PCM_STATE_XRUN) {
 			fprintf(stderr, "ALSA: write error. giving up\n");
 			return 0;
 		}               
@@ -97,73 +97,78 @@
 
 static int alsa_set_buffer(int fragment_size, int fragment_count)
 {
-	snd_pcm_channel_params_t params;
-	snd_pcm_channel_setup_t setup;
+	snd_pcm_params_t params;
+	snd_pcm_setup_t setup;
 	int err;
 			
 	memset(&params, 0, sizeof(params));
 
 	params.mode = mode;
-	params.channel = channel;
 	params.start_mode = SND_PCM_START_FULL;
-	params.stop_mode = SND_PCM_STOP_STOP;
-	params.buf.block.frag_size = fragment_size;
-	params.buf.block.frags_max = fragment_count;
-	params.buf.block.frags_min = 1;
+	params.xrun_mode = SND_PCM_XRUN_FLUSH;
+	params.frag_size =  output_rate * fragment_size / 1000;
+	params.buffer_size = output_rate * buffer_length /1000;
+	params.frames_min = format.rate * min_avail / 1000;
+	params.frames_xrun_max = 0;
+	
+	params.fill_mode = SND_PCM_FILL_SILENCE;
+	params.frames_fill_max = 2048;
+	
+	
 
 	memset(&format, 0, sizeof(format));
 	format.format =  SND_PCM_SFMT_S16_LE;
 	format.rate = output_rate;
-	format.voices = 2;
+	format.channels = 2;
 	format.interleave = 1;
 	memcpy(&params.format, &format, sizeof(format));
 		
-	snd_pcm_channel_flush(sound_handle, channel);
+	snd_pcm_flush(sound_handle);
 	
-	if ((err = snd_pcm_channel_params(sound_handle, &params)) < 0) {
+	if ((err = snd_pcm_params(sound_handle, &params)) < 0) {
 		fprintf(stderr, "ALSA->set_buffer(): parameter error \"%s\"\n",
 			snd_strerror(err));
 		return 0;
 	}
-	if ((err = snd_pcm_channel_prepare(sound_handle, channel)) < 0) {
+	if ((err = snd_pcm_prepare(sound_handle)) < 0) {
 		fprintf(stderr, "ALSA->set_buffer(): prepare error \"%s\"\n",
 			snd_strerror(err));
 		return 0;
 	}
 	memset(&setup, 0, sizeof(setup));
 	setup.mode = mode;
-	setup.channel = channel;
-	if ((err = snd_pcm_channel_setup(sound_handle, &setup)) < 0) {
+	if ((err = snd_pcm_setup(sound_handle, &setup)) < 0) {
 		fprintf(stderr, "ALSA->set_buffer(): setup error \"%s\"\n", 
 			snd_strerror(err));
 		return 0;
 	}	
-	frag_size = fragment_size;
-	frag_count = fragment_count;
-
 	return 1;
 }
 
 
 static int alsa_set_sample_rate(int rate)
 {
-	snd_pcm_channel_params_t params;
+	snd_pcm_params_t params;
 	int err;
 	
 	memset(&params, 0, sizeof(params));
 	
+      
 	params.mode = mode;
-	params.channel = channel;
 	params.start_mode = SND_PCM_START_FULL;
-	params.stop_mode = SND_PCM_STOP_STOP;
+	params.xrun_mode = SND_PCM_XRUN_FLUSH;
+	params.frag_size =  rate * fragment_size / 1000;
+	params.buffer_size = rate * buffer_length /1000;
+	params.frames_min = rate * min_avail / 1000;
+	params.frames_xrun_max = 0;
 	memset(&format, 0, sizeof(format));
 	format.format =  SND_PCM_SFMT_S16_LE;
 	format.rate = output_rate = rate;
-	format.voices = 2;
+	format.channels = 2;
 	format.interleave = 1;
 	memcpy(&params.format, &format, sizeof(format));
 	
-	if ((err = snd_pcm_channel_params(sound_handle, &params)) < 0) {
+	if ((err = snd_pcm_params(sound_handle, &params)) < 0) {
 		fprintf(stderr, "ALSA->set_sample_rate(): parameter error \"%s\"\n",
snd_strerror(err));
 		return 0;
 	}
@@ -179,7 +184,7 @@
 
 static int alsa_get_latency()
 {
-	return (frag_size * frag_count);
+  return (frag_length);
 }
 
 output_plugin alsa_output = {




[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic