4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "audio1394.h"
29 #include "playbackconfig.h"
30 #include "device1394input.h"
31 #include "device1394output.h"
32 #include "iec61883input.h"
33 #include "iec61883output.h"
34 #include "preferences.h"
35 #include "recordconfig.h"
36 #include "videoconfig.h"
37 #include "videodevice.h"
39 #define SAMPLES_PER_FRAME 2048
41 Audio1394::Audio1394(AudioDevice *device)
42 : AudioLowLevel(device)
48 Audio1394::~Audio1394()
53 int Audio1394::initialize()
62 int Audio1394::open_input()
65 if(!input_thread && !input_iec)
67 // Lock the channels for the DV format
68 device->in_channels = 2;
70 bytes_per_sample = device->in_channels * device->in_bits / 8;
73 if(device->idriver == AUDIO_DV1394 ||
74 device->idriver == AUDIO_1394)
76 input_thread = new Device1394Input;
77 result = input_thread->open(device->in_config->firewire_port,
78 device->in_config->firewire_channel,
81 device->in_samplerate,
88 input_iec = new IEC61883Input;
89 result = input_iec->open(device->in_config->firewire_port,
90 device->in_config->firewire_channel,
93 device->in_samplerate,
114 int Audio1394::open_output()
116 if(!output_thread && !output_iec)
118 // Lock the channels for the DV format
119 device->out_channels = 2;
120 device->out_bits = 16;
121 bytes_per_sample = device->out_channels * device->out_bits / 8;
124 if(device->odriver == AUDIO_DV1394)
126 output_thread = new Device1394Output(device);
127 output_thread->open(device->out_config->dv1394_path,
128 device->out_config->dv1394_port,
129 device->out_config->dv1394_channel,
131 device->out_channels,
133 device->out_samplerate,
134 device->out_config->dv1394_syt);
137 if(device->odriver == AUDIO_1394)
139 output_thread = new Device1394Output(device);
140 output_thread->open(device->out_config->firewire_path,
141 device->out_config->firewire_port,
142 device->out_config->firewire_channel,
144 device->out_channels,
146 device->out_samplerate,
147 device->out_config->firewire_syt);
151 output_iec = new IEC61883Output(device);
152 output_iec->open(device->out_config->firewire_port,
153 device->out_config->firewire_channel,
155 device->out_channels,
157 device->out_samplerate,
158 device->out_config->firewire_syt);
164 int Audio1394::close_all()
173 delete output_thread;
183 int Audio1394::read_buffer(char *buffer, int bytes)
187 input_thread->read_audio(buffer, bytes / bytes_per_sample);
192 input_iec->read_audio(buffer, bytes / bytes_per_sample);
198 int Audio1394::write_buffer(char *buffer, int bytes)
201 output_thread->write_samples(buffer, bytes / bytes_per_sample);
204 output_iec->write_samples(buffer, bytes / bytes_per_sample);
208 int64_t Audio1394::device_position()
211 return output_thread->get_audio_position();
214 return output_iec->get_audio_position();
220 int Audio1394::flush_device()
223 output_thread->flush();
230 int Audio1394::interrupt_playback()
233 output_thread->interrupt();
236 output_iec->interrupt();