[MPlayer-dev-eng] Export audio filter: a few patches
ed at catmur.co.uk
ed at catmur.co.uk
Fri Nov 14 07:05:00 CET 2003
I've been hacking on the export filter (trying to use it to import audio
into XMMS), and have generated a few alterations.
First off, the treatment of the sample count argument
(export=/path/to/file:<SAMPLES>) is broken; the sscanf is out by one:
- sscanf(str + i, "%d", &(s->sz));
+ sscanf(str + i + 1, "%d", &(s->sz));
Also, in two places the default sample count is used where the user
provided count is available:
- s->buf[i] = s->buf[0] + i*DEF_SZ*af->data->bps;
+ s->buf[i] = s->buf[0] + i*s->sz*af->data->bps;
When using the export as audio, it's more important that no data is lost
(than using it in e.g. a visualisation). My solution is to export the
data whenever the buffer is filled, but then continue to copy that audio
chunk into the beginning of the buffer. This means changing the nesting
of the loops that deinterleave the data.
+ int len = c->len/c->bps/c->nch; // Number of samples in data
chunk
...
+ for(i = 0; i < len; i++){
+ for(ch = 0; ch < nch; ch++){
+ int16_t *b = s->buf[ch]; // Current channel's buffer
+ b[wi] = a[i * nch + ch]; // Write sample into buffer
+ }
+ wi++;
+ if(wi >= sz){ // If this buffer is full
...
+ // Export this buffer to mapped area (allocated as one block)
+ memcpy(s->mmap_area + SIZE_HEADER, s->buf[0], sz * c->bps * nch);
+ s->count++; // increment counter (to sync)
+ memcpy(s->mmap_area + SIZE_HEADER - sizeof(s->count),
+ &(s->count), sizeof(s->count));
+ wi = 0; // Start a new buffer
}
Also, to make sure that a client process has a chance to read in the
data, I have put in a sleep of half the time the buffer holds, triggered
if the play function exports more than once from the same input audio
chunk. (I'm using nanosleep because the usleep man page said it was
deprecated...) By checking the mmapped area every quarter loop, I can
then guarantee to pick up when the buffer is updated, and no sound is
lost.
+ struct timespec wait = { 0, 1000000000l/c->rate*len/2 }; // half a
sample
...
+ if(!exported)
+ exported = 1;
+ else // we have already exported
data: give
+ nanosleep(&wait, NULL); // client processes a chance to
see it!
Also, I have corrected a few spelling mistakes.
I hope this all makes sense; thanks for reading this!
Ed
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mplayer-1.0_pre2-export-filter.patch
Type: text/x-patch
Size: 4361 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20031114/c6a0cbd7/attachment.bin>
More information about the MPlayer-dev-eng
mailing list