| 545 | warnings.warn(w) |
| 546 | |
| 547 | class Aifc_write: |
| 548 | # Variables used in this class: |
| 549 | # |
| 550 | # These variables are user settable through appropriate methods |
| 551 | # of this class: |
| 552 | # _file -- the open file with methods write(), close(), tell(), seek() |
| 553 | # set through the __init__() method |
| 554 | # _comptype -- the AIFF-C compression type ('NONE' in AIFF) |
| 555 | # set through the setcomptype() or setparams() method |
| 556 | # _compname -- the human-readable AIFF-C compression type |
| 557 | # set through the setcomptype() or setparams() method |
| 558 | # _nchannels -- the number of audio channels |
| 559 | # set through the setnchannels() or setparams() method |
| 560 | # _sampwidth -- the number of bytes per audio sample |
| 561 | # set through the setsampwidth() or setparams() method |
| 562 | # _framerate -- the sampling frequency |
| 563 | # set through the setframerate() or setparams() method |
| 564 | # _nframes -- the number of audio frames written to the header |
| 565 | # set through the setnframes() or setparams() method |
| 566 | # _aifc -- whether we're writing an AIFF-C file or an AIFF file |
| 567 | # set through the aifc() method, reset through the |
| 568 | # aiff() method |
| 569 | # |
| 570 | # These variables are used internally only: |
| 571 | # _version -- the AIFF-C version number |
| 572 | # _comp -- the compressor from builtin module cl |
| 573 | # _nframeswritten -- the number of audio frames actually written |
| 574 | # _datalength -- the size of the audio samples written to the header |
| 575 | # _datawritten -- the size of the audio samples actually written |
| 576 | |
| 577 | _file = None # Set here since __del__ checks it |
| 578 | |
| 579 | def __init__(self, f): |
| 580 | if isinstance(f, str): |
| 581 | file_object = builtins.open(f, 'wb') |
| 582 | try: |
| 583 | self.initfp(file_object) |
| 584 | except: |
| 585 | file_object.close() |
| 586 | raise |
| 587 | |
| 588 | # treat .aiff file extensions as non-compressed audio |
| 589 | if f.endswith('.aiff'): |
| 590 | self._aifc = 0 |
| 591 | else: |
| 592 | # assume it is an open file object already |
| 593 | self.initfp(f) |
| 594 | |
| 595 | def initfp(self, file): |
| 596 | self._file = file |
| 597 | self._version = _AIFC_version |
| 598 | self._comptype = b'NONE' |
| 599 | self._compname = b'not compressed' |
| 600 | self._convert = None |
| 601 | self._nchannels = 0 |
| 602 | self._sampwidth = 0 |
| 603 | self._framerate = 0 |
| 604 | self._nframes = 0 |