1 /*
2   ZynAddSubFX - a software synthesizer
3 
4   OSSaudiooutput.h - Audio output for Open Sound System
5   Copyright (C) 2002-2005 Nasca Octavian Paul
6   Author: Nasca Octavian Paul
7 
8   This program is free software; you can redistribute it and/or
9   modify it under the terms of the GNU General Public License
10   as published by the Free Software Foundation; either version 2
11   of the License, or (at your option) any later version.
12 */
13 
14 #ifndef OSS_ENGINE_H
15 #define OSS_ENGINE_H
16 
17 #include <sys/time.h>
18 #include "../globals.h"
19 #include "AudioOut.h"
20 #include "MidiIn.h"
21 
22 namespace zyn {
23 
24 struct OssMidiParse {
25         unsigned char *temp_cmd;
26         unsigned char temp_0[4];
27         unsigned char temp_1[4];
28         unsigned char state;
29 #define OSSMIDI_ST_UNKNOWN   0          /* scan for command */
30 #define OSSMIDI_ST_1PARAM    1
31 #define OSSMIDI_ST_2PARAM_1  2
32 #define OSSMIDI_ST_2PARAM_2  3
33 #define OSSMIDI_ST_SYSEX_0   4
34 #define OSSMIDI_ST_SYSEX_1   5
35 #define OSSMIDI_ST_SYSEX_2   6
36 };
37 
38 class OssEngine:public AudioOut, MidiIn
39 {
40     public:
41         OssEngine(const SYNTH_T &synth, const class oss_devs_t& oss_devs);
42         ~OssEngine();
43 
44         bool Start();
45         void Stop();
46 
47         void setAudioEn(bool nval);
48         bool getAudioEn() const;
49 
50         void setMidiEn(bool nval);
51         bool getMidiEn() const;
52 
53     protected:
54         void *audioThreadCb();
55         static void *_audioThreadCb(void *arg);
56 
57         void *midiThreadCb();
58         static void *_midiThreadCb(void *arg);
59 
60     private:
61         pthread_t *audioThread;
62         pthread_t *midiThread;
63 
64         //Audio
65         bool openAudio();
66         void stopAudio();
67 
68         struct audio {
69             int handle;
70             int buffersize;
71             union {
72                 /* Samples to be sent to soundcard */
73                 short int *ps16;
74                 int *ps32;
75             } smps;
76 
77             /* peak values used for compressor */
78             float peaks[1];
79 
80             bool en;
81             bool is32bit;
82         } audio;
83 
84         const char* linux_oss_wave_out_dev;
85 
86         //Midi
87         bool openMidi();
88         void stopMidi();
89 
90         struct midi {
91             struct OssMidiParse state;
92             int  handle;
93             bool en;
94             bool run;
95         } midi;
96 
97         const char* linux_oss_seq_in_dev;
98 };
99 
100 }
101 
102 #endif
103