All of lore.kernel.org
 help / color / mirror / Atom feed
* Question about the buffer length in the transfer callback of the PCM External Plugin
@ 2016-10-31  9:01 Bach, Andrea
  2016-10-31 10:10 ` Clemens Ladisch
  2016-10-31 18:11 ` Fernando Rodriguez
  0 siblings, 2 replies; 8+ messages in thread
From: Bach, Andrea @ 2016-10-31  9:01 UTC (permalink / raw)
  To: Alsa-devel@alsa-project.org

Hello,

how can I change the size that is provided inside the „transfer“-callback of an external PCM plugin?

Background:
I need to write a filter plugin and I have to use for processing a chunk size of power of two (32, 64, or 128 bytes … that’s because of the use of FFT). But I get inside the transfer callback a buffer of length 1000. That would be ok if I could just return let's say  960 bytes – but after some struggling I have some doubt about it because I got the impression that ALSA cannot change the bitrate inside such a plugin – the documentation states it could not change the sample rate – but actually how can I return less or more bytes – so maybe the bitrate should also be constant? Maybe I misunderstood the concepts of ALSA completely?

Kind regards

Dr. A. Bach, Software-Entwicklung Simulatoren
DFS Deutsche Flugsicherung GmbH
Forschungszentrum
Am DFS-Campus 5
63225 Langen
06103-707-5709

DFS Deutsche Flugsicherung GmbH
Am DFS-Campus
D - 63225 Langen

Tel.: +49-(0)6103-707-0

Sitz der Gesellschaft: Langen/Hessen
Zuständiges Registergericht: AG Offenbach am Main, HRB 34977
Vorsitzende des Aufsichtsrats: Dr. Martina Hinricher
Geschäftsführer: Prof. Klaus-Dieter Scheurle (Vors.), Robert Schickling, Dr. Michael Hann

Internet: http://www.dfs.de
Public-Key der DFS: http://www.dfs.de/dfs/public_key.asc
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Question about the buffer length in the transfer callback of the PCM External Plugin
  2016-10-31  9:01 Question about the buffer length in the transfer callback of the PCM External Plugin Bach, Andrea
@ 2016-10-31 10:10 ` Clemens Ladisch
       [not found]   ` <6c2af613d3b64138bc6e7c6cf69486cf@LGNMSXB01.prod.bk.dfs>
  2016-10-31 18:11 ` Fernando Rodriguez
  1 sibling, 1 reply; 8+ messages in thread
From: Clemens Ladisch @ 2016-10-31 10:10 UTC (permalink / raw)
  To: Bach, Andrea, Alsa-devel@alsa-project.org

Bach, Andrea wrote:
> how can I change the size that is provided inside the „transfer“-
> callback of an external PCM plugin?

You cannot.

ALSA assumes that there is a ring buffer that has the configured buffer
size, and that when N frames are reported as available, any number of
frames between 1 and N can be read/written.

> I need to write a filter plugin and I have to use for processing
> a chunk size of power of two (32, 64, or 128 bytes … that’s because of
> the use of FFT). But I get inside the transfer callback a buffer of
> length 1000. That would be ok if I could just return let's say
> 960 bytes

Handling less bytes than requested would imply that an error occured.

You could add your own buffer to keep any remaining frames of the
128-frame chunk until the next transfer call.


Regards,
Clemens
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Question about the buffer length in the transfer callback of the PCM External Plugin
  2016-10-31  9:01 Question about the buffer length in the transfer callback of the PCM External Plugin Bach, Andrea
  2016-10-31 10:10 ` Clemens Ladisch
@ 2016-10-31 18:11 ` Fernando Rodriguez
  2016-10-31 18:47   ` Fernando Rodriguez
  1 sibling, 1 reply; 8+ messages in thread
From: Fernando Rodriguez @ 2016-10-31 18:11 UTC (permalink / raw)
  To: Alsa-devel

On Mon, Oct 31, 2016 at 09:01:02AM +0000, Bach, Andrea wrote:
> Hello,
> 
> how can I change the size that is provided inside the „transfer“-callback of an external PCM plugin?
> 
> Background:
> I need to write a filter plugin and I have to use for processing a chunk size of power of two (32, 64, or 128 bytes … that’s because of the use of FFT). But I get inside the transfer callback a buffer of length 1000. That would be ok if I could just return let's say  960 bytes – but after some struggling I have some doubt about it because I got the impression that ALSA cannot change the bitrate inside such a plugin – the documentation states it could not change the sample rate – but actually how can I return less or more bytes – so maybe the bitrate should also be constant? Maybe I misunderstood the concepts of ALSA completely?
> 

Yes.
You're working with raw PCM data, so the bitrate (bits per second) is
constant ((bit_depth/8) * samplerate * channels). The term usually
refers to compressed audio streams.

I haven't done this but by looking at the definition for the transfer
callback it looks pretty standard. It returns snd_pcm_sframes_t so I
suppose you can write less than *size* frames and return what was
actually written. It is signed so a negative value would indicate an
error. So you'll probably have to buffer any leftovers and write them on
the next call. That's not the same as changing the framerate because
at the end of the pipeline alsa will take care of playing it at the
right rate).

