cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mtsOpenALPlay.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3 
4 /*
5 
6  Author(s): Marcin Balicki
7  Created on: 2011
8 
9  (C) Copyright 2011 Johns Hopkins University (JHU), All Rights
10  Reserved.
11 
12 --- begin cisst license - do not edit ---
13 
14 This software is provided "as is" under an open source license, with
15 no warranty. The complete license can be found in license.txt and
16 http://www.cisst.org/cisst/license.txt.
17 
18 --- end cisst license ---
19 
20 */
21 
22 #ifndef _mtsOpenALPlay_h
23 #define _mtsOpenALPlay_h
24 
25 #include <al.h>
26 #include <alc.h>
27 
29 
30 // forward declaration of header classes
31 struct osaOpenALCAIHeader;
32 struct osaOpenALWAVHeader;
33 
34 // Always include last!
36 
38  // used to control the log level
40 
41 protected:
42  enum FileType {CAI, WAV};
43 
45  FILE * SoundFile;
47 
48  char * Data;
49  unsigned int NumDataBytes;
50 
52 
53  ALuint SoundBuffer[1];
54  ALuint SoundSource[1];
55 
58 
62 
66 
67  double CalcStreamVolume(int samplePos);
68  double CalcStreamTime(int samplePos);
69 
70  std::string GetALErrorString(ALenum err);
71  bool CheckALError(std::string & error);
72 
74 
75  bool InitOpenAL(void);
76  bool CloseOpenAL(void);
77 
78  ALCdevice * Device;
79  ALCcontext * Context;
80 
82 
83 public:
84  enum SoundFormat {MONO8, MONO16, STEREO8, STEREO16};
85 
86  mtsOpenALPlay(const std::string & taskName, double period);
87  ~mtsOpenALPlay();
88  // all four methods are pure virtual in mtsTask
89  inline void Configure(const std::string & CMN_UNUSED(filename)) {};
90  void Startup(void); // set some initial values
91  void Play(void);
92  void Loop(void);
93  void Pause(void);
94  void Stop(void);
95  void OpenFile(const mtsStdString & fName);
96  void Run(void); // performed periodically
97 
98  //A the moment time is local, i.e. 0 is the start of the audio file.
99  void Seek(const mtsDouble & time);
100  void Cleanup(void) {}; // user defined cleanup
101  // 0.0 - 1.0
102  void SetVolume(const mtsDouble & volume);
103  int CalcStreamPos(double time);
104 };
105 
107 
108 #endif
mtsDouble StartTimeAbsolute
Definition: mtsOpenALPlay.h:60
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
FileType
Definition: mtsOpenALPlay.h:42
ALCdevice * Device
Definition: mtsOpenALPlay.h:78
mtsDouble LengthInSec
Definition: mtsOpenALPlay.h:61
Definition: mtsOpenALPlay.h:37
#define CMN_UNUSED(argument)
Definition: cmnPortability.h:479
CMN_DECLARE_SERVICES_INSTANTIATION(mtsOpenALPlay)
mtsDouble StreamVolume
Definition: mtsOpenALPlay.h:65
mtsDouble Volume
Definition: mtsOpenALPlay.h:64
mtsStdString FileName
Definition: mtsOpenALPlay.h:44
Definition: mtsFunctionVoid.h:36
Definition: osaOpenALAudioTypes.h:59
Definition: mtsOpenALPlay.h:84
void Cleanup(void)
Definition: mtsOpenALPlay.h:100
virtual void Startup(void)
Definition: mtsComponent.h:262
mtsDouble Time
Definition: mtsOpenALPlay.h:59
mtsBool IsPlaying
Definition: mtsOpenALPlay.h:63
osaOpenALCAIHeader * SoundSettings
Definition: mtsOpenALPlay.h:51
SoundFormat
Definition: mtsOpenALPlay.h:84
void Configure(const std::string &CMN_UNUSED(filename))
Definition: mtsOpenALPlay.h:89
#define CMN_LOG_ALLOW_ERRORS_AND_WARNINGS
Definition: cmnLogLoD.h:72
#define CMN_DECLARE_SERVICES(hasDynamicCreation, lod)
Definition: cmnClassRegisterMacros.h:116
mtsFunctionVoid RangeChangedEvent
Definition: mtsOpenALPlay.h:81
Defines a periodic task.
FileType FType
Definition: mtsOpenALPlay.h:46
char * Data
Definition: mtsOpenALPlay.h:48
Definition: osaOpenALAudioTypes.h:99
FILE * SoundFile
Definition: mtsOpenALPlay.h:45
Class for relative time.
Definition: osaTimeServer.h:73
osaOpenALWAVHeader * WAVHeader
Definition: mtsOpenALPlay.h:57
const osaTimeServer * TimeServer
Definition: mtsOpenALPlay.h:73
virtual void Run(void)=0
Definition: mtsTaskPeriodic.h:80
const int CMN_NO_DYNAMIC_CREATION
Definition: cmnClassRegisterMacros.h:328
unsigned int NumDataBytes
Definition: mtsOpenALPlay.h:49
osaOpenALCAIHeader * CAIHeader
Definition: mtsOpenALPlay.h:56
ALCcontext * Context
Definition: mtsOpenALPlay.h:79