示例#1
0
    def tearDown(self):
        decoder = FileDecoder(uri=self.source,
                              start=self.start,
                              duration=self.duration)

        decoder.setup(samplerate=self.samplerate,
                      channels=self.channels,
                      blocksize=self.blocksize)

        totalframes = 0

        while True:
            frames, eod = decoder.process()
            totalframes += frames.shape[0]
            if eod or decoder.eod:
                break
            self.assertEqual(frames.shape[0], decoder.blocksize())
            self.assertEqual(frames.shape[1], decoder.channels())

        ratio = decoder.output_samplerate / decoder.input_samplerate
        if 0:
            print "input / output_samplerate:", decoder.input_samplerate, '/', decoder.output_samplerate,
            print "ratio:", ratio
            print "input / output_channels:", decoder.input_channels, decoder.output_channels
            print "input_duration:", decoder.input_duration
            print "input_totalframes:", decoder.input_totalframes
            print "mime_type", decoder.mime_type()

        if self.channels:
            # when specified, check that the channels are the ones requested
            self.assertEqual(self.channels, decoder.output_channels)
        else:
            # otherwise check that the channels are preserved, if not specified
            self.assertEqual(decoder.input_channels, decoder.output_channels)
            # and if we know the expected channels, check the output match
            if self.expected_channels:
                self.assertEqual(self.expected_channels,
                                 decoder.output_channels)
        # do the same with the sampling rate
        if self.samplerate:
            self.assertEqual(self.samplerate, decoder.output_samplerate)
        else:
            self.assertEqual(decoder.input_samplerate,
                             decoder.output_samplerate)
            if self.expected_samplerate:
                self.assertEqual(self.expected_samplerate,
                                 decoder.output_samplerate)

        self.assertEqual(decoder.mime_type(), self.expected_mime_type)

        self.assertEqual(totalframes, self.expected_totalframes)
        input_duration = decoder.input_totalframes / decoder.input_samplerate
        output_duration = decoder.totalframes() / decoder.output_samplerate
        if self.test_exact_duration:
            self.assertEqual(input_duration, output_duration)
            self.assertEqual(input_duration, decoder.uri_duration)
            self.assertEqual(self.source_duration, decoder.uri_duration)
        else:
            self.assertAlmostEqual(input_duration, output_duration, places=1)
            self.assertAlmostEqual(input_duration,
                                   decoder.uri_duration,
                                   places=1)
            self.assertAlmostEqual(self.source_duration,
                                   decoder.uri_duration,
                                   places=1)
from timeside.core import *
from timeside.decoder import FileDecoder
from timeside.encoder import Mp3Encoder

import sys
if len(sys.argv) > 1:
    source = sys.argv[1]
else:
    import os.path
    source = os.path.join(os.path.dirname(__file__), "../samples/sweep.flac")

decoder = FileDecoder(source)

print "Creating decoder with id=%s for: %s" % (decoder.id(), source)
decoder.setup()

channels = decoder.channels()
print 'channels :', channels
samplerate = decoder.samplerate()
#nframes = decoder.nframes()

dest1 = "/tmp/test_filesink.mp3"
dest2 = "/tmp/test_appsink.mp3"
f = open(dest2, 'w')

streaming = True
encoder = Mp3Encoder(dest1, streaming=True, overwrite=True)
encoder.setup(channels=channels,
              samplerate=samplerate,
              blocksize=decoder.blocksize(),
示例#3
0
    def tearDown(self):
        decoder = FileDecoder(uri=self.source,
                              start=self.start,
                              duration=self.duration)

        decoder.setup(samplerate=self.samplerate, channels=self.channels,
                      blocksize=self.blocksize)

        totalframes = 0

        while True:
            frames, eod = decoder.process()
            totalframes += frames.shape[0]
            if eod or decoder.eod:
                break
            self.assertEqual(frames.shape[0], decoder.blocksize())
            self.assertEqual(frames.shape[1], decoder.channels())

        ratio = decoder.output_samplerate / decoder.input_samplerate
        if 0:
            print "input / output_samplerate:", decoder.input_samplerate, '/', decoder.output_samplerate,
            print "ratio:", ratio
            print "input / output_channels:", decoder.input_channels, decoder.output_channels
            print "input_duration:", decoder.input_duration
            print "input_totalframes:", decoder.input_totalframes
            print "mime_type", decoder.mime_type()

        if self.channels:
            # when specified, check that the channels are the ones requested
            self.assertEqual(self.channels, decoder.output_channels)
        else:
            # otherwise check that the channels are preserved, if not specified
            self.assertEqual(decoder.input_channels, decoder.output_channels)
            # and if we know the expected channels, check the output match
            if self.expected_channels:
                self.assertEqual(
                    self.expected_channels, decoder.output_channels)
        # do the same with the sampling rate
        if self.samplerate:
            self.assertEqual(self.samplerate, decoder.output_samplerate)
        else:
            self.assertEqual(
                decoder.input_samplerate, decoder.output_samplerate)
            if self.expected_samplerate:
                self.assertEqual(
                    self.expected_samplerate, decoder.output_samplerate)

        self.assertEqual(decoder.mime_type(), self.expected_mime_type)

        self.assertEqual(totalframes, self.expected_totalframes)
        input_duration = decoder.input_totalframes / decoder.input_samplerate
        output_duration = decoder.totalframes() / decoder.output_samplerate
        if self.test_exact_duration:
            self.assertEqual(input_duration, output_duration)
            self.assertEqual(input_duration,
                             decoder.uri_duration)
            self.assertEqual(self.source_duration,
                             decoder.uri_duration)
        else:
            self.assertAlmostEqual(input_duration, output_duration,
                                   places=1)
            self.assertAlmostEqual(input_duration,
                                   decoder.uri_duration,
                                   places=1)
            self.assertAlmostEqual(self.source_duration,
                                   decoder.uri_duration,
                                   places=1)
from timeside.core import *
from timeside.decoder import FileDecoder
from timeside.encoder import Mp3Encoder

import sys
if len(sys.argv) > 1:
    source = sys.argv[1]
else:
    import os.path
    source= os.path.join (os.path.dirname(__file__),  "../samples/sweep.flac")

decoder = FileDecoder(source)

print "Creating decoder with id=%s for: %s" % (decoder.id(), source)
decoder.setup()

channels  = decoder.channels()
print 'channels :', channels
samplerate = decoder.samplerate()
#nframes = decoder.nframes()

dest1 = "/tmp/test_filesink.mp3"
dest2 = "/tmp/test_appsink.mp3"
f = open(dest2,'w')

streaming=True
encoder = Mp3Encoder(dest1, streaming=True, overwrite=True)
encoder.setup(channels=channels, samplerate=samplerate,
              blocksize=decoder.blocksize(), totalframes=decoder.totalframes())
while True: