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
23 #include "audio1394.h"
24 #include "playbackconfig.h"
25 #include "device1394input.h"
26 #include "device1394output.h"
27 #include "iec61883input.h"
28 #include "iec61883output.h"
29 #include "preferences.h"
30 #include "recordconfig.h"
31 #include "videoconfig.h"
32 #include "videodevice.h"
34 #define SAMPLES_PER_FRAME 2048
36 Audio1394::Audio1394(AudioDevice *device)
37 : AudioLowLevel(device)
43 Audio1394::~Audio1394()
48 void Audio1394::initialize()
56 int Audio1394::open_input()
59 if(!input_thread && !input_iec)
61 // Lock the channels for the DV format
62 device->in_channels = 2;
64 bytes_per_sample = device->in_channels * device->in_bits / 8;
67 if(device->idriver == AUDIO_DV1394 ||
68 device->idriver == AUDIO_1394)
70 input_thread = new Device1394Input;
71 result = input_thread->open(device->in_config->firewire_path,
72 device->in_config->firewire_port,
73 device->in_config->firewire_channel,
76 device->in_samplerate,
83 input_iec = new IEC61883Input;
84 result = input_iec->open(device->in_config->firewire_port,
85 device->in_config->firewire_channel,
88 device->in_samplerate,
109 int Audio1394::open_output()
111 if(!output_thread && !output_iec)
113 // Lock the channels for the DV format
114 device->out_channels = 2;
115 device->out_bits = 16;
116 bytes_per_sample = device->out_channels * device->out_bits / 8;
119 if(device->odriver == AUDIO_DV1394)
121 output_thread = new Device1394Output(device);
122 output_thread->open(device->out_config->dv1394_path,
123 device->out_config->dv1394_port,
124 device->out_config->dv1394_channel,
126 device->out_channels,
128 device->out_samplerate,
129 device->out_config->dv1394_syt);
132 if(device->odriver == AUDIO_1394)
134 output_thread = new Device1394Output(device);
135 output_thread->open(device->out_config->firewire_path,
136 device->out_config->firewire_port,
137 device->out_config->firewire_channel,
139 device->out_channels,
141 device->out_samplerate,
142 device->out_config->firewire_syt);
146 output_iec = new IEC61883Output(device);
147 output_iec->open(device->out_config->firewire_port,
148 device->out_config->firewire_channel,
150 device->out_channels,
152 device->out_samplerate,
153 device->out_config->firewire_syt);
159 int Audio1394::close_all()
168 delete output_thread;
178 int Audio1394::read_buffer(char *buffer, int bytes)
182 input_thread->read_audio(buffer, bytes / bytes_per_sample);
187 input_iec->read_audio(buffer, bytes / bytes_per_sample);
193 int Audio1394::write_buffer(char *buffer, int bytes)
196 output_thread->write_samples(buffer, bytes / bytes_per_sample);
199 output_iec->write_samples(buffer, bytes / bytes_per_sample);
203 int64_t Audio1394::device_position()
206 return output_thread->get_audio_position();
209 return output_iec->get_audio_position();
215 int Audio1394::flush_device()
218 output_thread->flush();
225 int Audio1394::interrupt_playback()
228 output_thread->interrupt();
231 output_iec->interrupt();