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
22 #include "audio1394.h"
23 #include "playbackconfig.h"
24 #include "device1394input.h"
25 #include "device1394output.h"
26 #include "iec61883input.h"
27 #include "iec61883output.h"
28 #include "preferences.h"
29 #include "recordconfig.h"
30 #include "videoconfig.h"
31 #include "videodevice.h"
33 #define SAMPLES_PER_FRAME 2048
35 Audio1394::Audio1394(AudioDevice *device)
36 : AudioLowLevel(device)
42 Audio1394::~Audio1394()
47 void Audio1394::initialize()
55 int Audio1394::open_input()
58 if(!input_thread && !input_iec)
60 // Lock the channels for the DV format
61 device->in_channels = 2;
63 bytes_per_sample = device->in_channels * device->in_bits / 8;
66 if(device->idriver == AUDIO_DV1394 ||
67 device->idriver == AUDIO_1394)
69 input_thread = new Device1394Input;
70 result = input_thread->open(device->in_config->firewire_path,
71 device->in_config->firewire_port,
72 device->in_config->firewire_channel,
75 device->in_samplerate,
82 input_iec = new IEC61883Input;
83 result = input_iec->open(device->in_config->firewire_port,
84 device->in_config->firewire_channel,
87 device->in_samplerate,
108 int Audio1394::open_output()
110 if(!output_thread && !output_iec)
112 // Lock the channels for the DV format
113 device->out_channels = 2;
114 device->out_bits = 16;
115 bytes_per_sample = device->out_channels * device->out_bits / 8;
118 if(device->odriver == AUDIO_DV1394)
120 output_thread = new Device1394Output(device);
121 output_thread->open(device->out_config->dv1394_path,
122 device->out_config->dv1394_port,
123 device->out_config->dv1394_channel,
125 device->out_channels,
127 device->out_samplerate,
128 device->out_config->dv1394_syt);
131 if(device->odriver == AUDIO_1394)
133 output_thread = new Device1394Output(device);
134 output_thread->open(device->out_config->firewire_path,
135 device->out_config->firewire_port,
136 device->out_config->firewire_channel,
138 device->out_channels,
140 device->out_samplerate,
141 device->out_config->firewire_syt);
145 output_iec = new IEC61883Output(device);
146 output_iec->open(device->out_config->firewire_port,
147 device->out_config->firewire_channel,
149 device->out_channels,
151 device->out_samplerate,
152 device->out_config->firewire_syt);
158 int Audio1394::close_all()
167 delete output_thread;
177 int Audio1394::read_buffer(char *buffer, int bytes)
181 input_thread->read_audio(buffer, bytes / bytes_per_sample);
186 input_iec->read_audio(buffer, bytes / bytes_per_sample);
192 int Audio1394::write_buffer(char *buffer, int bytes)
195 output_thread->write_samples(buffer, bytes / bytes_per_sample);
198 output_iec->write_samples(buffer, bytes / bytes_per_sample);
202 int64_t Audio1394::device_position()
205 return output_thread->get_audio_position();
208 return output_iec->get_audio_position();
214 int Audio1394::flush_device()
217 output_thread->flush();
224 int Audio1394::interrupt_playback()
227 output_thread->interrupt();
230 output_iec->interrupt();