capture with non-interleaved mode
Hi. I'm developping a signal processing program which needs to compute data from each channel of soundcards separately.
After searches I found that I must open the soundcard with the SND_PCM_ACCESS_RW_NONINTERLEAVED flag but it doesn't works well : for each readn operation i get the -32 error code . Meanwhile, I tested capture in interleaved mode and it works well.
I had to use hw:x,y for the interleaved capture and plughw:x,y for the non- interleaved capture, I don't know if non-interleaved capture works with hw:x,y.
Any advice (or piece of source code) ?
Thanks,
Cyril Coquilleau
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program. SourceForge.net hosts over 70,000 Open Source Projects. See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php
Quoted 8 lines
Hi. I'm developping a signal processing program which needs to compute data from each channel of soundcards separately.
After searches I found that I must open the soundcard with theSND_PCM_ACCESS_RW_NONINTERLEAVEDflag but it doesn't works well : for each readn operation i get the -32 error code . Meanwhile, I tested capture in interleaved mode and it works well.
I had to use hw:x,y for the interleaved capture and plughw:x,y for the non- interleaved capture, I don't know if non-interleaved capture works with hw:x,y.
[ We need a FAQ ... ]
ALSA's "hw" devices can only be used with parameters that match capabilities offered by the underlying hardware. There's not much hardware out there that supports non-interleaved I/O, so as a result, most "hw" devices can't do this. The Hammerfall and ice1712 series are notable exceptions. But there is a corollary: if you were using a hammerfall, the "hw" device cannot do interleaved I/O either.
as to your error, its probably a bug in your code. JACK uses non-interleaved mode by default, and it works with both plughw and hw models of many different kinds. if you posted the relevant parts of it here, somebody can probably help you.
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program. SourceForge.net hosts over 70,000 Open Source Projects. See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php
Quoted 22 lines
Quoted 9 lines
Hi. I'm developping a signal processing program which needs to compute data
from each channel of soundcards separately.
After searches I found that I must open the soundcard with theSND_PCM_ACCESS_RW_NONINTERLEAVEDflag but it doesn't works well : for eachreadn operation i get the -32 error code . Meanwhile, I tested capture in interleaved mode and it works well.
I had to use hw:x,y for the interleaved capture and plughw:x,y for thenon-
Quoted 1 line
interleaved capture, I don't know if non-interleaved capture works with
hw:x,y.
[ We need a FAQ ... ]
ALSA's "hw" devices can only be used with parameters that match capabilities offered by the underlying hardware. There's not much hardware out there that supports non-interleaved I/O, so as a result, most "hw" devices can't do this. The Hammerfall and ice1712 series are notable exceptions. But there is a corollary: if you were using a hammerfall, the "hw" device cannot do interleaved I/O either.
Quoted 6 lines
as to your error, its probably a bug in your code. JACK uses non-interleaved mode by default, and it works with both plughw and hw models of many different kinds. if you posted the relevant parts of it here, somebody can probably help you.
I join the relevant parts of the source (without error handlers) :
#define BUF_SIZE 128
struct snd_card
{
snd_pcm_t *handle;
snd_pcm_hw_params_t *params;
short inputBuffer[BUF_SIZE*2];
void *buffer[2];
};
typedef struct snd_card snd_card_t;
int
main (....)
{
char card_id[32];
int err;
itn card = 0;
snd_card_t *card1;
card1 = calloc(1,sizeof(snd_card_t)); card1->buffer[0] = card1->inputBuffer; card1->buffer[1] = &card1->inputBuffer[BUF_SIZE]; snprintf (card_id, 32, "plughw:%d", card);
snd_pcm_open (&card1->handle, card_id, SND_PCM_STREAM_CAPTURE, 0); snd_pcm_hw_params_malloc (&card1->params); snd_pcm_hw_params_any (card1->handle, card1->params); snd_pcm_hw_params_set_channels (card1->handle, card1->params, 2); snd_pcm_hw_params_set_access (card1->handle, card1->params,SND_PCM_ACCESS_RW_NONINTERLEAVED);
snd_pcm_hw_params_set_format (card1->handle, card1->params,SND_PCM_FORMAT_S16_LE);
snd_pcm_hw_params_set_rate_near (card1->handle, card1->params, ECHANT, 0); snd_pcm_hw_params (card1->handle, card1->params); snd_pcm_hw_params_free (card1->params);
snd_pcm_prepare (card1->handle);
while (...)
{
err = snd_pcm_readn (card1->handle, card1->buffer, BUF_SIZE);
printf("err=%d, buff=%d\n", err, card1->buffer[0]);
... }
...
}
And here is the result of printf
err=-32, buff=-1
err=-32, buff=-1
err=-32, buff=-1
err=-32, buff=-1
err=-32, buff=-1
If you see the problem...
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program. SourceForge.net hosts over 70,000 Open Source Projects. See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php
At Tue, 14 Oct 2003 17:30:40 +0200,
Quoted 75 lines · [email protected] wrote:
Quoted 23 lines
Quoted 10 lines
Hi. I'm developping a signal processing program which needs to compute data
from each channel of soundcards separately.
After searches I found that I must open the soundcard with theSND_PCM_ACCESS_RW_NONINTERLEAVEDflag but it doesn't works well : for eachreadn operation i get the -32 error code . Meanwhile, I tested capture in interleaved mode and it works well.
I had to use hw:x,y for the interleaved capture and plughw:x,y for thenon-
Quoted 1 line
interleaved capture, I don't know if non-interleaved capture works with
hw:x,y.
[ We need a FAQ ... ]
ALSA's "hw" devices can only be used with parameters that match capabilities offered by the underlying hardware. There's not much hardware out there that supports non-interleaved I/O, so as a result, most "hw" devices can't do this. The Hammerfall and ice1712 series are notable exceptions. But there is a corollary: if you were using a hammerfall, the "hw" device cannot do interleaved I/O either.
Quoted 6 lines
as to your error, its probably a bug in your code. JACK uses non-interleaved mode by default, and it works with both plughw and hw models of many different kinds. if you posted the relevant parts of it here, somebody can probably help you.
I join the relevant parts of the source (without error handlers) :
#define
BUF_SIZE128struct
snd_card
{
snd_pcm_t*handle;
snd_pcm_hw_params_t*params;short inputBuffer[BUF_SIZE*2];
void *buffer[2];
};
typedef structsnd_cardsnd_card_t;int
main (....)
{
char card_id[32];
int err;
itn card = 0;
snd_card_t*card1;card1 = calloc(1,sizeof(snd_card_t)); card1->buffer[0] = card1->inputBuffer; card1->buffer[1] = &card1->inputBuffer[BUF_SIZE]; snprintf (card_id, 32, "plughw:%d", card);
snd_pcm_open(&card1->handle,card_id,SND_PCM_STREAM_CAPTURE, 0);snd_pcm_hw_params_malloc(&card1->params);snd_pcm_hw_params_any(card1->handle,card1->params);snd_pcm_hw_params_set_channels(card1->handle,card1->params, 2);snd_pcm_hw_params_set_access(card1->handle,card1->params,SND_PCM_ACCESS_RW_NONINTERLEAVED);
snd_pcm_hw_params_set_format(card1->handle,card1->params,SND_PCM_FORMAT_S16_LE);
snd_pcm_hw_params_set_rate_near(card1->handle,card1->params, ECHANT, 0);snd_pcm_hw_params(card1->handle,card1->params);snd_pcm_hw_params_free(card1->params);
snd_pcm_prepare(card1->handle);while (...)
{ err = snd_pcm_readn (card1->handle, card1->buffer, BUF_SIZE); printf("err=%d, buff=%d\n", err, card1->buffer[0]); ...
Quoted 8 lines
}
...
}And here is the result of printf
err=-32, buff=-1
-32 is EPIPE. it's likely buffer under/overrun.
Takashi
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program. SourceForge.net hosts over 70,000 Open Source Projects. See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php
Quoted 86 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Hi. I'm developping a signal processing program which needs to compute
data
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
from each channel of soundcards separately.
After searches I found that I must open the soundcard with theSND_PCM_ACCESS_RW_NONINTERLEAVEDflag but it doesn't works well : foreach
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
readn operation i get the -32 error code . Meanwhile, I tested capture
in
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
interleaved mode and it works well.
I had to use hw:x,y for the interleaved capture and plughw:x,y for thenon-
Quoted 1 line
interleaved capture, I don't know if non-interleaved capture works
with
Quoted 46 lines
Quoted 11 lines
hw:x,y.
[ We need a FAQ ... ]
ALSA's "hw" devices can only be used with parameters that match capabilities offered by the underlying hardware. There's not much hardware out there that supports non-interleaved I/O, so as a result, most "hw" devices can't do this. The Hammerfall and ice1712 series are notable exceptions. But there is a corollary: if you were using a hammerfall, the "hw" device cannot do interleaved I/O either.
Quoted 6 lines
as to your error, its probably a bug in your code. JACK uses non-interleaved mode by default, and it works with both plughw and hw models of many different kinds. if you posted the relevant parts of it here, somebody can probably help you.
I join the relevant parts of the source (without error handlers) :
#define
BUF_SIZE128
#define ECHANT 44100struct
snd_card
{
snd_pcm_t*handle;
snd_pcm_hw_params_t*params;short inputBuffer[BUF_SIZE*2];
void *buffer[2];
};
typedef structsnd_cardsnd_card_t;int
main (....)
{
char card_id[32];
int err;
itn card = 0;
snd_card_t*card1;card1 = calloc(1,sizeof(snd_card_t)); card1->buffer[0] = card1->inputBuffer; card1->buffer[1] = &card1->inputBuffer[BUF_SIZE]; snprintf (card_id, 32, "plughw:%d", card);Quoted 9 lines
snd_pcm_open(&card1->handle,card_id,SND_PCM_STREAM_CAPTURE, 0);snd_pcm_hw_params_malloc(&card1->params);snd_pcm_hw_params_any(card1->handle,card1->params);snd_pcm_hw_params_set_channels(card1->handle,card1->params, 2);snd_pcm_hw_params_set_access(card1->handle,card1->params,SND_PCM_ACCESS_RW_NONINTERLEAVED);
snd_pcm_hw_params_set_format(card1->handle,card1->params,SND_PCM_FORMAT_S16_LE);
snd_pcm_hw_params_set_rate_near(card1->handle,card1->params, ECHANT,0);
Quoted 15 lines
snd_pcm_hw_params (card1->handle, card1->params); snd_pcm_hw_params_free (card1->params); snd_pcm_prepare (card1->handle);while (...)
{ err = snd_pcm_readn (card1->handle, card1->buffer, BUF_SIZE); printf("err=%d, buff=%d\n", err, card1->buffer[0]); ...}
...
}
Quoted 6 lines
Quoted 2 lines
And here is the result of printf
err=-32, buff=-1-32 is EPIPE. it's likely buffer under/overrun.
I've not managed to fix this bug into my program... Do you see the error on my code (bad soundcard initialization or other) or have you got another way to propose me to capture the two channels of my soundcard separately ?
Cyril
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program. SourceForge.net hosts over 70,000 Open Source Projects. See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php
Quoted 4 lines
I've not managed to fix this bug into my program... Do you see the error on my
code (bad soundcard initialization or other) or have you got another way to propose me to capture the two channels of my soundcard separately ?
try increasing BUF_SIZE to 4096 and see what happens. 128 frames/period is in seriously low-latency territory, and i doubt that your program is designed for that. if i was to make a guess, you probably try to write to disk after reading from the audio interface, in the same thread, yes? sorry, you can't do that for 128 frames/period, and a general design rule, you shouldn't ever do it (though it obviously works for some simple programs with just stereo in).
--p
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program. SourceForge.net hosts over 70,000 Open Source Projects. See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php