source: trunk/src/testing/include/sageAudio.h @ 4

Revision 4, 5.2 KB checked in by ajaworski, 13 years ago (diff)

Added modified SAGE sources

Line 
1/******************************************************************************
2 * SAGE - Scalable Adaptive Graphics Environment
3 *
4 * Module: sageAudio.h
5 * Author : Hyejung Hur
6 *
7 * Copyright (C) 2004 Electronic Visualization Laboratory,
8 * University of Illinois at Chicago
9 *
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions are met:
14 *
15 *  * Redistributions of source code must retain the above copyright
16 *    notice, this list of conditions and the following disclaimer.
17 *  * Redistributions in binary form must reproduce the above
18 *    copyright notice, this list of conditions and the following disclaimer
19 *    in the documentation and/or other materials provided with the distribution.
20 *  * Neither the name of the University of Illinois at Chicago nor
21 *    the names of its contributors may be used to endorse or promote
22 *    products derived from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 *
36 * Direct questions, comments etc about SAGE to sage_users@listserv.uic.edu or
37 * http://www.evl.uic.edu/cavern/forum/
38 *
39 ***************************************************************************************************************************/
40
41#ifndef _SAGE_AUDIO_H
42#define _SAGE_AUDIO_H
43
44// portaudio header file
45#include <portaudio.h>
46
47#ifdef linux1
48#include <libiec61883/iec61883.h>
49#include <sys/select.h>
50#endif
51
52#include "sageAudioModule.h"
53#include "sageAudioCircBuf.h"
54#include "sageBase.h"
55
56class sageAudio {
57public:
58   /** audio mode
59   */
60   enum {AUDIO_PLAY, AUDIO_PAUSE, AUDIO_STOP};
61public:
62   sageAudio();
63   ~sageAudio();
64
65   /** set parameters for setting audio up and assign pointer of circular buffer 
66   */
67   int init( int id, sageAudioConfig &conf, sageAudioMode mode, sageAudioCircBuf *buf );
68   int reset( int id, sageAudioCircBuf *buf );
69
70   /** open audio stream in play mode or capture mode
71   */
72   virtual int   openStream();
73   
74   /** close audio stream
75   */
76   virtual int   closeStream();
77   
78   int play();
79   int pause();
80   int stop();
81
82   /** test audio input/output device
83   */
84   void testDevices();
85   
86   int getID();
87     
88   /** callback function for play audio stream
89   */
90   static int playCallback( const void *inputBuffer, void *outputBuffer,
91                        unsigned long framesPerBuffer,
92                        const PaStreamCallbackTimeInfo* timeInfo,
93                        PaStreamCallbackFlags statusFlags,
94                        void *userData );
95
96   /** callback function for capture audio stream
97   */
98   static int recordCallback( const void *inputBuffer, void *outputBuffer,
99                        unsigned long framesPerBuffer,
100                        const PaStreamCallbackTimeInfo* timeInfo,
101                        PaStreamCallbackFlags statusFlags,
102                        void *userData );   
103#ifdef linux1
104
105   static void* audioThread(void *args);
106   
107   /** callback function for capture firewire audio stream
108   */
109   static int recordFWCallback(iec61883_amdtp_t amdtp, char *data,
110                  int nsamples, unsigned int dbc,
111                  unsigned int dropped, void *callback_data);
112#endif           
113   
114protected:
115   int ID;
116   
117   /** circular buffer for saving audio stream block
118   */
119   sageAudioCircBuf* buffer;
120   
121   /** audio sample format : float, short, char, unsigned char
122   */
123   sageSampleFmt sampleFmt;
124   
125   /** numbers of audio channel
126   */
127   int  channels;
128   
129   /** object for audio streaming : portaudio object
130   */
131   PaStream*   audioStream;
132
133   /** parameters for audio streaming
134   */
135   PaStreamParameters*   audioParameters;
136
137   /** audio mode : play, capture
138   */
139   sageAudioMode audioMode;
140   
141   /** sound card device number : 0 is default device number
142   */
143   int deviceNum;
144   
145   /** according to audio sample format, byte per sample is different
146   */
147   int bytesPerSample;
148   
149   /** audio sampling rate : default is 44100
150   * standard sampling rate : 8000.0, 9600.0, 11025.0, 12000.0, 16000.0, 22050.0, 24000.0, 32000.0, 44100.0, 48000.0, 88200.0, 96000.0, 192000.0
151   */
152   long samplingRate;
153   
154   /** frames per buffer : default is 1024
155   */
156   int  framePerBuffer;
157
158   /** play flag : play, pause, stop
159   */
160   int   playFlag;   
161   
162#ifdef linux1
163   raw1394handle_t handle;
164   iec61883_amdtp_t amdtp;
165#endif
166   
167   /** latency
168   */
169   long minLatency;
170   long maxLatency;
171
172};
173
174#endif
Note: See TracBrowser for help on using the repository browser.