Skip to content

Commit 63bc9fe

Browse files
authored
Merge pull request #176 from dmitry42nd/master
do not restart audio output on next play request
2 parents f984074 + 48be8b4 commit 63bc9fe

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

trikControl/src/audioSynthDevices.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ AudioSynthDevice::AudioSynthDevice(QObject *parent, int sampleRate, int sampleSi
2121
: QIODevice(parent)
2222
, mBuffer(0)
2323
, mPos(0)
24+
, mHzFreq(0)
2425
, mSampleRate(sampleRate)
2526
, mSampleSize(sampleSize)
2627
{
28+
open(QIODevice::ReadOnly);
2729
}
2830

2931
AudioSynthDevice::~AudioSynthDevice()
@@ -32,26 +34,29 @@ AudioSynthDevice::~AudioSynthDevice()
3234

3335
void AudioSynthDevice::start(int hzFreq)
3436
{
35-
open(QIODevice::ReadOnly);
37+
reset();
38+
mPos = 0;
39+
newCall = true;
40+
mHzFreq = hzFreq;
3641
if (mBuffered) {
3742
const qint64 length = (mSampleRate * (mSampleSize / 8));
3843
mBuffer.resize(length);
3944
generate(mBuffer.data(), length, hzFreq);
40-
} else {
41-
mHzFreq = hzFreq;
4245
}
46+
emit readyRead();
4347
}
4448

4549
void AudioSynthDevice::stop()
4650
{
47-
newCall = true;
48-
mPos = 0;
49-
close();
51+
reset();
52+
mHzFreq = 0;
5053
}
5154

5255
// Modefied coupled first-order form algorithm with fixed point arithmetic
5356
int AudioSynthDevice::generate(char *data, int length, int hzFreq)
5457
{
58+
if(hzFreq == 0) return 0;
59+
5560
const int channelBytes = mSampleSize / 8;
5661

5762
qint64 maxlen = length / channelBytes;

trikControl/src/tonePlayer.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,26 @@ void TonePlayer::initializeAudio()
4545

4646
void TonePlayer::play(int hzFreq, int msDuration)
4747
{
48-
mOutput->reset();
48+
mDevice->start(hzFreq);
4949
switch (mOutput->state()) {
50-
case QAudio::IdleState: break;
51-
default:break;
50+
case QAudio::ActiveState:
51+
mOutput->suspend();
52+
mDevice->reset();
53+
mOutput->resume();
54+
break;
55+
case QAudio::SuspendedState: mOutput->resume(); break;
56+
case QAudio::StoppedState: mOutput->start(mDevice); break;
57+
case QAudio::IdleState: mOutput->start(mDevice); break;
58+
default: break;
5259
}
5360

5461
mTimer.setInterval(msDuration);
55-
mDevice->start(hzFreq);
5662
mTimer.start();
57-
mOutput->start(mDevice);
5863
}
5964

6065
void TonePlayer::stop()
6166
{
6267
mDevice->stop();
6368
mTimer.stop();
64-
mOutput->stop();
65-
6669
}
6770
}
68-
69-

0 commit comments

Comments
 (0)