r1005: Increase the number of displayed digits for resample audio dialog box
[cinelerra_cv/mob.git] / cinelerra / audio1394.C
blob26eb744911126658120a08ad7f275292a38b63b3
1 #include "audio1394.h"
2 #include "playbackconfig.h"
3 #include "device1394input.h"
4 #include "device1394output.h"
5 #include "iec61883input.h"
6 #include "iec61883output.h"
7 #include "preferences.h"
8 #include "recordconfig.h"
9 #include "videoconfig.h"
10 #include "videodevice.h"
12 #define SAMPLES_PER_FRAME 2048
14 Audio1394::Audio1394(AudioDevice *device)
15  : AudioLowLevel(device)
17         initialize();
21 Audio1394::~Audio1394()
23         close_all();
26 int Audio1394::initialize()
28         input_thread = 0;
29         output_thread = 0;
30         input_iec = 0;
31         output_iec = 0;
34 int Audio1394::open_input()
36         int result = 0;
37         if(!input_thread && !input_iec)
38         {
39 // Lock the channels for the DV format
40                 device->in_channels = 2;
41                 device->in_bits = 16;
42                 bytes_per_sample = device->in_channels * device->in_bits / 8;
45                 if(device->driver == AUDIO_DV1394 ||
46                         device->driver == AUDIO_1394)
47                 {
48                         input_thread = new Device1394Input;
49                         result = input_thread->open(device->in_config->firewire_path,
50                                 device->in_config->firewire_port, 
51                                 device->in_config->firewire_channel, 
52                                 30,
53                                 device->in_channels,
54                                 device->in_samplerate,
55                                 device->in_bits,
56                                 device->vconfig->w,
57                                 device->vconfig->h);
58                 }
59                 else
60                 {
61                         input_iec = new IEC61883Input;
62                         result = input_iec->open(device->in_config->firewire_port, 
63                                 device->in_config->firewire_channel, 
64                                 30,
65                                 device->in_channels,
66                                 device->in_samplerate,
67                                 device->in_bits,
68                                 device->vconfig->w,
69                                 device->vconfig->h);
70                 }
75                 if(result)
76                 {
77                         delete input_thread;
78                         input_thread = 0;
79                         delete input_iec;
80                         input_iec = 0;
81                 }
82         }
84         return result;
87 int Audio1394::open_output()
89         if(!output_thread && !output_iec)
90         {
91 // Lock the channels for the DV format
92                 device->out_channels = 2;
93                 device->out_bits = 16;
94                 bytes_per_sample = device->out_channels * device->out_bits / 8;
97                 if(device->driver == AUDIO_DV1394)
98                 {
99                         output_thread = new Device1394Output(device);
100                         output_thread->open(device->out_config->dv1394_path,
101                                 device->out_config->dv1394_port,
102                                 device->out_config->dv1394_channel,
103                                 30,
104                                 device->out_channels, 
105                                 device->out_bits, 
106                                 device->out_samplerate,
107                                 device->out_config->dv1394_syt);
108                 }
109                 else
110                 if(device->driver == AUDIO_1394)
111                 {
112                         output_thread = new Device1394Output(device);
113                         output_thread->open(device->out_config->firewire_path,
114                                 device->out_config->firewire_port,
115                                 device->out_config->firewire_channel,
116                                 30,
117                                 device->out_channels, 
118                                 device->out_bits, 
119                                 device->out_samplerate,
120                                 device->out_config->firewire_syt);
121                 }
122                 else
123                 {
124                         output_iec = new IEC61883Output(device);
125                         output_iec->open(device->out_config->firewire_port,
126                                 device->out_config->firewire_channel,
127                                 30,
128                                 device->out_channels, 
129                                 device->out_bits, 
130                                 device->out_samplerate,
131                                 device->out_config->firewire_syt);
132                 }
133         }
134         return 0;
137 int Audio1394::close_all()
139         if(input_thread)
140         {
141                 delete input_thread;
142         }
144         if(output_thread)
145         {
146                 delete output_thread;
147         }
148         delete input_iec;
149         delete output_iec;
151         initialize();
152         return 0;
156 int Audio1394::read_buffer(char *buffer, int bytes)
158         if(input_thread)
159         {
160                 input_thread->read_audio(buffer, bytes / bytes_per_sample);
161         }
162         else
163         if(input_iec)
164         {
165                 input_iec->read_audio(buffer, bytes / bytes_per_sample);
166         }
168         return 0;
171 int Audio1394::write_buffer(char *buffer, int bytes)
173         if(output_thread)
174                 output_thread->write_samples(buffer, bytes / bytes_per_sample);
175         else
176         if(output_iec)
177                 output_iec->write_samples(buffer, bytes / bytes_per_sample);
178         return 0;
181 int64_t Audio1394::device_position()
183         if(output_thread)
184                 return output_thread->get_audio_position();
185         else
186         if(output_iec)
187                 return output_iec->get_audio_position();
188         else
189                 return 0;
193 int Audio1394::flush_device()
195         if(output_thread)
196                 output_thread->flush();
197         else
198         if(output_iec)
199                 output_iec->flush();
200         return 0;
203 int Audio1394::interrupt_playback()
205         if(output_thread)
206                 output_thread->interrupt();
207         else
208         if(output_iec)
209                 output_iec->interrupt();
210         return 0;