Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / audiooss.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  * Copyright (C) 2003-2016 Cinelerra CV contributors
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22
23 #ifndef AUDIOOSS_H
24 #define AUDIOOSS_H
25
26 #include "audiodevice.h"
27 #include "condition.inc"
28 #include "playbackconfig.inc"
29
30 #ifdef HAVE_OSS
31 #include <sys/soundcard.h>
32
33 class OSSThread : public Thread
34 {
35 public:
36         OSSThread(AudioOSS *device);
37         ~OSSThread();
38
39         void run();
40         void write_data(int fd, unsigned char *data, int bytes);
41         void read_data(int fd, unsigned char *data, int bytes);
42 // Must synchronize reads and writes
43         void wait_read();
44         void wait_write();
45         int64_t device_position();
46
47         Condition *input_lock;
48         Condition *output_lock;
49         Condition *read_lock;
50         Condition *write_lock;
51         int rd, wr, fd;
52         unsigned char *data;
53         int bytes;
54         int done;
55         AudioOSS *device;
56
57         int64_t bytes_written;
58         Timer *timer;
59         int delay;
60         Mutex *timer_lock;
61
62 };
63
64 class AudioOSS : public AudioLowLevel
65 {
66 public:
67         AudioOSS(AudioDevice *device);
68         ~AudioOSS();
69
70         int open_input();
71         int open_output();
72         int write_buffer(char *buffer, int bytes);
73         int read_buffer(char *buffer, int bytes);
74         int close_all();
75         int64_t device_position();
76         int flush_device();
77         int interrupt_playback();
78         int stop_output() { return interrupt_playback(); }
79         int64_t samples_output();
80
81 private:
82         int get_fmt(int bits);
83         int sizetofrag(int samples, int channels, int bits);
84         int set_cloexec_flag(int desc, int value);
85         int get_output(int number);
86         int get_input(int number);
87         int dsp_in[MAXDEVICES], dsp_out[MAXDEVICES];
88         OSSThread *thread[MAXDEVICES];
89 // Temp for each device, Bytes allocated
90         unsigned char *data[MAXDEVICES];
91         int data_allocated[MAXDEVICES];
92 };
93
94 #endif
95
96 #endif