tearing when flashing image to audio

Pixilang programming language
Post Reply
User avatar
AutumnCheney
Posts: 403
Joined: Sun Dec 29, 2019 8:16 am
Location: tahlequah, ok, usa
Contact:

tearing when flashing image to audio

Post by AutumnCheney »

here's another question i had :fool:

in my demo lib project, i have a background image with the brightness of the image connected to the demo audio, so that it flashes to the audio. however, it seems that the audio samples change too quickly for the image renderer, and these "tears" happen as a result

you can really see it here:



and here's what my code looks like (approximately):

Code: Select all

flash = abs(demo_sound_pcm_stream[demo_sound_pcm_stream_ptr * demo_sound_channels]) + 1)
pixi(cover, 0, 0, get_color(flash, flash, flash), ((demo_xsize / cover_xsize)), ((demo_xsize / cover_xsize)))
i'm trying to fix it by linearly interpolating the samples, but that doesn't get rid of it completely. i'm thinking about implementing some kind of downsampling or rms, but i don't know how to actually implement either of these

what can i do? thank you!
User avatar
NightRadio
Site Admin
Posts: 3827
Joined: Fri Jan 23, 2004 12:28 am
Location: Ekaterinburg. Russia
Contact:

Re: tearing when flashing image to audio

Post by NightRadio »

try something like
speed = 0.1 //from 0 (freeze) to 1 (max speed)
flash = flash * (1-speed) + next_value * speed
User avatar
AutumnCheney
Posts: 403
Joined: Sun Dec 29, 2019 8:16 am
Location: tahlequah, ok, usa
Contact:

Re: tearing when flashing image to audio

Post by AutumnCheney »

NightRadio wrote: Tue Jan 10, 2023 3:50 pm try something like
speed = 0.1 //from 0 (freeze) to 1 (max speed)
flash = flash * (1-speed) + next_value * speed
thanks! maybe i just didn't implement the algorithm correctly the first time
Post Reply