• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • arts
 

arts

  • arts
  • kde
kaudioplaystream.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2003 Arnold Krille <arnold@arnoldarts.de>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License version 2 as published by the Free Software Foundation.
7
8 This library is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 Library General Public License for more details.
12
13 You should have received a copy of the GNU Library General Public License
14 along with this library; see the file COPYING.LIB. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
17
18*/
19
20#include "kaudioplaystream.h"
21#include "kaudioplaystream_p.h"
22
23#include <kartsserver.h>
24#include <kaudiomanagerplay.h>
25
26#include <artsflow.h>
27#include <soundserver.h>
28
29#include <tdeglobal.h>
30#include <kdebug.h>
31
32#include <tqstring.h>
33//#include <tqptrqueue.h>
34//#include <tqcstring.h> //QByteArray
35
36#include <string.h> // for strncpy
37
38//#include <assert.h>
39
40KAudioPlayStreamPrivate::KAudioPlayStreamPrivate( KArtsServer* server, const TQString title, TQObject* p, const char* n )
41 : TQObject( p,n )
42 , _server( server )
43 , _play( new KAudioManagerPlay( _server, title ) )
44 , _effectrack( Arts::StereoEffectStack::null() )
45 , _polling( true ), _attached( false ), _effects( true )
46{
47kdDebug( 400 ) << k_funcinfo << endl;
48 initaRts();
49}
50
51KAudioPlayStreamPrivate::~KAudioPlayStreamPrivate()
52{
53 kdDebug( 400 ) << k_funcinfo << endl;
54 _play->stop();
55 if ( _effects ) _effectrack.stop();
56 _bs2a.stop();
57}
58
59void KAudioPlayStreamPrivate::initaRts() {
60 kdDebug( 400 ) << k_funcinfo << endl;
61
62 _effectrack = Arts::DynamicCast( _server->server().createObject( "Arts::StereoEffectStack" ) );
63 if ( _effectrack.isNull() )
64 {
65 kdWarning( 400 ) << "Couldn't create EffectStack!" << endl;
66 _effects = false;
67 }
68
69 _bs2a = Arts::DynamicCast( _server->server().createObject( "Arts::ByteStreamToAudio" ) );
70 if ( _bs2a.isNull() )
71 kdFatal( 400 ) << "Couldn't create ByteStreamToAudio" << endl;
72
73 if ( _effects )
74 {
75 Arts::connect( _effectrack, _play->amanPlay() );
76 Arts::connect( _bs2a, _effectrack );
77 } else {
78 Arts::connect( _bs2a, _play->amanPlay() );
79 }
80
81 _play->start();
82 if ( _effects ) _effectrack.start();
83}
84
85KAudioPlayStream::KAudioPlayStream( KArtsServer* server, const TQString title, TQObject* p, const char* n )
86 : TQObject( p,n )
87 , d( new KAudioPlayStreamPrivate( server, title, this ) )
88{
89 kdDebug( 400 ) << k_funcinfo << endl;
90}
91KAudioPlayStream::~KAudioPlayStream()
92{
93 kdDebug( 400 ) << k_funcinfo << endl;
94}
95
96void KAudioPlayStream::setPolling( bool n ) { d->_polling = n; }
97bool KAudioPlayStream::polling() const { return d->_polling; }
98
99bool KAudioPlayStream::running() const { return d->_attached; }
100
101Arts::StereoEffectStack KAudioPlayStream::effectStack() const {
102 return d->_effectrack;
103}
104
105void KAudioPlayStream::start( int samplingRate, int bits, int channels )
106{
107 kdDebug( 400 ) << k_funcinfo << "samplingRate: " << samplingRate << " bits: " << bits << " channels: " << channels << endl;
108 if ( !d->_attached )
109 {
110 d->_bs2a.samplingRate( samplingRate );
111 d->_bs2a.channels( channels );
112 d->_bs2a.bits( bits );
113
114 d->_sender = new KByteSoundProducer( this, d->_server->server().minStreamBufferTime(), samplingRate, bits, channels, "PS" );
115 d->_artssender = Arts::ByteSoundProducerV2::_from_base( d->_sender );
116 Arts::connect( d->_artssender, "outdata", d->_bs2a, "indata" );
117
118 d->_bs2a.start();
119 d->_artssender.start();
120
121// // Needed?
122 Arts::Dispatcher::the()->ioManager()->processOneEvent( false );
123
124 d->_attached = true;
125 emit running( d->_attached );
126 }
127}
128void KAudioPlayStream::stop()
129{
130 kdDebug( 400 ) << k_funcinfo << endl;
131 if ( d->_attached )
132 {
133 d->_attached = false;
134
135 d->_bs2a.stop();
136 d->_artssender.stop();
137
138 // Shortly stop the play so we dont get clicks and artefacts
139 d->_play->stop();
140 d->_play->start();
141
142 Arts::disconnect( d->_artssender, d->_bs2a );
143 d->_artssender = Arts::ByteSoundProducerV2::null();
144 d->_sender = 0;
145
146 emit running( d->_attached );
147 }
148}
149
150void KAudioPlayStream::write( TQByteArray& )
151{
152}
153
154void KAudioPlayStream::fillData( Arts::DataPacket<Arts::mcopbyte> *packet )
155{
156 //kdDebug( 400 ) << k_funcinfo << "packet->size=" << packet->size << endl;
157 if ( d->_polling )
158 {
159 TQByteArray bytearray( packet->size );
160 bytearray.setRawData( ( char* )packet->contents, packet->size );
161 bytearray.fill( 0 );
162 emit requestData( bytearray );
163 bytearray.resetRawData( ( char* )packet->contents, packet->size );
164
165 //for ( int i=0; i<10; i++ )
166 // kdDebug() << packet->contents[ i ] << " : " << bytearray.data()[ i ] << endl;
167 } else {
169 }
170}
171
172// * * * KByteSoundProducer * * *
173
174KByteSoundProducer::KByteSoundProducer( KAudioPlayStream* impl, float minBufferTime, int rate, int bits, int channels, const char * title )
175 : _samplingRate( rate )
176 , _channels( channels )
177 , _bits( bits )
178 , _packets( 7 )
179 , _title( title )
180 , _impl( impl )
181{
182 // Calculate packet count (packetsize is fixed to packetCapacity = 4096
183 float streamBufferTime;
184 do {
185 _packets++;
186 streamBufferTime = ( float )( _packets * packetCapacity * 1000 )
187 / ( float )( _samplingRate * _channels * 2 );
188 } while ( streamBufferTime < minBufferTime );
189 //kdDebug( 400 ) << k_funcinfo << "_packets:" << _packets << " packetCapacity:" << packetCapacity << endl;
190}
191
192KByteSoundProducer::~KByteSoundProducer()
193{
194}
195
196void KByteSoundProducer::streamStart() { outdata.setPull( _packets, packetCapacity ); }
197void KByteSoundProducer::streamEnd() { outdata.endPull(); }
198
199void KByteSoundProducer::request_outdata( Arts::DataPacket<Arts::mcopbyte> *packet )
200{
201 if ( _impl->running() ) {
202 _impl->fillData( packet );
203 packet->send();
204 }
205}
206#include "kaudioplaystream.moc"
207#include "kaudioplaystream_p.moc"
KArtsServer
KArtsServer is a wrapper to conveniently get a reference to a SoundServer, and restart artsd when nec...
Definition: kartsserver.h:38
KAudioManagerPlay
KDE Wrapper for Arts::Synth_AMAN_PLAY.
Definition: kaudiomanagerplay.h:39
KAudioPlayStream
A wrapper around ByteSoundProducer/ByteStreamToAudio/Synth_AMAN_PLAY.
Definition: kaudioplaystream.h:42
KAudioPlayStream::polling
bool polling() const
Returns the polling state.
Definition: kaudioplaystream.cpp:97
KAudioPlayStream::setPolling
void setPolling(bool)
Controls wether this Stream should poll the data from you via the signal requestData() or you use wri...
Definition: kaudioplaystream.cpp:96
KAudioPlayStream::effectStack
Arts::StereoEffectStack effectStack() const
Definition: kaudioplaystream.cpp:101
KAudioPlayStream::KAudioPlayStream
KAudioPlayStream(KArtsServer *server, const TQString title, TQObject *parent=0, const char *name=0)
Creates a KAudioPlayStream on server with a title.
Definition: kaudioplaystream.cpp:85
KAudioPlayStream::write
void write(TQByteArray &data)
Write data into the inputbuffer.
Definition: kaudioplaystream.cpp:150
KAudioPlayStream::~KAudioPlayStream
~KAudioPlayStream()
Destructs the KAudioPlayStream.
Definition: kaudioplaystream.cpp:91
KAudioPlayStream::running
bool running() const
Definition: kaudioplaystream.cpp:99
KAudioPlayStream::fillData
void fillData(Arts::DataPacket< Arts::mcopbyte > *packet)
Definition: kaudioplaystream.cpp:154
KAudioPlayStream::requestData
void requestData(TQByteArray &)
This signal is emitted when audio should be played.
KAudioPlayStream::stop
void stop()
Stops the stream.
Definition: kaudioplaystream.cpp:128
KAudioPlayStream::start
void start(int samplingRate, int bits, int channels)
Start the stream.
Definition: kaudioplaystream.cpp:105
kdFatal
kdbgstream kdFatal(int area=0)
kdWarning
kdbgstream kdWarning(int area=0)
endl
kndbgstream & endl(kndbgstream &s)
kdDebug
kdbgstream kdDebug(int area=0)

arts

Skip menu "arts"
  • Main Page
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

arts

Skip menu "arts"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for arts by doxygen 1.9.4
This website is maintained by Timothy Pearson.