(shouting)

LunaDLL+SDL2_Mixer = FLAC,OGG,MOD,XM,IT, etc.

The second SMBX collab!

Do you like this idea with using of SDL Mixer?

Yes, I like it!
11
92%
No, I don't like this thing.
1
8%
I have another opinion...
0
No votes
 
Total votes: 12

User avatar
Willhart
Stalker, Doxxer, and Sexual Harasser
Banned
Posts: 2434
Joined: 13 years ago
Location: Finland

Re: LunaDLL+SDL2_Mixer = FLAC,OGG,MOD,XM,IT, etc.

Post by Willhart »

The code, which I posted earlier seems to place a dark gray background behind the hud, while the one from wohlstand does not. Does this have something to do with the lag?

Also wohlstand's code does not lag, but it is missing functionality for selecting the music based on the player location.
User avatar
Wohlstand
Moondust and TheXTech developer
Posts: 186
Joined: 10 years ago
First name: Vitaly
Pronouns: he/him/his
Location: Moscow, Russia

Re: LunaDLL+SDL2_Mixer = FLAC,OGG,MOD,XM,IT, etc.

Post by Wohlstand »

Willhart wrote:Also wohlstand's code does not lag, but it is missing functionality for selecting the music based on the player location.
;)
I doesn't put it because I wrote my example from scratch but how I checked your code, it can be easily mixed
User avatar
Willhart
Stalker, Doxxer, and Sexual Harasser
Banned
Posts: 2434
Joined: 13 years ago
Location: Finland

Re: LunaDLL+SDL2_Mixer = FLAC,OGG,MOD,XM,IT, etc.

Post by Willhart »

That code is actually originally from Hoeloe, and to me it does not look that easy to mix. Maybe I should take a break or something and try again later.
User avatar
Wohlstand
Moondust and TheXTech developer
Posts: 186
Joined: 10 years ago
First name: Vitaly
Pronouns: he/him/his
Location: Moscow, Russia

Re: LunaDLL+SDL2_Mixer = FLAC,OGG,MOD,XM,IT, etc.

Post by Wohlstand »

Willhart wrote:That code is actually originally from Hoeloe, and to me it does not look that easy to mix. Maybe I should take a break or something and try again later.
Mayby this? (I was mixed both codes)

Code: Select all

toggleOverrideMsg = false;

PlayNext = 0
WaitTicks = 0
local nextTrackName=nil

--Keeps track of the music currently playing, so it doesn't try to end a track to play itself.
local musicKey = nil;

--Pass a filename, and if it's different from our current tune, play it immediately
function playMusic(filename)
   if(filename ~= musicKey) then
      MusicOpen(filename);
      musicKey = filename;
      MusicPlay();
   end
end

--Pass a filename, and fade out the previous track over the specified time.
function changeMusic(fileName, milliseconds)
   if(fileName ~= nextTrackName) then
	NextMusic(fileName, milliseconds)      
   end
end

function NextMusic(track, milliseconds)
   MusicStopFadeOut(milliseconds);
   nextTrackName = track
   WaitTicks = (milliseconds / 1000)*65 -- Convert milliseconds into ticks (1 tick is 1/65 of second)
   WaitTicks += 30 -- add 30 ticks to wait between faded out music
   PlayNext = 1
end

function nextMusicWaiter()
   if(PlayNext ==1 ) then
      WaitTicks-=1
      if (WaitTicks<=0) then
         playMusic(nextTrackName)
         PlayNext=0
      end
   end
end

