annotate Plugins/Output/jack/bio2jack.c @ 1268:97fd96ee4b84 trunk

[svn] - generic info box support
author nenolod
date Thu, 15 Jun 2006 22:15:56 -0700
parents ea321d1dae48
children f12d7e208b43
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
325
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1 /*
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2 * Copyright 2003-2004 Chris Morgan <cmorgan@alum.wpi.edu>
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
3 *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
4 * This library is free software; you can redistribute it and/or
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
5 * modify it under the terms of the GNU Lesser General Public
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
6 * License as published by the Free Software Foundation; either
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
7 * version 2.1 of the License, or (at your option) any later version.
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
8 *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
9 * This library is distributed in the hope that it will be useful,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
12 * Lesser General Public License for more details.
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
13 *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
14 * You should have received a copy of the GNU Lesser General Public
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
15 * License along with this library; if not, write to the Free Software
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
17 */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
18
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
19 /* NOTE: All functions that take a jack_driver_t* do NOT lock the device, in order to get a */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
20 /* jack_driver_t* you must call getDriver() which will pthread_mutex_lock() */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
21
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
22 #include <stdio.h>
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
23 #include <errno.h>
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
24 #include <string.h>
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
25 #include <stdlib.h>
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
26 #include <fcntl.h>
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
27 #include <math.h>
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
28 #include <unistd.h>
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
29 #include <inttypes.h>
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
30 #include <jack/jack.h>
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
31 #include <jack/ringbuffer.h>
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
32 #include <pthread.h>
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
33 #include <sys/time.h>
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
34 #include <samplerate.h>
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
35
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
36 #include "bio2jack.h"
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
37
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
38 /* enable/disable TRACING through the JACK_Callback() function */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
39 /* this can sometimes be too much information */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
40 #define TRACE_CALLBACK 0
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
41
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
42 /* set to 1 for verbose output */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
43 #define VERBOSE_OUTPUT 0
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
44
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
45 /* set to 1 to enable debug messages */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
46 #define DEBUG_OUTPUT 0
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
47
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
48 /* set to 1 to enable tracing */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
49 #define TRACE_ENABLE 0
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
50
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
51 /* set to 1 to enable the function timers */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
52 #define TIMER_ENABLE 0
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
53
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
54 /* set to 1 to enable tracing of getDriver() and releaseDriver() */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
55 #define TRACE_getReleaseDevice 0
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
56
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
57 #define ENABLE_WARNINGS 0
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
58
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
59 #define DEFAULT_RB_SIZE 16384
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
60
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
61 #define OUTFILE stderr
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
62
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
63 #if TIMER_ENABLE
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
64 /* This seemingly construct makes timing arbitrary functions really easy
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
65 all you have to do is place a 'TIMER("start\n")' at the beginning and
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
66 a 'TIMER("stop\n")' at the end of any function and this does the rest
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
67 (naturally you can place any printf-compliant text you like in the argument
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
68 along with the associated values). */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
69 static struct timeval timer_now;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
70 #define TIMER(format,args...) gettimeofday(&timer_now,0); \
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
71 fprintf(OUTFILE, "%ld.%06ld: %s::%s(%d) "format, timer_now.tv_sec, timer_now.tv_usec, __FILE__, __FUNCTION__, __LINE__, ##args)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
72 #else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
73 #define TIMER(...)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
74 #endif
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
75
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
76 #if TRACE_ENABLE
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
77 #define TRACE(format,args...) fprintf(OUTFILE, "%s::%s(%d) "format, __FILE__, __FUNCTION__, __LINE__,##args); \
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
78 fflush(OUTFILE);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
79 #else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
80 #define TRACE(...)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
81 #endif
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
82
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
83 #if DEBUG_OUTPUT
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
84 #define DEBUG(format,args...) fprintf(OUTFILE, "%s::%s(%d) "format, __FILE__, __FUNCTION__, __LINE__,##args); \
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
85 fflush(OUTFILE);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
86 #else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
87 #define DEBUG(...)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
88 #endif
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
89
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
90 #if TRACE_CALLBACK
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
91 #define CALLBACK_TRACE(format,args...) fprintf(OUTFILE, "%s::%s(%d) "format, __FILE__, __FUNCTION__, __LINE__,##args); \
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
92 fflush(OUTFILE);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
93 #else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
94 #define CALLBACK_TRACE(...)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
95 #endif
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
96
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
97 #if ENABLE_WARNINGS
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
98 #define WARN(format,args...) fprintf(OUTFILE, "WARN: %s::%s(%d) "format, __FILE__,__FUNCTION__,__LINE__,##args); \
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
99 fflush(OUTFILE);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
100 #else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
101 #define WARN(...)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
102 #endif
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
103
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
104 #define ERR(format,args...) fprintf(OUTFILE, "ERR: %s::%s(%d) "format, __FILE__,__FUNCTION__,__LINE__,##args); \
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
105 fflush(OUTFILE);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
106
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
107 #define min(a,b) (((a) < (b)) ? (a) : (b))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
108 #define max(a,b) (((a) < (b)) ? (b) : (a))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
109
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
110 #define MAX_OUTPUT_PORTS 10
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
111 #define MAX_INPUT_PORTS 10
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
112
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
113 typedef struct jack_driver_s
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
114 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
115 bool allocated; /* whether or not this device has been allocated */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
116
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
117 int deviceID; /* id of this device */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
118 int clientCtr; /* to prevent overlapping client ids */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
119 long jack_sample_rate; /* jack samples(frames) per second */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
120
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
121 long client_sample_rate; /* client samples(frames) per second */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
122 double output_sample_rate_ratio; /* ratio between jack's output rate & ours */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
123 double input_sample_rate_ratio; /* ratio between our input rate & jack's */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
124
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
125 unsigned long num_input_channels; /* number of input channels(1 is mono, 2 stereo etc..) */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
126 unsigned long num_output_channels; /* number of output channels(1 is mono, 2 stereo etc..) */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
127
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
128 unsigned long bits_per_channel; /* number of bits per channel (only 8 & 16 are currently supported) */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
129
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
130 unsigned long bytes_per_output_frame; /* (num_output_channels * bits_per_channel) / 8 */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
131 unsigned long bytes_per_input_frame; /* (num_input_channels * bits_per_channel) / 8 */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
132
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
133 unsigned long bytes_per_jack_output_frame; /* (num_output_channels * bits_per_channel) / 8 */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
134 unsigned long bytes_per_jack_input_frame; /* (num_input_channels * bits_per_channel) / 8 */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
135
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
136 unsigned long latencyMS; /* latency in ms between writing and actual audio output of the written data */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
137
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
138 long clientBytesInJack; /* number of INPUT bytes(from the client of bio2jack) we wrote to jack(not necessary the number of bytes we wrote to jack) */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
139 long jack_buffer_size; /* size of the buffer jack will pass in to the process callback */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
140
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
141 unsigned long callback_buffer1_size; /* number of bytes in the buffer allocated for processing data in JACK_Callback */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
142 char *callback_buffer1;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
143 unsigned long callback_buffer2_size; /* number of bytes in the buffer allocated for processing data in JACK_Callback */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
144 char *callback_buffer2;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
145
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
146 unsigned long rw_buffer1_size; /* number of bytes in the buffer allocated for processing data in JACK_(Read|Write) */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
147 char *rw_buffer1;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
148
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
149 struct timeval previousTime; /* time of last JACK_Callback() write to jack, allows for MS accurate bytes played */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
150
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
151 unsigned long written_client_bytes; /* input bytes we wrote to jack, not necessarily actual bytes we wrote to jack due to channel and other conversion */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
152 unsigned long played_client_bytes; /* input bytes that jack has played */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
153
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
154 unsigned long client_bytes; /* total bytes written by the client of bio2jack via JACK_Write() */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
155
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
156 jack_port_t *output_port[MAX_OUTPUT_PORTS]; /* output ports */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
157 jack_port_t *input_port[MAX_OUTPUT_PORTS]; /* input ports */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
158
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
159 jack_client_t *client; /* pointer to jack client */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
160
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
161 char **jack_port_name; /* user given strings for the port names, can be NULL */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
162 unsigned int jack_port_name_count; /* the number of port names given */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
163
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
164 unsigned long jack_output_port_flags; /* flags to be passed to jack when opening the output ports */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
165 unsigned long jack_input_port_flags; /* flags to be passed to jack when opening the output ports */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
166
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
167 jack_ringbuffer_t *pPlayPtr; /* the playback ringbuffer */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
168 jack_ringbuffer_t *pRecPtr; /* the recording ringbuffer */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
169
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
170 SRC_STATE *output_src; /* SRC object for the output stream */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
171 SRC_STATE *input_src; /* SRC object for the output stream */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
172
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
173 enum status_enum state; /* one of PLAYING, PAUSED, STOPPED, CLOSED, RESET etc */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
174
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
175 unsigned int volume[MAX_OUTPUT_PORTS]; /* percentage of sample value to preserve, 100 would be no attenuation */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
176 enum JACK_VOLUME_TYPE volumeEffectType; /* linear or dbAttenuation, if dbAttenuation volume is the number of dBs of
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
177 attenuation to apply, 0 volume being no attenuation, full volume */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
178
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
179 long position_byte_offset; /* an offset that we will apply to returned position queries to achieve */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
180 /* the position that the user of the driver desires set */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
181
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
182 bool in_use; /* true if this device is currently in use */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
183
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
184 pthread_mutex_t mutex; /* mutex to lock this specific device */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
185
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
186 /* variables used for trying to restart the connection to jack */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
187 bool jackd_died; /* true if jackd has died and we should try to restart it */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
188 struct timeval last_reconnect_attempt;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
189 } jack_driver_t;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
190
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
191
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
192 static char *client_name; /* the name bio2jack will use when creating a new
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
193 jack client. client_name_%deviceID% will be used */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
194
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
195
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
196 static bool do_sample_rate_conversion; /* whether the client has requested sample rate conversion,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
197 default to on for improved compatibility */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
198
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
199 /*
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
200 Which SRC converter function we should use when doing sample rate conversion.
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
201 Default to the fastest of the 'good quality' set.
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
202 */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
203 static int preferred_src_converter = SRC_SINC_FASTEST;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
204
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
205 static bool init_done = 0; /* just to prevent clients from calling JACK_Init twice, that would be very bad */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
206
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
207 static enum JACK_PORT_CONNECTION_MODE port_connection_mode = CONNECT_ALL;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
208
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
209 /* enable/disable code that allows us to close a device without actually closing the jack device */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
210 /* this works around the issue where jack doesn't always close devices by the time the close function call returns */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
211 #define JACK_CLOSE_HACK 1
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
212
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
213 typedef jack_default_audio_sample_t sample_t;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
214 typedef jack_nframes_t nframes_t;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
215
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
216 /* allocate devices for output */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
217 /* if you increase this past 10, you might want to update 'out_client_name = ... ' in JACK_OpenDevice */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
218 #define MAX_OUTDEVICES 10
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
219 static jack_driver_t outDev[MAX_OUTDEVICES];
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
220
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
221 static pthread_mutex_t device_mutex = PTHREAD_MUTEX_INITIALIZER; /* this is to lock the entire outDev array
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
222 to make managing it in a threaded
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
223 environment sane */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
224
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
225 #if JACK_CLOSE_HACK
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
226 static void JACK_CloseDevice(jack_driver_t * drv, bool close_client);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
227 #else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
228 static void JACK_CloseDevice(jack_driver_t * drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
229 #endif
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
230
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
231
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
232 /* Prototypes */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
233 static int JACK_OpenDevice(jack_driver_t * drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
234 static unsigned long JACK_GetBytesFreeSpaceFromDriver(jack_driver_t * drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
235 static void JACK_ResetFromDriver(jack_driver_t * drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
236 static long JACK_GetPositionFromDriver(jack_driver_t * drv,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
237 enum pos_enum position, int type);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
238 static void JACK_CleanupDriver(jack_driver_t * drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
239
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
240
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
241 /* Return the difference between two timeval structures in terms of milliseconds */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
242 long
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
243 TimeValDifference(struct timeval *start, struct timeval *end)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
244 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
245 double long ms; /* milliseconds value */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
246
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
247 ms = end->tv_sec - start->tv_sec; /* compute seconds difference */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
248 ms *= (double) 1000; /* convert to milliseconds */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
249
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
250 ms += (double) (end->tv_usec - start->tv_usec) / (double) 1000; /* add on microseconds difference */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
251
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
252 return (long) ms;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
253 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
254
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
255 /* get a device and lock the devices mutex */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
256 /* */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
257 /* also attempt to reconnect to jack since this function is called from */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
258 /* most other bio2jack functions it provides a good point to attempt reconnection */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
259 /* */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
260 /* Ok, I know this looks complicated and it kind of is. The point is that when you're
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
261 trying to trace mutexes it's more important to know *who* called us than just that
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
262 we were called. This uses from pre-processor trickery so that the fprintf is actually
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
263 placed in the function making the getDriver call. Thus, the __FUNCTION__ and __LINE__
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
264 macros will actually reference our caller, rather than getDriver. The reason the
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
265 fprintf call is passes as a parameter is because this macro has to still return a
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
266 jack_driver_t* and we want to log both before *and* after the getDriver call for
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
267 easier detection of blocked calls.
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
268 */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
269 #if TRACE_getReleaseDevice
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
270 #define getDriver(x) _getDriver(x,fprintf(OUTFILE, "%s::%s(%d) getting driver %d\n", __FILE__, __FUNCTION__, __LINE__,x)); TRACE("got driver %d\n",x);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
271 jack_driver_t *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
272 _getDriver(int deviceID, int ignored)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
273 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
274 fflush(OUTFILE);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
275 #else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
276 jack_driver_t *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
277 getDriver(int deviceID)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
278 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
279 #endif
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
280 jack_driver_t *drv = &outDev[deviceID];
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
281
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
282 if(pthread_mutex_lock(&drv->mutex) != 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
283 ERR("lock returned an error\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
284
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
285 /* should we try to restart the jack server? */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
286 if(drv->jackd_died && drv->client == 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
287 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
288 struct timeval now;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
289 gettimeofday(&now, 0);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
290
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
291 /* wait 250ms before trying again */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
292 if(TimeValDifference(&drv->last_reconnect_attempt, &now) >= 250)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
293 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
294 JACK_OpenDevice(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
295 drv->last_reconnect_attempt = now;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
296 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
297 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
298
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
299 return drv;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
300 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
301
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
302 /* release a device's mutex */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
303 /* */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
304 /* This macro is similar to the one for getDriver above, only simpler since we only
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
305 really need to know when the lock was release for the sake of debugging.
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
306 */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
307 #if TRACE_getReleaseDevice
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
308 #define releaseDriver(x) TRACE("releasing driver %d\n",x->deviceID); _releaseDriver(x);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
309 void
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
310 _releaseDriver(jack_driver_t * drv)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
311 #else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
312 void
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
313 releaseDriver(jack_driver_t * drv)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
314 #endif
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
315 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
316 /*
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
317 #if TRACE_getReleaseDevice
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
318 TRACE("deviceID == %d\n", drv->deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
319 #endif
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
320 */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
321 if(pthread_mutex_unlock(&drv->mutex) != 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
322 ERR("lock returned an error\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
323 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
324
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
325
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
326 /* Return a string corresponding to the input state */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
327 char *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
328 DEBUGSTATE(enum status_enum state)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
329 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
330 if(state == PLAYING)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
331 return "PLAYING";
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
332 else if(state == PAUSED)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
333 return "PAUSED";
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
334 else if(state == STOPPED)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
335 return "STOPPED";
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
336 else if(state == CLOSED)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
337 return "CLOSED";
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
338 else if(state == RESET)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
339 return "RESET";
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
340 else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
341 return "unknown state";
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
342 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
343
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
344
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
345 #define SAMPLE_MAX_16BIT 32767.0f
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
346 #define SAMPLE_MAX_8BIT 127.0f
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
347
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
348 /* floating point volume routine */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
349 /* volume should be a value between 0.0 and 1.0 */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
350 static void
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
351 float_volume_effect(sample_t * buf, unsigned long nsamples, float volume,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
352 int skip)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
353 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
354 if(volume < 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
355 volume = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
356 if(volume > 1.0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
357 volume = 1.0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
358
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
359 while(nsamples--)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
360 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
361 *buf = (*buf) * volume;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
362 buf += skip;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
363 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
364 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
365
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
366 /* place one channel into a multi-channel stream */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
367 static inline void
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
368 mux(sample_t * dst, sample_t * src, unsigned long nsamples,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
369 unsigned long dst_skip)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
370 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
371 /* ALERT: signed sign-extension portability !!! */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
372 while(nsamples--)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
373 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
374 *dst = *src;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
375 dst += dst_skip;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
376 src++;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
377 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
378 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
379
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
380 /* pull one channel out of a multi-channel stream */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
381 static void
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
382 demux(sample_t * dst, sample_t * src, unsigned long nsamples,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
383 unsigned long src_skip)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
384 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
385 /* ALERT: signed sign-extension portability !!! */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
386 while(nsamples--)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
387 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
388 *dst = *src;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
389 dst++;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
390 src += src_skip;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
391 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
392 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
393
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
394 /* convert from 16 bit to floating point */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
395 static inline void
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
396 sample_move_short_float(sample_t * dst, short *src, unsigned long nsamples)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
397 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
398 /* ALERT: signed sign-extension portability !!! */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
399 unsigned long i;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
400 for(i = 0; i < nsamples; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
401 dst[i] = (sample_t) (src[i]) / SAMPLE_MAX_16BIT;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
402 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
403
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
404 /* convert from floating point to 16 bit */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
405 static inline void
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
406 sample_move_float_short(short *dst, sample_t * src, unsigned long nsamples)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
407 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
408 /* ALERT: signed sign-extension portability !!! */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
409 unsigned long i;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
410 for(i = 0; i < nsamples; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
411 dst[i] = (short) ((src[i]) * SAMPLE_MAX_16BIT);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
412 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
413
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
414 /* convert from 8 bit to floating point */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
415 static inline void
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
416 sample_move_char_float(sample_t * dst, char *src, unsigned long nsamples)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
417 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
418 /* ALERT: signed sign-extension portability !!! */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
419 unsigned long i;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
420 for(i = 0; i < nsamples; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
421 dst[i] = (sample_t) (src[i]) / SAMPLE_MAX_8BIT;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
422 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
423
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
424 /* convert from floating point to 8 bit */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
425 static inline void
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
426 sample_move_float_char(char *dst, sample_t * src, unsigned long nsamples)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
427 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
428 /* ALERT: signed sign-extension portability !!! */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
429 unsigned long i;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
430 for(i = 0; i < nsamples; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
431 dst[i] = (char) ((src[i]) * SAMPLE_MAX_8BIT);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
432 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
433
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
434 /* fill dst buffer with nsamples worth of silence */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
435 static void inline
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
436 sample_silence_float(sample_t * dst, unsigned long nsamples)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
437 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
438 /* ALERT: signed sign-extension portability !!! */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
439 while(nsamples--)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
440 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
441 *dst = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
442 dst++;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
443 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
444 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
445
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
446 static bool inline
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
447 ensure_buffer_size(char **buffer, unsigned long *cur_size,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
448 unsigned long needed_size)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
449 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
450 DEBUG("current size = %lu, needed size = %lu\n", *cur_size, needed_size);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
451 if(*cur_size >= needed_size)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
452 return TRUE;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
453 DEBUG("reallocing\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
454 char *tmp = realloc(*buffer, needed_size);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
455 if(tmp)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
456 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
457 *cur_size = needed_size;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
458 *buffer = tmp;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
459 return TRUE;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
460 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
461 DEBUG("reallocing failed\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
462 return FALSE;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
463 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
464
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
465 /******************************************************************
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
466 * JACK_callback
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
467 *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
468 * every time the jack server wants something from us it calls this
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
469 * function, so we either deliver it some sound to play or deliver it nothing
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
470 * to play
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
471 */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
472 static int
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
473 JACK_callback(nframes_t nframes, void *arg)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
474 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
475 jack_driver_t *drv = (jack_driver_t *) arg;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
476
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
477 unsigned int i;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
478 int src_error = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
479
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
480 TIMER("start\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
481 gettimeofday(&drv->previousTime, 0); /* record the current time */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
482
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
483 CALLBACK_TRACE("nframes %ld, sizeof(sample_t) == %d\n", (long) nframes,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
484 sizeof(sample_t));
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
485
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
486 if(!drv->client)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
487 ERR("client is closed, this is weird...\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
488
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
489 sample_t *out_buffer[MAX_OUTPUT_PORTS];
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
490 /* retrieve the buffers for the output ports */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
491 for(i = 0; i < drv->num_output_channels; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
492 out_buffer[i] = (sample_t *) jack_port_get_buffer(drv->output_port[i], nframes);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
493
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
494 sample_t *in_buffer[MAX_INPUT_PORTS];
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
495 /* retrieve the buffers for the input ports */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
496 for(i = 0; i < drv->num_input_channels; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
497 in_buffer[i] = (sample_t *) jack_port_get_buffer(drv->input_port[i], nframes);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
498
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
499 /* handle playing state */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
500 if(drv->state == PLAYING)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
501 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
502 /* handle playback data, if any */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
503 if(drv->num_output_channels > 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
504 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
505 unsigned long jackFramesAvailable = nframes; /* frames we have left to write to jack */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
506 unsigned long numFramesToWrite; /* num frames we are writing */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
507 size_t inputBytesAvailable = jack_ringbuffer_read_space(drv->pPlayPtr);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
508 unsigned long inputFramesAvailable; /* frames we have available */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
509
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
510 inputFramesAvailable = inputBytesAvailable / drv->bytes_per_jack_output_frame;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
511 size_t jackBytesAvailable = jackFramesAvailable * drv->bytes_per_jack_output_frame;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
512
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
513 long read = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
514
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
515 CALLBACK_TRACE("playing... jackFramesAvailable = %ld inputFramesAvailable = %ld\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
516 jackFramesAvailable, inputFramesAvailable);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
517
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
518 #if JACK_CLOSE_HACK
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
519 if(drv->in_use == FALSE)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
520 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
521 /* output silence if nothing is being outputted */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
522 for(i = 0; i < drv->num_output_channels; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
523 sample_silence_float(out_buffer[i], nframes);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
524
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
525 return -1;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
526 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
527 #endif
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
528
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
529 /* make sure our buffer is large enough for the data we are writing */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
530 /* ie. callback_buffer1_size < (bytes we already wrote + bytes we are going to write in this loop) */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
531 if(!ensure_buffer_size
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
532 (&drv->callback_buffer1, &drv->callback_buffer1_size,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
533 jackBytesAvailable))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
534 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
535 ERR("allocated %lu bytes, need %u bytes\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
536 drv->callback_buffer1_size, jackBytesAvailable);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
537 return -1;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
538 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
539
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
540 /* do sample rate conversion if needed & requested */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
541 if(drv->output_src && drv->output_sample_rate_ratio != 1.0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
542 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
543 long bytes_needed_write = nframes * drv->bytes_per_jack_output_frame;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
544
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
545 /* make a very good guess at how many raw bytes we'll need to satisfy jack's request after conversion */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
546 long bytes_needed_read = min(inputBytesAvailable,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
547 (double) (bytes_needed_write +
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
548 drv->
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
549 output_sample_rate_ratio
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
550 *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
551 drv->
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
552 bytes_per_jack_output_frame)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
553 / drv->output_sample_rate_ratio);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
554 DEBUG("guessing that we need %ld bytes in and %ld out for rate conversion ratio = %f\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
555 bytes_needed_read, bytes_needed_write,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
556 drv->output_sample_rate_ratio);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
557
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
558 if(!ensure_buffer_size(&drv->callback_buffer1,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
559 &drv->callback_buffer1_size,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
560 bytes_needed_read))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
561 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
562 ERR("could not realloc callback_buffer2!\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
563 return 1;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
564 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
565 if(!ensure_buffer_size(&drv->callback_buffer2,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
566 &drv->callback_buffer2_size,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
567 bytes_needed_write))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
568 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
569 ERR("could not realloc callback_buffer2!\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
570 return 1;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
571 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
572
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
573 if(jackFramesAvailable && inputBytesAvailable > 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
574 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
575 /* read in the data, but don't move the read pointer until we know how much SRC used */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
576 jack_ringbuffer_peek(drv->pPlayPtr, drv->callback_buffer1,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
577 bytes_needed_read);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
578
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
579 SRC_DATA srcdata;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
580 srcdata.data_in = (sample_t *) drv->callback_buffer1;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
581 srcdata.input_frames = bytes_needed_read / drv->bytes_per_jack_output_frame;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
582 srcdata.src_ratio = drv->output_sample_rate_ratio;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
583 srcdata.data_out = (sample_t *) drv->callback_buffer2;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
584 srcdata.output_frames = nframes;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
585 srcdata.end_of_input = 0; // it's a stream, it never ends
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
586 DEBUG("input_frames = %ld, output_frames = %ld\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
587 srcdata.input_frames, srcdata.output_frames);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
588 /* convert the sample rate */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
589 src_error = src_process(drv->output_src, &srcdata);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
590 DEBUG("used = %ld, generated = %ld, error = %d: %s.\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
591 srcdata.input_frames_used, srcdata.output_frames_gen,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
592 src_error, src_strerror(src_error));
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
593
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
594 if(src_error == 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
595 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
596 /* now we can move the read pointer */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
597 jack_ringbuffer_read_advance(drv->pPlayPtr,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
598 srcdata.
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
599 input_frames_used *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
600 drv->bytes_per_jack_output_frame);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
601 /* add on what we wrote */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
602 read = srcdata.input_frames_used * drv->bytes_per_output_frame;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
603 jackFramesAvailable -= srcdata.output_frames_gen; /* take away what was used */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
604 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
605 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
606
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
607 if(src_error == 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
608 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
609 /* demux the stream: we skip over the number of samples we have output channels as the channel data */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
610 /* is encoded like chan1,chan2,chan3,chan1,chan2,chan3... */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
611 for(i = 0; i < drv->num_output_channels; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
612 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
613 demux(out_buffer[i],
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
614 (sample_t *) drv->callback_buffer2 + i,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
615 (nframes - jackFramesAvailable), drv->num_output_channels);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
616 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
617 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
618 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
619 else /* no resampling needed or requested */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
620 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
621 /* read as much data from the buffer as is available */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
622 if(jackFramesAvailable && inputBytesAvailable > 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
623 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
624 /* write as many bytes as we have space remaining, or as much as we have data to write */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
625 numFramesToWrite = min(jackFramesAvailable, inputFramesAvailable);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
626 jack_ringbuffer_read(drv->pPlayPtr, drv->callback_buffer1,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
627 jackBytesAvailable);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
628 /* add on what we wrote */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
629 read = numFramesToWrite * drv->bytes_per_output_frame;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
630 jackFramesAvailable -= numFramesToWrite; /* take away what was written */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
631 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
632 /* demux the stream: we skip over the number of samples we have output channels as the channel data */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
633 /* is encoded like chan1,chan2,chan3,chan1,chan2,chan3... */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
634 for(i = 0; i < drv->num_output_channels; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
635 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
636 demux(out_buffer[i],
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
637 (sample_t *) drv->callback_buffer1 + i,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
638 (nframes - jackFramesAvailable), drv->num_output_channels);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
639 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
640 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
641
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
642 drv->written_client_bytes += read;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
643 drv->played_client_bytes += drv->clientBytesInJack; /* move forward by the previous bytes we wrote since those must have finished by now */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
644 drv->clientBytesInJack = read; /* record the input bytes we wrote to jack */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
645
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
646 /* see if we still have jackBytesLeft here, if we do that means that we
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
647 ran out of wave data to play and had a buffer underrun, fill in
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
648 the rest of the space with zero bytes so at least there is silence */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
649 if(jackFramesAvailable)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
650 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
651 WARN("buffer underrun of %ld frames\n", jackFramesAvailable);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
652 for(i = 0; i < drv->num_output_channels; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
653 sample_silence_float(out_buffer[i] +
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
654 (nframes - jackFramesAvailable),
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
655 jackFramesAvailable);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
656 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
657 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
658
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
659 /* handle record data, if any */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
660 if(drv->num_input_channels > 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
661 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
662 long jack_bytes = nframes * drv->bytes_per_jack_input_frame; /* how many bytes jack is feeding us */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
663
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
664 if(!ensure_buffer_size(&drv->callback_buffer1, &drv->callback_buffer1_size, jack_bytes))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
665 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
666 ERR("allocated %lu bytes, need %lu bytes\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
667 drv->callback_buffer1_size, jack_bytes);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
668 return -1;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
669 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
670
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
671 /* mux the invividual channels into one stream */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
672 for(i = 0; i < drv->num_input_channels; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
673 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
674 mux((sample_t *) drv->callback_buffer1 + i, in_buffer[i],
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
675 nframes, drv->num_input_channels);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
676 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
677
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
678 /* do sample rate conversion if needed & requested */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
679 if(drv->input_src && drv->input_sample_rate_ratio != 1.0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
680 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
681 /* make a very good guess at how many raw bytes we'll need to read all the data jack gave us */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
682 long bytes_needed_write = (double) (jack_bytes +
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
683 drv->input_sample_rate_ratio *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
684 drv->bytes_per_jack_input_frame) *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
685 drv->input_sample_rate_ratio;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
686 DEBUG("guessing that we need %ld bytes in and %ld out for rate conversion ratio = %f\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
687 nframes * drv->bytes_per_jack_input_frame,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
688 bytes_needed_write, drv->input_sample_rate_ratio);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
689
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
690 if(!ensure_buffer_size(&drv->callback_buffer2,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
691 &drv->callback_buffer2_size,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
692 bytes_needed_write))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
693 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
694 ERR("could not realloc callback_buffer2!\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
695 return 1;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
696 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
697
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
698 SRC_DATA srcdata;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
699 srcdata.data_in = (sample_t *) drv->callback_buffer1;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
700 srcdata.input_frames = nframes;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
701 srcdata.src_ratio = drv->input_sample_rate_ratio;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
702 srcdata.data_out = (sample_t *) drv->callback_buffer2;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
703 srcdata.output_frames = drv->callback_buffer2_size / drv->bytes_per_jack_input_frame;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
704 srcdata.end_of_input = 0; // it's a stream, it never ends
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
705 DEBUG("input_frames = %ld, output_frames = %ld\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
706 srcdata.input_frames, srcdata.output_frames);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
707 /* convert the sample rate */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
708 src_error = src_process(drv->input_src, &srcdata);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
709 DEBUG("used = %ld, generated = %ld, error = %d: %s.\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
710 srcdata.input_frames_used, srcdata.output_frames_gen,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
711 src_error, src_strerror(src_error));
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
712
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
713 if(src_error == 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
714 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
715 long write_space = jack_ringbuffer_write_space(drv->pRecPtr);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
716 long bytes_used = srcdata.output_frames_gen * drv->bytes_per_jack_input_frame;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
717 /* if there isn't enough room, make some. sure this discards data, but when dealing with input sources
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
718 it seems like it's better to throw away old data than new */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
719 if(write_space < bytes_used)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
720 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
721 /* the ringbuffer is designed such that only one thread should ever access each pointer.
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
722 since calling read_advance here will be touching the read pointer which is also accessed
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
723 by JACK_Read, we need to lock the mutex first for safety */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
724 getDriver(drv->deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
725
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
726 /* double check the write space after we've gained the lock, just in case JACK_Read was being called
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
727 before we gained it */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
728 write_space = jack_ringbuffer_write_space(drv->pRecPtr);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
729 if(write_space < bytes_used)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
730 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
731 /* hey, we warn about underruns, we might as well warn about overruns as well */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
732 WARN("buffer overrun of %ld bytes\n", jack_bytes - write_space);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
733 jack_ringbuffer_read_advance(drv->pRecPtr,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
734 bytes_used - write_space);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
735 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
736 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
737 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
738
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
739 jack_ringbuffer_write(drv->pRecPtr, drv->callback_buffer2,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
740 bytes_used);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
741 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
742 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
743 else /* no resampling needed */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
744 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
745 long write_space = jack_ringbuffer_write_space(drv->pRecPtr);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
746 /* if there isn't enough room, make some. sure this discards data, but when dealing with input sources
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
747 it seems like it's better to throw away old data than new */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
748 if(write_space < jack_bytes)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
749 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
750 /* the ringbuffer is designed such that only one thread should ever access each pointer.
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
751 since calling read_advance here will be touching the read pointer which is also accessed
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
752 by JACK_Read, we need to lock the mutex first for safety */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
753 getDriver(drv->deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
754
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
755 /* double check the write space after we've gained the lock, just in case JACK_Read was being called
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
756 before we gained it */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
757 write_space = jack_ringbuffer_write_space(drv->pRecPtr);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
758 if(write_space < jack_bytes)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
759 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
760 ERR("buffer overrun of %ld bytes\n", jack_bytes - write_space);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
761 jack_ringbuffer_read_advance(drv->pRecPtr,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
762 jack_bytes - write_space);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
763 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
764 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
765 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
766
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
767 jack_ringbuffer_write(drv->pRecPtr, drv->callback_buffer1,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
768 jack_bytes);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
769 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
770 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
771 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
772 else if(drv->state == PAUSED ||
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
773 drv->state == STOPPED ||
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
774 drv->state == CLOSED || drv->state == RESET)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
775 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
776 CALLBACK_TRACE("%s, outputting silence\n", DEBUGSTATE(drv->state));
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
777
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
778 /* output silence if nothing is being outputted */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
779 for(i = 0; i < drv->num_output_channels; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
780 sample_silence_float(out_buffer[i], nframes);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
781
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
782 /* if we were told to reset then zero out some variables */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
783 /* and transition to STOPPED */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
784 if(drv->state == RESET)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
785 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
786 drv->written_client_bytes = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
787 drv->played_client_bytes = 0; /* number of the clients bytes that jack has played */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
788
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
789 drv->client_bytes = 0; /* bytes that the client wrote to use */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
790
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
791 drv->clientBytesInJack = 0; /* number of input bytes in jack(not necessary the number of bytes written to jack) */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
792
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
793 drv->position_byte_offset = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
794
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
795 if(drv->pPlayPtr)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
796 jack_ringbuffer_reset(drv->pPlayPtr);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
797
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
798 if(drv->pRecPtr)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
799 jack_ringbuffer_reset(drv->pRecPtr);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
800
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
801 drv->state = STOPPED; /* transition to STOPPED */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
802 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
803 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
804
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
805 CALLBACK_TRACE("done\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
806 TIMER("finish\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
807
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
808 return 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
809 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
810
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
811
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
812 /******************************************************************
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
813 * JACK_bufsize
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
814 *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
815 * Called whenever the jack server changes the the max number
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
816 * of frames passed to JACK_callback
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
817 */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
818 static int
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
819 JACK_bufsize(nframes_t nframes, void *arg)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
820 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
821 jack_driver_t *drv = (jack_driver_t *) arg;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
822 TRACE("the maximum buffer size is now %lu frames\n", (long) nframes);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
823
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
824 drv->jack_buffer_size = nframes;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
825
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
826 return 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
827 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
828
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
829 /******************************************************************
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
830 * JACK_srate
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
831 */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
832 int
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
833 JACK_srate(nframes_t nframes, void *arg)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
834 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
835 jack_driver_t *drv = (jack_driver_t *) arg;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
836
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
837 drv->jack_sample_rate = (long) nframes;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
838
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
839 /* make sure to recalculate the ratios needed for proper sample rate conversion */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
840 drv->output_sample_rate_ratio = (double) drv->jack_sample_rate / (double) drv->client_sample_rate;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
841 if(drv->output_src) src_set_ratio(drv->output_src, drv->output_sample_rate_ratio);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
842
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
843 drv->input_sample_rate_ratio = (double) drv->client_sample_rate / (double) drv->jack_sample_rate;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
844 if(drv->input_src) src_set_ratio(drv->input_src, drv->input_sample_rate_ratio);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
845
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
846 TRACE("the sample rate is now %lu/sec\n", (long) nframes);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
847 return 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
848 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
849
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
850
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
851 /******************************************************************
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
852 * JACK_shutdown
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
853 *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
854 * if this is called then jack shut down... handle this appropriately */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
855 void
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
856 JACK_shutdown(void *arg)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
857 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
858 jack_driver_t *drv = (jack_driver_t *) arg;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
859
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
860 TRACE("\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
861
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
862 getDriver(drv->deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
863
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
864 drv->client = 0; /* reset client */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
865 drv->jackd_died = TRUE;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
866
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
867 TRACE("jack shutdown, setting client to 0 and jackd_died to true, closing device\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
868
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
869 #if JACK_CLOSE_HACK
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
870 JACK_CloseDevice(drv, TRUE);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
871 #else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
872 JACK_CloseDevice(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
873 #endif
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
874
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
875 TRACE("trying to reconnect right now\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
876 /* lets see if we can't reestablish the connection */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
877 if(JACK_OpenDevice(drv) != ERR_SUCCESS)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
878 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
879 ERR("unable to reconnect with jack\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
880 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
881
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
882 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
883 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
884
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
885
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
886 /******************************************************************
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
887 * JACK_Error
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
888 *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
889 * Callback for jack errors
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
890 */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
891 static void
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
892 JACK_Error(const char *desc)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
893 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
894 ERR("%s\n", desc);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
895 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
896
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
897
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
898 /******************************************************************
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
899 * JACK_OpenDevice
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
900 *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
901 * RETURNS: ERR_SUCCESS upon success
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
902 */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
903 static int
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
904 JACK_OpenDevice(jack_driver_t * drv)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
905 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
906 const char **ports;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
907 char *our_client_name = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
908 unsigned int i;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
909 int failed = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
910
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
911 TRACE("creating jack client and setting up callbacks\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
912
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
913 #if JACK_CLOSE_HACK
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
914 /* see if this device is already open */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
915 if(drv->client)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
916 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
917 /* if this device is already in use then it is bad for us to be in here */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
918 if(drv->in_use)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
919 return ERR_OPENING_JACK;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
920
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
921 TRACE("using existing client\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
922 drv->in_use = TRUE;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
923 return ERR_SUCCESS;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
924 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
925 #endif
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
926
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
927 /* set up an error handler */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
928 jack_set_error_function(JACK_Error);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
929
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
930
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
931 /* build the client name */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
932 our_client_name = (char *) malloc(snprintf
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
933 (our_client_name, 0, "%s_%d_%d%02d", client_name, getpid(),
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
934 drv->deviceID, drv->clientCtr + 1) + 1);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
935 sprintf(our_client_name, "%s_%d_%d%02d", client_name, getpid(),
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
936 drv->deviceID, drv->clientCtr++);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
937
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
938 /* try to become a client of the JACK server */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
939 TRACE("client name '%s'\n", our_client_name);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
940 if((drv->client = jack_client_new(our_client_name)) == 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
941 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
942 /* try once more */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
943 TRACE("trying once more to jack_client_new");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
944 if((drv->client = jack_client_new(our_client_name)) == 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
945 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
946 ERR("jack server not running?\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
947 free(our_client_name);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
948 return ERR_OPENING_JACK;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
949 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
950 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
951
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
952 free(our_client_name);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
953
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
954 TRACE("setting up jack callbacks\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
955
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
956 /* JACK server to call `JACK_callback()' whenever
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
957 there is work to be done. */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
958 jack_set_process_callback(drv->client, JACK_callback, drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
959
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
960 /* setup a buffer size callback */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
961 jack_set_buffer_size_callback(drv->client, JACK_bufsize, drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
962
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
963 /* tell the JACK server to call `srate()' whenever
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
964 the sample rate of the system changes. */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
965 jack_set_sample_rate_callback(drv->client, JACK_srate, drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
966
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
967 /* tell the JACK server to call `jack_shutdown()' if
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
968 it ever shuts down, either entirely, or if it
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
969 just decides to stop calling us. */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
970 jack_on_shutdown(drv->client, JACK_shutdown, drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
971
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
972 /* display the current sample rate. once the client is activated
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
973 (see below), you should rely on your own sample rate
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
974 callback (see above) for this value. */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
975 drv->jack_sample_rate = jack_get_sample_rate(drv->client);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
976 drv->output_sample_rate_ratio = (double) drv->jack_sample_rate / (double) drv->client_sample_rate;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
977 drv->input_sample_rate_ratio = (double) drv->client_sample_rate / (double) drv->jack_sample_rate;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
978 TRACE("client sample rate: %lu, jack sample rate: %lu, output ratio = %f, input ratio = %f\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
979 drv->client_sample_rate, drv->jack_sample_rate,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
980 drv->output_sample_rate_ratio, drv->input_sample_rate_ratio);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
981
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
982 drv->jack_buffer_size = jack_get_buffer_size(drv->client);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
983
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
984 /* create the output ports */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
985 TRACE("creating output ports\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
986 for(i = 0; i < drv->num_output_channels; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
987 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
988 char portname[32];
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
989 sprintf(portname, "out_%d", i);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
990 TRACE("port %d is named '%s'\n", i, portname);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
991 /* NOTE: Yes, this is supposed to be JackPortIsOutput since this is an output */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
992 /* port FROM bio2jack */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
993 drv->output_port[i] = jack_port_register(drv->client, portname,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
994 JACK_DEFAULT_AUDIO_TYPE,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
995 JackPortIsOutput, 0);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
996 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
997
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
998 /* create the input ports */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
999 TRACE("creating input ports\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1000 for(i = 0; i < drv->num_input_channels; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1001 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1002 char portname[32];
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1003 sprintf(portname, "in_%d", i);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1004 TRACE("port %d is named '%s'\n", i, portname);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1005 /* NOTE: Yes, this is supposed to be JackPortIsInput since this is an input */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1006 /* port TO bio2jack */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1007 drv->input_port[i] = jack_port_register(drv->client, portname,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1008 JACK_DEFAULT_AUDIO_TYPE,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1009 JackPortIsInput, 0);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1010 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1011
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1012 #if JACK_CLOSE_HACK
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1013 drv->in_use = TRUE;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1014 #endif
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1015
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1016 /* tell the JACK server that we are ready to roll */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1017 TRACE("calling jack_activate()\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1018 if(jack_activate(drv->client))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1019 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1020 ERR("cannot activate client\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1021 return ERR_OPENING_JACK;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1022 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1023
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1024 /* if we have output channels and the port connection mode isn't CONNECT_NONE */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1025 /* then we should connect up some ports */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1026 if((drv->num_output_channels > 0) && (port_connection_mode != CONNECT_NONE))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1027 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1028 /* determine how we are to acquire output port names */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1029 if((drv->jack_port_name_count == 0) || (drv->jack_port_name_count == 1))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1030 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1031 if(drv->jack_port_name_count == 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1032 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1033 TRACE("jack_get_ports() passing in NULL/NULL\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1034 ports = jack_get_ports(drv->client, NULL, NULL,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1035 drv->jack_output_port_flags);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1036 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1037 else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1038 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1039 TRACE("jack_get_ports() passing in port of '%s'\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1040 drv->jack_port_name[0]);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1041 ports = jack_get_ports(drv->client, drv->jack_port_name[0], NULL,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1042 drv->jack_output_port_flags);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1043 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1044
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1045 /* display a trace of the output ports we found */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1046 int num_ports = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1047 if(ports)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1048 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1049 for(i = 0; ports[i]; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1050 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1051 TRACE("ports[%d] = '%s'\n", i, ports[i]);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1052 num_ports++;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1053 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1054 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1055
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1056 /* ensure that we found enough ports */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1057 if(!ports || (i < drv->num_output_channels))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1058 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1059 TRACE("ERR: jack_get_ports() failed to find ports with jack port flags of 0x%lX'\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1060 drv->jack_output_port_flags);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1061 #if JACK_CLOSE_HACK
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1062 JACK_CloseDevice(drv, TRUE);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1063 #else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1064 JACK_CloseDevice(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1065 #endif
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1066 return ERR_PORT_NOT_FOUND;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1067 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1068
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1069 /* connect a port for each output channel. Note: you can't do this before
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1070 the client is activated (this may change in the future). */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1071 for(i = 0; i < drv->num_output_channels; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1072 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1073 TRACE("jack_connect() to port %d('%p')\n", i, drv->output_port[i]);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1074 if(jack_connect(drv->client, jack_port_name(drv->output_port[i]), ports[i]))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1075 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1076 ERR("cannot connect to output port %d('%s')\n", i, ports[i]);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1077 failed = 1;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1078 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1079 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1080
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1081 /* only if we are in CONNECT_ALL mode should we keep connecting ports up beyond */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1082 /* the minimum number of ports required for each output channel coming into bio2jack */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1083 if(port_connection_mode == CONNECT_ALL)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1084 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1085 /* It's much cheaper and easier to let JACK do the processing required to
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1086 connect 2 channels to 4 or 4 channels to 2 or any other combinations.
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1087 This effectively eliminates the need for sample_move_d16_d16() */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1088 if(drv->num_output_channels < num_ports)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1089 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1090 for(i = drv->num_output_channels; ports[i]; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1091 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1092 int n = i % drv->num_output_channels;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1093 TRACE("jack_connect() to port %d('%p')\n", i, drv->output_port[n]);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1094 if(jack_connect(drv->client, jack_port_name(drv->output_port[n]), ports[i]))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1095 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1096 // non fatal
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1097 ERR("cannot connect to output port %d('%s')\n", n, ports[i]);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1098 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1099 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1100 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1101 else if(drv->num_output_channels > num_ports)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1102 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1103 for(i = num_ports; i < drv->num_output_channels; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1104 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1105 int n = i % num_ports;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1106 TRACE("jack_connect() to port %d('%p')\n", i, drv->output_port[n]);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1107 if(jack_connect(drv->client, jack_port_name(drv->output_port[i]), ports[n]))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1108 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1109 // non fatal
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1110 ERR("cannot connect to output port %d('%s')\n", i, ports[n]);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1111 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1112 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1113 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1114 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1115
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1116 free(ports); /* free the returned array of ports */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1117 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1118 else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1119 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1120 for(i = 0; i < drv->jack_port_name_count; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1121 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1122 TRACE("jack_get_ports() portname %d of '%s\n", i,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1123 drv->jack_port_name[i]);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1124 ports = jack_get_ports(drv->client, drv->jack_port_name[i], NULL,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1125 drv->jack_output_port_flags);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1126
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1127 if(!ports)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1128 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1129 ERR("jack_get_ports() failed to find ports with jack port flags of 0x%lX'\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1130 drv->jack_output_port_flags);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1131 return ERR_PORT_NOT_FOUND;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1132 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1133
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1134 TRACE("ports[%d] = '%s'\n", 0, ports[0]); /* display a trace of the output port we found */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1135
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1136 /* connect the port */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1137 TRACE("jack_connect() to port %d('%p')\n", i, drv->output_port[i]);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1138 if(jack_connect(drv->client, jack_port_name(drv->output_port[i]), ports[0]))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1139 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1140 ERR("cannot connect to output port %d('%s')\n", 0, ports[0]);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1141 failed = 1;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1142 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1143 free(ports); /* free the returned array of ports */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1144 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1145 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1146 } /* if( drv->num_output_channels > 0 ) */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1147
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1148
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1149 if(drv->num_input_channels > 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1150 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1151 /* determine how we are to acquire input port names */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1152 if((drv->jack_port_name_count == 0) || (drv->jack_port_name_count == 1))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1153 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1154 if(drv->jack_port_name_count == 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1155 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1156 TRACE("jack_get_ports() passing in NULL/NULL\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1157 ports = jack_get_ports(drv->client, NULL, NULL, drv->jack_input_port_flags);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1158 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1159 else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1160 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1161 TRACE("jack_get_ports() passing in port of '%s'\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1162 drv->jack_port_name[0]);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1163 ports = jack_get_ports(drv->client, drv->jack_port_name[0], NULL,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1164 drv->jack_input_port_flags);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1165 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1166
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1167 /* display a trace of the input ports we found */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1168 int num_ports = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1169 if(ports)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1170 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1171 for(i = 0; ports[i]; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1172 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1173 TRACE("ports[%d] = '%s'\n", i, ports[i]);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1174 num_ports++;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1175 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1176 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1177
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1178 /* ensure that we found enough ports */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1179 if(!ports || (i < drv->num_input_channels))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1180 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1181 TRACE("ERR: jack_get_ports() failed to find ports with jack port flags of 0x%lX'\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1182 drv->jack_input_port_flags);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1183 #if JACK_CLOSE_HACK
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1184 JACK_CloseDevice(drv, TRUE);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1185 #else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1186 JACK_CloseDevice(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1187 #endif
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1188 return ERR_PORT_NOT_FOUND;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1189 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1190
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1191 /* connect the ports. Note: you can't do this before
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1192 the client is activated (this may change in the future). */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1193 for(i = 0; i < drv->num_input_channels; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1194 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1195 TRACE("jack_connect() to port %d('%p')\n", i, drv->input_port[i]);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1196 if(jack_connect(drv->client, ports[i], jack_port_name(drv->input_port[i])))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1197 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1198 ERR("cannot connect to input port %d('%s')\n", i, ports[i]);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1199 failed = 1;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1200 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1201 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1202
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1203 /* It's much cheaper and easier to let JACK do the processing required to
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1204 connect 2 channels to 4 or 4 channels to 2 or any other combinations.
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1205 This effectively eliminates the need for sample_move_d16_d16() */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1206 if(drv->num_input_channels < num_ports)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1207 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1208 for(i = drv->num_input_channels; ports[i]; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1209 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1210 int n = i % drv->num_input_channels;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1211 TRACE("jack_connect() to port %d('%p')\n", i, drv->input_port[n]);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1212 if(jack_connect(drv->client, ports[i], jack_port_name(drv->input_port[n])))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1213 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1214 // non fatal
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1215 ERR("cannot connect to input port %d('%s')\n", n, ports[i]);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1216 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1217 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1218 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1219 else if(drv->num_input_channels > num_ports)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1220 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1221 for(i = num_ports; i < drv->num_input_channels; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1222 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1223 int n = i % num_ports;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1224 TRACE("jack_connect() to port %d('%p')\n", i, drv->input_port[n]);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1225 if(jack_connect(drv->client, ports[n], jack_port_name(drv->input_port[i])))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1226 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1227 // non fatal
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1228 ERR("cannot connect to input port %d('%s')\n", i, ports[n]);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1229 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1230 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1231 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1232
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1233 free(ports); /* free the returned array of ports */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1234 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1235 else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1236 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1237 for(i = 0; i < drv->jack_port_name_count; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1238 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1239 TRACE("jack_get_ports() portname %d of '%s\n", i,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1240 drv->jack_port_name[i]);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1241 ports = jack_get_ports(drv->client, drv->jack_port_name[i], NULL,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1242 drv->jack_input_port_flags);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1243
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1244 if(!ports)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1245 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1246 ERR("jack_get_ports() failed to find ports with jack port flags of 0x%lX'\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1247 drv->jack_input_port_flags);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1248 return ERR_PORT_NOT_FOUND;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1249 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1250
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1251 TRACE("ports[%d] = '%s'\n", 0, ports[0]); /* display a trace of the input port we found */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1252
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1253 /* connect the port */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1254 TRACE("jack_connect() to port %d('%p')\n", i, drv->input_port[i]);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1255 if(jack_connect(drv->client, jack_port_name(drv->input_port[i]), ports[0]))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1256 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1257 ERR("cannot connect to input port %d('%s')\n", 0, ports[0]);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1258 failed = 1;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1259 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1260 free(ports); /* free the returned array of ports */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1261 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1262 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1263 } /* if( drv->num_input_channels > 0 ) */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1264
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1265 /* if something failed we need to shut the client down and return 0 */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1266 if(failed)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1267 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1268 TRACE("failed, closing and returning error\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1269 #if JACK_CLOSE_HACK
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1270 JACK_CloseDevice(drv, TRUE);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1271 #else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1272 JACK_CloseDevice(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1273 #endif
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1274 return ERR_OPENING_JACK;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1275 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1276
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1277 TRACE("success\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1278
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1279 drv->jackd_died = FALSE; /* clear out this flag so we don't keep attempting to restart things */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1280 drv->state = PLAYING; /* clients seem to behave much better with this on from the start, especially when recording */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1281
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1282 return ERR_SUCCESS; /* return success */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1283 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1284
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1285
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1286 /******************************************************************
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1287 * JACK_CloseDevice
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1288 *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1289 * Close the connection to the server cleanly.
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1290 * If close_client is TRUE we close the client for this device instead of
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1291 * just marking the device as in_use(JACK_CLOSE_HACK only)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1292 */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1293 #if JACK_CLOSE_HACK
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1294 static void
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1295 JACK_CloseDevice(jack_driver_t * drv, bool close_client)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1296 #else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1297 static void
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1298 JACK_CloseDevice(jack_driver_t * drv)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1299 #endif
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1300 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1301 unsigned int i;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1302
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1303 #if JACK_CLOSE_HACK
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1304 if(close_client)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1305 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1306 #endif
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1307
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1308 TRACE("closing the jack client thread\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1309 if(drv->client)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1310 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1311 TRACE("after jack_deactivate()\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1312 int errorCode = jack_client_close(drv->client);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1313 if(errorCode)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1314 ERR("jack_client_close() failed returning an error code of %d\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1315 errorCode);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1316 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1317
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1318 /* reset client */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1319 drv->client = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1320
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1321 /* free up the port strings */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1322 TRACE("freeing up %d port strings\n", drv->jack_port_name_count);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1323 if(drv->jack_port_name_count > 1)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1324 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1325 for(i = 0; i < drv->jack_port_name_count; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1326 free(drv->jack_port_name[i]);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1327 free(drv->jack_port_name);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1328 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1329 JACK_CleanupDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1330
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1331 JACK_ResetFromDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1332
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1333 #if JACK_CLOSE_HACK
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1334 } else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1335 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1336 TRACE("setting in_use to FALSE\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1337 drv->in_use = FALSE;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1338
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1339 if(!drv->client)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1340 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1341 TRACE("critical error, closing a device that has no client\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1342 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1343 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1344 #endif
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1345 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1346
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1347
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1348
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1349
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1350 /**************************************/
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1351 /* External interface functions below */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1352 /**************************************/
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1353
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1354 /* Clear out any buffered data, stop playing, zero out some variables */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1355 static void
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1356 JACK_ResetFromDriver(jack_driver_t * drv)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1357 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1358 TRACE("resetting drv->deviceID(%d)\n", drv->deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1359
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1360 /* NOTE: we use the RESET state so we don't need to worry about clearing out */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1361 /* variables that the callback modifies while the callback is running */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1362 /* we set the state to RESET and the callback clears the variables out for us */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1363 drv->state = RESET; /* tell the callback that we are to reset, the callback will transition this to STOPPED */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1364 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1365
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1366 /* Clear out any buffered data, stop playing, zero out some variables */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1367 void
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1368 JACK_Reset(int deviceID)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1369 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1370 jack_driver_t *drv = getDriver(deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1371 TRACE("resetting deviceID(%d)\n", deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1372 JACK_ResetFromDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1373 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1374 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1375
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1376
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1377 /*
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1378 * open the audio device for writing to
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1379 *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1380 * deviceID is set to the opened device
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1381 * if client is non-zero and in_use is FALSE then just set in_use to TRUE
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1382 *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1383 * return value is zero upon success, non-zero upon failure
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1384 *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1385 * if ERR_RATE_MISMATCH (*rate) will be updated with the jack servers rate
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1386 */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1387 int
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1388 JACK_Open(int *deviceID, unsigned int bits_per_channel, unsigned long *rate,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1389 int channels)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1390 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1391 /* we call through to JACK_OpenEx(), but default the input channels to 0 for better backwards
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1392 compatibility with clients written before recording was available */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1393 return JACK_OpenEx(deviceID, bits_per_channel,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1394 rate,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1395 0, channels,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1396 NULL, 0, JackPortIsPhysical);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1397 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1398
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1399 /*
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1400 * see JACK_Open() for comments
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1401 * NOTE: jack_port_name has three ways of being used:
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1402 * - NULL - finds all ports with the given flags
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1403 * - A single regex string used to retrieve all port names
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1404 * - A series of port names, one for each output channel
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1405 *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1406 * we set *deviceID
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1407 */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1408 int
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1409 JACK_OpenEx(int *deviceID, unsigned int bits_per_channel,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1410 unsigned long *rate,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1411 unsigned int input_channels, unsigned int output_channels,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1412 const char **jack_port_name,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1413 unsigned int jack_port_name_count, unsigned long jack_port_flags)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1414 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1415 jack_driver_t *drv = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1416 unsigned int i;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1417 int retval;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1418
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1419 if(input_channels < 1 && output_channels < 1)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1420 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1421 ERR("no input OR output channels, nothing to do\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1422 return ERR_OPENING_JACK;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1423 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1424
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1425 switch (bits_per_channel)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1426 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1427 case 8:
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1428 case 16:
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1429 break;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1430 default:
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1431 ERR("invalid bits_per_channel\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1432 return ERR_OPENING_JACK;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1433 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1434
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1435 /* Lock the device_mutex and find one that's not allocated already.
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1436 We'll keep this lock until we've either made use of it, or given up. */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1437 pthread_mutex_lock(&device_mutex);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1438
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1439 for(i = 0; i < MAX_OUTDEVICES; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1440 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1441 if(!outDev[i].allocated)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1442 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1443 drv = &outDev[i];
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1444 break;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1445 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1446 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1447
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1448 if(!drv)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1449 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1450 ERR("no more devices available\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1451 return ERR_OPENING_JACK;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1452 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1453
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1454 /* We found an unallocated device, now lock it for extra saftey */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1455 getDriver(drv->deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1456
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1457 TRACE("bits_per_channel=%d rate=%ld, input_channels=%d, output_channels=%d\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1458 bits_per_channel, *rate, input_channels, output_channels);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1459
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1460 if(output_channels > MAX_OUTPUT_PORTS)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1461 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1462 ERR("output_channels == %d, MAX_OUTPUT_PORTS == %d\n", output_channels,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1463 MAX_OUTPUT_PORTS);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1464 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1465 pthread_mutex_unlock(&device_mutex);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1466 return ERR_TOO_MANY_OUTPUT_CHANNELS;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1467 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1468
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1469 if(input_channels > MAX_INPUT_PORTS)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1470 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1471 ERR("input_channels == %d, MAX_INPUT_PORTS == %d\n", input_channels,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1472 MAX_INPUT_PORTS);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1473 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1474 pthread_mutex_unlock(&device_mutex);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1475 return ERR_TOO_MANY_INPUT_CHANNELS;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1476 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1477
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1478 drv->jack_output_port_flags = jack_port_flags | JackPortIsInput; /* port must be input(ie we can put data into it), so mask this in */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1479 drv->jack_input_port_flags = jack_port_flags | JackPortIsOutput; /* port must be output(ie we can get data from it), so mask this in */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1480
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1481 /* check that we have the correct number of port names
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1482 FIXME?: not sure how we should handle output ports vs input ports....
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1483 */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1484 if((jack_port_name_count > 1)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1485 && ((jack_port_name_count < output_channels)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1486 || (jack_port_name_count < input_channels)))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1487 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1488 ERR("specified individual port names but not enough, gave %d names, need %d\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1489 jack_port_name_count, output_channels);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1490 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1491 pthread_mutex_unlock(&device_mutex);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1492 return ERR_PORT_NAME_OUTPUT_CHANNEL_MISMATCH;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1493 } else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1494 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1495 /* copy this data into the device information */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1496 drv->jack_port_name_count = jack_port_name_count;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1497
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1498 if(drv->jack_port_name_count != 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1499 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1500 drv->jack_port_name =
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1501 (char **) malloc(sizeof(char *) * drv->jack_port_name_count);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1502 for(i = 0; i < drv->jack_port_name_count; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1503 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1504 drv->jack_port_name[i] = strdup(jack_port_name[i]);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1505 TRACE("jack_port_name[%d] == '%s'\n", i, jack_port_name[i]);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1506 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1507 } else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1508 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1509 drv->jack_port_name = NULL;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1510 TRACE("jack_port_name = NULL\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1511 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1512 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1513
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1514 /* initialize some variables */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1515 drv->in_use = FALSE;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1516
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1517 JACK_ResetFromDriver(drv); /* flushes all queued buffers, sets status to STOPPED and resets some variables */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1518
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1519 /* drv->jack_sample_rate is set by JACK_OpenDevice() */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1520 drv->client_sample_rate = *rate;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1521 drv->bits_per_channel = bits_per_channel;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1522 drv->num_input_channels = input_channels;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1523 drv->num_output_channels = output_channels;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1524 drv->bytes_per_input_frame = (drv->bits_per_channel * drv->num_input_channels) / 8;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1525 drv->bytes_per_output_frame = (drv->bits_per_channel * drv->num_output_channels) / 8;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1526 drv->bytes_per_jack_output_frame = sizeof(sample_t) * drv->num_output_channels;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1527 drv->bytes_per_jack_input_frame = sizeof(sample_t) * drv->num_input_channels;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1528
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1529 if(drv->num_output_channels > 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1530 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1531 drv->pPlayPtr = jack_ringbuffer_create(drv->num_output_channels *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1532 drv->bytes_per_jack_output_frame *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1533 DEFAULT_RB_SIZE);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1534 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1535
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1536 if(drv->num_input_channels > 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1537 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1538 drv->pRecPtr = jack_ringbuffer_create(drv->num_input_channels *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1539 drv->bytes_per_jack_input_frame *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1540 DEFAULT_RB_SIZE);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1541 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1542
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1543 DEBUG("bytes_per_output_frame == %ld\n", drv->bytes_per_output_frame);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1544 DEBUG("bytes_per_input_frame == %ld\n", drv->bytes_per_input_frame);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1545 DEBUG("bytes_per_jack_output_frame == %ld\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1546 drv->bytes_per_jack_output_frame);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1547 DEBUG("bytes_per_jack_input_frame == %ld\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1548 drv->bytes_per_jack_input_frame);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1549
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1550 /* go and open up the device */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1551 retval = JACK_OpenDevice(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1552 if(retval != ERR_SUCCESS)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1553 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1554 TRACE("error opening jack device\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1555 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1556 pthread_mutex_unlock(&device_mutex);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1557 return retval;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1558 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1559 else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1560 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1561 TRACE("succeeded opening jack device\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1562 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1563
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1564 /* setup SRC objects just in case they'll be needed but only if requested */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1565 if(do_sample_rate_conversion)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1566 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1567 int error;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1568 if(drv->num_output_channels > 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1569 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1570 drv->output_src = src_new(preferred_src_converter, drv->num_output_channels, &error);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1571 if(error != 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1572 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1573 src_delete(drv->output_src);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1574 drv->output_src = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1575 ERR("Could not created SRC object for output stream %d: %s\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1576 error, src_strerror(error));
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1577 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1578 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1579 if(drv->num_input_channels > 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1580 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1581 drv->input_src = src_new(preferred_src_converter, drv->num_input_channels, &error);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1582 if(error != 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1583 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1584 src_delete(drv->input_src);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1585 drv->input_src = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1586 ERR("Could not created SRC object for input stream %d: %s\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1587 error, src_strerror(error));
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1588 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1589 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1590 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1591 else if((long) (*rate) != drv->jack_sample_rate)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1592 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1593 TRACE("rate of %ld doesn't match jack sample rate of %ld, returning error\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1594 *rate, drv->jack_sample_rate);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1595 *rate = drv->jack_sample_rate;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1596 #if JACK_CLOSE_HACK
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1597 JACK_CloseDevice(drv, TRUE);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1598 #else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1599 JACK_CloseDevice(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1600 #endif
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1601 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1602 pthread_mutex_unlock(&device_mutex);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1603 return ERR_RATE_MISMATCH;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1604 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1605
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1606 drv->allocated = TRUE; /* record that we opened this device */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1607
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1608 DEBUG("sizeof(sample_t) == %d\n", sizeof(sample_t));
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1609
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1610 int periodSize = jack_get_buffer_size(drv->client);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1611 int periods = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1612 /* FIXME: maybe we should keep different latency values for input vs output? */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1613 if(drv->num_output_channels > 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1614 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1615 periods = jack_port_get_total_latency(drv->client,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1616 drv->output_port[0]) / periodSize;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1617 drv->latencyMS = periodSize * periods * 1000 / (drv->jack_sample_rate *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1618 (drv->bits_per_channel / 8 *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1619 drv->num_output_channels));
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1620 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1621 else if(drv->num_input_channels > 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1622 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1623 periods = jack_port_get_total_latency(drv->client,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1624 drv->input_port[0]) / periodSize;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1625 drv->latencyMS =
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1626 periodSize * periods * 1000 / (drv->jack_sample_rate *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1627 (drv->bits_per_channel / 8 *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1628 drv->num_input_channels));
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1629 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1630
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1631 TRACE("drv->latencyMS == %ldms\n", drv->latencyMS);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1632
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1633 *deviceID = drv->deviceID; /* set the deviceID for the caller */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1634 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1635 pthread_mutex_unlock(&device_mutex);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1636 return ERR_SUCCESS; /* success */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1637 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1638
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1639 /* Close the jack device */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1640 //FIXME: add error handling in here at some point...
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1641 /* NOTE: return 0 for success, non-zero for failure */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1642 int
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1643 JACK_Close(int deviceID)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1644 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1645 jack_driver_t *drv = getDriver(deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1646
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1647 TRACE("deviceID(%d)\n", deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1648
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1649 #if JACK_CLOSE_HACK
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1650 JACK_CloseDevice(drv, TRUE);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1651 #else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1652 JACK_CloseDevice(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1653 #endif
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1654
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1655 JACK_ResetFromDriver(drv); /* reset this device to a normal starting state */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1656
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1657 pthread_mutex_lock(&device_mutex);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1658
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1659 /* free buffer memory */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1660 drv->callback_buffer1_size = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1661 if(drv->callback_buffer1) free(drv->callback_buffer1);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1662 drv->callback_buffer1 = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1663
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1664 drv->callback_buffer2_size = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1665 if(drv->callback_buffer2) free(drv->callback_buffer2);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1666 drv->callback_buffer2 = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1667
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1668 drv->rw_buffer1_size = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1669 if(drv->rw_buffer1) free(drv->rw_buffer1);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1670 drv->rw_buffer1 = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1671
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1672 if(drv->pPlayPtr) jack_ringbuffer_free(drv->pPlayPtr);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1673 drv->pPlayPtr = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1674
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1675 if(drv->pRecPtr) jack_ringbuffer_free(drv->pRecPtr);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1676 drv->pRecPtr = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1677
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1678 /* free the SRC objects */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1679 if(drv->output_src) src_delete(drv->output_src);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1680 drv->output_src = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1681
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1682 if(drv->input_src) src_delete(drv->input_src);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1683 drv->input_src = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1684
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1685 drv->allocated = FALSE; /* release this device */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1686
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1687 pthread_mutex_unlock(&device_mutex);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1688
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1689 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1690
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1691 return 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1692 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1693
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1694 /* If we haven't already taken in the max allowed data then create a wave header */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1695 /* to package the audio data and attach the wave header to the end of the */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1696 /* linked list of wave headers */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1697 /* These wave headers will be peeled off as they are played by the callback routine */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1698 /* Return value is the number of bytes written */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1699 /* NOTE: this function takes the length of data to be written bytes */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1700 long
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1701 JACK_Write(int deviceID, unsigned char *data, unsigned long bytes)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1702 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1703 jack_driver_t *drv = getDriver(deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1704
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1705 long frames_free, frames;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1706
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1707 TIMER("start\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1708
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1709 TRACE("deviceID(%d), bytes == %ld\n", deviceID, bytes);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1710
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1711 /* check and see that we have enough space for this audio */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1712 frames_free =
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1713 jack_ringbuffer_write_space(drv->pPlayPtr) /
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1714 drv->bytes_per_jack_output_frame;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1715 frames = bytes / drv->bytes_per_output_frame;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1716 TRACE("frames free == %ld, bytes = %lu\n", frames_free, bytes);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1717
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1718 TRACE("state = '%s'\n", DEBUGSTATE(drv->state));
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1719 /* if we are currently STOPPED we should start playing now...
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1720 do this before the check for bytes == 0 since some clients like
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1721 to write 0 bytes the first time out */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1722 if(drv->state == STOPPED)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1723 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1724 TRACE("currently STOPPED, transitioning to PLAYING\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1725 drv->state = PLAYING;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1726 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1727
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1728 /* handle the case where the user calls this routine with 0 bytes */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1729 if(bytes == 0 || frames_free < 1)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1730 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1731 TRACE("no room left\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1732 TIMER("finish (nothing to do, buffer is full)\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1733 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1734 return 0; /* indicate that we couldn't write any bytes */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1735 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1736
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1737 frames = min(frames, frames_free);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1738 long jack_bytes = frames * drv->bytes_per_jack_output_frame;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1739 if(!ensure_buffer_size(&drv->rw_buffer1, &drv->rw_buffer1_size, jack_bytes))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1740 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1741 ERR("couldn't allocate enough space for the buffer\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1742 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1743 return 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1744 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1745 /* adjust bytes to be how many client bytes we're actually writing */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1746 bytes = frames * drv->bytes_per_output_frame;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1747
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1748 /* convert from client samples to jack samples
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1749 we have to tell it how many samples there are, which is frames * channels */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1750 switch (drv->bits_per_channel)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1751 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1752 case 8:
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1753 sample_move_char_float((sample_t *) drv->rw_buffer1, (char *) data,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1754 frames * drv->num_output_channels);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1755 case 16:
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1756 sample_move_short_float((sample_t *) drv->rw_buffer1, (short *) data,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1757 frames * drv->num_output_channels);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1758 break;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1759 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1760
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1761 int i;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1762 for(i = 0; i < drv->num_output_channels; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1763 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1764 /* apply volume to the floating value */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1765 if(drv->volumeEffectType == dbAttenuation)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1766 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1767 /* assume the volume setting is dB of attenuation, a volume of 0 */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1768 /* is 0dB attenuation */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1769 float volume = powf(10.0, -((float) drv->volume[i]) / 20.0);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1770 float_volume_effect((sample_t *) drv->rw_buffer1 + i,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1771 frames, volume, drv->num_output_channels);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1772 } else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1773 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1774 float_volume_effect((sample_t *) drv->rw_buffer1 + i, frames,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1775 ((float) drv->volume[i] / 100.0),
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1776 drv->num_output_channels);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1777 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1778 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1779
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1780 DEBUG("ringbuffer read space = %d, write space = %d\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1781 jack_ringbuffer_read_space(drv->pPlayPtr),
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1782 jack_ringbuffer_write_space(drv->pPlayPtr));
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1783
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1784 jack_ringbuffer_write(drv->pPlayPtr, drv->rw_buffer1, jack_bytes);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1785 DEBUG("wrote %lu bytes, %lu jack_bytes\n", bytes, jack_bytes);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1786
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1787 DEBUG("ringbuffer read space = %d, write space = %d\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1788 jack_ringbuffer_read_space(drv->pPlayPtr),
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1789 jack_ringbuffer_write_space(drv->pPlayPtr));
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1790
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1791 drv->client_bytes += bytes; /* update client_bytes */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1792
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1793 TIMER("finish\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1794
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1795 DEBUG("returning bytes written of %ld\n", bytes);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1796
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1797 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1798 return bytes; /* return the number of bytes we wrote out */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1799 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1800
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1801 long
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1802 JACK_Read(int deviceID, unsigned char *data, unsigned long bytes)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1803 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1804 jack_driver_t *drv = getDriver(deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1805
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1806 long frames_available, frames;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1807
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1808 TIMER("start\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1809
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1810 TRACE("deviceID(%d), bytes == %ld\n", deviceID, bytes);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1811
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1812 /* find out if there's any room to write this data */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1813 frames_available =
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1814 jack_ringbuffer_read_space(drv->pRecPtr) /
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1815 drv->bytes_per_jack_input_frame;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1816 frames = bytes / drv->bytes_per_input_frame;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1817 DEBUG("frames available = %ld, bytes = %lu\n", frames_available, bytes);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1818
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1819 TRACE("state = '%s'\n", DEBUGSTATE(drv->state));
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1820 /* if we are currently STOPPED we should start recording now... */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1821 if(drv->state == STOPPED)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1822 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1823 TRACE("currently STOPPED, transitioning to PLAYING\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1824 drv->state = PLAYING;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1825 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1826
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1827 /* handle the case where the user calls this routine with 0 bytes */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1828 if(bytes == 0 || frames_available < 1)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1829 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1830 TRACE("no bytes in buffer\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1831
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1832 TIMER("finish (nothing to do)\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1833 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1834 return 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1835 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1836
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1837 frames = min(frames, frames_available);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1838 long jack_bytes = frames * drv->bytes_per_jack_input_frame;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1839 if(!ensure_buffer_size(&drv->rw_buffer1, &drv->rw_buffer1_size, jack_bytes))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1840 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1841 ERR("couldn't allocate enough space for the buffer\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1842 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1843 return 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1844 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1845
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1846 DEBUG("ringbuffer read space = %d, write space = %d\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1847 jack_ringbuffer_read_space(drv->pRecPtr),
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1848 jack_ringbuffer_write_space(drv->pRecPtr));
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1849
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1850 jack_ringbuffer_read(drv->pRecPtr, drv->rw_buffer1,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1851 frames * drv->bytes_per_jack_input_frame);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1852
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1853 DEBUG("ringbuffer read space = %d, write space = %d\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1854 jack_ringbuffer_read_space(drv->pRecPtr),
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1855 jack_ringbuffer_write_space(drv->pRecPtr));
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1856
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1857 int i;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1858 for(i = 0; i < drv->num_output_channels; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1859 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1860 /* apply volume to the floating value */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1861 if(drv->volumeEffectType == dbAttenuation)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1862 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1863 /* assume the volume setting is dB of attenuation, a volume of 0 */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1864 /* is 0dB attenuation */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1865 float volume = powf(10.0, -((float) drv->volume[i]) / 20.0);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1866 float_volume_effect((sample_t *) drv->rw_buffer1 + i,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1867 frames, volume, drv->num_output_channels);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1868 } else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1869 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1870 float_volume_effect((sample_t *) drv->rw_buffer1 + i, frames,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1871 ((float) drv->volume[i] / 100.0),
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1872 drv->num_output_channels);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1873 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1874 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1875
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1876 /* convert from jack samples to client samples
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1877 we have to tell it how many samples there are, which is frames * channels */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1878 switch (drv->bits_per_channel)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1879 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1880 case 8:
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1881 sample_move_float_char((char *) data, (sample_t *) drv->rw_buffer1,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1882 frames * drv->num_input_channels);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1883 break;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1884 case 16:
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1885 sample_move_float_short((short *) data, (sample_t *) drv->rw_buffer1,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1886 frames * drv->num_input_channels);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1887 break;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1888 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1889
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1890 TIMER("finish\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1891
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1892 long read_bytes = frames * drv->bytes_per_input_frame;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1893
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1894 DEBUG("returning bytes read of %ld\n", bytes);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1895
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1896 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1897 return read_bytes;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1898 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1899
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1900 /* return ERR_SUCCESS for success */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1901 static int
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1902 JACK_SetVolumeForChannelFromDriver(jack_driver_t * drv,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1903 unsigned int channel, unsigned int volume)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1904 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1905 /* TODO?: maybe we should have different volume levels for input & output */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1906 /* ensure that we have the channel we are setting volume for */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1907 if(channel > (drv->num_output_channels - 1))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1908 return 1;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1909
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1910 if(volume > 100)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1911 volume = 100; /* check for values in excess of max */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1912
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1913 drv->volume[channel] = volume;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1914 return ERR_SUCCESS;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1915 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1916
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1917 /* return ERR_SUCCESS for success */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1918 int
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1919 JACK_SetVolumeForChannel(int deviceID, unsigned int channel,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1920 unsigned int volume)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1921 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1922 jack_driver_t *drv = getDriver(deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1923 int retval = JACK_SetVolumeForChannelFromDriver(drv, channel, volume);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1924 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1925 return retval;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1926 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1927
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1928 /* Set the volume */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1929 /* return 0 for success */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1930 /* NOTE: we check for invalid volume values */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1931 int
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1932 JACK_SetAllVolume(int deviceID, unsigned int volume)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1933 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1934 jack_driver_t *drv = getDriver(deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1935 unsigned int i;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1936
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1937 TRACE("deviceID(%d), setting volume of %d\n", deviceID, volume);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1938
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1939 for(i = 0; i < drv->num_output_channels; i++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1940 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1941 if(JACK_SetVolumeForChannelFromDriver(drv, i, volume) != ERR_SUCCESS)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1942 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1943 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1944 return 1;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1945 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1946 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1947
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1948 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1949 return ERR_SUCCESS;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1950 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1951
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1952 /* Return the current volume in the inputted pointers */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1953 /* NOTE: we check for null pointers being passed in just in case */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1954 void
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1955 JACK_GetVolumeForChannel(int deviceID, unsigned int channel,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1956 unsigned int *volume)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1957 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1958 jack_driver_t *drv = getDriver(deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1959
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1960 /* ensure that we have the channel we are getting volume for */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1961 if(channel > (drv->num_output_channels - 1))
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1962 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1963 ERR("asking for channel index %d but we only have %ld channels\n", channel, drv->num_output_channels);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1964 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1965 return;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1966 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1967
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1968 if(volume)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1969 *volume = drv->volume[channel];
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1970
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1971 #if VERBOSE_OUTPUT
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1972 if(volume)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1973 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1974 TRACE("deviceID(%d), returning volume of %d for channel %d\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1975 deviceID, *volume, channel);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1976 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1977 else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1978 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1979 TRACE("volume is null, can't dereference it\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1980 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1981 #endif
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1982
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1983 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1984 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1985
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1986
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1987 /* linear means 0 volume is silence, 100 is full volume */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1988 /* dbAttenuation means 0 volume is 0dB attenuation */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1989 /* Bio2jack defaults to linear */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1990 enum JACK_VOLUME_TYPE
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1991 JACK_SetVolumeEffectType(int deviceID, enum JACK_VOLUME_TYPE type)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1992 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1993 enum JACK_VOLUME_TYPE retval;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1994 jack_driver_t *drv = getDriver(deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1995
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1996 TRACE("setting type of '%s'\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1997 (type == dbAttenuation ? "dbAttenuation" : "linear"));
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1998
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
1999 retval = drv->volumeEffectType;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2000 drv->volumeEffectType = type;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2001
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2002 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2003 return retval;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2004 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2005
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2006
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2007 /* Controls the state of the playback(playing, paused, ...) */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2008 int
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2009 JACK_SetState(int deviceID, enum status_enum state)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2010 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2011 jack_driver_t *drv = getDriver(deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2012
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2013 switch (state)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2014 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2015 case PAUSED:
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2016 drv->state = PAUSED;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2017 break;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2018 case PLAYING:
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2019 drv->state = PLAYING;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2020 break;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2021 case STOPPED:
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2022 drv->state = STOPPED;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2023 break;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2024 default:
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2025 TRACE("unknown state of %d\n", state);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2026 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2027
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2028 TRACE("%s\n", DEBUGSTATE(drv->state));
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2029
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2030 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2031 return 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2032 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2033
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2034 /* Retrieve the current state of the device */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2035 enum status_enum
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2036 JACK_GetState(int deviceID)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2037 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2038 jack_driver_t *drv = getDriver(deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2039 enum status_enum return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2040
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2041 return_val = drv->state;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2042 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2043
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2044 TRACE("deviceID(%d), returning current state of %s\n", deviceID,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2045 DEBUGSTATE(return_val));
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2046 return return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2047 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2048
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2049 /* Retrieve the number of bytes per second we are outputting */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2050 unsigned long
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2051 JACK_GetOutputBytesPerSecondFromDriver(jack_driver_t * drv)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2052 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2053 unsigned long return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2054
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2055 return_val = drv->bytes_per_output_frame * drv->client_sample_rate;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2056
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2057 #if VERBOSE_OUTPUT
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2058 TRACE("deviceID(%d), return_val = %ld\n", drv->deviceID, return_val);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2059 #endif
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2060
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2061 return return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2062 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2063
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2064 /* Retrieve the number of bytes per second we are outputting */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2065 unsigned long
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2066 JACK_GetOutputBytesPerSecond(int deviceID)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2067 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2068 jack_driver_t *drv = getDriver(deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2069 unsigned long return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2070
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2071 return_val = JACK_GetOutputBytesPerSecondFromDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2072 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2073
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2074 return return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2075 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2076
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2077 /* Retrieve the number of input bytes(from jack) per second we are outputting
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2078 to the user of bio2jack */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2079 static long
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2080 JACK_GetInputBytesPerSecondFromDriver(jack_driver_t * drv)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2081 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2082 long return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2083
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2084 return_val = drv->bytes_per_input_frame * drv->client_sample_rate;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2085 #if VERBOSE_OUTPUT
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2086 TRACE("drv->deviceID(%d), return_val = %ld\n", drv->deviceID, return_val);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2087 #endif
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2088
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2089 return return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2090 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2091
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2092 /* Retrieve the number of input bytes(from jack) per second we are outputting
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2093 to the user of bio2jack */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2094 unsigned long
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2095 JACK_GetInputBytesPerSecond(int deviceID)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2096 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2097 jack_driver_t *drv = getDriver(deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2098 long return_val = JACK_GetInputBytesPerSecondFromDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2099 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2100
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2101 #if VERBOSE_OUTPUT
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2102 TRACE("deviceID(%d), return_val = %ld\n", deviceID, return_val);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2103 #endif
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2104
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2105 return return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2106 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2107
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2108 /* Return the number of bytes we have buffered thus far for output */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2109 /* NOTE: convert from output bytes to input bytes in here */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2110 static long
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2111 JACK_GetBytesStoredFromDriver(jack_driver_t * drv)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2112 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2113 if(drv->pPlayPtr == 0 || drv->bytes_per_jack_output_frame == 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2114 return 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2115
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2116 /* leave at least one frame in the buffer at all times to prevent underruns */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2117 long return_val =
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2118 jack_ringbuffer_read_space(drv->pPlayPtr) - drv->jack_buffer_size;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2119 if(return_val <= 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2120 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2121 return_val = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2122 } else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2123 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2124 /* adjust from jack bytes to client bytes */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2125 return_val =
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2126 return_val / drv->bytes_per_jack_output_frame *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2127 drv->bytes_per_output_frame;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2128 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2129
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2130 return return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2131 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2132
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2133 /* An approximation of how many bytes we have to send out to jack */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2134 /* that is computed as if we were sending jack a continuous stream of */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2135 /* bytes rather than chunks during discrete callbacks. */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2136 /* Return the number of bytes we have buffered thus far for output */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2137 /* NOTE: convert from output bytes to input bytes in here */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2138 unsigned long
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2139 JACK_GetBytesStored(int deviceID)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2140 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2141 jack_driver_t *drv = getDriver(deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2142 long retval = JACK_GetBytesStoredFromDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2143 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2144 TRACE("deviceID(%d), retval = %ld\n", deviceID, retval);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2145 return retval;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2146 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2147
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2148 static unsigned long
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2149 JACK_GetBytesFreeSpaceFromDriver(jack_driver_t * drv)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2150 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2151 if(drv->pPlayPtr == 0 || drv->bytes_per_jack_output_frame == 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2152 return 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2153
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2154 /* leave at least one frame in the buffer at all times to prevent underruns */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2155 long return_val = jack_ringbuffer_write_space(drv->pPlayPtr) - drv->jack_buffer_size;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2156 if(return_val <= 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2157 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2158 return_val = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2159 } else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2160 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2161 /* adjust from jack bytes to client bytes */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2162 return_val =
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2163 return_val / drv->bytes_per_jack_output_frame *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2164 drv->bytes_per_output_frame;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2165 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2166
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2167 return return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2168 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2169
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2170 /* Return the number of bytes we can write to the device */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2171 unsigned long
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2172 JACK_GetBytesFreeSpace(int deviceID)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2173 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2174 jack_driver_t *drv = getDriver(deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2175 unsigned long return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2176
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2177 return_val = JACK_GetBytesFreeSpaceFromDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2178 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2179
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2180 if(return_val < 0) return_val = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2181
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2182 TRACE("deviceID(%d), retval == %ld\n", deviceID, return_val);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2183
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2184 return return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2185 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2186
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2187 /* bytes of space used in the input buffer */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2188 unsigned long
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2189 JACK_GetBytesUsedSpace(int deviceID)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2190 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2191 jack_driver_t *drv = getDriver(deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2192 long return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2193
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2194 if(drv->pRecPtr == 0 || drv->bytes_per_jack_input_frame == 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2195 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2196 return_val = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2197 } else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2198 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2199 /* adjust from jack bytes to client bytes */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2200 return_val =
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2201 jack_ringbuffer_read_space(drv->pRecPtr) /
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2202 drv->bytes_per_jack_input_frame * drv->bytes_per_input_frame;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2203 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2204
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2205 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2206
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2207 if(return_val < 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2208 return_val = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2209 TRACE("deviceID(%d), retval == %ld\n", deviceID, return_val);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2210
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2211 return return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2212 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2213
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2214 /* Get the current position of the driver, either in bytes or */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2215 /* in milliseconds */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2216 /* NOTE: this is position relative to input bytes, output bytes may differ greatly due to
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2217 input vs. output channel count */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2218 static long
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2219 JACK_GetPositionFromDriver(jack_driver_t * drv, enum pos_enum position,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2220 int type)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2221 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2222 long return_val = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2223 struct timeval now;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2224 long elapsedMS;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2225 double sec2msFactor = 1000;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2226
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2227 char *type_str = "UNKNOWN type";
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2228
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2229 /* if we are reset we should return a position of 0 */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2230 if(drv->state == RESET)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2231 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2232 TRACE("we are currently RESET, returning 0\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2233 return 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2234 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2235
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2236 if(type == WRITTEN)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2237 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2238 type_str = "WRITTEN";
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2239 return_val = drv->client_bytes;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2240 } else if(type == WRITTEN_TO_JACK)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2241 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2242 type_str = "WRITTEN_TO_JACK";
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2243 return_val = drv->written_client_bytes;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2244 } else if(type == PLAYED) /* account for the elapsed time for the played_bytes */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2245 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2246 type_str = "PLAYED";
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2247 return_val = drv->played_client_bytes;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2248 gettimeofday(&now, 0);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2249
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2250 elapsedMS = TimeValDifference(&drv->previousTime, &now); /* find the elapsed milliseconds since last JACK_Callback() */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2251
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2252 TRACE("elapsedMS since last callback is '%ld'\n", elapsedMS);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2253
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2254 /* account for the bytes played since the last JACK_Callback() */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2255 /* NOTE: [Xms * (Bytes/Sec)] * (1 sec/1,000ms) */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2256 /* NOTE: don't do any compensation if no data has been sent to jack since the last callback */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2257 /* as this would result a bogus computed result */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2258 if(drv->clientBytesInJack != 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2259 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2260 return_val += (long) ((double) elapsedMS *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2261 ((double) JACK_GetOutputBytesPerSecondFromDriver(drv) /
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2262 sec2msFactor));
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2263 } else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2264 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2265 TRACE("clientBytesInJack == 0\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2266 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2267 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2268
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2269 /* add on the offset */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2270 return_val += drv->position_byte_offset;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2271
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2272 /* convert byte position to milliseconds value if necessary */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2273 if(position == MILLISECONDS)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2274 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2275 if(JACK_GetOutputBytesPerSecondFromDriver(drv) != 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2276 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2277 return_val = (long) (((double) return_val /
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2278 (double) JACK_GetOutputBytesPerSecondFromDriver(drv)) *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2279 (double) sec2msFactor);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2280 } else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2281 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2282 return_val = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2283 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2284 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2285
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2286 TRACE("drv->deviceID(%d), type(%s), return_val = %ld\n", drv->deviceID,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2287 type_str, return_val);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2288
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2289 return return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2290 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2291
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2292 /* Get the current position of the driver, either in bytes or */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2293 /* in milliseconds */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2294 /* NOTE: this is position relative to input bytes, output bytes may differ greatly due to input vs. output channel count */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2295 long
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2296 JACK_GetPosition(int deviceID, enum pos_enum position, int type)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2297 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2298 jack_driver_t *drv = getDriver(deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2299 long retval = JACK_GetPositionFromDriver(drv, position, type);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2300 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2301 TRACE("retval == %ld\n", retval);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2302 return retval;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2303 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2304
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2305 // Set position always applies to written bytes
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2306 // NOTE: we must apply this instantly because if we pass this as a message
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2307 // to the callback we risk the user sending us audio data in the mean time
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2308 // and there is no need to send this as a message, we don't modify any
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2309 // internal variables
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2310 void
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2311 JACK_SetPositionFromDriver(jack_driver_t * drv, enum pos_enum position,
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2312 long value)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2313 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2314 double sec2msFactor = 1000;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2315 #if TRACE_ENABLE
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2316 long input_value = value;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2317 #endif
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2318
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2319 /* convert the incoming value from milliseconds into bytes */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2320 if(position == MILLISECONDS)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2321 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2322 value = (long) (((double) value *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2323 (double) JACK_GetOutputBytesPerSecondFromDriver(drv)) /
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2324 sec2msFactor);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2325 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2326
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2327 /* ensure that if the user asks for the position */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2328 /* they will at this instant get the correct position */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2329 drv->position_byte_offset = value - drv->client_bytes;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2330
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2331 TRACE("deviceID(%d) input_value of %ld %s, new value of %ld, setting position_byte_offset to %ld\n",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2332 drv->deviceID, input_value, (position == MILLISECONDS) ? "ms" : "bytes",
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2333 value, drv->position_byte_offset);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2334 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2335
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2336 // Set position always applies to written bytes
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2337 // NOTE: we must apply this instantly because if we pass this as a message
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2338 // to the callback we risk the user sending us audio data in the mean time
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2339 // and there is no need to send this as a message, we don't modify any
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2340 // internal variables
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2341 void
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2342 JACK_SetPosition(int deviceID, enum pos_enum position, long value)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2343 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2344 jack_driver_t *drv = getDriver(deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2345 JACK_SetPositionFromDriver(drv, position, value);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2346 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2347
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2348 TRACE("deviceID(%d) value of %ld\n", drv->deviceID, value);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2349 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2350
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2351 /* Return the number of bytes per frame, or (output_channels * bits_per_channel) / 8 */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2352 unsigned long
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2353 JACK_GetBytesPerOutputFrame(int deviceID)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2354 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2355 jack_driver_t *drv = getDriver(deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2356 long return_val = drv->bytes_per_output_frame;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2357 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2358 TRACE("deviceID(%d), return_val = %ld\n", deviceID, return_val);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2359 return return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2360 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2361
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2362 /* Return the number of bytes per frame, or (input_channels * bits_per_channel) / 8 */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2363 unsigned long
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2364 JACK_GetBytesPerInputFrame(int deviceID)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2365 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2366 jack_driver_t *drv = getDriver(deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2367 long return_val = drv->bytes_per_input_frame;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2368 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2369 TRACE("deviceID(%d), return_val = %ld\n", deviceID, return_val);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2370 return return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2371 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2372
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2373 /* Return the number of output bytes we buffer max */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2374 long
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2375 JACK_GetMaxOutputBufferedBytes(int deviceID)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2376 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2377 jack_driver_t *drv = getDriver(deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2378 long return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2379
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2380 if(drv->pPlayPtr == 0 || drv->bytes_per_jack_output_frame == 0) return_val = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2381
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2382 /* adjust from jack bytes to client bytes */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2383 return_val =
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2384 (jack_ringbuffer_read_space(drv->pPlayPtr) +
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2385 jack_ringbuffer_write_space(drv->pPlayPtr)) /
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2386 drv->bytes_per_jack_output_frame * drv->bytes_per_output_frame;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2387
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2388 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2389
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2390 TRACE("return_val = %ld\n", return_val);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2391
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2392 return return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2393 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2394
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2395 /* Return the number of input bytes we buffer max */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2396 long
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2397 JACK_GetMaxInputBufferedBytes(int deviceID)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2398 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2399 jack_driver_t *drv = getDriver(deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2400 long return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2401
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2402 if(drv->pRecPtr == 0 || drv->bytes_per_jack_input_frame == 0) return_val = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2403
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2404 /* adjust from jack bytes to client bytes */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2405 return_val =
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2406 (jack_ringbuffer_read_space(drv->pRecPtr) +
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2407 jack_ringbuffer_write_space(drv->pRecPtr)) /
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2408 drv->bytes_per_jack_input_frame * drv->bytes_per_input_frame;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2409
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2410 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2411
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2412 TRACE("return_val = %ld\n", return_val);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2413
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2414 return return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2415 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2416
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2417 /* Get the number of output channels */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2418 int
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2419 JACK_GetNumOutputChannels(int deviceID)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2420 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2421 jack_driver_t *drv = getDriver(deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2422 int return_val = drv->num_output_channels;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2423 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2424 TRACE("getting num_output_channels of %d\n", return_val);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2425 return return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2426 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2427
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2428 /* Get the number of input channels */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2429 int
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2430 JACK_GetNumInputChannels(int deviceID)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2431 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2432 jack_driver_t *drv = getDriver(deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2433 int return_val = drv->num_input_channels;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2434 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2435 TRACE("getting num_input_channels of %d\n", return_val);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2436 return return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2437 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2438
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2439 /* Get the number of samples per second, the sample rate */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2440 long
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2441 JACK_GetSampleRate(int deviceID)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2442 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2443 jack_driver_t *drv = getDriver(deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2444 int return_val = drv->client_sample_rate;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2445 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2446 TRACE("getting sample_rate of %d\n", return_val);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2447 return return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2448 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2449
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2450 void
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2451 JACK_CleanupDriver(jack_driver_t * drv)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2452 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2453 TRACE("\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2454 /* things that need to be reset both in JACK_Init & JACK_CloseDevice */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2455 drv->client = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2456 drv->in_use = FALSE;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2457 drv->state = CLOSED;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2458 drv->jack_sample_rate = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2459 drv->output_sample_rate_ratio = 1.0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2460 drv->input_sample_rate_ratio = 1.0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2461 drv->jackd_died = FALSE;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2462 gettimeofday(&drv->previousTime, 0); /* record the current time */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2463 gettimeofday(&drv->last_reconnect_attempt, 0);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2464 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2465
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2466 /* Initialize the jack porting library to a clean state */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2467 void
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2468 JACK_Init(void)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2469 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2470 jack_driver_t *drv;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2471 int x, y;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2472
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2473 if(init_done)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2474 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2475 TRACE("not initing twice\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2476 return;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2477 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2478
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2479 init_done = 1;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2480
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2481 TRACE("\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2482
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2483 pthread_mutex_lock(&device_mutex);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2484
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2485 /* initialize the device structures */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2486 for(x = 0; x < MAX_OUTDEVICES; x++)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2487 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2488 drv = &outDev[x];
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2489
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2490 pthread_mutex_init(&drv->mutex, NULL);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2491
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2492 getDriver(x);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2493
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2494 memset(drv, 0, sizeof(jack_driver_t));
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2495 drv->volumeEffectType = linear;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2496 drv->deviceID = x;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2497
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2498 for(y = 0; y < MAX_OUTPUT_PORTS; y++) /* make all volume 25% as a default */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2499 drv->volume[y] = 25;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2500
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2501 JACK_CleanupDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2502 JACK_ResetFromDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2503 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2504 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2505
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2506 client_name = 0; /* initialize the name to null */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2507 do_sample_rate_conversion = TRUE; /* default to on */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2508 JACK_SetClientName("bio2jack");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2509
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2510 pthread_mutex_unlock(&device_mutex);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2511
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2512 TRACE("finished\n");
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2513 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2514
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2515 /* Get the latency, in frames, of jack */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2516 long
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2517 JACK_GetJackOutputLatency(int deviceID)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2518 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2519 jack_driver_t *drv = getDriver(deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2520 long return_val = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2521
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2522 if(drv->client && drv->num_output_channels)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2523 return_val = jack_port_get_total_latency(drv->client, drv->output_port[0]);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2524
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2525 TRACE("got latency of %ld frames\n", return_val);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2526
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2527 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2528 return return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2529 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2530
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2531 /* Get the latency, in frames, of jack */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2532 long
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2533 JACK_GetJackInputLatency(int deviceID)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2534 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2535 jack_driver_t *drv = getDriver(deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2536 long return_val = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2537
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2538 if(drv->client && drv->num_input_channels)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2539 return_val = jack_port_get_total_latency(drv->client, drv->input_port[0]);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2540
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2541 TRACE("got latency of %ld frames\n", return_val);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2542
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2543 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2544 return return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2545 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2546
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2547 /* bytes that jack requests during each callback */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2548 unsigned long
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2549 JACK_GetJackBufferedBytes(int deviceID)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2550 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2551 jack_driver_t *drv = getDriver(deviceID);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2552 long return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2553
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2554 if(drv->bytes_per_jack_output_frame == 0)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2555 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2556 return_val = 0;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2557 } else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2558 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2559 /* adjust from jack bytes to client bytes */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2560 return_val =
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2561 drv->jack_buffer_size / drv->bytes_per_jack_output_frame *
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2562 drv->bytes_per_output_frame * drv->num_output_channels;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2563 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2564
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2565 releaseDriver(drv);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2566 return return_val;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2567 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2568
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2569 /* value = TRUE, perform sample rate conversion */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2570 void
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2571 JACK_DoSampleRateConversion(bool value)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2572 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2573 do_sample_rate_conversion = value;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2574 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2575
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2576 /* FIXME: put the filename of the resample library header file with the decoders in here */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2577 /* consider mapping them in the bio2jack.h header file since its useless to the user unless */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2578 /* they can figure out wtf the settings on */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2579 void
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2580 JACK_SetSampleRateConversionFunction(int converter)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2581 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2582 preferred_src_converter = converter;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2583 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2584
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2585 /* set the client name that will be reported to jack when we open a */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2586 /* connection via JACK_OpenDevice() */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2587 void
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2588 JACK_SetClientName(char *name)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2589 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2590 if(name)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2591 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2592 if(client_name) free(client_name);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2593
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2594 /* jack_client_name_size() is the max length of a client name, including
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2595 the terminating null. */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2596 int size = strlen(name) + 1; /* take into account the terminating null */
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2597 if(size > jack_client_name_size())
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2598 size = jack_client_name_size();
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2599
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2600 client_name = malloc(size);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2601 if(client_name)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2602 snprintf(client_name, size, "%s", name);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2603 else
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2604 ERR("unable to allocate %d bytes for client_name\n", size);
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2605 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2606 }
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2607
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2608 void
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2609 JACK_SetPortConnectionMode(enum JACK_PORT_CONNECTION_MODE mode)
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2610 {
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2611 port_connection_mode = mode;
ea321d1dae48 [svn] JACKd output plugin via external contractor james@develia.org.
nenolod
parents:
diff changeset
2612 }