summaryrefslogtreecommitdiff
path: root/freebsd/oss/JackOSSDriver.h
blob: c5449b37640709a2aee1f484b0331f01766deba4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
Copyright (C) 2003-2007 Jussi Laako <jussi@sonarnerd.net>
Copyright (C) 2008 Grame & RTL 2008

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#ifndef __JackOSSDriver__
#define __JackOSSDriver__

#include "JackAudioDriver.h"

namespace Jack
{

typedef jack_default_audio_sample_t jack_sample_t;

#define OSS_DRIVER_DEF_DEV "/dev/dsp"
#define OSS_DRIVER_DEF_FS 48000
#define OSS_DRIVER_DEF_BLKSIZE 1024
#define OSS_DRIVER_DEF_NPERIODS 1
#define OSS_DRIVER_DEF_BITS 16
#define OSS_DRIVER_DEF_INS 2
#define OSS_DRIVER_DEF_OUTS 2

/*!
\brief The OSS driver.
*/

class JackOSSDriver : public JackAudioDriver
{
    private:

        int fInFD;
        int fOutFD;

        int fBits;
        int fNperiods;
        bool fCapture;
        bool fPlayback;
        bool fExcl;
        bool fIgnoreHW;

        unsigned int fInSampleSize;
        unsigned int fOutSampleSize;

        unsigned int fInputBufferSize;
        unsigned int fOutputBufferSize;

        void* fInputBuffer;
        void* fOutputBuffer;

        jack_nframes_t fInBlockSize;
        jack_nframes_t fOutBlockSize;
        jack_nframes_t fInMeanStep;
        jack_nframes_t fOutMeanStep;
        jack_nframes_t fOSSInBuffer;
        jack_nframes_t fOSSOutBuffer;

        jack_time_t fOSSReadSync;
        long long fOSSReadOffset;
        jack_time_t fOSSWriteSync;
        long long fOSSWriteOffset;

        // Buffer balance and sync correction
        long long fBufferBalance;
        bool fForceBalancing;
        bool fForceSync;

        int OpenInput();
        int OpenOutput();
        int OpenAux();
        void CloseAux();
        void DisplayDeviceInfo();
        int ProbeInBlockSize();
        int ProbeOutBlockSize();
        int Discard(jack_nframes_t frames);
        int WriteSilence(jack_nframes_t frames);
        int WaitAndSync();

    protected:
        virtual void UpdateLatencies();

    public:

        JackOSSDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table)
                : JackAudioDriver(name, alias, engine, table),
                fInFD(-1), fOutFD(-1), fBits(0),
                fNperiods(0), fCapture(false), fPlayback(false), fExcl(false), fIgnoreHW(true),
                fInSampleSize(0), fOutSampleSize(0),
                fInputBufferSize(0), fOutputBufferSize(0),
                fInputBuffer(NULL), fOutputBuffer(NULL),
                fInBlockSize(1), fOutBlockSize(1),
                fInMeanStep(0), fOutMeanStep(0),
                fOSSInBuffer(0), fOSSOutBuffer(0),
                fOSSReadSync(0), fOSSReadOffset(0), fOSSWriteSync(0), fOSSWriteOffset(0),
                fBufferBalance(0), fForceBalancing(false), fForceSync(false)
        {}

        virtual ~JackOSSDriver()
        {}

        int Open(jack_nframes_t frames_per_cycle,
                 int user_nperiods,
                 jack_nframes_t rate,
                 bool capturing,
                 bool playing,
                 int chan_in,
                 int chan_out,
                 bool vmix,
                 bool monitor,
                 const char* capture_driver_name,
                 const char* playback_driver_name,
                 jack_nframes_t capture_latency,
                 jack_nframes_t playback_latency,
                 int bits,
                 bool ignorehwbuf);

        int Close();

        int Read();
        int Write();

        // BufferSize can be changed
        bool IsFixedBufferSize()
        {
            return false;
        }

        int SetBufferSize(jack_nframes_t buffer_size);

};

} // end of namespace

#endif