[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-multimedia
Subject: [PATCH] resampler underrun check
From: Stefan Westerfeld <stefan () space ! twc ! de>
Date: 2000-09-11 9:36:10
[Download RAW message or body]
Hi!
When an external stream disconnects (i.e. artsdsp/artscat/C API), aRts should
still play all the packets that have been sent so far and not immediately
drop playing the sound. To do so, it queries ByteStreamToAudio::running() to
see if there is still work to do.
However, the ByteStreamToAudio::running() method is currently always returning
false, which isn't optimal for this kind of thing ;).
So here is a patch that fixes this, I'll apply it tomorrow if there are no
objections.
Cu... Stefan
--
-* Stefan Westerfeld, stefan@space.twc.de (PGP!), Hamburg/Germany
KDE Developer, project infos at http://space.twc.de/~stefan/kde *-
["20000911-resampler-underrun-addition.diff" (text/plain)]
Index: resample.cc
===================================================================
RCS file: /home/kde/kdelibs/arts/flow/resample.cc,v
retrieving revision 1.1
diff -b -u -p -r1.1 resample.cc
--- resample.cc 2000/09/06 12:39:15 1.1
+++ resample.cc 2000/09/11 09:32:09
@@ -37,14 +37,26 @@
using namespace Arts;
+class Arts::ResamplerPrivate {
+public:
+ bool underrun;
+};
+
Resampler::Resampler(Refiller *refiller) :
dropBytes(0), refiller(refiller), pos(0.0), step(1.0), channels(2),
bits(16),
block(0), haveBlock(-1)
{
+ d = new ResamplerPrivate();
+ d->underrun = false;
updateSampleSize();
}
+Resampler::~Resampler()
+{
+ delete d;
+}
+
void Resampler::updateSampleSize()
{
sampleSize = channels * bits / 8;
@@ -68,6 +80,11 @@ void Resampler::setBits(int newBits)
updateSampleSize();
}
+bool Resampler::underrun()
+{
+ return d->underrun;
+}
+
void Resampler::ensureRefill()
{
if(haveBlock == block) return;
@@ -77,6 +94,8 @@ void Resampler::ensureRefill()
{
missing = bufferSize+sampleSize
- refiller->read(buffer,bufferSize+sampleSize);
+
+ d->underrun = (missing == bufferSize+sampleSize);
}
else
{
@@ -93,8 +112,14 @@ void Resampler::ensureRefill()
{
missing = bufferSize
- refiller->read(&buffer[sampleSize], bufferSize);
+
+ d->underrun = (missing == bufferSize);
+ }
+ else
+ {
+ missing = bufferSize;
+ d->underrun = true;
}
- else missing = bufferSize;
}
haveBlock++;
assert(haveBlock == block);
Index: resample.h
===================================================================
RCS file: /home/kde/kdelibs/arts/flow/resample.h,v
retrieving revision 1.1
diff -b -u -p -r1.1 resample.h
--- resample.h 2000/09/06 12:39:15 1.1
+++ resample.h 2000/09/11 09:32:09
@@ -32,6 +32,8 @@ public:
virtual ~Refiller();
};
+class ResamplerPrivate;
+
class Resampler {
protected:
static const unsigned int bufferSize = 256; // 64 samples in buffer
@@ -55,10 +57,14 @@ protected:
void ensureRefill();
public:
Resampler(Refiller *refiller);
+ ~Resampler();
+
void setStep(double step);
void setChannels(int channels);
void setBits(int bits);
void run(float *left, float *right, unsigned long samples);
+
+ bool underrun();
};
};
Index: convert.cc
===================================================================
RCS file: /home/kde/kdelibs/arts/flow/convert.cc,v
retrieving revision 1.8
diff -b -u -p -r1.8 convert.cc
--- convert.cc 2000/08/24 16:13:48 1.8
+++ convert.cc 2000/09/11 09:32:11
@@ -267,3 +267,17 @@ unsigned long uni_convert_stereo_2float(
}
return doSamples;
}
+
+// undefine all that stuff (due to --enable-final)
+#undef compose_16le
+#undef conv_16le_float
+#undef convert_16le_float
+#undef conv_8_float
+#undef convert_8_float
+#undef datatype_16le
+#undef datasize_16le
+#undef datatype_8
+#undef datasize_8
+#undef datatype_float
+#undef datasize_float
+#undef mk_converter
Index: bytestreamtoaudio_impl.cc
===================================================================
RCS file: /home/kde/kdelibs/arts/flow/bytestreamtoaudio_impl.cc,v
retrieving revision 1.8
diff -b -u -p -r1.8 bytestreamtoaudio_impl.cc
--- bytestreamtoaudio_impl.cc 2000/09/06 12:39:15 1.8
+++ bytestreamtoaudio_impl.cc 2000/09/11 09:32:11
@@ -30,10 +30,11 @@ using namespace Arts;
class PacketRefiller : public Refiller {
-public:
+protected:
queue< DataPacket<mcopbyte>* > inqueue;
int pos;
+public:
PacketRefiller() : pos(0)
{
}
@@ -73,10 +74,9 @@ class ByteStreamToAudio_impl : public By
PacketRefiller refiller;
Resampler resampler;
long _samplingRate, _channels, _bits;
- bool _running;
public:
ByteStreamToAudio_impl() :resampler(&refiller),
- _samplingRate(44100), _channels(2), _bits(16), _running(false)
+ _samplingRate(44100), _channels(2), _bits(16)
{
//
}
@@ -99,7 +99,7 @@ public:
resampler.setBits(_bits);
}
- bool running() { return _running; }
+ bool running() { return !resampler.underrun(); }
void process_indata(DataPacket<mcopbyte> *packet)
{
_______________________________________________
Kde-multimedia mailing list
Kde-multimedia@master.kde.org
http://master.kde.org/mailman/listinfo/kde-multimedia
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic