Пример #1
0
    def __init__(
        self,
        buffer: SynthizerSoundBuffer,
        context: synthizer.Context,
    ) -> None:

        super().__init__(buffer=buffer)

        self._context = context
        self._generator = synthizer.BufferGenerator(self._context)
        self._generator.buffer = cast(SynthizerSoundBuffer, self._buffer)._buffer

        self._source = synthizer.Source3D(self._context)

        self._last_position = 0.0
        self._playing = False
Пример #2
0
 def load(self, filename):
     if self.handle != None: self.close()
     if isinstance(filename, str):  # Asume path on disk.
         self.generator = synthizer.BufferGenerator(self.context)
         self.buffer = gsbm.buffer(filename)
         self.length = self.buffer.get_length_in_seconds()
         self.generator.buffer = self.buffer
         if self.type == "3d":
             self.source = synthizer.Source3D(self.context)
         elif self.type == "direct":
             self.source = synthizer.DirectSource(self.context)
         elif self.type == "panned":
             self.source = synthizer.PannedSource(self.context)
     if self.is_active:
         self.filename = filename
         return True
     return False
Пример #3
0
"""Read a file into memory in Python, then ask the buffer to decode it for us.
Demonstrates how to decode encoded data from places that aren't the disk, e.g.
the result of an http request.

usage: buffer_from_memory.py myfile."""
import sys

import synthizer

with synthizer.initialized():
    ctx = synthizer.Context()
    with open(sys.argv[1], "rb") as f:
        data = f.read()
    buffer = synthizer.Buffer.from_encoded_data(data)
    gen = synthizer.BufferGenerator(ctx)
    gen.buffer = buffer
    src = synthizer.DirectSource(ctx)
    src.add_generator(gen)
    print("Press enter to exit")
    input()