rasdaman complete source
rviewSound.hh
Go to the documentation of this file.
1 /*
2 * This file is part of rasdaman community.
3 *
4 * Rasdaman community is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * Rasdaman community 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 General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
18 rasdaman GmbH.
19 *
20 * For more information please see <http://www.rasdaman.org>
21 * or contact Peter Baumann via <baumann@rasdaman.com>.
22 /
23 
49 #ifndef _RVIEW_SOUND_H_
50 #define _RVIEW_SOUND_H_
51 
52 
53 #include <stdio.h>
54 #include <signal.h>
55 
56 #ifdef __VISUALC__
57 #include <windows.h>
58 #endif
59 
60 
61 #ifdef __HAL_ONLY__
62 #ifndef __VISUALC__
63 #include "bool.h"
64 #endif
65 typedef bool bool;
66 #ifndef TRUE
67 #define TRUE true
68 #define FALSE false
69 #endif
70 #else
71 #include "rviewUtils.hh"
72 #include "rviewDisplay.hh"
73 #endif // HAL
74 
75 
76 
77 /* Default latency of sound playback */
78 #define RVIEW_SND_LATENCY 100
79 /* Timer interval relative to sample buffer runtime */
80 #define RVIEW_SND_RELPERIOD 0.5
81 
82 /* Number of sample buffers (NT only) */
83 #define RVIEW_SND_BUFFERS 3
84 
85 
87 {
93 };
94 
95 
96 
97 /*
98  * soundPlayer: hardware abstraction layer
99  */
100 
102 {
103 public:
104 
105  // Base constructor
106  soundPlayer(void);
107  // Constructor for input from file
108  soundPlayer(int frq, int ch, FILE *fp, rviewSoundFormat fmt, int lat=RVIEW_SND_LATENCY);
109  // Constructor for 8bit linear (default)
110  soundPlayer(int frq, int ch, const signed char *data, int len, rviewSoundFormat fmt=rsf_lin8, int lat=RVIEW_SND_LATENCY);
111  // Constructor for 8bit ulaw (default)
112  soundPlayer(int frq, int ch, const unsigned char *data, int len, rviewSoundFormat fmt=rsf_ulaw8, int lat=RVIEW_SND_LATENCY);
113  // Constructor for 16bit linear (default)
114  soundPlayer(int frq, int ch, const short *data, int len, rviewSoundFormat fmt=rsf_lin16, int lat=RVIEW_SND_LATENCY);
115 
116  ~soundPlayer(void);
117 
118  // For changing during playback
119  int newSample(int frq, int ch, FILE *fp, rviewSoundFormat fmt, int lat=RVIEW_SND_LATENCY);
120  int newSample(int frq, int ch, const signed char *data, int len, rviewSoundFormat=rsf_lin8, int lat=RVIEW_SND_LATENCY);
121  int newSample(int frq, int ch, const unsigned char *data, int len, rviewSoundFormat=rsf_ulaw8, int lat=RVIEW_SND_LATENCY);
122  int newSample(int frq, int ch, const short *data, int len, rviewSoundFormat=rsf_lin16, int lat=RVIEW_SND_LATENCY);
123 
124  int playbackGetOffset(void);
125  int playbackActive(void);
126  void playbackSuspend(void);
127  void playbackResume(void);
128  void playbackStop(void);
129  int playbackSetPosition(int position);
130  int playbackLoopMode(int lpMode);
131 
132 #ifdef __VISUALC__
133  void writeSamples(DWORD systime);
134 #else
135  void writeSamples(void);
136 #endif
137 
138 
139 protected:
140 
141  void setupVariables(void);
142  const char *ensureSamplesForDevice(const char *source, int len);
143  const char *ensureSamples(int &num);
144  int configureDevice(int frq, int ch, int len, rviewSoundFormat fmt, int lat);
145  void ensureUlawTable(int ulawsize);
146  void ensureLinearTable(void);
147  char *ensureConvBuff(int size);
148  char *ensureSampleBuff(int size);
149 
150  int setTimerInterval(unsigned int ti);
151  int startTimer(int ap=1);
152  int stopTimer(int ap=1);
153  int handleOutOfData(int dataSize);
154 
158  FILE *sampleFile;
162  char *buffer, *convBuff;
163  const char *inData;
164  unsigned char *LinToUlaw;
165  short *UlawToLin;
169  int loopMode;
171 
172  // Unix specifics
173 #ifdef __VISUALC__
174  void freeWaveHeaders(void);
175 
176  HWAVEOUT waveOut;
177  WAVEFORMATEX waveFmt;
178  WAVEHDR waveHdrs[RVIEW_SND_BUFFERS];
179  UINT timerID;
183 #else
185  struct timeval lastSyncTime;
186  struct sigaction oact;
187  struct itimerval ovalue;
188 #endif
189 };
190 
191 
192 
193 #ifndef __HAL_ONLY__
194 
195 /*
196  * rviewSoundPlayer: sound player widget
197  */
198 
200 {
201 public:
202 
203  rviewSoundPlayer(mdd_frame *mf, unsigned int flags=0);
204  ~rviewSoundPlayer(void);
205 
206  void label(void);
207  int process(wxObject &obj, wxEvent &evt);
208  virtual int openViewer(void);
209 
210  virtual const char *getFrameName(void) const;
211  virtual rviewFrameType getFrameType(void) const;
212  virtual int getViewerType(void) const;
213 
214  void OnSize(int w, int h);
215 
216  int newProjection(void);
217  void prepareToDie(void);
218 
219  typedef struct format_desc
220  {
221  const char *labelName;
224  } format_desc;
225 
226  // constants
227  // Sound player window button size
228  static const int sound_bwidth;
229  static const int sound_bheight;
230  // Sound player window slider height
231  static const int sound_sheight;
232  // Sound player window text size
233  static const int sound_twidth;
234  static const int sound_theight;
235  // Sount player choice size
236  static const int sound_cwidth;
237  static const int sound_cheight;
238  // Sound player window ctrl area size
239  static const int sound_ctrly;
240  // Sound player frame size
241  static const int sound_width;
242  static const int sound_height;
243  // Number of latency entries
244  static const int sound_latencies;
245 
246 
247 protected:
248 
249  int buildSample(void);
250  int newSample(void);
251  int startPlayback(void);
252  int stopPlayback(void);
253  void setSlider(int offset);
254  bool setLoopMode(bool lm);
255 
264  int *latencies;
267  bool paused;
269  bool loopMode;
270  int dim1, dim2;
273  unsigned int freeDims;
274 
275  static const format_desc soundFormatDesc[];
276 };
277 
278 #endif // HAL
279 
280 #endif
static const int sound_sheight
Definition: rviewSound.hh:231
int cbuffSize
Definition: rviewSound.hh:161
bool playbackOn
Definition: rviewSound.hh:268
rviewButton * toStart
Definition: rviewSound.hh:257
void playbackResume(void)
int stopTimer(int ap=1)
rviewChoice * fmtWidget
Definition: rviewSound.hh:261
rviewSoundPlayer(mdd_frame *mf, unsigned int flags=0)
int samplesWriteahead
Definition: rviewSound.hh:160
int inLength
Definition: rviewSound.hh:159
static const int sound_height
Definition: rviewSound.hh:242
static const int sound_cwidth
Definition: rviewSound.hh:236
void label(void)
static const int sound_ctrly
Definition: rviewSound.hh:239
const char * ensureSamplesForDevice(const char *source, int len)
void writeSamples(void)
int channels
Definition: rviewSound.hh:262
int * latencies
Definition: rviewSound.hh:264
rviewButton * toEnd
Definition: rviewSound.hh:257
static const int sound_cheight
Definition: rviewSound.hh:237
Definition: rviewSound.hh:92
char * ensureSampleBuff(int size)
char * buffer
Definition: rviewSound.hh:162
void setupVariables(void)
unsigned int freeDims
Definition: rviewSound.hh:273
rviewText * frqWidget
Definition: rviewSound.hh:260
int sampleLength
Definition: rviewSound.hh:266
Definition: rviewSound.hh:90
bool timerActive
Definition: rviewSound.hh:170
virtual int getViewerType(void) const
int startPlayback(void)
int loopMode
Definition: rviewSound.hh:169
virtual const char * getFrameName(void) const
int latency
Definition: rviewSound.hh:160
int frequency
Definition: rviewSound.hh:262
int sampleSize
Definition: rviewSound.hh:157
int audioDevice
Definition: rviewSound.hh:184
int latency
Definition: rviewSound.hh:262
rviewButton * pbLoop
Definition: rviewSound.hh:258
static const int sound_bwidth
Definition: rviewSound.hh:228
int stopPlayback(void)
Definition: rviewSound.hh:219
rviewSoundFormat fmt
Definition: rviewSound.hh:222
struct itimerval ovalue
Definition: rviewSound.hh:187
Definition: rviewUtils.hh:636
rviewChoice * latWidget
Definition: rviewSound.hh:261
int playbackSetPosition(int position)
int dim1
Definition: rviewSound.hh:270
const char * labelName
Definition: rviewSound.hh:221
Definition: rviewDisplay.hh:56
void ensureUlawTable(int ulawsize)
rviewSoundFormat devFormat
Definition: rviewSound.hh:156
unsigned char * LinToUlaw
Definition: rviewSound.hh:164
static const int sound_theight
Definition: rviewSound.hh:234
int process(wxObject &obj, wxEvent &evt)
Definition: rviewUtils.hh:671
UINT timerID
Definition: rviewSound.hh:179
int playbackLoopMode(int lpMode)
Definition: rviewUtils.hh:701
int emptyBuffers
Definition: rviewSound.hh:182
rviewButton * pbStop
Definition: rviewSound.hh:258
void setSlider(int offset)
static const int sound_latencies
Definition: rviewSound.hh:244
WAVEHDR waveHdrs[RVIEW_SND_BUFFERS]
Definition: rviewSound.hh:178
int frequency
Definition: rviewSound.hh:160
void * sampleBuffer
Definition: rviewSound.hh:265
struct rviewSoundPlayer::format_desc format_desc
soundPlayer(void)
void OnSize(int w, int h)
Definition: rviewSound.hh:88
int newSample(void)
rviewSoundFormat
Definition: rviewSound.hh:86
rviewFrameType
Definition: rviewUtils.hh:443
int currentHeader
Definition: rviewSound.hh:181
Definition: rviewSound.hh:199
rviewSlider * slider
Definition: rviewSound.hh:259
int sampleSize
Definition: rviewSound.hh:223
static const int sound_twidth
Definition: rviewSound.hh:233
struct sigaction oact
Definition: rviewSound.hh:186
const char * ensureSamples(int &num)
soundPlayer player
Definition: rviewSound.hh:256
int buildSample(void)
Definition: rviewSound.hh:91
WAVEFORMATEX waveFmt
Definition: rviewSound.hh:177
void playbackSuspend(void)
int handleOutOfData(int dataSize)
virtual int openViewer(void)
bool paused
Definition: rviewSound.hh:267
int dim2
Definition: rviewSound.hh:270
int devSampSize
Definition: rviewSound.hh:157
virtual rviewFrameType getFrameType(void) const
Definition: rviewSound.hh:89
int currentFormat
Definition: rviewSound.hh:272
int setTimerInterval(unsigned int ti)
Definition: rviewSound.hh:101
HWAVEOUT waveOut
Definition: rviewSound.hh:176
char * convBuff
Definition: rviewSound.hh:162
int buffSize
Definition: rviewSound.hh:161
rviewSoundFormat format
Definition: rviewSound.hh:155
soundPlayer * suspendedPlayer
Definition: rviewSound.hh:168
int lastOffset
Definition: rviewSound.hh:263
void freeWaveHeaders(void)
static const int sound_bheight
Definition: rviewSound.hh:229
void prepareToDie(void)
int newSample(int frq, int ch, FILE *fp, rviewSoundFormat fmt, int lat=RVIEW_SND_LATENCY)
const char * inData
Definition: rviewSound.hh:163
rviewButton * pbStart
Definition: rviewSound.hh:258
void ensureLinearTable(void)
int typeLength
Definition: rviewSound.hh:271
short * UlawToLin
Definition: rviewSound.hh:165
DWORD lastSyncTime
Definition: rviewSound.hh:180
int dataOffset
Definition: rviewSound.hh:159
rviewButton * pbPause
Definition: rviewSound.hh:258
Definition: rviewUtils.hh:663
int playbackActive(void)
char * ensureConvBuff(int size)
int channels
Definition: rviewSound.hh:160
bool loopMode
Definition: rviewSound.hh:269
Definition: rviewUtils.hh:297
int playbackGetOffset(void)
int newProjection(void)
int samplesWritten
Definition: rviewSound.hh:167
int ldUlawSize
Definition: rviewSound.hh:166
~soundPlayer(void)
static const int sound_width
Definition: rviewSound.hh:241
int startTimer(int ap=1)
FILE * sampleFile
Definition: rviewSound.hh:158
static const format_desc soundFormatDesc[]
Definition: rviewSound.hh:275
void playbackStop(void)
bool setLoopMode(bool lm)
int configureDevice(int frq, int ch, int len, rviewSoundFormat fmt, int lat)