Hi, I'm new here! I just started using Löve, to make a simple program to play with the pitch of a sound.
The code is as follows:
:::::CODE STARTS:::::
function load()
sound = love.audio.newSound("catmeow.wav")
src1 = love.audio.newSource(sound)
src1:setVolume(0.9) -- is this necessary to set the volume?
x = love.mouse.getX()
end
function update(dt)
src1:setPitch(x)
love.audio.play(src1)
end
:::::CODE ENDS:::::
As you can see, I want the position of x of the mouse to control the pitch of the .wav sample, so the pitch can be controlled in real time.
but when the program loads, the window pops up as expected, but there is no sound.
I wrote simple scripts without any functions to load up the .wav and play it, and they worked. I also wrote one with the pitch set to a predetermined number (example: 3) and it worked.
But if I want to control the pitch in real time, how can it be done?
First Löve attempt with sound & pitch not working, pls help!
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: First Löve attempt with sound & pitch not working, pls help!
Hi there.alex_ wrote:Hi, I'm new here! I just started using Löve, to make a simple program to play with the pitch of a sound.
0.6.0 uses love.load() instead of load() etc.
You do x = love.mouse.getX() in load(), which means x will be set to the mouse position at the time of load().
Code: Select all
function love.load()
sound = love.audio.newSound("catmeow.wav")
src1 = love.audio.newSource(sound)
love.audio.play(src1)
end
function love.update(dt)
src1:setPitch(love.mouse.getX())
end
Help us help you: attach a .love.
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Denver, CO
- Contact:
Re: First Löve attempt with sound & pitch not working, pls help!
Corrections to robin's code.
Controlled with the mouse.
Up/Down is volume (1.0 is a normal volume)
Left/Right is pitch (goes from 0 (actually an invalid pitch) to 1.0 (normal pitch))
Controlled with the mouse.
Up/Down is volume (1.0 is a normal volume)
Left/Right is pitch (goes from 0 (actually an invalid pitch) to 1.0 (normal pitch))
Code: Select all
function love.load()
sound = love.audio.newSound("catmeow.wav") --Create a sound object for catmeow
src1 = love.audio.newSource(sound) --Create a source object for sound
src1:setLooping(true) --Keeps looping src1s playback
love.audio.play(src1) --Starts playing src1
end
function love.update(dt)
src1:setVolume(1-love.mouse.getY()/love.graphics.getHeight()) --ratio of the screen
src1:setPitch(love.mouse.getX()/love.graphics.getWidth()) --ratio of the screen
end
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: First Löve attempt with sound & pitch not working, pls help!
Right, of course. Have I mentioned I know nothing of the sound system?
Help us help you: attach a .love.
Re: First Löve attempt with sound & pitch not working, pls help!
Let me start off by saying both of you have been incredibly helpful!
I tried the above code and it worked except for one problem, the sound does not actually loop. The sample plays through once and then stops. Or at least, it is no longer heard.
I will try and figure it out for myself but if someone notices something wrong please post it!
Thanks a lot.
I tried the above code and it worked except for one problem, the sound does not actually loop. The sample plays through once and then stops. Or at least, it is no longer heard.
I will try and figure it out for myself but if someone notices something wrong please post it!
Thanks a lot.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: First Löve attempt with sound & pitch not working, pls help!
It is possible this is a bug, what kind of audio file are you using? (type)
Re: First Löve attempt with sound & pitch not working, pls help!
The type of file is .wav
Nothing special
Nothing special
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: First Löve attempt with sound & pitch not working, pls help!
Well, yes, having worked personally on mp3 I can say that mp3 supports looping and I just heard that wavs (and other files handled by libmodplug, like xm) fail to loop.
EDIT: TechnoCat reports that wav looping *should* work, but with a delay.
EDIT: TechnoCat reports that wav looping *should* work, but with a delay.
Re: First Löve attempt with sound & pitch not working, pls help!
Oh, ok, sweet. I'll just convert the samples to mp3! Thanks a lot.
Re: First Löve attempt with sound & pitch not working, pls help!
.xm files loop for me, as long as I explicitly tell them to...
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 3 guests