1
/* This file is part of the KDE project.
3
Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
5
This library is free software: you can redistribute it and/or modify
6
it under the terms of the GNU Lesser General Public License as published by
7
the Free Software Foundation, either version 2.1 or 3 of the License.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU Lesser General Public License for more details.
14
You should have received a copy of the GNU Lesser General Public License
15
along with this library. If not, see <http://www.gnu.org/licenses/>.
18
#include "mediaobjectaudionode.h"
19
#include "quicktimeaudioplayer.h"
20
#include "quicktimevideoplayer.h"
21
#include "audiomixer.h"
30
MediaObjectAudioNode::MediaObjectAudioNode(QuickTimeAudioPlayer *player1, QuickTimeAudioPlayer *player2) : AudioNode(0, 1)
35
m_mixer = new AudioMixerAudioNode();
37
m_connection1 = new AudioConnection(m_player1, 0, m_mixer, 0);
38
m_connection2 = new AudioConnection(m_player2, 0, m_mixer, 1);
43
MediaObjectAudioNode::~MediaObjectAudioNode()
53
void MediaObjectAudioNode::createAndConnectAUNodes()
55
DEBUG_AUDIO_GRAPH("(MediaObjectAudioNode" << int(this) << "createAndConnectAUNodes called)" )
56
m_player1->createAndConnectAUNodes();
57
m_player2->createAndConnectAUNodes();
58
m_mixer->createAndConnectAUNodes();
60
m_connection1->connect(m_audioGraph);
61
m_connection2->connect(m_audioGraph);
64
void MediaObjectAudioNode::createAudioUnits()
66
DEBUG_AUDIO_GRAPH("(MediaObjectAudioNode" << int(this) << "createAudioUnits called)" )
67
m_player1->createAudioUnits();
68
m_player2->createAudioUnits();
69
m_mixer->createAudioUnits();
72
void MediaObjectAudioNode::setGraph(AudioGraph *audioGraph)
74
DEBUG_AUDIO_GRAPH("MediaObjectAudioNode" << int(this) << "is setting graph:" << int(audioGraph))
75
m_audioGraph = audioGraph;
76
m_player1->setGraph(audioGraph);
77
m_player2->setGraph(audioGraph);
78
m_mixer->setGraph(audioGraph);
81
AUNode MediaObjectAudioNode::getOutputAUNode()
83
return m_mixer->getOutputAUNode();
86
bool MediaObjectAudioNode::fillInStreamSpecification(AudioConnection *connection, ConnectionSide side)
89
DEBUG_AUDIO_STREAM("(MediaObjectAudioNode" << int(this) << "fillInStreamSpecification called, role = source)")
90
return m_mixer->fillInStreamSpecification(connection, side);
92
DEBUG_AUDIO_STREAM("(MediaObjectAudioNode" << int(this) << "fillInStreamSpecification called, role = sink)")
93
return (m_connection2->updateStreamSpecification() && m_connection1->updateStreamSpecification());
97
bool MediaObjectAudioNode::setStreamSpecification(AudioConnection *connection, ConnectionSide side)
100
DEBUG_AUDIO_STREAM("(MediaObjectAudioNode" << int(this) << "setStreamSpecification called, role = source)")
101
return m_mixer->setStreamSpecification(connection, side);
106
void MediaObjectAudioNode::setMute(bool mute)
109
m_mixer->setVolume(m_mute ? 0 : m_volume1, m_connection1->m_sinkInputBus);
110
m_mixer->setVolume(m_mute ? 0 : m_volume2, m_connection2->m_sinkInputBus);
113
void MediaObjectAudioNode::updateVolume()
118
QuickTimeVideoPlayer *player1 = static_cast<QuickTimeAudioPlayer *>(m_connection1->m_sourceAudioNode)->videoPlayer();
119
QuickTimeVideoPlayer *player2 = static_cast<QuickTimeAudioPlayer *>(m_connection2->m_sourceAudioNode)->videoPlayer();
121
player1->setRelativeVolume(m_volume1);
123
player2->setRelativeVolume(m_volume2);
125
m_mixer->setVolume(m_volume1, m_connection1->m_sinkInputBus);
126
m_mixer->setVolume(m_volume2, m_connection2->m_sinkInputBus);
129
void MediaObjectAudioNode::startCrossFade(qint64 duration)
131
m_fadeDuration = duration;
134
AudioConnection *tmp = m_connection1;
135
m_connection1 = m_connection2;
139
if (m_fadeDuration > 0){
149
float MediaObjectAudioNode::applyCurve(float volume)
153
newValue = float(0.5f * (2 + log10(volume)));
157
void MediaObjectAudioNode::updateCrossFade(qint64 currentTime)
159
// Assume that currentTime starts at 0 and progress.
160
if (m_fadeDuration > 0){
161
float volume = float(currentTime) / float(m_fadeDuration);
166
m_volume1 = applyCurve(volume);
167
m_volume2 = 1 - volume;
172
bool MediaObjectAudioNode::isCrossFading()
174
return (m_fadeDuration > 0);
177
void MediaObjectAudioNode::cancelCrossFade()
185
void MediaObjectAudioNode::mediaNodeEvent(const MediaNodeEvent *event)
187
switch (event->type()){
188
case MediaNodeEvent::AudioGraphAboutToBeDeleted:
189
m_connection1->invalidate();
190
m_connection2->invalidate();
192
case MediaNodeEvent::AudioGraphCannotPlay:
193
case MediaNodeEvent::AudioGraphInitialized:
200
m_player1->mediaNodeEvent(event);
201
m_player2->mediaNodeEvent(event);
202
m_mixer->mediaNodeEvent(event);
205
}} //namespace Phonon::QT7