function onLoop()
   --Passive call of music fader
   nextMusicWaiter()

   --Section 1
   if(-190000 > player.x) then
     changeMusic("music-1.XM",1000)
   --Section 2
   elseif(-178432 > player.x) then
     changeMusic("music-2.mp3",500)
   elseif(-177344 > player.x) then
     changeMusic("music-3.mp3",500)
   elseif(-170000 > player.x) then
     changeMusic("Music-4e.ogg",500)
   --Section 3
   elseif(-150000 > player.x) then
     changeMusic("music-5.mp3",500)
   --Section 4
   elseif(-130000 > player.x) then
     changeMusic("music-6.XM",500)
   --Section 5
   elseif(-110000 > player.x) then
     changeMusic("music-7.mp3",500)

   --Section 6
   elseif(-90000 > player.x) then
     changeMusic("music-8.ogg",500)
   --Section 7
   elseif(-70000 > player.x) then
     changeMusic("music-7.mp3",500)
   --Section 8
   elseif(-50000 > player.x) then
     changeMusic("music-10.ogg",500)
   --Section 9
   elseif(-30000 > player.x) then
     changeMusic("music-7.mp3",500)
   --Section 10
   elseif(-10000 > player.x) then
     changeMusic("Music-9.ogg",500)
   
   --Section 11
   elseif(10000 > player.x) then
     changeMusic("music-10.ogg",500)
   --Section 12
   elseif(30000 > player.x) then
     changeMusic("music-8.mp3",500)
   --Section 13
   elseif(50000 > player.x) then
     changeMusic("music-8.mp3",500)
   --Section 14
   elseif(70000 > player.x) then
     changeMusic("music-0placeholder.ogg",500)
   --Section 15
   elseif(90000 > player.x) then
     changeMusic("music-0placeholder.ogg",500)
   end
end
User avatar
Willhart
Stalker, Doxxer, and Sexual Harasser
Banned
Posts: 2434
Joined: 13 years ago
Location: Finland

Re: LunaDLL+SDL2_Mixer = FLAC,OGG,MOD,XM,IT, etc.

Post by Willhart »

lunadll.lua:30: '=' expected near '+'

The error seems to point to this line.

Code: Select all

WaitTicks += 30 -- add 30 ticks to wait between faded out music
User avatar
Wohlstand
Moondust and TheXTech developer
Posts: 186
Joined: 10 years ago
First name: Vitaly
Pronouns: he/him/his
Location: Moscow, Russia

Re: LunaDLL+SDL2_Mixer = FLAC,OGG,MOD,XM,IT, etc.

Post by Wohlstand »

Willhart wrote:lunadll.lua:30: '=' expected near '+'

The error seems to point to this line.

Code: Select all

WaitTicks += 30 -- add 30 ticks to wait between faded out music
Ouch :P

Code: Select all

WaitTicks = WaitTicks+30 
User avatar
Willhart
Stalker, Doxxer, and Sexual Harasser
Banned
Posts: 2434
Joined: 13 years ago
Location: Finland

Re: LunaDLL+SDL2_Mixer = FLAC,OGG,MOD,XM,IT, etc.

Post by Willhart »

It was still super laggy after fixing the errors, but then I added this to the top and it works perfectly now. Thank you for help. I'll be using this to change the music in the hub.

Code: Select all

package.path = package.path .. ";./worlds/cinematX_World/?.lua" ..  ";./town/?.lua" .. ";./?.lua"
cinematX = loadSharedAPI("cinematX")
cinematX.config (true, false)
User avatar
Hoeloe
A2XT person
Posts: 1022
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: LunaDLL+SDL2_Mixer = FLAC,OGG,MOD,XM,IT, etc.

Post by Hoeloe »

Willhart wrote:It was still super laggy after fixing the errors, but then I added this to the top and it works perfectly now. Thank you for help. I'll be using this to change the music in the hub.

Code: Select all

package.path = package.path .. ";./worlds/cinematX_World/?.lua" ..  ";./town/?.lua" .. ";./?.lua"
cinematX = loadSharedAPI("cinematX")
cinematX.config (true, false)
If that fixed it, the original code will probably also not be laggy any more. I'm using it in my MAGLX2 level and have no lag issues.
Image
Image
Image
Image
Image
User avatar
Wohlstand
Moondust and TheXTech developer
Posts: 186
Joined: 10 years ago
First name: Vitaly
Pronouns: he/him/his
Location: Moscow, Russia

Re: LunaDLL+SDL2_Mixer = FLAC,OGG,MOD,XM,IT, etc.

Post by Wohlstand »