That should clear some of the confussion. You'll probably have to look
at alsa-lib or some plugin's source code for more details.


> Kind regards
> 
> Dr. A. Bach, Software-Entwicklung Simulatoren
> DFS Deutsche Flugsicherung GmbH
> Forschungszentrum
> Am DFS-Campus 5
> 63225 Langen
> 06103-707-5709
> 
> DFS Deutsche Flugsicherung GmbH
> Am DFS-Campus
> D - 63225 Langen
> 
> Tel.: +49-(0)6103-707-0
> 
> Sitz der Gesellschaft: Langen/Hessen
> Zuständiges Registergericht: AG Offenbach am Main, HRB 34977
> Vorsitzende des Aufsichtsrats: Dr. Martina Hinricher
> Geschäftsführer: Prof. Klaus-Dieter Scheurle (Vors.), Robert Schickling, Dr. Michael Hann
> 
> Internet: http://www.dfs.de
> Public-Key der DFS: http://www.dfs.de/dfs/public_key.asc
> _______________________________________________
> Alsa-devel mailing list
> Alsa-devel@alsa-project.org
> http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

-- 
Fernando Rodriguez
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Question about the buffer length in the transfer callback of the PCM External Plugin
  2016-10-31 18:11 ` Fernando Rodriguez
@ 2016-10-31 18:47   ` Fernando Rodriguez
  0 siblings, 0 replies; 8+ messages in thread
From: Fernando Rodriguez @ 2016-10-31 18:47 UTC (permalink / raw)
  To: Alsa-devel

On Mon, Oct 31, 2016 at 02:11:17PM -0400, Fernando Rodriguez wrote:
> On Mon, Oct 31, 2016 at 09:01:02AM +0000, Bach, Andrea wrote:
> > Hello,
> > 
> > how can I change the size that is provided inside the „transfer“-callback of an external PCM plugin?
> > 
> > Background:
> > I need to write a filter plugin and I have to use for processing a chunk size of power of two (32, 64, or 128 bytes … that’s because of the use of FFT). But I get inside the transfer callback a buffer of length 1000. That would be ok if I could just return let's say  960 bytes – but after some struggling I have some doubt about it because I got the impression that ALSA cannot change the bitrate inside such a plugin – the documentation states it could not change the sample rate – but actually how can I return less or more bytes – so maybe the bitrate should also be constant? Maybe I misunderstood the concepts of ALSA completely?
> > 
> 
> Yes.
> You're working with raw PCM data, so the bitrate (bits per second) is
> constant ((bit_depth/8) * samplerate * channels). The term usually
> refers to compressed audio streams.

Oops, that was in bytes. It's bitdepth * samplerate * channels.

> 
> I haven't done this but by looking at the definition for the transfer
> callback it looks pretty standard. It returns snd_pcm_sframes_t so I
> suppose you can write less than *size* frames and return what was
> actually written. It is signed so a negative value would indicate an
> error. So you'll probably have to buffer any leftovers and write them on
> the next call. That's not the same as changing the framerate because
> at the end of the pipeline alsa will take care of playing it at the
> right rate).
> 
> That should clear some of the confussion. You'll probably have to look
> at alsa-lib or some plugin's source code for more details.
> 
> 
> > Kind regards
> > 
> > Dr. A. Bach, Software-Entwicklung Simulatoren
> > DFS Deutsche Flugsicherung GmbH
> > Forschungszentrum
> > Am DFS-Campus 5
> > 63225 Langen
> > 06103-707-5709
> > 
> > DFS Deutsche Flugsicherung GmbH
> > Am DFS-Campus
> > D - 63225 Langen
> > 
> > Tel.: +49-(0)6103-707-0
> > 
> > Sitz der Gesellschaft: Langen/Hessen
> > Zuständiges Registergericht: AG Offenbach am Main, HRB 34977
> > Vorsitzende des Aufsichtsrats: Dr. Martina Hinricher
> > Geschäftsführer: Prof. Klaus-Dieter Scheurle (Vors.), Robert Schickling, Dr. Michael Hann
> > 
> > Internet: http://www.dfs.de
> > Public-Key der DFS: http://www.dfs.de/dfs/public_key.asc
> > _______________________________________________
> > Alsa-devel mailing list
> > Alsa-devel@alsa-project.org
> > http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
> 
> -- 
> Fernando Rodriguez

-- 
Fernando Rodriguez
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Question about the buffer length in the transfer callback of the PCM External Plugin
       [not found]   ` <6c2af613d3b64138bc6e7c6cf69486cf@LGNMSXB01.prod.bk.dfs>
@ 2016-11-01 11:49     ` Clemens Ladisch
       [not found]       ` <165e6496dc554e18836006a6b77461ce@LGNMSXB01.prod.bk.dfs>
  0 siblings, 1 reply; 8+ messages in thread
From: Clemens Ladisch @ 2016-11-01 11:49 UTC (permalink / raw)
  To: Bach, Andrea; +Cc: alsa-devel

Bach, Andrea wrote:
> Ok, what about the output buffer?

"Output" from which point of view?  Playback or capture?

> When just 960 bytes are ready to be returned but I have to return 1000 bytes?

In theory, this is an underrun.

You could wait until the next 40 bytes are available.


Regards,
Clemens

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Question about the buffer length in the transfer callback of the PCM External Plugin
       [not found]       ` <165e6496dc554e18836006a6b77461ce@LGNMSXB01.prod.bk.dfs>
