-
Notifications
You must be signed in to change notification settings - Fork 57
/
setup.py
executable file
·1096 lines (921 loc) · 40.5 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
# Audio Tools, a module and set of tools for manipulating audio data
# Copyright (C) 2007-2016 Brian Langenberger
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
from __future__ import print_function
import sys
if sys.version_info[0] == 3:
if sys.version_info[1] < 3:
print("*** Python 3.3 or better required")
sys.exit(1)
elif sys.version_info[0] == 2:
if sys.version_info[1] < 7:
print("*** Python 2.7 or better required")
sys.exit(1)
import os
import os.path
import re
import subprocess
from distutils.core import setup, Extension
from distutils.command.build_ext import build_ext as _build_ext
try:
from configparser import (RawConfigParser, NoSectionError, NoOptionError)
except ImportError:
from ConfigParser import (RawConfigParser, NoSectionError, NoOptionError)
configfile = RawConfigParser()
configfile.read(["setup.cfg"])
VERSION = re.search(r'VERSION\s*=\s"(.+?)"',
open(os.path.join(
os.path.dirname(sys.argv[0]),
"audiotools/__init__.py")).read()).group(1)
LIBRARY_URLS = {"libcdio_paranoia": "http://www.gnu.org/software/libcdio/",
"libcdio": "http://www.gnu.org/software/libcdio/",
"libdvd-audio": "http://libdvd-audio.sourceforge.net",
"libmpg123": "http://www.mpg123.org",
"vorbisfile": "http://xiph.org",
"opusfile": "http://www.opus-codec.org",
"opus": "http://www.opus-codec.org",
"mp3lame": "http://lame.sourceforge.net",
"twolame": "http://twolame.sourceforge.net",
"vorbisenc": "http://www.xiph.org",
"alsa": "http://www.alsa-project.org",
"libasound2": "http://www.alsa-project.org",
"libpulse": "http://www.freedesktop.org",
"wavpack": "http://www.wavpack.com"}
class SystemLibraries(object):
def __init__(self, configfile):
self.configfile = configfile
def guaranteed_present(self, library):
"""given library name string
returns True if library is guaranteed present,
False if library is not present,
None if one should probe for the library
default is None"""
try:
if self.configfile.get("Libraries", library) == "probe":
return None
else:
try:
return self.configfile.getboolean("Libraries", library)
except ValueError:
return None
except NoSectionError:
return None
except NoOptionError:
return None
def present(self, library):
"""returns True if the given library is present on the system,
returns False if it cannot be found"""
present = self.guaranteed_present(library)
if present is None:
# probe for library using pkg-config, if available
try:
pkg_config = subprocess.Popen(
["pkg-config", "--exists", library],
stdout=open(os.devnull, "wb"),
stderr=open(os.devnull, "wb"))
return (pkg_config.wait() == 0)
except OSError:
# pkg-config not found, so assume library isn't found
return False
else:
return present
def extra_compile_args(self, library):
"""returns a list of compile argument strings for populating
an extension's 'extra_compile_args' argument
the list may be empty"""
try:
pkg_config = subprocess.Popen(
["pkg-config", "--cflags", library],
stdout=subprocess.PIPE,
stderr=open(os.devnull, "wb"),
universal_newlines=True)
pkg_config_stdout = pkg_config.stdout.read().strip()
if pkg_config.wait() == 0:
# libraries found
return pkg_config_stdout.split()
else:
# library not found
return []
except OSError:
# pkg-config not found
return []
def extra_link_args(self, library):
"""returns a list of link argument strings for populating
an extension's 'extra_link_args' argument
the list may be empty"""
try:
pkg_config = subprocess.Popen(
["pkg-config", "--libs", library],
stdout=subprocess.PIPE,
stderr=open(os.devnull, "wb"),
universal_newlines=True)
pkg_config_stdout = pkg_config.stdout.read().strip()
if pkg_config.wait() == 0:
# libraries found
return pkg_config_stdout.split()
else:
# library not found
return []
except OSError:
# pkg-config not found
return []
def executable_present(self, executable, *args):
"""returns True if the given executable
and any arguments execute with a 0 return status"""
try:
sub = subprocess.Popen([executable] + list(args),
stdout=open(os.devnull, "wb"),
stderr=open(os.devnull, "wb"))
return (sub.wait() == 0)
except OSError:
return False
def lib_version(self, library):
"""returns the library's version as a tuple"""
try:
pkg_config = subprocess.Popen(
["pkg-config", "--modversion", library],
stdout=subprocess.PIPE,
stderr=open(os.devnull, "wb"),
universal_newlines=True)
pkg_config_stdout = pkg_config.stdout.read().strip()
if pkg_config.wait() == 0:
try:
return tuple(int(s) for s in pkg_config_stdout.split("."))
except ValueError:
# version isn't all integers
return tuple()
else:
# library not found
return tuple()
except OSError:
# pkg-config not found
return tuple()
system_libraries = SystemLibraries(configfile)
class output_table(object):
def __init__(self):
"""a class for formatting rows for display"""
self.__rows__ = []
def row(self):
"""returns a output_table_row object which columns can be added to"""
row = output_table_row()
self.__rows__.append(row)
return row
def blank_row(self):
"""inserts a blank table row with no output"""
self.__rows__.append(output_table_blank())
def divider_row(self, dividers):
"""adds a row of unicode divider characters
there should be one character in dividers per output column"""
self.__rows__.append(output_table_divider(dividers))
def total_width(self):
return sum([
max([row.column_width(col) for row in self.__rows__])
for col in range(len(self.__rows__[0]))])
def format(self):
"""yields one formatted string per row"""
if len(self.__rows__) == 0:
# no rows, so do nothing
return
if (len(set([len(r) for r in self.__rows__ if
not isinstance(r, output_table_blank)])) != 1):
raise ValueError("all rows must have same number of columns")
column_widths = [
max([row.column_width(col) for row in self.__rows__])
for col in range(len(self.__rows__[0]))]
for row in self.__rows__:
yield row.format(column_widths)
class output_table_row(object):
def __init__(self):
"""a class for formatting columns for display"""
self.__columns__ = []
def __len__(self):
return len(self.__columns__)
def add_column(self, text, alignment="left"):
"""adds text which is a plain string and an optional alignment
alignment may be 'left', 'center', 'right'"""
if alignment not in ("left", "center", "right"):
raise ValueError("alignment must be 'left', 'center', or 'right'")
self.__columns__.append((text, alignment))
def column_width(self, column):
return len(self.__columns__[column][0])
def format(self, column_widths):
"""returns formatted row as a string"""
def align_left(text, width):
spaces = width - len(text)
if spaces > 0:
return text + " " * spaces
else:
return text
def align_right(text, width):
spaces = width - len(text)
if spaces > 0:
return " " * spaces + text
else:
return text
def align_center(text, width):
left_spaces = (width - len(text)) // 2
right_spaces = width - (left_spaces + len(text))
if (left_spaces + right_spaces) > 0:
return (" " * left_spaces +
text +
" " * right_spaces)
else:
return text
# attribute to method mapping
align_meth = {"left": align_left,
"right": align_right,
"center": align_center}
assert(len(column_widths) == len(self.__columns__))
return "".join([align_meth[alignment](text, width)
for ((text, alignment), width) in
zip(self.__columns__, column_widths)]).rstrip()
class output_table_divider(object):
"""a class for formatting a row of divider characters"""
def __init__(self, dividers):
self.__dividers__ = dividers[:]
def __len__(self):
return len(self.__dividers__)
def column_width(self, column):
return 0
def format(self, column_widths):
"""returns formatted row as a string"""
assert(len(column_widths) == len(self.__dividers__))
return "".join([divider * width
for (divider, width) in
zip(self.__dividers__, column_widths)]).rstrip()
class output_table_blank(object):
"""a class for an empty table row"""
def __init__(self):
pass
def column_width(self, column):
return 0
def format(self, column_widths):
"""returns formatted row as a string"""
return ""
class build_ext(_build_ext):
def build_extensions(self):
_build_ext.build_extensions(self)
# lib_name -> ([used for, ...], is present)
libraries = {}
for extension in self.extensions:
if ((hasattr(extension, "library_manifest") and
callable(extension.library_manifest))):
for (library,
used_for,
is_present) in extension.library_manifest():
if library in libraries:
libraries[library] = (
libraries[library][0] + [used_for],
libraries[library][1] and is_present)
else:
libraries[library] = ([used_for], is_present)
if ext_audiotools_cdio not in self.extensions:
libraries["libcdio"] = (["CDDA data extraction"], False)
if ext_audiotools_dvdaudio not in self.extensions:
libraries["libdvd-audio"] = (["DVD-Audio extraction"], False)
all_libraries_present = (set([l[1] for l in libraries.values()]) ==
set([True]))
table = output_table()
header = table.row()
header.add_column("library", "right")
header.add_column(" ")
header.add_column("present?")
header.add_column(" ")
header.add_column("used for")
if not all_libraries_present:
header.add_column(" ")
header.add_column("download URL")
if not all_libraries_present:
table.divider_row(["-", " ", "-", " ", "-", " ", "-"])
else:
table.divider_row(["-", " ", "-", " ", "-"])
for library in sorted(libraries.keys()):
row = table.row()
row.add_column(library, "right")
row.add_column(" ")
row.add_column("yes" if libraries[library][1] else "no")
row.add_column(" ")
row.add_column(", ".join(libraries[library][0]))
if not all_libraries_present:
row.add_column(" ")
if not libraries[library][1]:
row.add_column(LIBRARY_URLS[library])
else:
row.add_column("")
try:
pkg_config = subprocess.Popen(
["pkg-config", "--version"],
stdout=open(os.devnull, "wb"),
stderr=open(os.devnull, "wb"))
pkg_config_found = (pkg_config.wait() == 0)
except OSError:
pkg_config_found = False
print("=" * table.total_width())
print("Python Audio Tools {} Setup".format(VERSION))
print("=" * table.total_width())
if not pkg_config_found:
def add_row(table, text, alignment="left"):
row = table.row()
row.add_column("*")
row.add_column(text, alignment)
row.add_column("*")
table2 = output_table()
row = table2.row()
row.add_column("*")
row.add_column("*" * 60)
row.add_column("*")
add_row(table2, "pkg-config not found", "center")
add_row(table2,
"some libraries may not be located automatically",
"center")
add_row(table2, "")
add_row(table2, " download pkg-config from:")
add_row(table2,
" http://www.freedesktop.org/wiki/Software/pkg-config/")
add_row(table2, "")
add_row(table2,
" or specify which libraries are available " +
"in \"setup.cfg\"")
row = table2.row()
row.add_column("*")
row.add_column("*" * 60)
row.add_column("*")
for row in table2.format():
print(row)
for row in table.format():
print(row)
print()
class audiotools_cdio(Extension):
def __init__(self, system_libraries):
"""extra_link_args is a list of argument strings
from pkg-config, or None if we're to use the standard
libcdio libraries"""
self.__library_manifest__ = []
sources = []
libraries = set()
extra_compile_args = []
extra_link_args = []
if system_libraries.present("libcdio_paranoia"):
if system_libraries.guaranteed_present("libcdio_paranoia"):
libraries.update(set(["libcdio",
"libcdio_cdda",
"libcdio_paranoia"]))
try:
paranoia_ver = tuple(int(s) for s in
system_libraries.configfile.get(
"Libraries",
"libcdio_paranoia_version"))
if paranoia_ver < (0, 90):
paranoia_version = [("PARANOIA_LT_0_90", None)]
elif paranoia_va < (0, 93):
paranoia_version = [("PARANOIA_LT_0_93", None)]
else:
paranoia_version = []
except (KeyError, ValueError):
paranoia_version = []
else:
extra_compile_args.extend(
system_libraries.extra_compile_args("libcdio_paranoia"))
extra_link_args.extend(
system_libraries.extra_link_args("libcdio_paranoia"))
try:
paranoia_ver = system_libraries.lib_version("libcdio")
if paranoia_ver < (0, 90):
paranoia_version = [("PARANOIA_LT_0_90", None)]
elif paranoia_ver < (0, 93):
paranoia_version = [("PARANOIA_LT_0_93", None)]
else:
paranoia_version = []
except (KeyError, ValueError):
paranoia_version = []
sources.extend(["src/cdiomodule.c",
"src/framelist.c",
"src/pcm_conv.c"])
self.__library_manifest__.append(("libcdio",
"CDDA data extraction",
True))
else:
self.__library_manifest__.append(("libcdio",
"CDDA data extraction",
False))
paranoia_version = []
Extension.__init__(
self,
"audiotools.cdio",
sources=sources,
libraries=list(libraries),
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
define_macros=paranoia_version)
def library_manifest(self):
for values in self.__library_manifest__:
yield values
def libraries_present(self):
for (library, used_for, is_present) in self.library_manifest():
if not is_present:
return False
else:
return True
class audiotools_dvdaudio(Extension):
def __init__(self, system_libraries):
self.__library_manifest__ = []
sources = []
libraries = set()
extra_compile_args = []
extra_link_args = []
if system_libraries.present("libdvd-audio"):
if system_libraries.guaranteed_present("libdvd-audio"):
libraries.update(set(["libdvd-audio"]))
else:
extra_compile_args.extend(
system_libraries.extra_compile_args("libdvd-audio"))
extra_link_args.extend(
system_libraries.extra_link_args("libdvd-audio"))
sources.extend(["src/dvdamodule.c",
"src/framelist.c",
"src/pcm_conv.c"])
self.__library_manifest__.append(("libdvd-audio",
"DVD-Audio data extraction",
True))
else:
self.__library_manifest__.append(("libdvd-audio",
"DVD-Audio data extraction",
False))
Extension.__init__(
self,
"audiotools.dvda",
sources=sources,
libraries=list(libraries),
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args)
def library_manifest(self):
for values in self.__library_manifest__:
yield values
def libraries_present(self):
for (library, used_for, is_present) in self.library_manifest():
if not is_present:
return False
else:
return True
class audiotools_pcm(Extension):
def __init__(self):
Extension.__init__(self,
"audiotools.pcm",
sources=["src/pcm.c",
"src/pcm_conv.c"],
define_macros=[("PCM_MODULE", None)])
class audiotools_pcmconverter(Extension):
def __init__(self):
Extension.__init__(self,
"audiotools.pcmconverter",
sources=["src/pcmconverter.c",
"src/framelist.c",
"src/pcmreader.c",
"src/pcm_conv.c",
"src/bitstream.c",
"src/buffer.c",
"src/func_io.c",
"src/mini-gmp.c",
"src/samplerate/samplerate.c",
"src/samplerate/src_sinc.c",
"src/samplerate/src_zoh.c",
"src/samplerate/src_linear.c"],
define_macros=[("HAS_PYTHON", None)])
class audiotools_replaygain(Extension):
def __init__(self):
Extension.__init__(self,
"audiotools.replaygain",
sources=["src/replaygain.c",
"src/framelist.c",
"src/pcmreader.c",
"src/bitstream.c",
"src/buffer.c",
"src/func_io.c",
"src/mini-gmp.c"],
define_macros=[("HAS_PYTHON", None)])
class audiotools_decoders(Extension):
def __init__(self, system_libraries):
self.__library_manifest__ = []
defines = [("VERSION", VERSION), ("HAS_PYTHON", None)]
sources = ["src/pcm_conv.c",
"src/framelist.c",
"src/bitstream.c",
"src/buffer.c",
"src/func_io.c",
"src/mini-gmp.c",
"src/huffman.c",
"src/decoders/flac.c",
"src/ogg.c",
"src/ogg_crc.c",
"src/common/flac_crc.c",
"src/common/tta_crc.c",
"src/common/m4a_atoms.c",
"src/common/md5.c",
"src/mpc/mpc_crc32.c",
"src/libmpcdec/huffman.c",
"src/libmpcdec/mpc_bits_reader.c",
"src/libmpcdec/mpc_decoder.c",
"src/libmpcdec/mpc_demux.c",
"src/libmpcdec/mpc_reader.c",
"src/libmpcdec/requant.c",
"src/libmpcdec/streaminfo.c",
"src/libmpcdec/synth_filter.c",
"src/decoders/alac.c",
"src/decoders/tta.c",
"src/decoders/mpc.c",
"src/decoders/sine.c",
"src/decoders.c"]
libraries = set()
extra_link_args = []
extra_compile_args = []
if system_libraries.present("libmpg123"):
if system_libraries.guaranteed_present("libmpg123"):
libraries.add("mpg123")
else:
extra_compile_args.extend(
system_libraries.extra_compile_args("libmpg123"))
extra_link_args.extend(
system_libraries.extra_link_args("libmpg123"))
defines.append(("HAS_MP3", None))
sources.append("src/decoders/mp3.c")
self.__library_manifest__.append(("libmpg123",
"MP3/MP2 decoding",
True))
else:
self.__library_manifest__.append(("libmpg123",
"MP3/MP2 decoding",
False))
if system_libraries.present("vorbisfile"):
if system_libraries.guaranteed_present("vorbisfile"):
libraries.update(set(["vorbisfile", "vorbis", "ogg"]))
else:
extra_compile_args.extend(
system_libraries.extra_compile_args("vorbisfile"))
extra_link_args.extend(
system_libraries.extra_link_args("vorbisfile"))
defines.append(("HAS_VORBIS", None))
sources.append("src/decoders/vorbis.c")
self.__library_manifest__.append(("vorbisfile",
"Ogg Vorbis decoding",
True))
else:
self.__library_manifest__.append(("vorbisfile",
"Ogg Vorbis decoding",
False))
if system_libraries.present("opusfile"):
if system_libraries.guaranteed_present("opusfile"):
libraries.add("opusfile")
else:
extra_compile_args.extend(
system_libraries.extra_compile_args("opusfile"))
extra_link_args.extend(
system_libraries.extra_link_args("opusfile"))
defines.append(("HAS_OPUS", None))
sources.append("src/decoders/opus.c")
self.__library_manifest__.append(("opusfile",
"Opus decoding",
True))
else:
self.__library_manifest__.append(("opusfile",
"Opus decoding",
False))
if system_libraries.present("wavpack"):
if system_libraries.guaranteed_present("wavpack"):
libraries.add("wavpack")
else:
extra_compile_args.extend(
system_libraries.extra_compile_args("wavpack"))
extra_link_args.extend(
system_libraries.extra_link_args("wavpack"))
defines.append(("HAS_WAVPACK", None))
sources.append("src/decoders/wavpack.c")
self.__library_manifest__.append(("wavpack",
"Wavpack decoding",
True))
else:
self.__library_manifest__.append(("wavpack",
"Wavpack decoding",
False))
Extension.__init__(self,
"audiotools.decoders",
sources=sources,
define_macros=defines,
libraries=list(libraries),
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args)
def library_manifest(self):
for values in self.__library_manifest__:
yield values
class audiotools_encoders(Extension):
def __init__(self, system_libraries):
self.__library_manifest__ = []
defines = [("VERSION", VERSION), ("HAS_PYTHON", None)]
sources = ["src/pcmreader.c",
"src/framelist.c",
"src/pcm_conv.c",
"src/bitstream.c",
"src/buffer.c",
"src/func_io.c",
"src/libmpcenc/analy_filter.c",
"src/libmpcenc/bitstream.c",
"src/libmpcenc/encode_sv7.c",
"src/libmpcenc/huffsv7.c",
"src/libmpcenc/quant.c",
"src/libmpcpsy/ans.c",
"src/libmpcpsy/cvd.c",
"src/libmpcpsy/fft4g.c",
"src/libmpcpsy/fft_routines.c",
"src/libmpcpsy/profile.c",
"src/libmpcpsy/psy.c",
"src/libmpcpsy/psy_tab.c",
"src/encoders/mpc.c",
"src/mpc/mpc_crc32.c",
"src/mini-gmp.c",
"src/common/md5.c",
"src/encoders/flac.c",
"src/common/flac_crc.c",
"src/common/tta_crc.c",
"src/encoders/alac.c",
"src/common/m4a_atoms.c",
"src/encoders/tta.c",
"src/encoders.c"]
libraries = set()
extra_link_args = []
extra_compile_args = []
# Since mp3lame doesn't show up in pkg-config,
# assume it's present if the user guarantees it is
# or if the lame executable is present.
# This may fail if the user has installed the binary
# with a lame-dev package of some kind.
mp3lame_present = system_libraries.guaranteed_present("mp3lame")
if mp3lame_present is None:
mp3lame_present = system_libraries.executable_present(
"lame", "--version")
if mp3lame_present:
libraries.add("mp3lame")
defines.append(("HAS_MP3", None))
sources.append("src/encoders/mp3.c")
self.__library_manifest__.append(("mp3lame",
"MP3 encoding",
True))
else:
self.__library_manifest__.append(("mp3lame",
"MP3 encoding",
False))
if system_libraries.present("twolame"):
if system_libraries.guaranteed_present("twolame"):
libraries.add("twolame")
else:
extra_compile_args.extend(
system_libraries.extra_compile_args("twolame"))
extra_link_args.extend(
system_libraries.extra_link_args("twolame"))
defines.append(("HAS_MP2", None))
sources.append("src/encoders/mp2.c")
self.__library_manifest__.append(("twolame",
"MP2 encoding",
True))
else:
self.__library_manifest__.append(("twolame",
"MP2 encoding",
False))
if system_libraries.present("vorbisenc"):
if system_libraries.guaranteed_present("vorbisenc"):
libraries.update(set(["vorbisenc", "vorbis", "ogg"]))
else:
extra_compile_args.extend(
system_libraries.extra_compile_args("vorbisenc"))
extra_link_args.extend(
system_libraries.extra_link_args("vorbisenc"))
defines.append(("HAS_VORBIS", None))
sources.append("src/encoders/vorbis.c")
self.__library_manifest__.append(("vorbisenc",
"Ogg Vorbis encoding",
True))
else:
self.__library_manifest__.append(("vorbisenc",
"Ogg Vorbis encoding",
False))
if system_libraries.present("opus"):
if system_libraries.guaranteed_present("opus"):
libraries.add("opus")
else:
extra_compile_args.extend(
system_libraries.extra_compile_args("opus"))
extra_link_args.extend(
system_libraries.extra_link_args("opus"))
defines.append(("HAS_OPUS", None))
sources.append("src/encoders/opus.c")
self.__library_manifest__.append(("opus",
"Opus encoding",
True))
else:
self.__library_manifest__.append(("opus",
"Opus encoding",
False))
if system_libraries.present("wavpack"):
if system_libraries.guaranteed_present("wavpack"):
libraries.add("wavpack")
else:
extra_compile_args.extend(
system_libraries.extra_compile_args("wavpack"))
extra_link_args.extend(
system_libraries.extra_link_args("wavpack"))
defines.append(("HAS_WAVPACK", None))
sources.append("src/encoders/wavpack.c")
self.__library_manifest__.append(("wavpack",
"Wavpack encoding",
True))
else:
self.__library_manifest__.append(("wavpack",
"Wavpack encoding",
False))
Extension.__init__(self,
"audiotools.encoders",
sources=sources,
define_macros=defines,
libraries=list(libraries),
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args)
def library_manifest(self):
for values in self.__library_manifest__:
yield values
class audiotools_bitstream(Extension):
def __init__(self):
Extension.__init__(self,
"audiotools.bitstream",
sources=["src/mod_bitstream.c",
"src/bitstream.c",
"src/buffer.c",
"src/func_io.c",
"src/mini-gmp.c",
"src/huffman.c"],
define_macros=[("HAS_PYTHON", None)])
class audiotools_ogg(Extension):
def __init__(self):
Extension.__init__(self,
"audiotools._ogg",
sources=["src/ogg.c",
"src/ogg_crc.c",
"src/mod_ogg.c",
"src/bitstream.c",
"src/func_io.c",
"src/mini-gmp.c",
"src/buffer.c"],
define_macros=[("HAS_PYTHON", None)])
class audiotools_accuraterip(Extension):
def __init__(self):
Extension.__init__(self,
"audiotools._accuraterip",
sources=["src/accuraterip.c"])
class audiotools_output(Extension):
def __init__(self, system_libraries):
self.__library_manifest__ = []
sources = ["src/output.c"]
defines = []
libraries = set()
extra_compile_args = []
extra_link_args = []
# assume MacOS X always has CoreAudio
if sys.platform == "darwin":
sources.append("src/output/core_audio.c")
defines.append(("CORE_AUDIO", "1"))
extra_link_args.extend(["-framework", "AudioToolbox",
"-framework", "AudioUnit",
"-framework", "CoreServices"])
self.__library_manifest__.append(("CoreAudio",
"Core Audio output",
True))
elif sys.platform.startswith("linux"):
# only check for ALSA on Linux
if system_libraries.present("alsa"):
if system_libraries.guaranteed_present("alsa"):
libraries.add("asound")
else:
extra_compile_args.extend(
system_libraries.extra_compile_args("alsa"))
extra_link_args.extend(
system_libraries.extra_link_args("alsa"))
sources.append("src/output/alsa.c")
sources.append("src/framelist.c")
defines.append(("ALSA", "1"))
self.__library_manifest__.append(("libasound2",
"ALSA output",
True))
else:
self.__library_manifest__.append(("libasound2",
"ALSA output",
False))
if system_libraries.present("libpulse"):
if system_libraries.guaranteed_present("libpulse"):
libraries.add("pulse")
else:
extra_compile_args.extend(
system_libraries.extra_compile_args("libpulse"))
extra_link_args.extend(
system_libraries.extra_link_args("libpulse"))
sources.append("src/output/pulseaudio.c")
# only include pcmconv once
if "src/framelist.c" not in sources:
sources.append("src/framelist.c")
defines.append(("PULSEAUDIO", "1"))
self.__library_manifest__.append(("libpulse",
"PulseAudio output",
True))