File: PlayBack-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 (169 lines) | stat: -rw-r--r-- 5,510 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
/***************************************************************************
         PlayBack-OSS.h  -  playback device for standard linux OSS
                             -------------------
    begin                : Sat May 19 2001
    copyright            : (C) 2001 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 PLAY_BACK_OSS_H
#define PLAY_BACK_OSS_H

#include "config.h"
#ifdef HAVE_OSS_SUPPORT

#include <QByteArray>
#include <QList>
#include <QString>

#include "libkwave/PlayBackDevice.h"
#include "libkwave/SampleArray.h"
#include "libkwave/SampleFormat.h"

namespace Kwave
{

    class SampleEncoder;

    class PlayBackOSS: public Kwave::PlayBackDevice
    {
    public:

        /** Default constructor */
        PlayBackOSS();

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

        /**
         * Opens the device for playback.
         * @see PlayBackDevice::open
         */
        virtual QString open(const QString &device, double rate,
                             unsigned int channels, unsigned int bits,
                             unsigned int bufbase) override;

        /**
         * Writes an array of samples to the output device.
         * @see PlayBackDevice::write
         */
        int write(const Kwave::SampleArray &samples) override;

        /**
         * Closes the output device.
         * @see PlayBackDevice::close
         */
        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;

        /**
         * returns a list of supported bits per sample resolutions
         * of a given device.
         *
         * @param device filename of the device
         * @return list of supported bits per sample, or empty on errors
         */
        virtual QList<unsigned int> supportedBits(const QString &device)
            override;

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

    protected:

        /**
         * split a device format bitmask into its parameters.
         * (copied from playback plugin)
         *
         * @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, int &compression,
                         int &bits,
                         Kwave::SampleFormat::Format &sample_format) const;

        /**
         * Opens a physical device and returns its file descriptor
         *
         * @param device filename of the device
         * @return file descriptor >= 0 or negative value on errors
         */
        int openDevice(const QString &device);

        /** Writes the output buffer to the device */
        void flush();

        /** Name of the output device */
        QString m_device_name;

        /** Handle of the output device */
        int m_handle;

        /** Playback rate [samples/second] */
        double m_rate;

        /** Number of channels */
        unsigned int m_channels;

        /** Resolution in bits per sample */
        unsigned int m_bits;

        /** Exponent of the buffer size */
        unsigned int m_bufbase;

        /** buffer with samples data */
        Kwave::SampleArray m_buffer;

        /** buffer with raw data */
        QByteArray m_raw_buffer;

        /** Buffer size on bytes */
        unsigned int m_buffer_size;

        /** number of bytes in the buffer */
        unsigned int m_buffer_used;

        /** encoder for converting from samples to raw format */
        Kwave::SampleEncoder *m_encoder;

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

#endif /* HAVE_OSS_SUPPORT */

#endif /* PLAY_BACK_OSS_H */

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