Just added link to experimental LunaLUA v0.5.3+SDL Build.
What's new:
  • New functions: MusicIsPlaying(), MusicIsPaused(), MusicIsFading() which you can use in Lua, and later will be more!
  • Several fixes and improvements such an adding of better resampler for MP3 48000 to 44100 which fixes noise for those 48000 MP3's so, you can play them without any problems, but still recommended to re-sample your music files into 44100 to keep better performance (real-time re-sampling usually eats more of your CPU time).
  • Experimental communicator: Added shared memory server which giving able to accept file paths to run test of any level file instantly by special call (which was implemented into PGE Editor, I will record video about this feature later)
  • Experimental hardcoded graphics customizing system (graphics.ini can define a name of file in the graphics/common/ folder which can custmize any hardcoded graphics file). I will make more user friendly specification, but now you should know addresses of each file (regular image and it's mask if uses). Read examples in the _ini_examples/ folder!
User avatar
Hoeloe
A2XT person
Posts: 1022
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: LunaDLL+SDL2_Mixer = FLAC,OGG,MOD,XM,IT, etc.

Post by Hoeloe »

Wohlstand wrote:Just added link to experimental LunaLUA v0.5.3+SDL Build.
What's new:
I'd like to suggest a feature, if I may: Alternating-dual-stream audio.

The idea is that there are two music streams, rather than one. Every time MusicPlay is called, it runs on the other stream to the previous time (it alternates between the two). The benefit of this is that you can crossfade music. If music is playing on stream 1, and you start fading it out, you could immediately begin fading music in on stream 2, which would sound a lot more natural than music fading out completely, then in again.
Image
Image
Image
Image
Image
Doctor Shemp
Banned
Posts: 0
Joined: 11 years ago

Re: LunaDLL+SDL2_Mixer = FLAC,OGG,MOD,XM,IT, etc.

Post by Doctor Shemp »

Hoeloe wrote:
Wohlstand wrote:Just added link to experimental LunaLUA v0.5.3+SDL Build.
What's new:
I'd like to suggest a feature, if I may: Alternating-dual-stream audio.

The idea is that there are two music streams, rather than one. Every time MusicPlay is called, it runs on the other stream to the previous time (it alternates between the two). The benefit of this is that you can crossfade music. If music is playing on stream 1, and you start fading it out, you could immediately begin fading music in on stream 2, which would sound a lot more natural than music fading out completely, then in again.
Further to this, if the streams were synchronised with each other, it would be possible to vary the instrumentation of a track to fit the conditions of a level by having two versions of the same track playing simultaneously. The other way to achieve that would be through multiple MIDI streams, which is how games usually handle that, although without an in-built synthesizer or sample engine to play the MIDIs and have custom instruments they'd have the tacky General MIDI sound.
User avatar
SAJewers
ASMBXT Level Wrangler/A2XT Project Coordinator /AAT Level Designer
Posts: 4217
Joined: 12 years ago
Location: Nova Scotia

Re: LunaDLL+SDL2_Mixer = FLAC,OGG,MOD,XM,IT, etc.

Post by SAJewers »

This is starting to sound like the main Gimmick in Giana Sisters: Twisted Dreams.


ImageImageImageImageImage | Image | Image
Sharenite | RetroAchievements | NameMC | IGDB
User avatar
Rednaxela
Maker of Shenanigans
Posts: 897
Joined: 10 years ago
Pronouns: they/them
https://rednaxela.talkhaus.com

Re: LunaDLL+SDL2_Mixer = FLAC,OGG,MOD,XM,IT, etc.

Post by Rednaxela »

Doctor Shemp wrote:although without an in-built synthesizer or sample engine
Speaking of which, today I learned... trying to use playSFXSDL in a rhythmic fashion doesn't work too great... perhaps due to a jittery SMBX frame rate that's not bad enough to be visually noticeable, but is still noticeable to the ear?... :roll:
Last edited by Rednaxela 9 years ago, edited 1 time in total.
User avatar
Wohlstand
Moondust and TheXTech developer
Posts: 186
Joined: 10 years ago
First name: Vitaly
Pronouns: he/him/his
Location: Moscow, Russia

Re: LunaDLL+SDL2_Mixer = FLAC,OGG,MOD,XM,IT, etc.

Post by Wohlstand »

Rednaxela wrote:
Doctor Shemp wrote:although without an in-built synthesizer or sample engine
Speaking of which, today I learned... trying to use playSFXSDL in a rhythmic fashion doesn't work too great... perhaps due to a jittery SMBX's frame rate that's not bad enough to be visually noticeable, but is still noticeable to the ear?... :roll:
SMBX's frame frequency is 65 Hz, so you need to use a ticks based delay:

Code: Select all

WaitFor=0
function onLoop()
   WaitFor= WaitFor-1
   if (WaitFor <=0) then
   playSFXSDL("kickdrum.ogg")
   WaitFor=32;
   end
end
But little note if you will try to play sounds too often: I think, you hear some junk delays while lakutu's shoe flight or grinder saw is working, but rithm should be stable like clock.
User avatar
Rednaxela
Maker of Shenanigans
Posts: 897
Joined: 10 years ago
Pronouns: they/them
https://rednaxela.talkhaus.com

Re: LunaDLL+SDL2_Mixer = FLAC,OGG,MOD,XM,IT, etc.

Post by Rednaxela »

Wohlstand wrote:SMBX's frame frequency is 65 Hz, so you need to use a ticks based delay:

Code: Select all

WaitFor=0
function onLoop()
   WaitFor= WaitFor-1
   if (WaitFor <=0) then
   playSFXSDL("kickdrum.ogg")
   WaitFor=32;
   end
end
I'm aware of that, and thus am indeed working in integer multiples of ticks like that, but it still sounds pretty darn jittery/inconsistent to me.

If you want I could set up a test level for download and a youtube recording of it showing the inconsistency I'm hearing (in case it happens more on my computer than some others?)
User avatar
Rednaxela
Maker of Shenanigans
Posts: 897
Joined: 10 years ago
Pronouns: they/them
https://rednaxela.talkhaus.com

Re: LunaDLL+SDL2_Mixer = FLAC,OGG,MOD,XM,IT, etc.

Post by Rednaxela »

Test Level: MusicBox.zip
Video: Link
User avatar
Hoeloe
A2XT person
Posts: 1022
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: LunaDLL+SDL2_Mixer = FLAC,OGG,MOD,XM,IT, etc.

Post by Hoeloe »

Wohlstand wrote:SMBX's frame frequency is 65 Hz
That's a bad idea. You can never guarantee that frame frequency will remain consistent. The way I do timers is to use Lua's os.clock() method to catch ticks, like this:

Code: Select all

local prevTime = 0;
local deltaTime = 0;

function onLoad()
	prevTime = os.clock();
end

function onLoop()
	local t = os.clock();
	deltaTime = t-prevTime;
	prevTime = t;
end
Now, I can make all of my timers in seconds, like this:

Code: Select all

local timer = 2;

function onLoop()
	timer = timer - deltaTime;
	if(timer <= 0) then
		--do something
	end
end
The deltaTime variable stores the actual time between this frame and the last, so your timers are accurate to the nearest frame, irrespective of lag or other frequency variations. This allows timers to work independently of the frame rate of the game, and is much more effective. This is how most games use timers.
Image
Image
Image
Image
Image
User avatar
Wohlstand
Moondust and TheXTech developer
Posts: 186
Joined: 10 years ago
First name: Vitaly
Pronouns: he/him/his
Location: Moscow, Russia

Re: LunaDLL+SDL2_Mixer = FLAC,OGG,MOD,XM,IT, etc.

Post by Wohlstand »

Hoeloe wrote:
Wohlstand wrote:SMBX's frame frequency is 65 Hz
That's a bad idea. You can never guarantee that frame frequency will remain consistent. The way I do timers is to use Lua's os.clock() method to catch ticks, like this:

Code: Select all

local prevTime = 0;
local deltaTime = 0;

function onLoad()
	prevTime = os.clock();
end

function onLoop()
	local t = os.clock();
	deltaTime = t-prevTime;
	prevTime = t;
end
Now, I can make all of my timers in seconds, like this:

Code: Select all

local timer = 2;

function onLoop()
	timer = timer - deltaTime;
	if(timer <= 0) then
		--do something
	end
end
The deltaTime variable stores the actual time between this frame and the last, so your timers are accurate to the nearest frame, irrespective of lag or other frequency variations. This allows timers to work independently of the frame rate of the game, and is much more effective. This is how most games use timers.
Oh, great! This will be framerate independent, because I wish to use LunaLUA Foundation as native part for PGE Engine. I Don't like 65 hz framerate, because it can't give smooth and accurate movement even with 250 fps with OpenGL acceleration, I think to use 75 or more hz of mainloop. But also I wish to give able to have less loops for slow machines (smbx is too much laggy on Pentiun IV pc or even on AMD Athlon 64: this is a simple platform game which requires minimum cpu load and shouldn't steal all your cpu time
Zygl
Posts: 616
Joined: 11 years ago

Re: LunaDLL+SDL2_Mixer = FLAC,OGG,MOD,XM,IT, etc.

Post by Zygl »

Hoeloe wrote:This allows timers to work independently of the frame rate of the game
Would that break with frameskip disabled then?
User avatar
Hoeloe
A2XT person
Posts: 1022
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: LunaDLL+SDL2_Mixer = FLAC,OGG,MOD,XM,IT, etc.

Post by Hoeloe »

Zyglrox Odyssey wrote:
Hoeloe wrote:This allows timers to work independently of the frame rate of the game
Would that break with frameskip disabled then?
A mundane countdown would break, but a deltaTime countdown won't.
Image
Image
Image
Image
Image
User avatar
Hoeloe
A2XT person
Posts: 1022
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: LunaDLL+SDL2_Mixer = FLAC,OGG,MOD,XM,IT, etc.

Post by Hoeloe »

I'd like to put in another request.

The playSFXSDL function is good, but could be a lot better.

First of all, can it return a reference to the stream containing the sound being played? This could be extremely useful, for reasons I'm about to go into.

Secondly, can we have a property allowing a specific sound effect to loop indefinitely?

Thirdly, can we have an option to set the volume of sound effects?

These together would allow ambient environment sounds, that can fade in and out depending on the player's location. It would be a huge change in how sound effects can be used in SMBX.
Image
Image
Image
Image
Image
User avatar
Rednaxela
Maker of Shenanigans
Posts: 897
Joined: 10 years ago
Pronouns: they/them
https://rednaxela.talkhaus.com

Re: LunaDLL+SDL2_Mixer = FLAC,OGG,MOD,XM,IT, etc.

Post by Rednaxela »

Funny the os.clock() stuff should be mentioned. I had also tried that for making playSFXSDL calls at a regular pace earlier, but that also didn't work very well, as a 1/65th of a second discrepancy in timing of a rhythm is quite audible.

For my purposes (which involve having music sync'ed to gameplay, I'm thinking I'm going to change from using a playSFXSDL per note, to using a playSFXSDL per musical phrase as a little timing discrepancy there should be much less noticable, and running os.clock() at the same time as I run playSFXSDL so that in later frames I have a good idea of which point the audio is at (though... if playSFXSDL returned a reference as Hoeloe wants... perhaps that reference could allow getting the current time in the stream? That would make certain things simpler... hmm...)
User avatar
Hoeloe
A2XT person
Posts: 1022
Joined: 12 years ago
Pronouns: she/her
Location: Spaaace

Re: LunaDLL+SDL2_Mixer = FLAC,OGG,MOD,XM,IT, etc.

Post by Hoeloe »

Rednaxela wrote:(though... if playSFXSDL returned a reference as Hoeloe wants... perhaps that reference could allow getting the current time in the stream? That would make certain things simpler... hmm...)
That is also something I'd be looking for. It's an extremely useful tool.
Image
Image
Image
Image
Image
User avatar
Wohlstand
Moondust and TheXTech developer
Posts: 186
Joined: 10 years ago
First name: Vitaly
Pronouns: he/him/his
Location: Moscow, Russia

Re: LunaDLL+SDL2_Mixer = FLAC,OGG,MOD,XM,IT, etc.

Post by Wohlstand »

Hoeloe wrote:
Rednaxela wrote:(though... if playSFXSDL returned a reference as Hoeloe wants... perhaps that reference could allow getting the current time in the stream? That would make certain things simpler... hmm...)
That is also something I'd be looking for. It's an extremely useful tool.
By default playSFXSDL() is a proxy over Mix_PlayChannel() function which returns number of channel where it was played. Also it supports a loops, fades, etc. But I wasn't made it in LUA
http://www.libsdl.org/projects/SDL_mixe ... html#SEC28
If you will read more specification of SDL2_mixer library, you will can understand more. So, I think, I would to implement all functions of SDL2_mixer, and you will able to make controllable sounds (but be careful: I was allocated 32 channels only for all sounds. I.e. 32 parallel sounds can be played in one time). In next time I will add more features of SDL2_mixer.

Also about crossfade of musics: there is impossible without implementation of second music channel into SDL2_mixer directly (so, we have all sources and have a freedom to implementation of any features (I made attempt to implement the SPC format, but I need resampler from 32000 to 44100) )
User avatar
WestonSmith
Bunny
Posts: 191
Joined: 11 years ago

Re: LunaDLL+SDL2_Mixer = FLAC,OGG,MOD,XM,IT, etc.

Post by WestonSmith »

Not sure if this is being worked on still, but curious if the ability to change sounds on a per level basis was ever implemented (or is it still per world)?
Post Reply