@ 2016-11-03 10:26         ` Clemens Ladisch
       [not found]           ` <1ce46f88056b4b2caa2ecf770da07d76@LGNMSXB01.prod.bk.dfs>
  0 siblings, 1 reply; 8+ messages in thread
From: Clemens Ladisch @ 2016-11-03 10:26 UTC (permalink / raw)
  To: Bach, Andrea; +Cc: alsa-devel

Bach, Andrea wrote:
> how can I wait inside the transfer callback until the next bytes are available...

That depends on where you get the bytes from.


Regards,
Clemens

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Question about the buffer length in the transfer callback of the PCM External Plugin
       [not found]           ` <1ce46f88056b4b2caa2ecf770da07d76@LGNMSXB01.prod.bk.dfs>
@ 2016-11-03 14:44             ` Clemens Ladisch
       [not found]               ` <e48b1619d89d4f7faf5640fd2d337555@LGNMSXB01.prod.bk.dfs>
  0 siblings, 1 reply; 8+ messages in thread
From: Clemens Ladisch @ 2016-11-03 14:44 UTC (permalink / raw)
  To: Bach, Andrea; +Cc: alsa-devel

I mean, what is that thing that you're interfacing ALSA with?
Obviously, it somehow generates samples, but how exactly?


Regards,
Clemens

Bach, Andrea wrote:
> Mmh - I get them from the buffer argument of the transfer callback of the PCM external plugin.
> I do not have a second source... maybe I missed the "main thing" so is there an example of a PCM external plugin I can look at?
>
> Thank you
> Andrea
>
>> how can I wait inside the transfer callback until the next bytes are available...
>
> That depends on where you get the bytes from.
>
>
> Regards,
> Clemens
> DFS Deutsche Flugsicherung GmbH
> Am DFS-Campus
> D - 63225 Langen
>
> Tel.: +49-(0)6103-707-0
>
> Sitz der Gesellschaft: Langen/Hessen
> Zuständiges Registergericht: AG Offenbach am Main, HRB 34977
> Vorsitzende des Aufsichtsrats: Dr. Martina Hinricher
> Geschäftsführer: Prof. Klaus-Dieter Scheurle (Vors.), Robert Schickling, Dr. Michael Hann
>
> Internet: http://www.dfs.de
> Public-Key der DFS: http://www.dfs.de/dfs/public_key.asc

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Question about the buffer length in the transfer callback of the PCM External Plugin
       [not found]               ` <e48b1619d89d4f7faf5640fd2d337555@LGNMSXB01.prod.bk.dfs>
@ 2016-11-06 11:26                 ` Clemens Ladisch
  0 siblings, 0 replies; 8+ messages in thread
From: Clemens Ladisch @ 2016-11-06 11:26 UTC (permalink / raw)
  To: Bach, Andrea; +Cc: alsa-devel

Bach, Andrea wrote:
> What I tried is to copy the buffer I get in chunks of a 64 bytes into
> an intermediate buffer for processing and whenever I processed
> 64 bytes I copied the result to the output buffer .... but what to do
> with the remaining 40 bytes...

Leave them in the intermediate buffer, and handle them later when you've
got 24 more bytes.

> and what to return in the output buffer when the remaining bytes could
> not be processed??

Delay the entire chain by 64 bytes, i.e., insert 64 byte at the start of
the stream.  Then you always have too many bytes instead of too few
bytes, and those can be handled with the intermediate buffer.


Regards,
Clemens

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-11-06 11:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-31  9:01 Question about the buffer length in the transfer callback of the PCM External Plugin Bach, Andrea
2016-10-31 10:10 ` Clemens Ladisch
     [not found]   ` <6c2af613d3b64138bc6e7c6cf69486cf@LGNMSXB01.prod.bk.dfs>
2016-11-01 11:49     ` Clemens Ladisch
     [not found]       ` <165e6496dc554e18836006a6b77461ce@LGNMSXB01.prod.bk.dfs>
2016-11-03 10:26         ` Clemens Ladisch
     [not found]           ` <1ce46f88056b4b2caa2ecf770da07d76@LGNMSXB01.prod.bk.dfs>
2016-11-03 14:44             ` Clemens Ladisch
     [not found]               ` <e48b1619d89d4f7faf5640fd2d337555@LGNMSXB01.prod.bk.dfs>
2016-11-06 11:26                 ` Clemens Ladisch
2016-10-31 18:11 ` Fernando Rodriguez
2016-10-31 18:47   ` Fernando Rodriguez

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.