File: Record-OSS.h

package info (click to toggle)
kwave 25.04.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,272 kB
  • sloc: cpp: 56,173; xml: 817; perl: 688; sh: 57; makefile: 11
file content (217 lines) | stat: -rw-r--r-- 7,833 bytes parent folder | download
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*************************************************************************
           Record-OSS.h  -  device for audio recording via OSS
                             -------------------
    begin                : Sun Jul 24 2005
    copyright            : (C) 2005 by Thomas Eschenbacher
    email                : Thomas.Eschenbacher@gmx.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef RECORD_OSS_H
#define RECORD_OSS_H

#include "config.h"
#ifdef HAVE_OSS_SUPPORT

#include <QByteArray>
#include <QString>

#include "RecordDevice.h"

namespace Kwave
{
    class RecordOSS: public Kwave::RecordDevice
    {
    public:

        /** Constructor */
        RecordOSS();

        /** Destructor */
        ~RecordOSS() override;

        /**
         * Open the record device.
         * @param dev path of the record device
         * @return zero-length string if successful, or an error
         *         message if failed
         */
        QString open(const QString &dev) override;

        /**
         * Read the raw audio data from the record device.
         * @param buffer array of bytes to receive the audio data
         *        might be resized for alignment
         * @param offset offset in bytes within the buffer
         * @return number of bytes read, zero or negative if failed
         */
        virtual int read(QByteArray &buffer, unsigned int offset)
            override;

        /** Close the device */
        int close() override;

        /** return a string list with supported device names */
        QStringList supportedDevices() override;

        /** return a string suitable for a "File Open..." dialog */
        QString fileFilter() override;

        /**
         * Detect the minimum and maximum number of tracks.
         * If the detection fails, minimum and maximum are set to zero.
         * @param min receives the lowest supported number of tracks
         * @param max receives the highest supported number of tracks
         * @return zero or positive number if ok,
         *         negative error number if failed
         */
        virtual int detectTracks(unsigned int &min, unsigned int &max)
            override;

        /**
         * Try to set a new number of tracks.
         * @note the device must be open
         * @param tracks the number of tracks to be set, can be modified and
         *        decreased to the next supported number of tracks if the
         *        underlying driver supports that.
         * @return zero on success, negative error code if failed
         */
        int setTracks(unsigned int &tracks) override;

        /** Returns the current number of tracks */
        int tracks() override;

        /** get a list of supported sample rates */
        QList<double> detectSampleRates() override;

        /**
         * Try to set a new sample rate.
         * @param new_rate the sample rate to be set [samples/second], can
         *        be modified and rounded up/down to the nearest supported
         *        sample rate if the underlying driver supports that.
         * @return zero on success, negative error code if failed
         */
        int setSampleRate(double &new_rate) override;

        /** Returns the current sample rate of the device */
        double sampleRate() override;

        /**
         * Gets a list of supported compression types. If no compression is
         * supported, the list might be empty.
         */
        virtual QList<Kwave::Compression::Type> detectCompressions()
            override;

        /**
         * Try to set a new compression type.
         * @param new_compression the identifier of the new compression
         * @return zero on success, negative error code if failed
         * @see class Compression
         */
        virtual int setCompression(Kwave::Compression::Type new_compression)
            override;

        /** Returns the current compression type (0==none) */
        Kwave::Compression::Type compression() override;

        /**
         * Detect a list of supported bits per sample.
         * @note this depends on the compression type
         * @return a list of bits per sample, empty if failed
         */
        QList <unsigned int> supportedBits() override;

        /**
         * Set the resolution in bits per sample
         * @param new_bits resolution [bits/sample]
         */
        int setBitsPerSample(unsigned int new_bits) override;

        /**
         * Returns the current resolution in bits per sample or a negative
         * error code if failed
         */
        int bitsPerSample() override;

        /**
         * Gets a list of supported sample formats.
         * @note this depends on the current setting of the compression!
         */
        virtual QList<Kwave::SampleFormat::Format> detectSampleFormats()
            override;

        /**
         * Try to set a new sample format (signed/unsigned)
         * @param new_format the identifier for the new format
         * @return zero on success, negative error code if failed
         * @see class SampleFormat
         */
        virtual int setSampleFormat(Kwave::SampleFormat::Format new_format)
            override;

        /** Returns the current sample format (signed/unsigned) */
        Kwave::SampleFormat::Format sampleFormat() override;

        /** Returns the current endianness (big/little/cpu) */
        Kwave::byte_order_t endianness() override;

    private:

        /**
         * split a device format bitmask into it's parameters.
         * @param format the device specific format
         * @param compression receives a compression type
         * @see Compression
         * @param bits receives the number of bits per sample, related
         *        to the decoded stream
         * @param sample_format receives the sample format, as defined in
         *        libaudiofile (signed or unsigned)
         */
        void format2mode(int format, Kwave::Compression::Type &compression,
                         int &bits,
                         Kwave::SampleFormat::Format &sample_format);

        /**
         * create a device format bitmask from it's parameters.
         * @param compression the compression type
         * @see Compression
         * @param bits the number of bits per sample, related
         *        to the decoded stream
         * @param sample_format the sample format, as defined in
         *        libaudiofile (signed or unsigned)
         * @return the device specific format
         */
        int mode2format(Kwave::Compression::Type compression, int bits,
                        Kwave::SampleFormat::Format sample_format);

    private:

        /** file descriptor of the device or -1 if not open */
        int m_fd;

        /** sample rate  */
        int m_rate;

        /** number of tracks  */
        int m_tracks;

        /** OSS driver version  */
        int m_oss_version;
    };
}

#endif /* HAVE_OSS_SUPPORT */

#endif /* RECORD_OSS_H */

//***************************************************************************
//***************************************************************************