How to make tone signal and multiple tone signals?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
darkfrei
Party member
Posts: 1186
Joined: Sat Feb 08, 2020 11:09 pm

How to make tone signal and multiple tone signals?

Post by darkfrei »

Hi all!

Is it possible to make a tone signal? I've tried with the 1000 Hz 1 second wave file, but I hear small pause every second. Is it possible to make it continuously?

How to make 1000 Hz signal and 1500 Hz signal simultaneously?

UPD: fixed mistakes
Last edited by darkfrei on Mon Apr 20, 2020 8:41 am, edited 2 times in total.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
zorg
Party member
Posts: 3449
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: How to make ton signal and multiple ton signals?

Post by zorg »

Hi and welcome to the forums.

you mean a tone signal, and yes, you can do that even without a wave file.

Code: Select all

local frequency = 1000
local SD = love.sound.newSoundData(math.floor(44100/frequency),44100,16,1)
for i=0, SD:getSampleCount()-1 do
    SD:setSample(i, math.sin(i * math.pi * 2 * frequency / 44100))
end
local sound = love.audio.newSource(SD)
sound:setLooping(true)
sound:play()
that said, if you are hearing a small pause, that can be because of two things,
- the wav file has some silence somewhere in it, either at the end or at the beginning, or
- the wav file's length isn't a multiple of the sine wave in it, meaning it will pop due to discontinuities.

As for the last question, math to the rescue: you add the two signals together.
...or, just have two Sources play the same wav file, one with :setPitch(1.5).
...or have two separate wav files.
Last edited by zorg on Mon Apr 13, 2020 1:59 am, edited 1 time in total.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Andlac028
Party member
Posts: 174
Joined: Fri Dec 14, 2018 2:27 pm
Location: Slovakia

Re: How to make ton signal and multiple ton signals?

Post by Andlac028 »

I think, you thought SD:setSample (not SD:setSampleCount in for loop) and you must set sample position (as first parameter) - its variable i in for loop
User avatar
zorg
Party member
Posts: 3449
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: How to make ton signal and multiple ton signals?

Post by zorg »

Yep, edited the mistakes.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
darkfrei
Party member
Posts: 1186
Joined: Sat Feb 08, 2020 11:09 pm

Re: How to make ton signal and multiple ton signals?

Post by darkfrei »

zorg wrote: Sun Apr 12, 2020 6:08 am Hi and welcome to the forums.
Thank you a lot! I need test it before, but I need also the example how to play two tone signals simultaneously.
For example 440 and 880 Hz with sinus form wave.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
zorg
Party member
Posts: 3449
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: How to make tone signal and multiple tone signals?

Post by zorg »

As i said previously, it depends on how you want to do it; there's no one solution.
If you really want me to give you the answer though, then here's a way of doing it that i don't endorse:

Code: Select all

local f1 = 440
local f2 = 880
local SD1 = love.sound.newSoundData(math.floor(44100/f1),44100,16,1)
local SD2 = love.sound.newSoundData(math.floor(44100/f2),44100,16,1)
for i=0, SD1:getSampleCount()-1 do
    SD1:setSample(i, math.sin(i * math.pi * 2 * f1/ 44100))
end
for i=0, SD2:getSampleCount()-1 do
    SD2:setSample(i, math.sin(i * math.pi * 2 * f2/ 44100))
end
local S1= love.audio.newSource(SD1)
local S2= love.audio.newSource(SD1)
S1:setLooping(true)
S2:setLooping(true)
love.audio.play(S1, S2)
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Google [Bot] and 6 guests