mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-25 16:48:11 +00:00
example: Use do_fill in AudioTestSrc instead of do_create
With the new mapping API we can efficiently use the ->fill vmethod which is sensibly better.
This commit is contained in:
parent
d365954fc0
commit
986d6d12fb
1 changed files with 14 additions and 11 deletions
|
@ -148,7 +148,7 @@ class AudioTestSrc(GstBase.BaseSrc):
|
||||||
|
|
||||||
return start, end
|
return start, end
|
||||||
|
|
||||||
def do_create(self, offset, length):
|
def do_fill(self, offset, length, buf):
|
||||||
if length == -1:
|
if length == -1:
|
||||||
samples = SAMPLESPERBUFFER
|
samples = SAMPLESPERBUFFER
|
||||||
else:
|
else:
|
||||||
|
@ -162,16 +162,19 @@ class AudioTestSrc(GstBase.BaseSrc):
|
||||||
next_byte = self.next_byte + bytes_
|
next_byte = self.next_byte + bytes_
|
||||||
next_time = Gst.util_uint64_scale_int(next_sample, Gst.SECOND, self.info.rate)
|
next_time = Gst.util_uint64_scale_int(next_sample, Gst.SECOND, self.info.rate)
|
||||||
|
|
||||||
if not self.mute:
|
try:
|
||||||
r = np.repeat(
|
with buf.map(Gst.MapFlags.WRITE) as info:
|
||||||
np.arange(self.accumulator, self.accumulator + samples),
|
array = np.ndarray(shape = self.info.channels * samples, dtype = np.float32, buffer = info.data)
|
||||||
self.info.channels)
|
if not self.mute:
|
||||||
data = ((np.sin(2 * np.pi * r * self.freq / self.info.rate) * self.volume)
|
r = np.repeat(np.arange(self.accumulator, self.accumulator + samples),
|
||||||
.astype(np.float32))
|
self.info.channels)
|
||||||
else:
|
np.sin(2 * np.pi * r * self.freq / self.info.rate, out=array)
|
||||||
data = [0] * bytes_
|
array *= self.volume
|
||||||
|
else:
|
||||||
buf = Gst.Buffer.new_wrapped(bytes(data))
|
array[:] = 0
|
||||||
|
except Exception as e:
|
||||||
|
Gst.error("Mapping error: %s" % e)
|
||||||
|
return Gst.FlowReturn.ERROR
|
||||||
|
|
||||||
buf.offset = self.next_sample
|
buf.offset = self.next_sample
|
||||||
buf.offset_end = next_sample
|
buf.offset_end = next_sample
|
||||||
|
|
Loading…
Reference in a new issue