Re: [mpg123-users] mpg123_read() (Error reading the stream. (code 18))
Brought to you by:
sobukus
From: Leonard B. <leo...@gm...> - 2021-02-26 09:47:26
|
Thanks! > On 26/02/2021, at 10:02 PM, Thomas Orgis <tho...@or...> wrote: > > Am Fri, 26 Feb 2021 21:34:31 +1300 > schrieb Leonard Bocock <leo...@gm...>: > >> (1) The use of fread() > > I didn't follow quite what was the issue here, but I am joyous that you > worked it out! > >> (2) The small buffer size from mpg123_outblock(mh) which is >> inadequate for ALSA (a small buffer causes ALSA to play with jitter) > > I don't quite understand this. You configure the buffers ALSA uses, > independent of the chunks to write. See > > http://scm.orgis.org/view/mpg123/trunk/src/libout123/modules/alsa.c?view=markup > , > which you could use via libout123, too. In essence: > > 34 #define BUFFER_LENGTH (ao->device_buffer > 0. ? ao->device_buffer : 0.2) > 116 buffer_size = rate * BUFFER_LENGTH; > 117 if (snd_pcm_hw_params_set_buffer_size_near(pcm, hw, &buffer_size) < 0) { > 118 if(!AOQUIET) error("initialize_device(): cannot set buffer size"); > 119 return -1; > 120 } > 121 debug1("buffer_size=%lu", (unsigned long)buffer_size); > 122 period_size = buffer_size / 3; /* 3 periods is so much more common. */ > 123 if (snd_pcm_hw_params_set_period_size_near(pcm, hw, &period_size, NULL) < 0) { > 124 if(!AOQUIET) error("initialize_device(): cannot set period size"); > 125 return -1; > 126 } > 127 debug1("period_size=%lu", (unsigned long)period_size); > 128 if (snd_pcm_hw_params(pcm, hw) < 0) { > 129 if(!AOQUIET) error("initialize_device(): cannot set hw params"); > 130 return -1; > 131 } > 132 > > Important was that one, which I only realized quite recently: > > 138 /* Start playing once we got at least full period ... this is not default? */ > 139 if (snd_pcm_sw_params_set_start_threshold(pcm, sw, buffer_size/2) < 0) { > 140 if(!AOQUIET) error("initialize_device(): cannot set start threshold"); > 141 return -1; > 142 } > > And then the writing with whatever chunk size: > > 230 frames = snd_pcm_bytes_to_frames(pcm, bytes); > 231 while > 232 ( /* Try to write, recover if error, try again if recovery successful. */ > 233 (written = snd_pcm_writei(pcm, buf, frames)) < 0 > 234 && snd_pcm_recover(pcm, (int)written, 0) == 0 > 235 ) > 236 { > 237 debug2("recovered from alsa issue %i while trying to write %lu frames", (int)written, (unsigned long)frames); > 238 } > > > Of course, you could also do it like > > http://scm.orgis.org/view/mpg123/trunk/doc/examples/mpg123_to_out123.c?view=markup > > and let out123 do the ALSA dance, but it's your pick;-) > > > Alrighty then, > > Thomas > > > _______________________________________________ > mpg123-users mailing list > mpg...@li... > https://lists.sourceforge.net/lists/listinfo/mpg123-users Leonard Bocock leo...@gm... |