Exemplo n.º 1
0
 def write(self, filename):
     h_s = BinaryStream()
     h_s.pack(self._waveformatex, self.h_format_tag, self.h_channels,
              self.h_samples_per_sec, self.h_avg_bytes_per_sec,
              self.h_block_align, self.h_bits_per_sample)
     if self.h_size is not None:
         h_s.write_uint16(self.h_size)
         if self.h_format_tag == WAVE_FORMAT_XMA2:
             # hack so mono sounds end up center rather than left
             if self.h_channels == 1 and self.hx_channel_mask == 1:
                 hx_channel_mask = 0
             else:
                 hx_channel_mask = self.hx_channel_mask
             h_s.pack(self._waveformat_xma2, self.hx_num_streams,
                      hx_channel_mask, self.hx_samples_encoded,
                      self.hx_bytes_per_block, self.hx_play_begin,
                      self.hx_play_length, self.hx_loop_begin,
                      self.hx_loop_length, self.hx_loop_count,
                      self.hx_encoder_version, self.hx_block_count)
         elif self.h_format_tag == WAVE_FORMAT_EXTENSIBLE:
             h_s.pack(self._waveformat_extensible,
                      self.he_valid_bits_per_sample, self.he_channel_mask,
                      self.he_subformat.bytes_le)
             if self.he_remainder:
                 h_s.write(self.he_remainder)
         if self.h_remainder:
             h_s.write(self.h_remainder)
     header_raw = h_s.getvalue()
     if self.dpds_raw:
         dpds_size = len(self.dpds_raw)
     else:
         dpds_size = None
     if self.seek_raw:
         seek_size = len(self.seek_raw)
     else:
         seek_size = None
     o_s = BinaryStream()
     if self.h_format_tag == WAVE_FORMAT_WMAUDIO2 or self.h_format_tag == WAVE_FORMAT_WMAUDIO3:
         riff_type = b'XWMA'
     else:
         riff_type = b'WAVE'
     self.write_header(o_s, riff_type, len(header_raw), len(self.data_raw),
                       dpds_size, seek_size)
     self.write_chunk(o_s, b'fmt ', header_raw)
     if self.dpds_raw:
         self.write_chunk(o_s, b'dpds', self.dpds_raw)
     if self.seek_raw:
         self.write_chunk(o_s, b'seek', self.seek_raw)
     self.write_chunk(o_s, b'data', self.data_raw)
     if self.h_format_tag == WAVE_FORMAT_XMA2:
         full_filename = filename + '.xma'
     elif self.h_format_tag == WAVE_FORMAT_WMAUDIO2 or self.h_format_tag == WAVE_FORMAT_WMAUDIO2:
         full_filename = filename + '.xwma'
     else:
         full_filename = filename + '.wav'
     o_s.write_file(full_filename)
Exemplo n.º 2
0
 def write(self, filename):
     h_s = BinaryStream()
     h_s.pack(self._waveformatex, self.h_format_tag, self.h_channels, self.h_samples_per_sec,
              self.h_avg_bytes_per_sec, self.h_block_align, self.h_bits_per_sample)
     if self.h_size is not None:
         h_s.write_uint16(self.h_size)
         if self.h_format_tag == WAVE_FORMAT_XMA2:
             # hack so mono sounds end up center rather than left
             if self.h_channels == 1 and self.hx_channel_mask == 1:
                 hx_channel_mask = 0
             else:
                 hx_channel_mask = self.hx_channel_mask
             h_s.pack(self._waveformat_xma2, self.hx_num_streams, hx_channel_mask, self.hx_samples_encoded,
                      self.hx_bytes_per_block, self.hx_play_begin, self.hx_play_length, self.hx_loop_begin,
                      self.hx_loop_length, self.hx_loop_count, self.hx_encoder_version, self.hx_block_count)
         elif self.h_format_tag == WAVE_FORMAT_EXTENSIBLE:
             h_s.pack(self._waveformat_extensible, self.he_valid_bits_per_sample, self.he_channel_mask,
                      self.he_subformat.bytes_le)
             if self.he_remainder:
                 h_s.write(self.he_remainder)
         if self.h_remainder:
             h_s.write(self.h_remainder)
     header_raw = h_s.getvalue()
     if self.dpds_raw:
         dpds_size = len(self.dpds_raw)
     else:
         dpds_size = None
     if self.seek_raw:
         seek_size = len(self.seek_raw)
     else:
         seek_size = None
     o_s = BinaryStream()
     if self.h_format_tag == WAVE_FORMAT_WMAUDIO2 or self.h_format_tag == WAVE_FORMAT_WMAUDIO3:
         riff_type = b'XWMA'
     else:
         riff_type = b'WAVE'
     self.write_header(o_s, riff_type, len(header_raw), len(self.data_raw), dpds_size, seek_size)
     self.write_chunk(o_s, b'fmt ', header_raw)
     if self.dpds_raw:
         self.write_chunk(o_s, b'dpds', self.dpds_raw)
     if self.seek_raw:
         self.write_chunk(o_s, b'seek', self.seek_raw)
     self.write_chunk(o_s, b'data', self.data_raw)
     if self.h_format_tag == WAVE_FORMAT_XMA2:
         full_filename = filename + '.xma'
     elif self.h_format_tag == WAVE_FORMAT_WMAUDIO2 or self.h_format_tag == WAVE_FORMAT_WMAUDIO2:
         full_filename = filename + '.xwma'
     else:
         full_filename = filename + '.wav'
     o_s.write_file(full_filename)