Skip to content

Callbacks slow down the applications #3

@wilsonsilva

Description

@wilsonsilva

Here's an example:

ProcessAudio = FFI::Function.new(:void, [:pointer, :uint]) do |buffer, frames|
# samples = buffer.to_a
# average = 0.0 # Temporary average volume
#
# frames.times do |frame|
# left = samples[frame * 2]
# right = samples[frame * 2 + 1]
#
# left = (left.abs ** $exponent) * (left < 0.0 ? -1.0 : 1.0)
# right = (right.abs ** $exponent) * (right < 0.0 ? -1.0 : 1.0)
#
# average += (left.abs / frames) + (right.abs / frames)
# end
#
# # Moving history to the left
# $average_volume.shift(399)
# $average_volume << average # Adding last average value
end
# Initialization
# --------------------------------------------------------------------------------------
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 450
Raylib.init_window(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [audio] example - processing mixed output")
Raylib.init_audio_device # Initialize audio device
# Raylib.attach_audio_mixed_processor(ProcessAudio) # FIXME: Uncomment when callbacks are supported

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions