1
/***************************************************************************
2
* Copyright (C) 2005 by Olivier Goffart *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, write to *
17
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
18
* Boston, MA 02110-1301, USA. *
19
***************************************************************************/
21
#include <config-workspace.h>
25
#include "soundrecorder_arts.h"
27
#include <arts/kaudiorecordstream.h>
28
#include <arts/kartsserver.h>
29
#include <arts/kartsdispatcher.h>
39
#define ABS(X) ( ((X)>0) ? (X) : -(X) )
43
KHotKeys::SoundRecorder* khotkeys_soundrecorder_create( QObject* parent, const char* name )
45
return new KHotKeys::SoundRecorderArts( parent, name );
52
SoundRecorderArts::SoundRecorderArts(QObject *parent, const char *name)
53
: SoundRecorder(parent, name) ,
54
m_dis(new KArtsDispatcher( this) ),
55
m_server( new KArtsServer( this ) ) ,
56
m_recStream( new KAudioRecordStream( m_server, i18n("khotkeys"), m_server ) )
58
create_ptr check = khotkeys_soundrecorder_create; // check the type matches
61
m_recStream->usePolling( false );
62
connect( m_recStream, SIGNAL(data (QByteArray &)), this, SLOT(slotDataReceived(QByteArray& )));
65
SoundRecorderArts::~SoundRecorderArts()
72
void SoundRecorderArts::start()
74
m_recStream->start(FS,BITS,2);
78
void SoundRecorderArts::stop()
81
QTimer::singleShot(400,this,SLOT(slotEmitSignal()));
84
void SoundRecorderArts::abort()
91
Sound SoundRecorderArts::sound()
95
uint length=m_data.size()/BytePS;
96
QMemArray<Q_INT32> da(length);
99
for(uint f=0;f<length; f++)
102
int nb=(unsigned char)(m_data[f]) -128;
104
int nb=(m_data[2*f] &0x000000FF ) | ( (m_data[2*f+1] &0x000000FF ) << 8 ) ;
108
#error BITS is not 16 or 8
110
if(s.max < (uint)ABS(nb))
112
s.max= (uint)ABS(nb);
120
void SoundRecorderArts::slotDataReceived(QByteArray & data)
122
uint pos=m_data.size();
123
m_data.resize(pos + data.size());
124
for(uint f=0;f<data.size(); f++)
126
m_data[pos+f]=data[f];
130
void SoundRecorderArts::slotEmitSignal()
132
emit recorded( sound() );
137
#include "soundrecorder_arts.moc"