Commit 1ee1d5df authored by Ivica Bukvic's avatar Ivica Bukvic
Browse files

*began backporting blocksize feature

parent b45255e2
...@@ -65,7 +65,7 @@ proc ::dialog_audio::apply {mytoplevel} { ...@@ -65,7 +65,7 @@ proc ::dialog_audio::apply {mytoplevel} {
$audio_sr \ $audio_sr \
$audio_advance \ $audio_advance \
$audio_callback \ $audio_callback \
$audio_blocksize" \ $audio_blocksize \
\;] \;]
# Pd always makes devices contiguous-- for example, if you only set # Pd always makes devices contiguous-- for example, if you only set
......
...@@ -63,12 +63,15 @@ static int audio_state; ...@@ -63,12 +63,15 @@ static int audio_state;
static int audio_naudioindev = -1; static int audio_naudioindev = -1;
static int audio_audioindev[MAXAUDIOINDEV]; static int audio_audioindev[MAXAUDIOINDEV];
static int audio_audiochindev[MAXAUDIOINDEV]; static int audio_audiochindev[MAXAUDIOINDEV];
static char audio_indevnames[MAXMIDIINDEV * DEVDESCSIZE];
static int audio_naudiooutdev = -1; static int audio_naudiooutdev = -1;
static int audio_audiooutdev[MAXAUDIOOUTDEV]; static int audio_audiooutdev[MAXAUDIOOUTDEV];
static int audio_audiochoutdev[MAXAUDIOOUTDEV]; static int audio_audiochoutdev[MAXAUDIOOUTDEV];
static char audio_outdevnames[MAXMIDIINDEV * DEVDESCSIZE];
static int audio_rate; static int audio_rate;
static int audio_advance; static int audio_advance = -1;
static int audio_callback; static int audio_callback;
static int audio_blocksize;
static int audio_callback_is_open; /* reflects true actual state */ static int audio_callback_is_open; /* reflects true actual state */
static int audio_nextinchans, audio_nextoutchans; static int audio_nextinchans, audio_nextoutchans;
...@@ -80,7 +83,7 @@ void sched_reopenmeplease(void); ...@@ -80,7 +83,7 @@ void sched_reopenmeplease(void);
extern int jack_get_srate(void); extern int jack_get_srate(void);
#endif /* JACK */ #endif /* JACK */
static int audio_isopen(void) int audio_isopen(void)
{ {
return (audio_state && return (audio_state &&
((audio_naudioindev > 0 && audio_audiochindev[0] > 0) ((audio_naudioindev > 0 && audio_audiochindev[0] > 0)
...@@ -90,48 +93,60 @@ static int audio_isopen(void) ...@@ -90,48 +93,60 @@ static int audio_isopen(void)
void sys_get_audio_params( void sys_get_audio_params(
int *pnaudioindev, int *paudioindev, int *chindev, int *pnaudioindev, int *paudioindev, int *chindev,
int *pnaudiooutdev, int *paudiooutdev, int *choutdev, int *pnaudiooutdev, int *paudiooutdev, int *choutdev,
int *prate, int *padvance, int *pcallback) int *prate, int *padvance, int *pcallback, int *pblocksize)
{ {
int i; int i, devn;
*pnaudioindev = audio_naudioindev; *pnaudioindev = audio_naudioindev;
for (i = 0; i < MAXAUDIOINDEV; i++) for (i = 0; i < audio_naudioindev; i++)
paudioindev[i] = audio_audioindev[i], {
chindev[i] = audio_audiochindev[i]; if ((devn = sys_audiodevnametonumber(0,
&audio_indevnames[i * DEVDESCSIZE])) >= 0)
paudioindev[i] = devn;
else paudioindev[i] = audio_audioindev[i];
chindev[i] = audio_audiochindev[i];
}
*pnaudiooutdev = audio_naudiooutdev; *pnaudiooutdev = audio_naudiooutdev;
for (i = 0; i < MAXAUDIOOUTDEV; i++) for (i = 0; i < audio_naudiooutdev; i++)
paudiooutdev[i] = audio_audiooutdev[i],
choutdev[i] = audio_audiochoutdev[i];
#ifdef USEAPI_JACK
if (sys_audioapiopened == API_JACK)
{ {
if (jack_get_srate()) if ((devn = sys_audiodevnametonumber(1,
{ &audio_outdevnames[i * DEVDESCSIZE])) >= 0)
audio_rate = jack_get_srate(); paudiooutdev[i] = devn;
} else paudiooutdev[i] = audio_audiooutdev[i];
choutdev[i] = audio_audiochoutdev[i];
} }
#endif /* JACK */
*prate = audio_rate; *prate = audio_rate;
*padvance = audio_advance; *padvance = audio_advance;
*pcallback = audio_callback; *pcallback = audio_callback;
*pblocksize = audio_blocksize;
} }
void sys_save_audio_params( void sys_save_audio_params(
int naudioindev, int *audioindev, int *chindev, int naudioindev, int *audioindev, int *chindev,
int naudiooutdev, int *audiooutdev, int *choutdev, int naudiooutdev, int *audiooutdev, int *choutdev,
int rate, int advance, int callback) int rate, int advance, int callback, int blocksize)
{ {
int i; int i;
audio_naudioindev = naudioindev; audio_naudioindev = naudioindev;
for (i = 0; i < MAXAUDIOINDEV; i++) for (i = 0; i < naudioindev; i++)
{
audio_audioindev[i] = audioindev[i], audio_audioindev[i] = audioindev[i],
audio_audiochindev[i] = chindev[i]; audio_audiochindev[i] = chindev[i];
sys_audiodevnumbertoname(0, audioindev[i],
&audio_indevnames[i * DEVDESCSIZE], DEVDESCSIZE);
}
audio_naudiooutdev = naudiooutdev; audio_naudiooutdev = naudiooutdev;
for (i = 0; i < MAXAUDIOOUTDEV; i++) for (i = 0; i < naudiooutdev; i++)
{
audio_audiooutdev[i] = audiooutdev[i], audio_audiooutdev[i] = audiooutdev[i],
audio_audiochoutdev[i] = choutdev[i]; audio_audiochoutdev[i] = choutdev[i];
sys_audiodevnumbertoname(1, audiooutdev[i],
&audio_outdevnames[i * DEVDESCSIZE], DEVDESCSIZE);
}
audio_rate = rate; audio_rate = rate;
audio_advance = advance; audio_advance = advance;
audio_callback = callback; audio_callback = callback;
audio_blocksize = blocksize;
fprintf(stderr,"blocksize=%d\n", blocksize);
} }
/* init routines for any API which needs to set stuff up before /* init routines for any API which needs to set stuff up before
...@@ -196,9 +211,9 @@ void sys_setchsr(int chin, int chout, int sr) ...@@ -196,9 +211,9 @@ void sys_setchsr(int chin, int chout, int sr)
void sys_set_audio_settings(int naudioindev, int *audioindev, int nchindev, void sys_set_audio_settings(int naudioindev, int *audioindev, int nchindev,
int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev, int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev,
int *choutdev, int rate, int advance, int callback) int *choutdev, int rate, int advance, int callback, int blocksize)
{ {
int i; int i, *ip;
int defaultchannels = SYS_DEFAULTCH; int defaultchannels = SYS_DEFAULTCH;
int inchans, outchans, nrealindev, nrealoutdev; int inchans, outchans, nrealindev, nrealoutdev;
int realindev[MAXAUDIOINDEV], realoutdev[MAXAUDIOOUTDEV]; int realindev[MAXAUDIOINDEV], realoutdev[MAXAUDIOOUTDEV];
...@@ -211,8 +226,10 @@ void sys_set_audio_settings(int naudioindev, int *audioindev, int nchindev, ...@@ -211,8 +226,10 @@ void sys_set_audio_settings(int naudioindev, int *audioindev, int nchindev,
if (rate < 1) if (rate < 1)
rate = DEFAULTSRATE; rate = DEFAULTSRATE;
if (advance <= 0) if (advance < 0)
advance = DEFAULTADVANCE; advance = DEFAULTADVANCE;
if (blocksize != (1 << ilog2(blocksize)) || blocksize < DEFDACBLKSIZE)
blocksize = DEFDACBLKSIZE;
audio_init(); audio_init();
/* Since the channel vector might be longer than the /* Since the channel vector might be longer than the
audio device vector, or vice versa, we fill the shorter one audio device vector, or vice versa, we fill the shorter one
...@@ -339,8 +356,10 @@ void sys_set_audio_settings(int naudioindev, int *audioindev, int nchindev, ...@@ -339,8 +356,10 @@ void sys_set_audio_settings(int naudioindev, int *audioindev, int nchindev,
sys_log_error(ERR_NOTHING); sys_log_error(ERR_NOTHING);
audio_nextinchans = inchans; audio_nextinchans = inchans;
audio_nextoutchans = outchans; audio_nextoutchans = outchans;
sys_setchsr(audio_nextinchans, audio_nextoutchans, rate);
sys_save_audio_params(nrealindev, realindev, realinchans, sys_save_audio_params(nrealindev, realindev, realinchans,
nrealoutdev, realoutdev, realoutchans, rate, advance, callback); nrealoutdev, realoutdev, realoutchans, rate, advance, callback,
blocksize);
} }
void sys_close_audio(void) void sys_close_audio(void)
...@@ -389,9 +408,10 @@ void sys_reopen_audio( void) ...@@ -389,9 +408,10 @@ void sys_reopen_audio( void)
{ {
int naudioindev, audioindev[MAXAUDIOINDEV], chindev[MAXAUDIOINDEV]; int naudioindev, audioindev[MAXAUDIOINDEV], chindev[MAXAUDIOINDEV];
int naudiooutdev, audiooutdev[MAXAUDIOOUTDEV], choutdev[MAXAUDIOOUTDEV]; int naudiooutdev, audiooutdev[MAXAUDIOOUTDEV], choutdev[MAXAUDIOOUTDEV];
int rate, advance, callback, outcome = 0; int rate, advance, callback, blocksize, outcome = 0;
sys_get_audio_params(&naudioindev, audioindev, chindev, sys_get_audio_params(&naudioindev, audioindev, chindev,
&naudiooutdev, audiooutdev, choutdev, &rate, &advance, &callback); &naudiooutdev, audiooutdev, choutdev, &rate, &advance, &callback,
&blocksize);
sys_setchsr(audio_nextinchans, audio_nextoutchans, rate); sys_setchsr(audio_nextinchans, audio_nextoutchans, rate);
if (!naudioindev && !naudiooutdev) if (!naudioindev && !naudiooutdev)
{ {
...@@ -429,7 +449,8 @@ void sys_reopen_audio( void) ...@@ -429,7 +449,8 @@ void sys_reopen_audio( void)
be open for both input and output. */ be open for both input and output. */
if (sys_audioapi == API_ALSA) if (sys_audioapi == API_ALSA)
outcome = alsa_open_audio(naudioindev, audioindev, naudioindev, outcome = alsa_open_audio(naudioindev, audioindev, naudioindev,
chindev, naudiooutdev, audiooutdev, naudiooutdev, choutdev, rate); chindev, naudiooutdev, audiooutdev, naudiooutdev, choutdev, rate,
audio_blocksize);
else else
#endif #endif
#ifdef USEAPI_MMIO #ifdef USEAPI_MMIO
...@@ -660,7 +681,7 @@ void glob_audio_properties(t_pd *dummy, t_floatarg flongform) ...@@ -660,7 +681,7 @@ void glob_audio_properties(t_pd *dummy, t_floatarg flongform)
audioinchan1, audioinchan2, audioinchan3, audioinchan4, audioinchan1, audioinchan2, audioinchan3, audioinchan4,
audiooutdev1, audiooutdev2, audiooutdev3, audiooutdev4, audiooutdev1, audiooutdev2, audiooutdev3, audiooutdev4,
audiooutchan1, audiooutchan2, audiooutchan3, audiooutchan4; audiooutchan1, audiooutchan2, audiooutchan3, audiooutchan4;
int rate, advance, callback; int rate, advance, callback, blocksize;
/* these are all the devices on your system: */ /* these are all the devices on your system: */
char indevlist[MAXNDEV*DEVDESCSIZE], outdevlist[MAXNDEV*DEVDESCSIZE]; char indevlist[MAXNDEV*DEVDESCSIZE], outdevlist[MAXNDEV*DEVDESCSIZE];
int nindevs = 0, noutdevs = 0, canmulti = 0, cancallback = 0, i; int nindevs = 0, noutdevs = 0, canmulti = 0, cancallback = 0, i;
...@@ -679,7 +700,8 @@ void glob_audio_properties(t_pd *dummy, t_floatarg flongform) ...@@ -679,7 +700,8 @@ void glob_audio_properties(t_pd *dummy, t_floatarg flongform)
outdevlist + i * DEVDESCSIZE); outdevlist + i * DEVDESCSIZE);
sys_get_audio_params(&naudioindev, audioindev, chindev, sys_get_audio_params(&naudioindev, audioindev, chindev,
&naudiooutdev, audiooutdev, choutdev, &rate, &advance, &callback); &naudiooutdev, audiooutdev, choutdev, &rate, &advance, &callback,
&blocksize);
#ifdef USEAPI_JACK #ifdef USEAPI_JACK
if (sys_audioapiopened == API_JACK) if (sys_audioapiopened == API_JACK)
...@@ -719,7 +741,7 @@ void glob_audio_properties(t_pd *dummy, t_floatarg flongform) ...@@ -719,7 +741,7 @@ void glob_audio_properties(t_pd *dummy, t_floatarg flongform)
audiooutdev1, audiooutdev2, audiooutdev3, audiooutdev4, audiooutdev1, audiooutdev2, audiooutdev3, audiooutdev4,
audiooutchan1, audiooutchan2, audiooutchan3, audiooutchan4, audiooutchan1, audiooutchan2, audiooutchan3, audiooutchan4,
rate, advance, canmulti, (cancallback ? callback : -1), rate, advance, canmulti, (cancallback ? callback : -1),
(flongform != 0)); (flongform != 0), blocksize);
gfxstub_deleteforkey(0); gfxstub_deleteforkey(0);
gfxstub_new(&glob_pdobject, (void *)glob_audio_properties, buf); gfxstub_new(&glob_pdobject, (void *)glob_audio_properties, buf);
} }
...@@ -728,13 +750,17 @@ extern int pa_foo; ...@@ -728,13 +750,17 @@ extern int pa_foo;
/* new values from dialog window */ /* new values from dialog window */
void glob_audio_dialog(t_pd *dummy, t_symbol *s, int argc, t_atom *argv) void glob_audio_dialog(t_pd *dummy, t_symbol *s, int argc, t_atom *argv)
{ {
int i, nindev, noutdev; int naudioindev, audioindev[MAXAUDIOINDEV], chindev[MAXAUDIOINDEV];
int naudiooutdev, audiooutdev[MAXAUDIOOUTDEV], choutdev[MAXAUDIOOUTDEV];
int rate, advance, audioon, i, nindev, noutdev;
int audioindev1, audioinchan1, audiooutdev1, audiooutchan1;
int newaudioindev[4], newaudioinchan[4], int newaudioindev[4], newaudioinchan[4],
newaudiooutdev[4], newaudiooutchan[4]; newaudiooutdev[4], newaudiooutchan[4];
/* the new values the dialog came back with: */ /* the new values the dialog came back with: */
int newrate = atom_getintarg(16, argc, argv); int newrate = atom_getintarg(16, argc, argv);
int newadvance = atom_getintarg(17, argc, argv); int newadvance = atom_getintarg(17, argc, argv);
int newcallback = atom_getintarg(18, argc, argv); int newcallback = atom_getintarg(18, argc, argv);
int newblocksize = atom_getintarg(19, argc, argv);
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
{ {
...@@ -767,14 +793,28 @@ void glob_audio_dialog(t_pd *dummy, t_symbol *s, int argc, t_atom *argv) ...@@ -767,14 +793,28 @@ void glob_audio_dialog(t_pd *dummy, t_symbol *s, int argc, t_atom *argv)
} }
} }
if (newcallback < 0) sys_set_audio_settings_reopen(nindev, newaudioindev, nindev, newaudioinchan,
newcallback = 0;
if (!audio_callback_is_open && !newcallback)
sys_close_audio();
sys_set_audio_settings(nindev, newaudioindev, nindev, newaudioinchan,
noutdev, newaudiooutdev, noutdev, newaudiooutchan, noutdev, newaudiooutdev, noutdev, newaudiooutchan,
newrate, newadvance, (newcallback >= 0 ? newcallback : 0)); newrate, newadvance, newcallback, newblocksize);
if (!audio_callback_is_open && !newcallback) }
void sys_set_audio_settings_reopen(int naudioindev, int *audioindev, int nchindev,
int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev,
int *choutdev, int rate, int advance, int callback, int newblocksize)
{
if (callback < 0)
callback = 0;
if (newblocksize != (1<<ilog2(newblocksize)) ||
newblocksize < DEFDACBLKSIZE || newblocksize > 2048)
newblocksize = DEFDACBLKSIZE;
if (!audio_callback_is_open && !callback)
sys_close_audio();
sys_set_audio_settings(naudioindev, audioindev, nchindev, chindev,
naudiooutdev, audiooutdev, nchoutdev, choutdev,
rate, advance, (callback >= 0 ? callback : 0), newblocksize);
if (!audio_callback_is_open && !callback)
sys_reopen_audio(); sys_reopen_audio();
else sched_reopenmeplease(); else sched_reopenmeplease();
} }
...@@ -946,3 +986,62 @@ void glob_foo(void *dummy, t_symbol *s, int argc, t_atom *argv) ...@@ -946,3 +986,62 @@ void glob_foo(void *dummy, t_symbol *s, int argc, t_atom *argv)
} }
#endif #endif
} }
/* convert a device name to a (1-based) device number. (Output device if
'output' parameter is true, otherwise input device). Negative on failure. */
int sys_audiodevnametonumber(int output, const char *name)
{
char indevlist[MAXNDEV*DEVDESCSIZE], outdevlist[MAXNDEV*DEVDESCSIZE];
int nindevs = 0, noutdevs = 0, i, canmulti, cancallback;
sys_get_audio_devs(indevlist, &nindevs, outdevlist, &noutdevs,
&canmulti, &cancallback, MAXNDEV, DEVDESCSIZE);
if (output)
{
for (i = 0; i < noutdevs; i++)
{
unsigned int comp = strlen(name);
if (comp > strlen(outdevlist + i * DEVDESCSIZE))
comp = strlen(outdevlist + i * DEVDESCSIZE);
if (!strncmp(name, outdevlist + i * DEVDESCSIZE, comp))
return (i);
}
}
else
{
for (i = 0; i < nindevs; i++)
{
unsigned int comp = strlen(name);
if (comp > strlen(indevlist + i * DEVDESCSIZE))
comp = strlen(indevlist + i * DEVDESCSIZE);
if (!strncmp(name, indevlist + i * DEVDESCSIZE, comp))
return (i);
}
}
return (-1);
}
/* convert a (1-based) device number to a device name. (Output device if
'output' parameter is true, otherwise input device). Empty string on failure.
*/
void sys_audiodevnumbertoname(int output, int devno, char *name, int namesize)
{
char indevlist[MAXNDEV*DEVDESCSIZE], outdevlist[MAXNDEV*DEVDESCSIZE];
int nindevs = 0, noutdevs = 0, i, canmulti, cancallback;
if (devno < 0)
{
*name = 0;
return;
}
sys_get_audio_devs(indevlist, &nindevs, outdevlist, &noutdevs,
&canmulti, &cancallback, MAXNDEV, DEVDESCSIZE);
if (output && (devno < noutdevs))
strncpy(name, outdevlist + devno * DEVDESCSIZE, namesize);
else if (!output && (devno < nindevs))
strncpy(name, indevlist + devno * DEVDESCSIZE, namesize);
else *name = 0;
name[namesize-1] = 0;
}
...@@ -233,12 +233,14 @@ static int alsaio_setup(t_alsa_dev *dev, int out, int *channels, int *rate, ...@@ -233,12 +233,14 @@ static int alsaio_setup(t_alsa_dev *dev, int out, int *channels, int *rate,
/* return 0 on success */ /* return 0 on success */
int alsa_open_audio(int naudioindev, int *audioindev, int nchindev, int alsa_open_audio(int naudioindev, int *audioindev, int nchindev,
int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev, int *chindev, int naudiooutdev, int *audiooutdev, int nchoutdev,
int *choutdev, int rate) int *choutdev, int rate, int blocksize)
{ {
int err, inchans = 0, outchans = 0, subunitdir; int err, inchans = 0, outchans = 0, subunitdir;
char devname[512]; char devname[512];
int frag_size = (sys_blocksize ? sys_blocksize : ALSA_DEFFRAGSIZE); snd_output_t* out;
int frag_size = (blocksize ? blocksize : ALSA_DEFFRAGSIZE);
int nfrags, i, iodev, dev2; int nfrags, i, iodev, dev2;
int wantinchans, wantoutchans, device;
nfrags = sys_schedadvance * (float)rate / (1e6 * frag_size); nfrags = sys_schedadvance * (float)rate / (1e6 * frag_size);
/* save our belief as to ALSA's buffer size for later */ /* save our belief as to ALSA's buffer size for later */
...@@ -254,7 +256,7 @@ int alsa_open_audio(int naudioindev, int *audioindev, int nchindev, ...@@ -254,7 +256,7 @@ int alsa_open_audio(int naudioindev, int *audioindev, int nchindev,
alsa_numbertoname(audioindev[iodev], devname, 512); alsa_numbertoname(audioindev[iodev], devname, 512);
err = snd_pcm_open(&alsa_indev[alsa_nindev].a_handle, devname, err = snd_pcm_open(&alsa_indev[alsa_nindev].a_handle, devname,
SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK); SND_PCM_STREAM_CAPTURE, SND_PCM_NONBLOCK);
check_error(err, "snd_pcm_open (input)"); check_error(err, "snd_pcm_open");
if (err < 0) if (err < 0)
continue; continue;
alsa_indev[alsa_nindev].a_devno = audioindev[iodev]; alsa_indev[alsa_nindev].a_devno = audioindev[iodev];
...@@ -268,7 +270,7 @@ int alsa_open_audio(int naudioindev, int *audioindev, int nchindev, ...@@ -268,7 +270,7 @@ int alsa_open_audio(int naudioindev, int *audioindev, int nchindev,
alsa_numbertoname(audiooutdev[iodev], devname, 512); alsa_numbertoname(audiooutdev[iodev], devname, 512);
err = snd_pcm_open(&alsa_outdev[alsa_noutdev].a_handle, devname, err = snd_pcm_open(&alsa_outdev[alsa_noutdev].a_handle, devname,
SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK); SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);
check_error(err, "snd_pcm_open (output)"); check_error(err, "snd_pcm_open");
if (err < 0) if (err < 0)
continue; continue;
alsa_outdev[alsa_noutdev].a_devno = audiooutdev[iodev]; alsa_outdev[alsa_noutdev].a_devno = audiooutdev[iodev];
...@@ -290,7 +292,7 @@ int alsa_open_audio(int naudioindev, int *audioindev, int nchindev, ...@@ -290,7 +292,7 @@ int alsa_open_audio(int naudioindev, int *audioindev, int nchindev,
if (alsa_usemmap) if (alsa_usemmap)
{ {
post("using mmap audio interface"); post("using mmap audio interface");
if (alsamm_open_audio(rate)) if (alsamm_open_audio(rate, blocksize))
goto blewit; goto blewit;
else return (0); else return (0);
} }
...@@ -336,7 +338,8 @@ int alsa_open_audio(int naudioindev, int *audioindev, int nchindev, ...@@ -336,7 +338,8 @@ int alsa_open_audio(int naudioindev, int *audioindev, int nchindev,
check_error(err, "snd_pcm_status_malloc"); check_error(err, "snd_pcm_status_malloc");
} }
/* fill the buffer with silence */ /* fill the buffer with silence and prime the output FIFOs. This
should automatically start the output devices. */
memset(alsa_snd_buf, 0, alsa_snd_bufsize); memset(alsa_snd_buf, 0, alsa_snd_bufsize);
if (outchans) if (outchans)
...@@ -349,11 +352,15 @@ int alsa_open_audio(int naudioindev, int *audioindev, int nchindev, ...@@ -349,11 +352,15 @@ int alsa_open_audio(int naudioindev, int *audioindev, int nchindev,
DEFDACBLKSIZE); DEFDACBLKSIZE);
} }
} }
else if (inchans) if (inchans)
{ {
/* some of the ADC devices might already have been started by
starting the outputs above, but others might still need it. */
for (iodev = 0; iodev < alsa_nindev; iodev++) for (iodev = 0; iodev < alsa_nindev; iodev++)
if ((err = snd_pcm_start(alsa_indev[iodev].a_handle)) < 0) if (snd_pcm_state(alsa_indev[iodev].a_handle)
check_error(err, "input start failed\n"); != SND_PCM_STATE_RUNNING)
if ((err = snd_pcm_start(alsa_indev[iodev].a_handle)) < 0)
check_error(err, "input start failed");
} }
return (0); return (0);
blewit: blewit:
......
...@@ -175,17 +175,24 @@ static void check_error(int err, const char *why) ...@@ -175,17 +175,24 @@ static void check_error(int err, const char *why)
error("%s: %s\n", why, snd_strerror(err)); error("%s: %s\n", why, snd_strerror(err));
} }
int alsamm_open_audio(int rate) int alsamm_open_audio(int rate, int blocksize)
{ {
int err, i; int err;
char devname[80];
char *cardname;
snd_pcm_hw_params_t* hw_params; snd_pcm_hw_params_t* hw_params;
snd_pcm_sw_params_t* sw_params; snd_pcm_sw_params_t* sw_params;
/* fragsize is an old concept now use periods, used to be called fragments. */ /* fragsize is an old concept now use periods, used to be called fragments. */
/* Be aware in ALSA periodsize can be in bytes, where buffersize is in frames, /* Be aware in ALSA periodsize can be in bytes, where buffersize is in frames,
but sometimes buffersize is in bytes and periods in frames, crazy alsa... but sometimes buffersize is in bytes and periods in frames, crazy alsa...
...we use periodsize and buffersize in frames */ ...we use periodsize and buffersize in frames */
int i;
short* tmp_buf;
unsigned int tmp_uint;
snd_pcm_hw_params_alloca(&hw_params); snd_pcm_hw_params_alloca(&hw_params);
snd_pcm_sw_params_alloca(&sw_params); snd_pcm_sw_params_alloca(&sw_params);
...@@ -224,16 +231,16 @@ int alsamm_open_audio(int rate) ...@@ -224,16 +231,16 @@ int alsamm_open_audio(int rate)
/* set the asked buffer time (alsa buffertime in us)*/ /* set the asked buffer time (alsa buffertime in us)*/
alsamm_buffertime = alsamm_buffersize = 0; alsamm_buffertime = alsamm_buffersize = 0;
if(sys_blocksize == 0) if(blocksize == 0)
alsamm_buffertime = sys_schedadvance; alsamm_buffertime = sys_schedadvance;
else else
alsamm_buffersize = sys_blocksize; alsamm_buffersize = blocksize;
if(sys_verbose) if(sys_verbose)
post("syschedadvance=%d us(%d Samples)so buffertime max should be this=%d" post("syschedadvance=%d us(%d Samples)so buffertime max should be this=%d"
"or sys_blocksize=%d (samples) to use buffersize=%d", "or sys_blocksize=%d (samples) to use buffersize=%d",
sys_schedadvance,sys_advance_samples,alsamm_buffertime, sys_schedadvance,sys_advance_samples,alsamm_buffertime,
sys_blocksize,alsamm_buffersize); blocksize,alsamm_buffersize);
alsamm_periods = 0; /* no one wants periods setting from command line ;-) */ alsamm_periods = 0; /* no one wants periods setting from command line ;-) */
...@@ -308,6 +315,8 @@ int alsamm_open_audio(int rate) ...@@ -308,6 +315,8 @@ int alsamm_open_audio(int rate)
/* check for linked handles of input for each output*/ /* check for linked handles of input for each output*/
for(i=0; i<(alsa_noutdev < alsa_nindev ? alsa_noutdev:alsa_nindev); i++){ for(i=0; i<(alsa_noutdev < alsa_nindev ? alsa_noutdev:alsa_nindev); i++){
t_alsa_dev *ad = &alsa_outdev[i];
if (alsa_outdev[i].a_devno == alsa_indev[i].a_devno){ if (alsa_outdev[i].a_devno == alsa_indev[i].a_devno){
if ((err = snd_pcm_link (alsa_indev[i].a_handle, if ((err = snd_pcm_link (alsa_indev[i].a_handle,
alsa_outdev[i].a_handle)) == 0){ alsa_outdev[i].a_handle)) == 0){
......
...@@ -321,7 +321,8 @@ void sys_loadpreferences( void) ...@@ -321,7 +321,8 @@ void sys_loadpreferences( void)
int naudiooutdev, audiooutdev[MAXAUDIOOUTDEV], choutdev[MAXAUDIOOUTDEV]; int naudiooutdev, audiooutdev[MAXAUDIOOUTDEV], choutdev[MAXAUDIOOUTDEV];
int nmidiindev, midiindev[MAXMIDIINDEV]; int nmidiindev, midiindev[MAXMIDIINDEV];
int nmidioutdev, midioutdev[MAXMIDIOUTDEV]; int nmidioutdev, midioutdev[MAXMIDIOUTDEV];
int i, rate = 0, advance = 0, callback = 0, api, nolib, maxi; int i, rate = 0, advance = -1, callback = 0, blocksize = 0,
api, nolib, maxi;
char prefbuf[MAXPDSTRING], keybuf[80]; char prefbuf[MAXPDSTRING], keybuf[80];