Doubt on implementing .readi and .readn methods
I'm a bit confused about what "areas" and "frames" are supposed to mean, and in which order the data pointed to by **bufs corresponds to the data that's written to disk in the .writen functions. I tried to follow the logic in the functions snd_pcm_areas_from_buf(), snd_pcm_areas_from_bufs(), snd_pcm_file_add_frames(), and snd_pcm_areas_copy(), and it feels like a labyrinth.
Another thing, are the .readi and .readn functions supposed to block, or can they return less bytes (frames?) than requested?
Cheers,
Juan
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
At Fri, 12 May 2006 16:27:51 -0300,
Quoted 7 lines · Juan Carlos Castro y Castro
I'm a bit confused about what "areas" and "frames" are supposed to mean, and in which order the data pointed to by **bufs corresponds to the data that's written to disk in the .writen functions. I tried to follow the logic in the functions
snd_pcm_areas_from_buf(),snd_pcm_areas_from_bufs(),snd_pcm_file_add_frames(), andsnd_pcm_areas_copy(), and it feels like a labyrinth.
"area" refers to snd_pcm_channel_area_t. It's an exported struct defined in pcm.h:
/** PCM area specification */
typedef struct _snd_pcm_channel_area {
/** base address of channel samples */
void *addr;
/** offset to first sample in bits */
unsigned int first;
/** samples distance in bits */
unsigned int step;
} snd_pcm_channel_area_t;An area array is used for a stream with multiple channels. Each element of the array contains the area information for one channel. For example, in the case of 16bit 4-channel interleaved format,
area[*].addr = base_addr area[0].first = 0 area[1].first = 16 area[2].first = 32 area[3].first = 48 area[*].step = 64
"frame" is the unit of samples, and 1 frame = sample-width * chanenels. e.g. for 16bit 4-channel format, 1 frame = 2 * 4 = 8 bytes.
Quoted 2 lines
Another thing, are the .readi and .readn functions supposed to block, or can they return less bytes (frames?) than requested?
Yes if opened without O_NONBLOCK flag.
Takashi
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
Nice, that clears up a lot of doubts I had. Now I'd like to clear up a few things in turn -- namely, what exactly I am trying to accomplish.
I want to make a "sound bridge" -- Applications A and B both do sound input and output, and I want A's sound output to become B's sound input and vice versa. Call it the Acoustic Coupler From Hell if you may. ;) If the file plugin did emulate sound input via file as well as it does sound output, I'd be all set.
Now comes the tricky part. I put debug messages in the .readi and .readn functions in the file plugin, called arecord using that PCM (which works fine as output, i.e., with aplay) as a source and... NONE of that functions EVER get called! It's not a library installation problem -- debug messages in the open function do get shown.
That got me baffled. I imagined some polling problem, but I use the null plugin as a slave, and that one always has bytes available. I'm pretty sure I'm doing something stupid due to lack of familiarity with the ALSA architecture. The question is, what?
Cheers,
JuanP.S.: By the way, how many people here would find this functionality a nice thing to have? (Besides me of course)
Quoted 38 lines · Takashi Iwai
At Fri, 12 May 2006 16:27:51 -0300,
Quoted 3 lines · Juan Carlos Castro y Castro
I'm a bit confused about what "areas" and "frames" are supposed to mean, and in which order the data pointed to by **bufs corresponds to the data that's written to disk in the .writen functions. I tried to follow the logic in the functions
snd_pcm_areas_from_buf(),snd_pcm_areas_from_bufs(),snd_pcm_file_add_frames(), andsnd_pcm_areas_copy(), and it feels like a labyrinth."area" refers to
snd_pcm_channel_area_t. It's an exported struct defined inpcm.h:/** PCM area specification */
typedef struct _snd_pcm_channel_area { /** base address of channel samples */ void *addr; /** offset to first sample in bits */ unsigned int first; /** samples distance in bits */ unsigned int step; } snd_pcm_channel_area_t;An area array is used for a stream with multiple channels. Each element of the array contains the area information for one channel. For example, in the case of 16bit 4-channel interleaved format,
area[*].addr = base_addr area[0].first = 0 area[1].first = 16 area[2].first = 32 area[3].first = 48 area[*].step = 64"frame" is the unit of samples, and 1 frame = sample-width * chanenels. e.g. for 16bit 4-channel format, 1 frame = 2 * 4 = 8 bytes.
Quoted 11 lines
Quoted 3 lines
Another thing, are the .readi and .readn functions supposed to block, or can they return less bytes (frames?) than requested?
Yes if opened without
O_NONBLOCKflag.Takashi
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
Some more info: Attached are my .asoundrc and the diff of the changes I've made to pcm_file.c.
Quoted 52 lines · Juan Carlos Castro y Castro
Nice, that clears up a lot of doubts I had. Now I'd like to clear up a few things in turn -- namely, what exactly I am trying to accomplish.
I want to make a "sound bridge" -- Applications A and B both do sound input and output, and I want A's sound output to become B's sound input and vice versa. Call it the Acoustic Coupler From Hell if you may. ;) If the file plugin did emulate sound input via file as well as it does sound output, I'd be all set.
Now comes the tricky part. I put debug messages in the .readi and .readn functions in the file plugin, called arecord using that PCM (which works fine as output, i.e., with aplay) as a source and... NONE of that functions EVER get called! It's not a library installation problem -- debug messages in the open function do get shown.
That got me baffled. I imagined some polling problem, but I use the null plugin as a slave, and that one always has bytes available. I'm pretty sure I'm doing something stupid due to lack of familiarity with the ALSA architecture. The question is, what?
Cheers,
JuanP.S.: By the way, how many people here would find this functionality a nice thing to have? (Besides me of course)Quoted 37 lines · Takashi Iwai
At Fri, 12 May 2006 16:27:51 -0300,
Quoted 1 line · Juan Carlos Castro y Castro
I'm a bit confused about what "areas" and "frames" are supposed to mean, and in which order the data pointed to by **bufs corresponds to the data that's written to disk in the .writen functions. I tried to follow the logic in the functions
snd_pcm_areas_from_buf(),snd_pcm_areas_from_bufs(),snd_pcm_file_add_frames(), andsnd_pcm_areas_copy(), and it feels like a labyrinth."area" refers to
snd_pcm_channel_area_t. It's an exported struct defined inpcm.h:/** PCM area specification */
typedef struct _snd_pcm_channel_area { /** base address of channel samples */ void *addr; /** offset to first sample in bits */ unsigned int first; /** samples distance in bits */ unsigned int step; } snd_pcm_channel_area_t;An area array is used for a stream with multiple channels. Each element of the array contains the area information for one channel. For example, in the case of 16bit 4-channel interleaved format,
area[*].addr = base_addr area[0].first = 0 area[1].first = 16 area[2].first = 32 area[3].first = 48 area[*].step = 64"frame" is the unit of samples, and 1 frame = sample-width * chanenels. e.g. for 16bit 4-channel format, 1 frame = 2 * 4 = 8 bytes.
Quoted 1 line
Another thing, are the .readi and .readn functions supposed to block, or can they return less bytes (frames?) than requested?
Yes if opened without
O_NONBLOCKflag.Takashi
Quoted 6 lines · Juan Carlos Castro y Castro
Cheers,
JuanP.S.: By the way, how many people here would find this functionality a
nice thing to have? (Besides me of course)
What will it give us that JACK doesn't?
Lee
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
Quoted 11 lines · Lee Revell
Quoted 5 lines · Juan Carlos Castro y Castro
Cheers,
JuanP.S.: By the way, how many people here would find this functionality a nice thing to have? (Besides me of course)What will it give us that JACK doesn't?
Erm... (does a quick search of what JACK does) not having to recode the app?
OK, but anyway you got me curious. If one of my apps wasn't proprietary, and I decided to alter both to use JACK instead of ALSA, you say I could do acoustic coupling?
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
Quoted 10 lines · Juan Carlos Castro y Castro
Quoted 8 lines · Lee Revell
Quoted 5 lines · Juan Carlos Castro y Castro
Cheers,
JuanP.S.: By the way, how many people here would find this functionality a nice thing to have? (Besides me of course)
Quoted 5 lines
Quoted 3 lines
What will it give us that JACK doesn't?
Erm... (does a quick search of what JACK does) not having to recode the app?
Yes, that's the main difference ;-)
Quoted 4 lines
OK, but anyway you got me curious. If one of my apps wasn't proprietary, and I decided to alter both to use JACK instead of ALSA, you say I could do acoustic coupling?
Yes, it's exactly what JACK was designed for.
There are some things JACK isn't suitable for (like VOIP due to the lack of resampling).
Lee
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
Quoted 8 lines · Lee Revell
Quoted 3 lines
OK, but anyway you got me curious. If one of my apps wasn't proprietary, and I decided to alter both to use JACK instead of ALSA, you say I could do acoustic coupling?
Yes, it's exactly what JACK was designed for.
There are some things JACK isn't suitable for (like VOIP due to the lack of resampling).
Which the file plugin does wonderfully well (for output at least.) Or, rather, it isn't the file plugin that does this, it's the... plug plugin, right? The .asoundrc below works well for output but I don't fully grok it.
------------------------------------------------------------
pcm.fileout {
type file
file /home/jcastro/alsaout.raw
slave.pcm null
}
pcm_slave.sl3 {
pcm "fileout"
format S16_LE
channels 1
rate 48000
}
pcm.complex_convert {
type plug
slave sl3
}
------------------------------------------------------------
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
Quoted 24 lines · Takashi Iwai
"area" refers to
snd_pcm_channel_area_t. It's an exported struct defined inpcm.h:/** PCM area specification */
typedef struct _snd_pcm_channel_area { /** base address of channel samples */ void *addr; /** offset to first sample in bits */ unsigned int first; /** samples distance in bits */ unsigned int step; } snd_pcm_channel_area_t;An area array is used for a stream with multiple channels. Each element of the array contains the area information for one channel. For example, in the case of 16bit 4-channel interleaved format,
area[*].addr = base_addr area[0].first = 0 area[1].first = 16 area[2].first = 32 area[3].first = 48 area[*].step = 64
Quoted 4 lines
"frame" is the unit of samples, and 1 frame = sample-width * chanenels. e.g. for 16bit 4-channel format, 1 frame = 2 * 4 = 8 bytes.
OK, let me see if I get this straight. My main concern here is how I have to do the implementation of _readn(). Let's suppose the raw file has the following 16-bit words in it: A, B, C, D, E, F, G, H, I...
After performing the _readn(), the memory ponted to by buf[0] to buf[3] (four channels) will have to contain the following 16-bit words:
buf[0] -> A, E, I, ...
buf[1] -> B, F, J, ...
buf[2] -> C, G, K, ...
buf[3] -> D, H, L, ...
So, I'll have to read from the file to a temporary buffer and do the juggling of the words (each consisting of (pcm->sample_bits >> 3) bytes). Check?
Juan
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
At Tue, 16 May 2006 18:17:14 -0300,
Quoted 35 lines · Juan Carlos Castro y Castro
Quoted 24 lines · Takashi Iwai
"area" refers to
snd_pcm_channel_area_t. It's an exported struct defined inpcm.h:/** PCM area specification */
typedef struct _snd_pcm_channel_area { /** base address of channel samples */ void *addr; /** offset to first sample in bits */ unsigned int first; /** samples distance in bits */ unsigned int step; } snd_pcm_channel_area_t;An area array is used for a stream with multiple channels. Each element of the array contains the area information for one channel. For example, in the case of 16bit 4-channel interleaved format,
area[*].addr = base_addr area[0].first = 0 area[1].first = 16 area[2].first = 32 area[3].first = 48 area[*].step = 64Quoted 4 lines
"frame" is the unit of samples, and 1 frame = sample-width * chanenels. e.g. for 16bit 4-channel format, 1 frame = 2 * 4 = 8 bytes.
OK, let me see if I get this straight. My main concern here is how I have to do the implementation of
_readn(). Let's suppose the raw file has the following 16-bit words in it: A, B, C, D, E, F, G, H, I...
Quoted 7 lines
After performing the
_readn(), the memory ponted to by buf[0] to buf[3] (four channels) will have to contain the following 16-bit words:buf[0] -> A, E, I, ...
buf[1] -> B, F, J, ...
buf[2] -> C, G, K, ...
buf[3] -> D, H, L, ...
No, the non-interleaved format is a kind of bundled mono streams. Suppose you have a buffer with N * B samples, where N is the number of channels. Then the whole buffer consists of N times of mono-streams each of which has B samples:
<-- B --> <-- B --> <-- B --> ... <- B ->
|000000...|1111.....|2222.....|...|(N-1)...|Then, area array is set up like below (assume S16 format):
area[0].addr = buf_addr area[1].addr = buf_addr + B * 2 area[2].addr = buf_addr + B * 4 ... area[N-1].addr = buf_addr + B * 2 * (N-1) area[*].first = 0; area[*].step = 16; /* 16bit format */
Takashi
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642