Skip to content

Commit

Permalink
ptttL_audio_encoder: add ptttl_to_sample_data method
Browse files Browse the repository at this point in the history
  • Loading branch information
eriknyquist committed Nov 18, 2018
1 parent 7ecf3ae commit e02ea2e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions tones/mixer.py
Expand Up @@ -391,20 +391,28 @@ def mix(self):

return ret

def write_wav(self, filename):
def sample_data(self):
"""
Mixes all trackes down into a single stream of samples and returns the
samples as a 16-bit PCM stream packed into a string
"""
return self.mix().serialize()

def write_wav(self, filename, sampledata=None):
"""
Mixes all tracks into a single stream of samples and writes to a
.wav audio file
:param str filename: name of file to write
"""

samples = self.mix()

f = wave.open(filename, 'w')

f.setparams((tones.NUM_CHANNELS, tones.DATA_SIZE, self._rate,
int(len(samples) / 2), "NONE", "Uncompressed"))

f.writeframes(samples.serialize())
if sampledata is None:
sampledata = self.mix().serialize()

f.writeframes(sampledata)
f.close()

0 comments on commit e02ea2e

Please sign in to comment.