[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-multimedia
Subject: Re: How to use Synth_AMAN_PLAY
From: Malte Starostik <malte () kde ! org>
Date: 2002-01-15 16:54:53
[Download RAW message or body]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Am Tuesday 15 January 2002 15:18 schrieb Stefan Westerfeld:
> Hi!
>
[snip]
> What you want to do instead is create the Synth_AMAN_PLAY object inside
> artsd (not in your process), like
>
> Synth_AMAN_PLAY play =
> DynamicCast(server.createObject("Arts::Synth_AMAN_PLAY"));
> if(!play.isNull()) {
> play.title("foo");
> }
Thanks alot, exactly what I was looking for :))
Attached is a new patch to implement ARTS_P_VOLUME for output streams in artsc
and a small test proggie. Is it okay to do it this way? If so, I'd like to
send a patch to the xine authors... :)
- --
Malte Starostik
PGP: 1024D/D2F3C787 [C138 2121 FAF3 410A 1C2A 27CD 5431 7745 D2F3 C787]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQE8RF7hVDF3RdLzx4cRAm+lAJwOm1samHV8QFNqqwgPO1tQkdfFEgCdFmeE
GoT0LdixLKRc/3hE/4Shtds=
=tt4z
-----END PGP SIGNATURE-----
["Makefile" (text/x-makefile)]
CFLAGS := $(shell artsc-config --cflags)
LDFLAGS := $(shell artsc-config --libs) -Wl,--rpath -Wl,$(shell artsc-config --arts-prefix)/lib -lm
voltest: voltest.o
gcc -o $@ $(LDFLAGS) $<
voltest.o: voltest.c
gcc -c -o $@ $(CFLAGS) $<
clean:
rm -f voltest voltest.o
["voltest.c" (text/x-csrc)]
#include <math.h>
#include <stdint.h>
#include <sys/signal.h>
#include <artsc.h>
int intr = 0;
void sig_handler(int sig)
{
intr = 1;
}
int main()
{
arts_stream_t str;
int16_t data[44100];
int i, vol = 100;
arts_init();
str = arts_play_stream(44100, 16, 1, "Volume Test");
for (i = 0; i < 44100; ++i)
data[i] = floor(sin(i * 2.0 * M_PI / 100.0) * 0x7fff);
signal(SIGINT, sig_handler);
for (i = 0; !intr; ++i)
{
arts_stream_set(str, ARTS_P_VOLUME, 50 + floor(cos((i % 20) * 2.0 * M_PI / 20.0) * 50.0));
arts_write(str, data, sizeof(data));
}
arts_close_stream(str);
arts_free();
}
["artsc.diff" (text/x-diff)]
Index: artsc.h
===================================================================
RCS file: /home/kde/kdelibs/arts/artsc/artsc.h,v
retrieving revision 1.9
diff -u -3 -d -p -r1.9 artsc.h
--- artsc.h 2000/12/07 22:21:15 1.9
+++ artsc.h 2002/01/15 16:26:17
@@ -64,7 +64,8 @@ enum arts_parameter_t_enum {
ARTS_P_BLOCKING = 6,
ARTS_P_PACKET_SIZE = 7,
ARTS_P_PACKET_COUNT = 8,
- ARTS_P_PACKET_SETTINGS = 9
+ ARTS_P_PACKET_SETTINGS = 9,
+ ARTS_P_VOLUME = 10
};
/**
@@ -125,6 +126,9 @@ enum arts_parameter_t_enum {
* The format is 0xCCCCSSSS, where 2^SSSS is the packet size, and CCCC is
* the packet count. Note that when writing this, you don't necessarily
* get the settings you requested.
+ *
+ * @li ARTS_P_VOLUME (rw)
+ * This sets / retrieves the stream's volume (0-100).
*/
typedef enum arts_parameter_t_enum arts_parameter_t;
Index: artscbackend.cc
===================================================================
RCS file: /home/kde/kdelibs/arts/artsc/artscbackend.cc,v
retrieving revision 1.18
diff -u -3 -d -p -r1.18 artscbackend.cc
--- artscbackend.cc 2001/11/30 15:24:20 1.18
+++ artscbackend.cc 2002/01/15 16:26:17
@@ -27,6 +27,7 @@
#include "artsc.h"
#include "soundserver.h"
#include "stdsynthmodule.h"
+#include "connect.h"
#include <stdio.h>
#include <unistd.h>
@@ -425,6 +426,10 @@ class Sender : public ByteSoundProducer_
* this object although not using smartwrappers to access it
*/
ByteSoundProducer bsWrapper;
+ ByteStreamToAudio convert;
+ StereoVolumeControl volume;
+ Synth_AMAN_PLAY out;
+ int _volume;
protected:
virtual void attach()
@@ -433,8 +438,20 @@ protected:
{
isAttached = true;
- server.attach(bsWrapper);
+ convert.samplingRate(_samplingRate);
+ convert.channels(_channels);
+ convert.bits(_bits);
+
+ connect(bsWrapper, "outdata", convert, "indata");
+ connect(convert, volume);
+ connect(volume, out);
+
+ out.title(_name);
+
start();
+ convert.start();
+ volume.start();
+ out.start();
/*
* TODO: this processOneEvent looks a bit strange here... it is
@@ -452,11 +469,41 @@ protected:
public:
Sender(SoundServer server, int rate, int bits, int channels,
- string name) : Stream( server, rate, bits, channels, name)
+ string name) : Stream( server, rate, bits, channels, name),
+ convert(DynamicCast(server.createObject("Arts::ByteStreamToAudio"))),
+ volume(DynamicCast(server.createObject("Arts::StereoVolumeControl"))),
+ out(DynamicCast(server.createObject("Arts::Synth_AMAN_PLAY")))
{
bsWrapper = ByteSoundProducer::_from_base(this);
}
+ virtual int stream_set(arts_parameter_t param, int value)
+ {
+ switch (param)
+ {
+ case ARTS_P_VOLUME:
+ if (value < 0 || value > 100) return ARTS_E_NOIMPL;
+
+ volume.scaleFactor(value / 100.0);
+ return value;
+
+ default:
+ return Stream::stream_set(param, value);
+ }
+ }
+
+ virtual int stream_get(arts_parameter_t param)
+ {
+ switch (param)
+ {
+ case ARTS_P_VOLUME:
+ return (int) (volume.scaleFactor() * 100.0);
+
+ default:
+ return Stream::stream_get(param);
+ }
+ }
+
virtual ~Sender() {
//
}
_______________________________________________
kde-multimedia mailing list
kde-multimedia@mail.kde.org
http://mail.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