Loop sound with dynamical pitch and volume modification

Hi there,

is it possible to play a sound (wav, etc) in a infinity loop and change dynamically the pitch and volume like a engine sound of a car?

@Dominik I would say yes, but I don’t have anything at the moment to prove it.

EDIT: If you look at the reference for sound, you will see a lot of parameters that can be changed.

@Dominik After looking at sound some more in the reference and trying things, it looks like once sound starts with given values, they can’t be changed until sound ends and then starts again.

@Dominik have a look here - this might help. I looked into doing something similar with an onscreen piano. Worked with the included sound files.

https://codea.io/talk/discussion/6532/problem-with-sound-partially-solved-includes-a-simple-piano

Didn’t try it in a loop - you might run into issues with initiating a new “play sound” command each loop but will depend on your particular needs

@Dominik How about this?

-- Use this function to perform your initial setup
function setup()
    s = sound("A Hero's Quest:Rain",  1,  1,  0,  true)
    parameter.number("Volume",0,1,1)
    parameter.number("Pitch",0,1,1)
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(40, 40, 50)
    
    s.pitch = Pitch
    s.volume = Volume
end

When you start the project you’ll hear the sound of rain looping infinitely. You can then use the parameters on the left to change the volume and pitch of the rain, without it restarting the sound effect.

@Kolosso Thanks. It helps me a lot.

Thanks to all for your posts.