Page 3 of 5

Re: Music like in Nintendo games

Posted: Tue Apr 26, 2016 4:39 pm
by zorg
Ivan only said that
- It might be possible to send data to the pc speaker via os.execute, depending on what os you run it on, and that
- Nowadays it's easier to -render-, that is, simulate the sounds, and play it back as a wav file on your actual speakers or headphones.

But to answer your question, sound = love.audio.newSource("music.wav" , os.PCspeaker) will not work, since löve can't handle that second parameter.

Also, read this. The most important parts:
- Eventually because of the lack of hardware to communicate with, support for Beep was dropped in Windows Vista and Windows XP 64-Bit Edition.
- In Windows 7, Beep was rewritten to pass the beep to the default sound device for the session. This is normally the sound card, except when run under Terminal Services, in which case the beep is rendered on the client.

So whatever you do, the beep will happen on the normal speakers, or it won't happen at all, on windows at least.

It's sad really, my first synthesizer program was written in turbopascal in DOS, and it used the beep function, and it was "polyphonic"... with some cheating.

Re: Music like in Nintendo games

Posted: Tue Apr 26, 2016 4:50 pm
by Davidobot
This seems awfully complicated and as others said, not a lot of mobos even have a speaker nowadays, mostly IBM ones.
This could help: http://superuser.com/questions/227939/h ... and-prompt

Also, if you run

Code: Select all

print("\7")
it plays the bell sound, but there is no way to pitch that.

Re: Music like in Nintendo games

Posted: Tue Apr 26, 2016 5:48 pm
by zorg
Davidobot wrote:This seems awfully complicated and as others said, not a lot of mobos even have a speaker nowadays, mostly IBM ones.
This could help: http://superuser.com/questions/227939/h ... and-prompt
Also, if you run

Code: Select all

print("\7")
it plays the bell sound, but there is no way to pitch that.
(I tested that, win7 x64 did not do anything, that's why i didn't mention it.)

Re: Music like in Nintendo games

Posted: Wed Apr 27, 2016 6:12 am
by Davidobot
zorg wrote:(I tested that, win7 x64 did not do anything, that's why i didn't mention it.)
(You need to have the console window open for it to work - t.console = true)

Re: Music like in Nintendo games

Posted: Sun May 01, 2016 9:21 pm
by DekuJuice
As master both said, you can use a music tracker to compose your songs.

Since you brought up SMB as an example, I recommend http://famitracker.com/

Re: Music like in Nintendo games

Posted: Sun May 01, 2016 10:00 pm
by zorg
Except:
Nutte wrote:I want to program music not use a file, can i do that with Love?
Not with löve... yet : 3
One can render an mp3 or something from Famitracker, sure, or even use a more sampling oriented one, and load the module files themselves for less hdd space, but that's not what the OP wanted to do.

Re: Music like in Nintendo games

Posted: Tue May 03, 2016 2:24 pm
by Nutte
Thank you for all the answer.

Re: Music like in Nintendo games

Posted: Fri Jun 02, 2017 9:19 pm
by therektafire
I was actually thinking about doing this too recently :) I think by far the biggest issue with making a software based chiptune/music-in-general player in Love is timing issues. There are no events that get triggered at a predictable periodic rate afaik. Love.update and love.draw get called once per *rendered frame* i think meaning the quality of the music would heavily depend on the framerate. Retro console programmers had it easy when it comes to this kind of thing because they had hardware timers that always fired at the same rate every frame (on the NES you get an event fired every time a frame is finished rendering for example). This made music programming very easy since all you had to do is write the sound engine code then provide a pointer to it in the interrupt vector table (which is at the very end of the program since the CPU looks for interrupt handler pointers at the very last few bytes of RAM, at least on the 6502 which is what the NES uses). Of course in real life applications the music code would be sharing valuable CPU time with other things like controller input, physics/sprite updates etc, but thats beside the point :D

Re: Music like in Nintendo games

Posted: Fri Jun 02, 2017 9:53 pm
by zorg
I already made a player that needs perfect timing, mr. necropost-by-googling-and-old-thread. :3

https://github.com/zorggn/LoveTracker
therektafire wrote: Fri Jun 02, 2017 9:19 pm I think by far the biggest issue with making a software based chiptune/music-in-general player in Love is timing issues.
There are no events that get triggered at a predictable periodic rate afaik. Love.update and love.draw get called once per *rendered frame* i think meaning the quality of the music would heavily depend on the framerate.
False, you can edit love.run or have vsync turned off, or you can use a separate thread for generatin audio alltogether.
Also, you're rendering into a buffer, the quality won't depend on anything; if you use a buffer smaller than how much you can render at once, it will underrun, that's all there is to it.
therektafire wrote: Fri Jun 02, 2017 9:19 pm Retro console programmers had it easy when it comes to this kind of thing because they had hardware timers that always fired at the same rate every frame (on the NES you get an event fired every time a frame is finished rendering for example). This made music programming very easy since all you had to do is write the sound engine code then provide a pointer to it in the interrupt vector table (which is at the very end of the program since the CPU looks for interrupt handler pointers at the very last few bytes of RAM, at least on the 6502 which is what the NES uses).
Nothing was very easy back then, and if this was a C app, you probably could access the 3 hardware timers that pc-s still have... but the question is why, computers are fast enough for you to just rely on the os scheduler to run your code as fast as it does...
therektafire wrote: Fri Jun 02, 2017 9:19 pm Of course in real life applications the music code would be sharing valuable CPU time with other things like controller input, physics/sprite updates etc, but thats beside the point :D
As you said, if i had threaded my thing, that would give it even more guarantees, in that other processing wouldn't block the audio generation thread. Everything's on the main thread, renders into a tiny buffer for the least amount of delay, and it works without any hitches still.

Hell, someone implemented a game boy emulator with löve (without sound for now, iirc he's waiting for 0.11 to come out because better generative sound API stuff, just like in my project), that also works besides the fact that löve doesn't give you access to hardware timer interrupts on the pc... not like you need them; just edit the default love.run or set vsync to false if you don't want it to run as fast as your screen's refresh rate.

Re: Music like in Nintendo games

Posted: Wed Jun 14, 2017 12:07 am
by therektafire
Now how do you create multiple threads in lua? :/ I know about coroutines but I don't think those are the same thing?