* Doubt on implementing .readi and .readn methods @ 2006-05-12 19:27 Juan Carlos Castro y Castro 2006-05-15 9:29 ` Takashi Iwai 0 siblings, 1 reply; 10+ messages in thread From: Juan Carlos Castro y Castro @ 2006-05-12 19:27 UTC (permalink / raw) To: alsa-devel 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Doubt on implementing .readi and .readn methods 2006-05-12 19:27 Doubt on implementing .readi and .readn methods Juan Carlos Castro y Castro @ 2006-05-15 9:29 ` Takashi Iwai 2006-05-15 20:05 ` Juan Carlos Castro y Castro 2006-05-16 21:17 ` Juan Carlos Castro y Castro 0 siblings, 2 replies; 10+ messages in thread From: Takashi Iwai @ 2006-05-15 9:29 UTC (permalink / raw) To: Juan Carlos Castro y Castro; +Cc: alsa-devel At Fri, 12 May 2006 16:27:51 -0300, Juan Carlos Castro y Castro wrote: > > 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. "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. > 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Doubt on implementing .readi and .readn methods 2006-05-15 9:29 ` Takashi Iwai @ 2006-05-15 20:05 ` Juan Carlos Castro y Castro 2006-05-15 20:31 ` Juan Carlos Castro y Castro 2006-05-15 20:38 ` Lee Revell 2006-05-16 21:17 ` Juan Carlos Castro y Castro 1 sibling, 2 replies; 10+ messages in thread From: Juan Carlos Castro y Castro @ 2006-05-15 20:05 UTC (permalink / raw) To: Takashi Iwai; +Cc: alsa-devel 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, Juan P.S.: By the way, how many people here would find this functionality a nice thing to have? (Besides me of course) Takashi Iwai wrote: >At Fri, 12 May 2006 16:27:51 -0300, >Juan Carlos Castro y Castro wrote: > > >>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. >> >> > >"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. > > > > >>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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Doubt on implementing .readi and .readn methods 2006-05-15 20:05 ` Juan Carlos Castro y Castro @ 2006-05-15 20:31 ` Juan Carlos Castro y Castro 2006-05-15 20:38 ` Lee Revell 1 sibling, 0 replies; 10+ messages in thread From: Juan Carlos Castro y Castro @ 2006-05-15 20:31 UTC (permalink / raw) To: Takashi Iwai; +Cc: alsa-devel [-- Attachment #1: Type: text/plain, Size: 2990 bytes --] Some more info: Attached are my .asoundrc and the diff of the changes I've made to pcm_file.c. Juan Carlos Castro y Castro wrote: > 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, > Juan > P.S.: By the way, how many people here would find this functionality a > nice thing to have? (Besides me of course) > > Takashi Iwai wrote: > >> At Fri, 12 May 2006 16:27:51 -0300, >> Juan Carlos Castro y Castro wrote: >> >>> 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. >> >> "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. >> >>> 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 > [-- Attachment #2: coupler.tgz --] [-- Type: application/x-gzip, Size: 2000 bytes --] ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Doubt on implementing .readi and .readn methods 2006-05-15 20:05 ` Juan Carlos Castro y Castro 2006-05-15 20:31 ` Juan Carlos Castro y Castro @ 2006-05-15 20:38 ` Lee Revell 2006-05-15 20:56 ` Juan Carlos Castro y Castro 1 sibling, 1 reply; 10+ messages in thread From: Lee Revell @ 2006-05-15 20:38 UTC (permalink / raw) To: Juan Carlos Castro y Castro; +Cc: Takashi Iwai, alsa-devel On Mon, 2006-05-15 at 17:05 -0300, Juan Carlos Castro y Castro wrote: > Cheers, > Juan > P.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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Doubt on implementing .readi and .readn methods 2006-05-15 20:38 ` Lee Revell @ 2006-05-15 20:56 ` Juan Carlos Castro y Castro 2006-05-15 21:19 ` Lee Revell 0 siblings, 1 reply; 10+ messages in thread From: Juan Carlos Castro y Castro @ 2006-05-15 20:56 UTC (permalink / raw) To: Lee Revell; +Cc: Takashi Iwai, alsa-devel Lee Revell wrote: >On Mon, 2006-05-15 at 17:05 -0300, Juan Carlos Castro y Castro wrote: > > >>Cheers, >>Juan >>P.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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Doubt on implementing .readi and .readn methods 2006-05-15 20:56 ` Juan Carlos Castro y Castro @ 2006-05-15 21:19 ` Lee Revell 2006-05-15 21:29 ` Juan Carlos Castro y Castro 0 siblings, 1 reply; 10+ messages in thread From: Lee Revell @ 2006-05-15 21:19 UTC (permalink / raw) To: Juan Carlos Castro y Castro; +Cc: Takashi Iwai, alsa-devel On Mon, 2006-05-15 at 17:56 -0300, Juan Carlos Castro y Castro wrote: > Lee Revell wrote: > > >On Mon, 2006-05-15 at 17:05 -0300, Juan Carlos Castro y Castro wrote: > > > > > >>Cheers, > >>Juan > >>P.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? > Yes, that's the main difference ;-) > 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Doubt on implementing .readi and .readn methods 2006-05-15 21:19 ` Lee Revell @ 2006-05-15 21:29 ` Juan Carlos Castro y Castro 0 siblings, 0 replies; 10+ messages in thread From: Juan Carlos Castro y Castro @ 2006-05-15 21:29 UTC (permalink / raw) To: Lee Revell; +Cc: Takashi Iwai, alsa-devel Lee Revell wrote: >>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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Doubt on implementing .readi and .readn methods 2006-05-15 9:29 ` Takashi Iwai 2006-05-15 20:05 ` Juan Carlos Castro y Castro @ 2006-05-16 21:17 ` Juan Carlos Castro y Castro 2006-05-17 13:37 ` Takashi Iwai 1 sibling, 1 reply; 10+ messages in thread From: Juan Carlos Castro y Castro @ 2006-05-16 21:17 UTC (permalink / raw) To: Takashi Iwai; +Cc: alsa-devel Takashi Iwai wrote: >"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. > > 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Doubt on implementing .readi and .readn methods 2006-05-16 21:17 ` Juan Carlos Castro y Castro @ 2006-05-17 13:37 ` Takashi Iwai 0 siblings, 0 replies; 10+ messages in thread From: Takashi Iwai @ 2006-05-17 13:37 UTC (permalink / raw) To: Juan Carlos Castro y Castro; +Cc: alsa-devel At Tue, 16 May 2006 18:17:14 -0300, Juan Carlos Castro y Castro wrote: > > Takashi Iwai wrote: > > >"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. > > > > > 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, ... 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 ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2006-05-17 13:37 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2006-05-12 19:27 Doubt on implementing .readi and .readn methods Juan Carlos Castro y Castro 2006-05-15 9:29 ` Takashi Iwai 2006-05-15 20:05 ` Juan Carlos Castro y Castro 2006-05-15 20:31 ` Juan Carlos Castro y Castro 2006-05-15 20:38 ` Lee Revell 2006-05-15 20:56 ` Juan Carlos Castro y Castro 2006-05-15 21:19 ` Lee Revell 2006-05-15 21:29 ` Juan Carlos Castro y Castro 2006-05-16 21:17 ` Juan Carlos Castro y Castro 2006-05-17 13:37 ` Takashi Iwai
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.