CLAM-Development  1.4.0
AudioOut.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
3  * UNIVERSITAT POMPEU FABRA
4  *
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  */
21 
22 #include "AudioOut.hxx"
23 #include "AudioManager.hxx"
24 #include "ProcessingFactory.hxx"
25 
26 
27 
28 namespace CLAM
29 {
30 
31 namespace Hidden
32 {
33  static const char * metadata[] = {
34  "key", "AudioOut",
35 // "category", "Audio I/O",
36 // "description", "AudioOut",
37  0
38  };
39  static FactoryRegistrator<ProcessingFactory, AudioOut> reg = metadata;
40 }
41 
43  : mInput( "Audio Input", this )
44 {
45  mpDevice = 0;
47 }
48 
50  : mInput( "Audio Input", this )
51 {
52  mpDevice = 0;
53  Configure(c);
54 }
55 
57 {
58  try {
59  if (mpDevice)
60  mpDevice->Unregister(*this);
61  }
62  catch (Err &e) {
63  std::cerr << "AudioOut::~AudioOut: unregistering processing: " << e.what() << std::endl;
64  }
65 }
66 
68  throw(ErrProcessingObj)
69 {
70  CopyAsConcreteConfig(mConfig, c);
71 
72  if (mpDevice)
73  mpDevice->Unregister(*this);
74 
75  AudioManager *m;
76 
77  try {
78  m = &(AudioManager::Current());
79  }
80  catch (Err &e) {
81  ErrProcessingObj ne("AudioOut::ConcreteConfigure(): No AudioManager found.",this);
82  ne.Embed(e);
83  throw(ne);
84  }
85 
86  bool res;
87  try {
88  res = m->Register(*this);
89  }
90  catch (Err &e) {
91  AddConfigErrorMessage( e.what() );
92  res = false;
93  }
94 
95  if (res == false)
96  AddConfigErrorMessage( "AudioOut::ConcreteConfigure(): "
97  "Failed to register in AudioManager.") ;
98 
99  mInput.SetSize(mConfig.GetFrameSize());
100  return res;
101 }
102 
104 {
105  if (!mpDevice)
106  throw Err("AudioOut::ConcreteStart(): No Device found!");
107  try
108  {
109  mpDevice->Start();
110  }
111  catch (Err &e) {
112  std::cerr << " AudioOut::ConcreteStart(): could not start audio device: maybe another program is blocking it" << std::endl;
113  std::cerr << " Received error message: <"<<e.what() << std::endl;
114  }
115  return true;
116 }
117 
119 {
120  mpDevice->Stop();
121  return true;
122 }
123 
125 {
126  if (mpDevice)
127  mpDevice->GetInfo(info);
128  else
129  info.Reset();
130 }
131 
133 {
134  bool res = Do(mInput.GetAudio());
135  mInput.Consume();;
136  return res;
137 }
138 
139 }
140