root/ossiedev/branches/0.7.x/platform/AudioDevice/src/AudioDevice.h @ 8807

Revision 8807, 5.2 KB (checked in by jgaeddert, 4 years ago)

fleshing out callbacks

Line 
1/****************************************************************************
2
3Copyright 2009 Virginia Polytechnic Institute and State University
4
5This file is part of the OSSIE AudioDevice.
6
7OSSIE AudioDevice is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12OSSIE AudioDevice is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OSSIE AudioDevice; if not, write to the Free Software
19Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21
22****************************************************************************/
23
24#ifndef __OSSIE_AUDIO_DEVICE_H__
25#define __OSSIE_AUDIO_DEVICE_H__
26
27#include <stdlib.h>
28#include "ossie/cf.h"
29#include "ossie/PortTypes.h"
30#include "ossie/Device_impl.h"
31#include "ossie/Resource_impl.h"
32#include "ossie/debug.h"
33
34#include "standardinterfaces/complexShort.h"
35#include "standardinterfaces/complexShort_u.h"
36
37#include "portaudio.h"
38
39static int portaudio_callback_playback(
40    const void *inputBuffer,
41    void *outputBuffer,
42    unsigned long framesPerBuffer,
43    const PaStreamCallbackTimeInfo* timeInfo,
44    PaStreamCallbackFlags statusFlags,
45    void *userData );
46
47static int portaudio_callback_record(
48    const void *inputBuffer,
49    void *outputBuffer,
50    unsigned long framesPerBuffer,
51    const PaStreamCallbackTimeInfo* timeInfo,
52    PaStreamCallbackFlags statusFlags,
53    void *userData );
54
55/// Main sound card device (capture) definition
56class AudioDevice_i : public virtual Device_impl
57{
58public:
59    /// Initializing constructor
60    AudioDevice_i(char *uuid, char* label, char* profile, omni_condition *condition);
61
62    /// Default destructor
63    ~AudioDevice_i();
64
65    /// Sets isRunning to True (start)
66    void start()
67        throw (CF::Resource::StartError, CORBA::SystemException);
68
69    /// static function for omni thread: capture_sound()
70    static void run_capture( void * data );
71
72    /// static function for omni thread: playback_sound()
73    static void run_playback( void * data );
74
75    /// Sets isRunning to False (pause)
76    void stop()
77        throw (CF::Resource::StopError, CORBA::SystemException);
78
79    /// Returns CORBA object pointer to port
80    CORBA::Object_ptr getPort(const char* portName)
81        throw(CF::PortSupplier::UnknownPort, CORBA::SystemException);
82
83    /// Checks if sound card device (capture) is already in use
84    void initialize()
85        throw (CF::LifeCycle::InitializeError, CORBA::SystemException);
86
87    /// Sets the following properties (currently NOT read from .prf.xml)
88    ///   - Access mode
89    ///   - Format
90    ///   - Number of channels
91    ///   - Sampling rate
92    ///   - Period size
93    ///   - Buffer size
94    ///   - Hardware parameters
95    void configure(const CF::Properties &props)
96        throw (CORBA::SystemException,
97               CF::PropertySet::InvalidConfiguration,
98               CF::PropertySet::PartialConfiguration);
99
100    ///
101    void releaseObject()
102        throw (CF::LifeCycle::ReleaseError, CORBA::SystemException);
103
104private:
105    /// Disallow default constructor
106    AudioDevice_i();
107
108    /// Disallow copy constructor
109    AudioDevice_i(AudioDevice_i&);
110
111    /// main processing loop for capturing sound
112    void capture_sound();
113
114    /// main processing loop for playing sound
115    void playback_sound();
116
117    omni_condition *component_running; ///< for component shutdown
118    omni_thread *capture_thread;    ///< for component writer function
119    omni_thread *playback_thread;    ///< for component writer function
120
121    CORBA::UShort *simple_ptr;
122    CORBA::UShort simple_value;
123    unsigned int simplesequencelength;
124    CORBA::ShortSeq *simplesequence_ptr;
125    //simplesequence_ptr = new short[simplesequencelength];
126
127    /// Port: output sound samples
128    standardInterfaces_i::complexShort_u *dataOut;
129
130    // properties configured flags
131    bool configured;
132    bool configured_prop_samplerate_record;
133    bool configured_prop_samplerate_playback;
134    bool configured_prop_buffersize_record;
135    bool configured_prop_buffersize_playback;
136
137    void ConfigureStreams();
138    void OpenStreams()  throw (CF::Resource::StartError);
139    void StartStreams() throw (CF::Resource::StartError);
140    void StopStreams()  throw (CF::Resource::StopError);
141    void CloseStreams() throw (CF::Resource::StopError);
142
143    // Until I look at omni_condition... -TT
144    bool isRunning;  ///< starts/stops loop in capture_sound()
145
146    // portaudio: specific properties
147    PaStreamParameters pa_params_record;
148    PaStreamParameters pa_params_playback;
149    PaStream *pa_stream_record;
150    PaStream *pa_stream_playback;
151
152    //
153    unsigned int samplerate_record;
154    unsigned int samplerate_playback;
155    unsigned int buffersize_record;
156    unsigned int buffersize_playback;
157
158    PortTypes::ShortSequence playback_data_L;
159    PortTypes::ShortSequence playback_data_R;
160
161    PortTypes::ShortSequence record_data_L;
162    PortTypes::ShortSequence record_data_R;
163
164};
165
166#endif // __OSSIE_AUDIO_DEVICE_H__
167
Note: See TracBrowser for help on using the browser.