annotate libao2/ao_alsa1x.c @ 6589:1595ca898d3b

cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
author alex
date Fri, 28 Jun 2002 16:48:10 +0000
parents 156144ee6810
children 769246a4eb41
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
1 /*
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
2 ao_alsa9 - ALSA-0.9.x output plugin for MPlayer
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
3
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
4 (C) Alex Beregszaszi <alex@naxine.org>
6193
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
5
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
6 modified for better alsa-0.9.0beta12(rc1)-support by Joy Winter <joy@pingfm.org>
6193
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
7 additional AC3 passthrough support by Andy Lo A Foe <andy@alsaplayer.org>
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
8
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
9 Any bugreports regarding to this driver are welcome either to the mplayer-user-mailinglist or directly to the authors.
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
10 */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
11
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
12 #include <errno.h>
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
13 #include <sys/time.h>
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
14 #include <stdlib.h>
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
15 //#include <unistd.h>
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
16 //#include <string.h>
5855
c21948cd027d fix for latest alsa (sys/asoundlib.h has been moved to alsa/asoundlib.h)
pl
parents: 5790
diff changeset
17
5857
d9641a4e7dbb 10l pl =)
atmos4
parents: 5855
diff changeset
18 #include "../config.h"
d9641a4e7dbb 10l pl =)
atmos4
parents: 5855
diff changeset
19
5855
c21948cd027d fix for latest alsa (sys/asoundlib.h has been moved to alsa/asoundlib.h)
pl
parents: 5790
diff changeset
20 #if HAVE_SYS_ASOUNDLIB_H
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
21 #include <sys/asoundlib.h>
5855
c21948cd027d fix for latest alsa (sys/asoundlib.h has been moved to alsa/asoundlib.h)
pl
parents: 5790
diff changeset
22 #elif HAVE_ALSA_ASOUNDLIB_H
c21948cd027d fix for latest alsa (sys/asoundlib.h has been moved to alsa/asoundlib.h)
pl
parents: 5790
diff changeset
23 #include <alsa/asoundlib.h>
c21948cd027d fix for latest alsa (sys/asoundlib.h has been moved to alsa/asoundlib.h)
pl
parents: 5790
diff changeset
24 #else
c21948cd027d fix for latest alsa (sys/asoundlib.h has been moved to alsa/asoundlib.h)
pl
parents: 5790
diff changeset
25 #error "asoundlib.h is not in sys/ or alsa/ - please bugreport"
c21948cd027d fix for latest alsa (sys/asoundlib.h has been moved to alsa/asoundlib.h)
pl
parents: 5790
diff changeset
26 #endif
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
27
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
28 #include "audio_out.h"
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
29 #include "audio_out_internal.h"
1058
cab5ba9ffc6c fixed AFMT_ stuff (inclue afmt.h)
arpi_esp
parents: 1050
diff changeset
30 #include "afmt.h"
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
31
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
32 extern int verbose;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
33
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
34 static ao_info_t info =
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
35 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
36 "ALSA-0.9.x audio output",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
37 "alsa9",
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
38 "Alex Beregszaszi <alex@naxine.org>, Joy Winter <joy@pingfm.org>",
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
39 "under developement"
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
40 };
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
41
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
42 LIBAO_EXTERN(alsa9)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
43
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
44
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
45 static snd_pcm_t *alsa_handler;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
46 static snd_pcm_format_t alsa_format;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
47 static snd_pcm_hw_params_t *alsa_hwparams;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
48 static snd_pcm_sw_params_t *alsa_swparams;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
49 static char *alsa_device;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
50
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
51 static int alsa_fragsize = OUTBURST; /* possible 4096, original 8192, OUTBURST is set statically to 512 in config.h but now its not used cause chunksize is allocated dynamically. */
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
52 static int alsa_fragcount = 8;
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
53
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
54 static int chunk_size = -1;
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
55 static int buffer_size = 0;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
56 static int start_delay = 0;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
57 static int stop_delay = 0;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
58 static size_t bits_per_sample, bits_per_frame;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
59 static size_t chunk_bytes;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
60
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
61 #define ALSA_DEVICE_SIZE 48
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
62
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
63 #define BUFFERTIME /* last undef */
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
64 #undef SET_PERIOD /* only function now is to set chunksize staticaly, last defined */
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
65 #define SW_PARAMS /* last undef */
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
66
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
67
6193
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
68 snd_pcm_t *
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
69 spdif_init(int acard, int adevice)
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
70 {
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
71 //char *pcm_name = "hw:0,2"; /* first card second device */
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
72 char pcm_name[255];
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
73 static snd_aes_iec958_t spdif;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
74 snd_pcm_info_t *info;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
75 snd_pcm_t *handler;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
76 snd_pcm_format_t format = SND_PCM_FORMAT_S16_LE;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
77 unsigned int channels = 2;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
78 unsigned int rate = 48000;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
79 int err, c;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
80
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
81 if (err = snprintf(&pcm_name[0], 11, "hw:%1d,%1d", acard, adevice) <= 0)
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
82 {
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
83 return NULL;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
84 }
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
85
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
86 if ((err = snd_pcm_open(&handler, pcm_name, SND_PCM_STREAM_PLAYBACK, 0)) < 0)
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
87 {
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
88 fprintf(stderr, "open: %s\n", snd_strerror(err));
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
89 return NULL;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
90 }
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
91
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
92 snd_pcm_info_alloca(&info);
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
93
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
94 if ((err = snd_pcm_info(handler, info)) < 0) {
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
95 fprintf(stderr, "info: %s\n", snd_strerror(err));
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
96 snd_pcm_close(handler);
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
97 return NULL;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
98 }
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
99 printf("device: %d, subdevice: %d\n", snd_pcm_info_get_device(info),
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
100 snd_pcm_info_get_subdevice(info));
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
101 {
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
102 snd_ctl_elem_value_t *ctl;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
103 snd_ctl_t *ctl_handler;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
104 char ctl_name[12];
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
105 int ctl_card;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
106
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
107 spdif.status[0] = IEC958_AES0_NONAUDIO |
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
108 IEC958_AES0_CON_EMPHASIS_NONE;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
109 spdif.status[1] = IEC958_AES1_CON_ORIGINAL |
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
110 IEC958_AES1_CON_PCM_CODER;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
111 spdif.status[2] = 0;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
112 spdif.status[3] = IEC958_AES3_CON_FS_48000;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
113
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
114 snd_ctl_elem_value_alloca(&ctl);
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
115 snd_ctl_elem_value_set_interface(ctl, SND_CTL_ELEM_IFACE_PCM);
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
116 snd_ctl_elem_value_set_device(ctl, snd_pcm_info_get_device(info));
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
117 snd_ctl_elem_value_set_subdevice(ctl, snd_pcm_info_get_subdevice(info));
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
118 snd_ctl_elem_value_set_name(ctl, SND_CTL_NAME_IEC958("", PLAYBACK,PCM_STREAM));
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
119 snd_ctl_elem_value_set_iec958(ctl, &spdif);
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
120 ctl_card = snd_pcm_info_get_card(info);
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
121 if (ctl_card < 0) {
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
122 fprintf(stderr, "Unable to setup the IEC958 (S/PDIF) interface - PCM has no assigned card");
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
123 goto __diga_end;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
124 }
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
125 sprintf(ctl_name, "hw:%d", ctl_card);
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
126 printf("hw:%d\n", ctl_card);
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
127 if ((err = snd_ctl_open(&ctl_handler, ctl_name, 0)) < 0) {
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
128 fprintf(stderr, "Unable to open the control interface '%s': %s", ctl_name, snd_strerror(err));
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
129 goto __diga_end;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
130 }
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
131 if ((err = snd_ctl_elem_write(ctl_handler, ctl)) < 0) {
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
132 fprintf(stderr, "Unable to update the IEC958 control: %s", snd_strerror(err));
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
133 goto __diga_end;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
134 }
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
135 snd_ctl_close(ctl_handler);
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
136 __diga_end:
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
137
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
138 }
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
139
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
140 {
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
141 snd_pcm_hw_params_t *params;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
142 snd_pcm_sw_params_t *swparams;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
143
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
144 snd_pcm_hw_params_alloca(&params);
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
145 snd_pcm_sw_params_alloca(&swparams);
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
146
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
147 err = snd_pcm_hw_params_any(handler, params);
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
148 if (err < 0) {
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
149 fprintf(stderr, "Broken configuration for this PCM: no configurations available");
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
150 return NULL;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
151 }
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
152 err = snd_pcm_hw_params_set_access(handler, params,
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
153 SND_PCM_ACCESS_RW_INTERLEAVED);
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
154 if (err < 0) {
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
155 fprintf(stderr, "Access tyep not available");
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
156 return NULL;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
157 }
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
158 err = snd_pcm_hw_params_set_format(handler, params, format);
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
159
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
160 if (err < 0) {
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
161 fprintf(stderr, "Sample format non available");
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
162 return NULL;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
163 }
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
164
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
165 err = snd_pcm_hw_params_set_channels(handler, params, channels);
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
166
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
167 if (err < 0) {
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
168 fprintf(stderr, "Channels count non avaible");
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
169 return NULL;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
170 }
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
171
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
172 err = snd_pcm_hw_params_set_rate_near(handler, params, rate, 0); assert(err >= 0);
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
173
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
174 err = snd_pcm_hw_params(handler, params);
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
175
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
176 if (err < 0) {
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
177 fprintf(stderr, "Cannot set buffer size\n");
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
178 return NULL;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
179 }
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
180 snd_pcm_sw_params_current(handler, swparams);
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
181 }
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
182 return handler;
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
183 }
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
184
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
185
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
186 /* to set/get/query special features/parameters */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
187 static int control(int cmd, int arg)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
188 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
189 return(CONTROL_UNKNOWN);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
190 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
191
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
192
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
193 /*
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
194 open & setup audio device
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
195 return: 1=success 0=fail
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
196 */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
197 static int init(int rate_hz, int channels, int format, int flags)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
198 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
199 int err;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
200 int cards = -1;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
201 snd_pcm_info_t *alsa_info;
1180
c50cd5db2359 added warning message
al3x
parents: 1146
diff changeset
202
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
203 size_t xfer_align; //new
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
204 snd_pcm_uframes_t start_threshold, stop_threshold; //new
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
205
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
206 printf("alsa-init: testing and bugreports are welcome.\n");
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
207 printf("alsa-init: requested format: %d Hz, %d channels, %s\n", rate_hz,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
208 channels, audio_out_format_name(format));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
209
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
210 alsa_handler = NULL;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
211
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
212 if (verbose)
2059
3c390543302c alsa9 pecs by joy_ping <joy@pingfm.org>
pontscho
parents: 1207
diff changeset
213 printf("alsa-init: compiled for ALSA-%s\n", SND_LIB_VERSION_STR);
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
214
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
215 if ((err = snd_card_next(&cards)) < 0 || cards < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
216 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
217 printf("alsa-init: no soundcards found: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
218 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
219 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
220
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
221 ao_data.samplerate = rate_hz;
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
222 ao_data.bps = channels; /* really this is bytes per frame so bad varname */
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
223 ao_data.format = format;
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
224 ao_data.channels = channels;
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
225 ao_data.outburst = OUTBURST;
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
226 ao_data.buffersize = 16384;
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
227
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
228 switch (format)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
229 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
230 case AFMT_S8:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
231 alsa_format = SND_PCM_FORMAT_S8;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
232 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
233 case AFMT_U8:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
234 alsa_format = SND_PCM_FORMAT_U8;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
235 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
236 case AFMT_U16_LE:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
237 alsa_format = SND_PCM_FORMAT_U16_LE;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
238 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
239 case AFMT_U16_BE:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
240 alsa_format = SND_PCM_FORMAT_U16_BE;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
241 break;
5790
d141f1e9cc36 AFMT_AC3 autodetect/fallback to S16
arpi
parents: 3135
diff changeset
242 #ifndef WORDS_BIGENDIAN
d141f1e9cc36 AFMT_AC3 autodetect/fallback to S16
arpi
parents: 3135
diff changeset
243 case AFMT_AC3:
d141f1e9cc36 AFMT_AC3 autodetect/fallback to S16
arpi
parents: 3135
diff changeset
244 #endif
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
245 case AFMT_S16_LE:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
246 alsa_format = SND_PCM_FORMAT_S16_LE;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
247 break;
5790
d141f1e9cc36 AFMT_AC3 autodetect/fallback to S16
arpi
parents: 3135
diff changeset
248 #ifdef WORDS_BIGENDIAN
d141f1e9cc36 AFMT_AC3 autodetect/fallback to S16
arpi
parents: 3135
diff changeset
249 case AFMT_AC3:
d141f1e9cc36 AFMT_AC3 autodetect/fallback to S16
arpi
parents: 3135
diff changeset
250 #endif
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
251 case AFMT_S16_BE:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
252 alsa_format = SND_PCM_FORMAT_S16_BE;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
253 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
254 default:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
255 alsa_format = SND_PCM_FORMAT_MPEG;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
256 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
257 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
258
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
259 switch(alsa_format)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
260 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
261 case SND_PCM_FORMAT_S16_LE:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
262 case SND_PCM_FORMAT_U16_LE:
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
263 ao_data.bps *= 2;
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
264 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
265 case -1:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
266 printf("alsa-init: invalid format (%s) requested - output disabled\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
267 audio_out_format_name(format));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
268 return(0);
1115
a16b569f2702 -Wall style cleanups, TEST IT, it can be working by others
al3x
parents: 1058
diff changeset
269 default:
a16b569f2702 -Wall style cleanups, TEST IT, it can be working by others
al3x
parents: 1058
diff changeset
270 break;
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
271 }
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
272
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
273 if (ao_subdevice != NULL) // ?? makes no sense
3129
6d965759dd01 ao_subdevice fixed. 10l...
arpi
parents: 3095
diff changeset
274 alsa_device = ao_subdevice;
1207
bf18175dfad7 ao_subdevice support added
al3x
parents: 1180
diff changeset
275
1146
a84610bb5476 hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents: 1129
diff changeset
276 if (alsa_device == NULL)
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
277 {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
278 int tmp_device, tmp_subdevice, err;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
279
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
280 if ((err = snd_pcm_info_malloc(&alsa_info)) < 0)
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
281 {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
282 printf("alsa-init: memory allocation error: %s\n", snd_strerror(err));
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
283 return(0);
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
284 }
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
285
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
286 if ((alsa_device = alloca(ALSA_DEVICE_SIZE)) == NULL)
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
287 {
1146
a84610bb5476 hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents: 1129
diff changeset
288 printf("alsa-init: memory allocation error: %s\n", strerror(errno));
a84610bb5476 hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents: 1129
diff changeset
289 return(0);
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
290 }
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
291
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
292 if ((tmp_device = snd_pcm_info_get_device(alsa_info)) < 0)
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
293 {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
294 printf("alsa-init: cant get device\n");
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
295 return(0);
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
296 }
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
297
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
298 if ((tmp_subdevice = snd_pcm_info_get_subdevice(alsa_info)) < 0)
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
299 {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
300 printf("alsa-init: cant get subdevice\n");
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
301 return(0);
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
302 }
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
303
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
304 if (verbose)
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
305 printf("alsa-init: got device=%i, subdevice=%i\n", tmp_device, tmp_subdevice);
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
306
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
307 if ((err = snprintf(alsa_device, ALSA_DEVICE_SIZE, "hw:%1d,%1d", tmp_device, tmp_subdevice)) <= 0)
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
308 {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
309 printf("alsa-init: cant wrote device-id\n");
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
310 }
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
311
1146
a84610bb5476 hacked aocontrol_set_device working, and cleaned up a bit
al3x
parents: 1129
diff changeset
312 snd_pcm_info_free(alsa_info);
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
313 }
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
314
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
315 printf("alsa-init: %d soundcard%s found, using: %s\n", cards+1,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
316 (cards >= 0) ? "" : "s", alsa_device);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
317
6193
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
318 if (format == AFMT_AC3) {
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
319 // Try to initialize the SPDIF interface
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
320 alsa_handler = spdif_init(0, 2);
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
321 }
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
322
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
323 if (!alsa_handler) {
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
324 if ((err = snd_pcm_open(&alsa_handler,alsa_device,SND_PCM_STREAM_PLAYBACK,0)) < 0)
6193
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
325 {
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
326 printf("alsa-init: playback open error: %s\n", snd_strerror(err));
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
327 return(0);
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
328 }
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
329 }
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
330
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
331 snd_pcm_hw_params_alloca(&alsa_hwparams);
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
332 snd_pcm_sw_params_alloca(&alsa_swparams);
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
333
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
334 // setting hw-parameters
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
335 if ((err = snd_pcm_hw_params_any(alsa_handler, alsa_hwparams)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
336 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
337 printf("alsa-init: unable to get initial parameters: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
338 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
339 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
340 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
341
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
342 if ((err = snd_pcm_hw_params_set_access(alsa_handler, alsa_hwparams,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
343 SND_PCM_ACCESS_RW_INTERLEAVED)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
344 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
345 printf("alsa-init: unable to set access type: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
346 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
347 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
348 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
349
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
350 if ((err = snd_pcm_hw_params_set_format(alsa_handler, alsa_hwparams,
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
351 alsa_format)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
352 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
353 printf("alsa-init: unable to set format: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
354 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
355 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
356 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
357
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
358 if ((err = snd_pcm_hw_params_set_channels(alsa_handler, alsa_hwparams,
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
359 ao_data.channels)) < 0)
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
360 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
361 printf("alsa-init: unable to set channels: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
362 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
363 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
364 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
365
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
366 if ((err = snd_pcm_hw_params_set_rate_near(alsa_handler, alsa_hwparams, ao_data.samplerate, 0)) < 0)
2059
3c390543302c alsa9 pecs by joy_ping <joy@pingfm.org>
pontscho
parents: 1207
diff changeset
367 {
3c390543302c alsa9 pecs by joy_ping <joy@pingfm.org>
pontscho
parents: 1207
diff changeset
368 printf("alsa-init: unable to set samplerate-2: %s\n",
3c390543302c alsa9 pecs by joy_ping <joy@pingfm.org>
pontscho
parents: 1207
diff changeset
369 snd_strerror(err));
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
370 //snd_pcm_hw_params_dump(alsa_hwparams, errlog); jp
2059
3c390543302c alsa9 pecs by joy_ping <joy@pingfm.org>
pontscho
parents: 1207
diff changeset
371 return(0);
3c390543302c alsa9 pecs by joy_ping <joy@pingfm.org>
pontscho
parents: 1207
diff changeset
372 }
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
373
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
374
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
375 #ifdef SET_PERIOD
1115
a16b569f2702 -Wall style cleanups, TEST IT, it can be working by others
al3x
parents: 1058
diff changeset
376 {
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
377 if ((err = snd_pcm_hw_params_set_period_size(alsa_handler, alsa_hwparams, alsa_fragsize, 0)) < 0)
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
378 {
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
379 printf("alsa-init: unable to set periodsize: %s\n", snd_strerror(err));
1128
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
380 return(0);
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
381 }
d2dd25dd11bc Hacked it working, still needs fixings!
atmosfear
parents: 1115
diff changeset
382 }
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
383 #endif
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
384
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
385 #ifdef BUFFERTIME
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
386 {
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
387 int alsa_buffer_time = 500000; /* original 60 */
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
388
2059
3c390543302c alsa9 pecs by joy_ping <joy@pingfm.org>
pontscho
parents: 1207
diff changeset
389 if ((err = snd_pcm_hw_params_set_buffer_time_near(alsa_handler, alsa_hwparams, alsa_buffer_time, 0)) < 0)
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
390 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
391 printf("alsa-init: unable to set buffer time near: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
392 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
393 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
394 } else
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
395 alsa_buffer_time = err;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
396
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
397 if ((err = snd_pcm_hw_params_set_period_time_near(alsa_handler, alsa_hwparams, alsa_buffer_time/4, 0)) < 0)
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
398 /* original: alsa_buffer_time/ao_data.bps */
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
399 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
400 printf("alsa-init: unable to set period time: %s\n",
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
401 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
402 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
403 }
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
404 if (verbose)
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
405 printf("alsa-init: buffer_time: %d, period_time :%d\n",alsa_buffer_time, err);
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
406 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
407 #endif
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
408
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
409 /* get chunk-size */
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
410 if ((err = snd_pcm_hw_params_get_period_size(alsa_hwparams, 0)) < 0)
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
411 {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
412 printf("alsa-init: unable to get chunk-size in hw-params: %s\n", snd_strerror(err));
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
413 return(0);
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
414 } else
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
415 {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
416 chunk_size = err;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
417 if (verbose) {printf("alsa-init: got chunksize %i\n", chunk_size);}
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
418 }
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
419
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
420 /* get buffer size */
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
421 if ((err = snd_pcm_hw_params_get_buffer_size(alsa_hwparams)) < 0)
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
422 {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
423 printf("alsa-init: unable to get buffersize in hw-params: %s\n", snd_strerror(err));
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
424 return(0);
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
425 } else
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
426 {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
427 ao_data.buffersize = err;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
428 if (verbose) {printf("alsa-init: got buffersize %i\n", ao_data.buffersize);}
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
429 }
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
430
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
431 if (MAX_OUTBURST > ao_data.buffersize) { //warning if MAX_OUTBURST is bigger than buffersize
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
432 printf("alsa-init: WARNING! MAX_OUTBURST exceeds your available buffersize.\nalsa-init: MAX_OUTBURST=%i, buffersize=%i\n",MAX_OUTBURST,ao_data.buffersize);}
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
433
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
434 if (chunk_size == ao_data.buffersize)
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
435 {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
436 printf("alsa-init: Can't use period equal to buffer size (%u == %lu)", chunk_size, (long)buffer_size);
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
437 return(0);
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
438 }
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
439
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
440 /* finally install hardware parameters */
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
441 if ((err = snd_pcm_hw_params(alsa_handler, alsa_hwparams)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
442 {
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
443 printf("alsa-init: unable to set hw-parameters: %s\n",
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
444 snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
445 return(0);
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
446 }
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
447 // end setting hw-params
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
448
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
449 #ifdef SW_PARAMS
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
450 {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
451 size_t n;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
452 xfer_align = snd_pcm_sw_params_get_xfer_align(alsa_swparams);
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
453 if (xfer_align == 0)
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
454 xfer_align = 4;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
455 n = (ao_data.buffersize / xfer_align) * xfer_align;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
456
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
457 if (start_delay <= 0) {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
458 start_threshold = n + (double) ao_data.samplerate * start_delay / 1000000;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
459 } else {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
460 start_threshold = (double) ao_data.samplerate * start_delay / 1000000;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
461 }
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
462 if (start_threshold < 1)
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
463 start_threshold = 1;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
464 if (start_threshold > n)
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
465 start_threshold = n;
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
466
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
467 if (stop_delay <= 0) {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
468 stop_threshold = ao_data.buffersize + (double) ao_data.samplerate * stop_delay / 1000000;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
469 } else {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
470 stop_threshold = (double) ao_data.samplerate * stop_delay / 1000000;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
471 }
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
472
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
473 if (verbose) {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
474 printf("alsa-init: start_threshold=%lu, stop_threshold=%lu\n",start_threshold,stop_threshold);
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
475 printf("alsa-init: n=%i\n", n);
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
476 }
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
477
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
478 if ((err = snd_pcm_sw_params_current(alsa_handler, alsa_swparams)) < 0)
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
479 {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
480 printf("alsa-init: unable to get parameters: %s\n",snd_strerror(err));
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
481 return(0);
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
482 }
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
483
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
484 //set min available frames to consider pcm ready (4)
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
485 if ((err = snd_pcm_sw_params_set_avail_min(alsa_handler, alsa_swparams, 4)) < 0)
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
486 {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
487 printf("alsa-init: unable to set avail_min %s\n",snd_strerror(err));
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
488 return(0);
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
489 }
2209
a59f952fad34 applied patch by Joy Winter <joy@pingfm.org>
arpi
parents: 2059
diff changeset
490
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
491 if ((err = snd_pcm_sw_params_set_start_threshold(alsa_handler, alsa_swparams, start_threshold)) < 0)
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
492 {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
493 printf("alsa-init: unable to set start_threshold %s\n",snd_strerror(err));
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
494 return(0);
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
495 }
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
496
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
497 if ((err = snd_pcm_sw_params_set_stop_threshold(alsa_handler, alsa_swparams, stop_threshold)) < 0)
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
498 {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
499 printf("alsa-init: unable to set stop_threshold %s\n",snd_strerror(err));
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
500 return(0);
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
501 }
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
502
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
503 //transfers stream aligned to 4 in nonblocking-mode it would be 1
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
504 if ((err = snd_pcm_sw_params_set_xfer_align(alsa_handler, alsa_swparams, 4)) < 0)
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
505 {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
506 printf("alsa-init: unable to set xfer_align: %s\n",snd_strerror(err));
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
507 return(0);
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
508 }
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
509
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
510 if ((err = snd_pcm_sw_params(alsa_handler, alsa_swparams)) < 0)
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
511 {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
512 printf("alsa-init: unable to install sw-params\n");
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
513 return(0);
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
514 }
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
515
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
516 bits_per_sample = snd_pcm_format_physical_width(alsa_format);
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
517 bits_per_frame = bits_per_sample * channels;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
518 chunk_bytes = chunk_size * bits_per_frame / 8;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
519
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
520 if (verbose) {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
521 printf("alsa-init: bits per sample (bps)=%i, bits per frame (bpf)=%i, chunk_bytes=%i\n",bits_per_sample,bits_per_frame,chunk_bytes);}
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
522 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
523
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
524 #endif //end swparams
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
525
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
526 if ((err = snd_pcm_prepare(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
527 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
528 printf("alsa-init: pcm prepare error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
529 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
530 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
531
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
532 printf("alsa9: %d Hz/%d channels/%d bpf/%d bytes buffer/%s\n",
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
533 ao_data.samplerate, ao_data.channels, ao_data.bps, ao_data.buffersize,
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
534 snd_pcm_format_description(alsa_format));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
535 return(1);
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
536 } // end init
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
537
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
538
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
539 /* close audio device */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
540 static void uninit()
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
541 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
542 int err;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
543
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
544 //if (alsa_device != NULL)
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
545 //free(alsa_device);
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
546
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
547 //snd_pcm_hw_params_free(alsa_hwparams);
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
548
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
549 if ((err = snd_pcm_drain(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
550 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
551 printf("alsa-uninit: pcm drain error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
552 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
553 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
554
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
555 if ((err = snd_pcm_close(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
556 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
557 printf("alsa-uninit: pcm close error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
558 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
559 }
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
560 else {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
561 alsa_handler = NULL;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
562 alsa_device = NULL;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
563 printf("alsa-uninit: pcm closed\n");
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
564 }
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
565 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
566
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
567 static void audio_pause()
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
568 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
569 int err;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
570
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
571 if ((err = snd_pcm_drain(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
572 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
573 printf("alsa-pause: pcm drain error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
574 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
575 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
576
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
577 #ifdef reset
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
578 if ((err = snd_pcm_reset(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
579 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
580 printf("alsa-pause: pcm reset error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
581 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
582 }
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
583 #endif
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
584 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
585
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
586 static void audio_resume()
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
587 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
588 int err;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
589
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
590 if ((err = snd_pcm_prepare(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
591 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
592 printf("alsa-resume: pcm prepare error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
593 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
594 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
595 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
596
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
597 /* stop playing and empty buffers (for seeking/pause) */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
598 static void reset()
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
599 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
600 int err;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
601
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
602 if ((err = snd_pcm_drain(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
603 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
604 printf("alsa-reset: pcm drain error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
605 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
606 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
607
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
608 if ((err = snd_pcm_prepare(alsa_handler)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
609 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
610 printf("alsa-reset: pcm prepare error: %s\n", snd_strerror(err));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
611 return;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
612 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
613
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
614 }
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
615
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
616 #ifndef timersub
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
617 #define timersub(a, b, result) \
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
618 do { \
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
619 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
620 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
621 if ((result)->tv_usec < 0) { \
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
622 --(result)->tv_sec; \
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
623 (result)->tv_usec += 1000000; \
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
624 } \
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
625 } while (0)
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
626 #endif
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
627
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
628 /*
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
629 plays 'len' bytes of 'data'
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
630 returns: number of bytes played
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
631 modified last at 26.06.02 by jp
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
632 */
6193
2fd9ec444098 AC3 passthrough support by Andy Lo A Foe <andy at alsaplayer dot org>
alex
parents: 5857
diff changeset
633
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
634 static int play(void* data, int len, int flags)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
635 {
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
636
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
637 snd_pcm_status_t *status;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
638
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
639 int num_frames=len/ao_data.bps;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
640 signed short *output_samples=data;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
641 snd_pcm_sframes_t res = 0;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
642
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
643 if (!alsa_handler) {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
644 printf("alsa-play: device configuration error");
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
645 return 0;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
646 }
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
647
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
648 do {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
649 if (res == -EPIPE) { /* underrun */
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
650 snd_pcm_status_alloca(&status);
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
651 if ((res = snd_pcm_status(alsa_handler, status))<0) {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
652 printf("alsa-play: buffer underrun. can't determine length");
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
653 } else {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
654 if (snd_pcm_status_get_state(status) == SND_PCM_STATE_XRUN) {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
655 struct timeval now, diff, tstamp;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
656 gettimeofday(&now, 0);
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
657 snd_pcm_status_get_trigger_tstamp(status, &tstamp);
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
658 timersub(&now, &tstamp, &diff);
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
659 printf("alsa-play: xrun of at least %.3f msecs. resetting stream",
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
660 diff.tv_sec * 1000 + diff.tv_usec / 1000.0);
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
661 } else
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
662 printf("alsa-play: xrun. can't determine length");
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
663 }
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
664 res = snd_pcm_prepare(alsa_handler);
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
665 }
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
666 else if (res == -ESTRPIPE) { /* suspend */
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
667 printf("alsa-play: pcm in suspend mode. trying to resume");
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
668 while ((res = snd_pcm_resume(alsa_handler)) == -EAGAIN)
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
669 sleep(1);
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
670 if (res < 0)
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
671 res = snd_pcm_prepare(alsa_handler);
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
672 }
2059
3c390543302c alsa9 pecs by joy_ping <joy@pingfm.org>
pontscho
parents: 1207
diff changeset
673
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
674 if (res >= 0)
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
675 res = snd_pcm_writei(alsa_handler, (void *)output_samples, num_frames);
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
676
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
677 if (res > 0) {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
678 output_samples += ao_data.channels * res;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
679 num_frames -= res;
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
680 }
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
681
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
682 } while (res == -EPIPE || num_frames > 0);
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
683
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
684 if (res < 0) {
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
685 printf("alsa-play: write error %s", snd_strerror(res));
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
686 return 0;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
687 }
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
688 return res < 0 ? (int)res : len;
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
689 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
690
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
691
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
692 /* how many byes are free in the buffer */
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
693 static int get_space()
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
694 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
695 snd_pcm_status_t *status;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
696 int ret;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
697
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
698 if ((ret = snd_pcm_status_malloc(&status)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
699 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
700 printf("alsa-space: memory allocation error: %s\n", snd_strerror(ret));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
701 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
702 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
703
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
704 if ((ret = snd_pcm_status(alsa_handler, status)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
705 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
706 printf("alsa-space: cannot get pcm status: %s\n", snd_strerror(ret));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
707 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
708 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
709
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
710 switch(snd_pcm_status_get_state(status))
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
711 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
712 case SND_PCM_STATE_OPEN:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
713 case SND_PCM_STATE_PREPARED:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
714 case SND_PCM_STATE_RUNNING:
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
715 ret = snd_pcm_status_get_avail(status) * ao_data.bps;
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
716 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
717 default:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
718 ret = 0;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
719 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
720
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
721 snd_pcm_status_free(status);
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
722
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
723 if (ret < 0)
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
724 ret = 0;
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
725 //printf("alsa-space: free space = %i",ret);
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
726 return(ret);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
727 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
728
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
729 /* delay in seconds between first and last sample in buffer */
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
730 static float get_delay()
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
731 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
732 snd_pcm_status_t *status;
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
733 float ret;
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
734
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
735 if ((ret = snd_pcm_status_malloc(&status)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
736 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
737 printf("alsa-delay: memory allocation error: %s\n", snd_strerror(ret));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
738 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
739 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
740
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
741 if ((ret = snd_pcm_status(alsa_handler, status)) < 0)
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
742 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
743 printf("alsa-delay: cannot get pcm status: %s\n", snd_strerror(ret));
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
744 return(0);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
745 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
746
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
747 switch(snd_pcm_status_get_state(status))
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
748 {
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
749 case SND_PCM_STATE_OPEN:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
750 case SND_PCM_STATE_PREPARED:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
751 case SND_PCM_STATE_RUNNING:
3095
981a9e5118ce interface to libao2 changed ao_plugin added
anders
parents: 2209
diff changeset
752 ret = (float)snd_pcm_status_get_delay(status)/(float)ao_data.samplerate;
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
753 break;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
754 default:
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
755 ret = 0;
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
756 }
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
757
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
758 snd_pcm_status_free(status);
1129
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
759
705fa4ac4fed hacked to work seek/pause/resume/uninit
al3x
parents: 1128
diff changeset
760 if (ret < 0)
6589
1595ca898d3b cleanup and bufferhandling fix by Joy Ping <joy at pingfm.org>. Bufferhandling fix based on idea by Marius David <marius at rohost.com>
alex
parents: 6194
diff changeset
761 ret = 0;
1050
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
762 return(ret);
87eb4325baf6 first release, meg nem akar menni :(
al3x
parents:
diff changeset
763 }