コード例 #1
0
 def test_read_all_from_file(self):
     _f = open(self.test_filename, "r")
     f = SndFile(_f)
     data, n_samples = f.read(dtype=np.float64)
     self.assertEqual(n_samples, 19968)
     f.close()
     _f.close()
コード例 #2
0
 def test_open_filename(self):
     f = SndFile(self.test_filename)
     self.assertEqual(f.samplerate, 8000)
     self.assertEqual(
         f.format,
         FILE_FORMATS.SF_FORMAT_WAV | FILE_FORMATS.SF_FORMAT_PCM_16)
     self.assertEqual(f.channels, 1)
     f.close()
コード例 #3
0
    def test_write_from_file(self):
        _f = open(self.test_filename, "r")
        f = SndFile(_f)
        data, n_samples = f.read(dtype=np.float64)
        f.close()
        _f.close()

        _g = open(self.test_filename + "_tmp", "w")

        g = SndFile(_g,
                    writeSamplerate=8000,
                    open_mode=OPEN_MODES.SFM_WRITE,
                    writeFormat=FILE_FORMATS.SF_FORMAT_WAV
                    | FILE_FORMATS.SF_FORMAT_PCM_16,
                    writeNbChannels=1)
        g.write(data)
        g.close()
        _g.close()
コード例 #4
0
    def test_write(self):
        f = SndFile(self.test_filename)
        data, n_samples = f.read(dtype=np.float64)
        self.assertEqual(n_samples, 19968)
        f.close()

        f = SndFile(self.test_filename + "_tmp",
                    open_mode=OPEN_MODES.SFM_WRITE,
                    writeSamplerate=8000,
                    writeFormat=FILE_FORMATS.SF_FORMAT_WAV
                    | FILE_FORMATS.SF_FORMAT_PCM_16,
                    writeNbChannels=1)
        f.write(data)
        f.close()

        f = SndFile(self.test_filename + "_tmp")
        data2, n_samples2 = f.read(dtype=np.float64)
        f.close()

        self.assertEqual(n_samples, n_samples2)
        self.assertEqual(data[100], data2[100])
コード例 #5
0
    def test_read_all(self):
        f = SndFile(self.test_filename)
        data, n_samples = f.read(dtype=np.float64)
        self.assertEqual(n_samples, 19968)
        f.close()

        f = SndFile(self.test_filename)
        data, n_samples = f.read(dtype="float64")
        self.assertEqual(n_samples, 19968)
        f.close()

        f = SndFile(self.test_filename)
        data, n_samples = f.read(dtype="short")
        self.assertEqual(n_samples, 19968)
        f.close()
コード例 #6
0
        _g = open(self.test_filename + "_tmp", "w")

        g = SndFile(_g,
                    writeSamplerate=8000,
                    open_mode=OPEN_MODES.SFM_WRITE,
                    writeFormat=FILE_FORMATS.SF_FORMAT_WAV
                    | FILE_FORMATS.SF_FORMAT_PCM_16,
                    writeNbChannels=1)
        g.write(data)
        g.close()
        _g.close()


if __name__ == "__main__":
    with SndFile("LS100673.WAV") as f:
        #print various information
        print f
        #read from 1 to 3 seconds
        data, nbFramesRead = f.readFromTo(1 * f.samplerate,
                                          3 * f.samplerate,
                                          dtype=np.float64)
        print "nb frames read:", nbFramesRead

        #get the left channel
        lChannel = data[:, 0]

        from scipy.signal import butter, lfilter
        cutoffL = 200.
        # Low-pass filter on the left channel at 200 Hz
        b, a = butter(3, cutoffL / (f.samplerate / 2), btype="low")
コード例 #7
0
ファイル: decoder.py プロジェクト: wtlim/celp_codec
parser.add_argument('--subframes',
                    type=int,
                    default=4,
                    help='numbre of subframes')
parser.add_argument('--fixed-cb-size',
                    type=int,
                    default=4,
                    help='fixed codebook size')

args = parser.parse_args()

in_file = args.i

out_file = SndFile(args.o,
                   open_mode=OPEN_MODES.SFM_WRITE,
                   writeSamplerate=8000,
                   writeFormat=FILE_FORMATS.SF_FORMAT_WAV
                   | FILE_FORMATS.SF_FORMAT_PCM_16,
                   writeNbChannels=1)

celp_decoder = celp.CELP(frame_length=args.frame_length,
                         n_subframes=args.subframes,
                         lpc_order=args.lpc_order,
                         fixed_codebook_size=args.fixed_cb_size)

bytes_per_frame = celp_decoder.bytes_per_frame()

while True:
    frame_bits = in_file.read(bytes_per_frame)
    if len(frame_bits) < bytes_per_frame:
        break
コード例 #8
0
                    type=str,
                    default="boxcar",
                    help='frame windows (boxcar, hamming, hanning, etc)')
parser.add_argument('--weigthing-coeff-1',
                    type=float,
                    default=0.9,
                    help='first coefficient of the weigthing filter'
                    ' W(z) = A(z/coeff_1) / A(z/coeff_2)')
parser.add_argument('--weigthing-coeff-2',
                    type=float,
                    default=0.6,
                    help='second coefficient of the weigthing filter'
                    ' W(z) = A(z/coeff_1) / A(z/coeff_2)')
args = parser.parse_args()

in_file = SndFile(args.i)

assert in_file.samplerate == 8000
assert in_file.channels == 1

out_file = args.o

celp_encoder = celp.CELP(frame_length=args.frame_length,
                         n_subframes=args.subframes,
                         lpc_order=args.lpc_order,
                         fixed_codebook_size=args.fixed_cb_size,
                         frame_window=args.frame_window,
                         weigthing_coeff_1=args.weigthing_coeff_1,
                         weigthing_coeff_2=args.weigthing_coeff_2)

bytes_per_frame = celp_encoder.bytes_per_frame()