mirror of
https://github.com/OpenDiablo2/OpenDiablo2
synced 2024-09-27 05:35:57 -04:00
Added music support
This commit is contained in:
parent
8e81f0cbbc
commit
52ae254b0a
@ -25,16 +25,17 @@ namespace OpenDiablo2.SDL2_
|
|||||||
{
|
{
|
||||||
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
||||||
private IntPtr music = IntPtr.Zero;
|
private IntPtr music = IntPtr.Zero;
|
||||||
|
private int musicChannel;
|
||||||
|
|
||||||
public SDL2MusicPlayer()
|
public SDL2MusicPlayer()
|
||||||
{
|
{
|
||||||
if (SDL_mixer.Mix_OpenAudio(22050, SDL_mixer.MIX_DEFAULT_FORMAT, 2, 2048) < 0)
|
if (SDL_mixer.Mix_OpenAudio(22050, SDL_mixer.MIX_DEFAULT_FORMAT, 2, 1024) < 0)
|
||||||
log.Error($"SDL_mixer could not initialize! SDL_mixer Error: {SDL.SDL_GetError()}");
|
log.Error($"SDL_mixer could not initialize! SDL_mixer Error: {SDL.SDL_GetError()}");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PlaySong()
|
public void PlaySong()
|
||||||
{
|
{
|
||||||
SDL_mixer.Mix_PlayChannel(-1, music, 1);
|
musicChannel = SDL_mixer.Mix_PlayChannel(-1, music, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadSong(Stream data)
|
public void LoadSong(Stream data)
|
||||||
@ -51,6 +52,7 @@ namespace OpenDiablo2.SDL2_
|
|||||||
{
|
{
|
||||||
if (music == IntPtr.Zero)
|
if (music == IntPtr.Zero)
|
||||||
return;
|
return;
|
||||||
|
SDL_mixer.Mix_HaltChannel(musicChannel);
|
||||||
SDL_mixer.Mix_FreeChunk(music);
|
SDL_mixer.Mix_FreeChunk(music);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,21 +62,6 @@ namespace OpenDiablo2.SDL2_
|
|||||||
SDL_mixer.Mix_CloseAudio();
|
SDL_mixer.Mix_CloseAudio();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
musicStream = data;
|
|
||||||
SDL.SDL_AudioSpec want = new SDL.SDL_AudioSpec
|
|
||||||
{
|
|
||||||
freq = 22050,
|
|
||||||
format = SDL.AUDIO_S16LSB,
|
|
||||||
channels = 2,
|
|
||||||
samples = 4096,
|
|
||||||
callback = AudioCallback
|
|
||||||
};
|
|
||||||
|
|
||||||
SDL.SDL_OpenAudio(ref want, out audioSpec);
|
|
||||||
SDL.SDL_PauseAudio(0);
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,20 @@
|
|||||||
using System;
|
/* OpenDiablo 2 - An open source re-implementation of Diablo 2 in C#
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenDiablo2.Common;
|
using OpenDiablo2.Common;
|
||||||
@ -24,6 +40,8 @@ namespace OpenDiablo2.Scenes
|
|||||||
IRenderWindow renderWindow,
|
IRenderWindow renderWindow,
|
||||||
ISceneManager sceneManager,
|
ISceneManager sceneManager,
|
||||||
IResourceManager resourceManager,
|
IResourceManager resourceManager,
|
||||||
|
IMusicProvider musicProvider,
|
||||||
|
IMPQProvider mpqProvider,
|
||||||
Func<eButtonType, IButton> createButton,
|
Func<eButtonType, IButton> createButton,
|
||||||
Func<eSceneType, IScene> getScene // Temporary until SDL load functions are sped up
|
Func<eSceneType, IScene> getScene // Temporary until SDL load functions are sped up
|
||||||
)
|
)
|
||||||
@ -71,11 +89,8 @@ namespace OpenDiablo2.Scenes
|
|||||||
getScene(scenesToLoad[i]);
|
getScene(scenesToLoad[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
musicProvider.LoadSong(mpqProvider.GetStream("data\\global\\music\\introedit.wav"));
|
musicProvider.LoadSong(mpqProvider.GetStream("data\\global\\music\\introedit.wav"));
|
||||||
musicProvider.PlaySong();
|
musicProvider.PlaySong();
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnVisitWebsiteClicked()
|
private void OnVisitWebsiteClicked()
|
||||||
|
Loading…
Reference in New Issue
Block a user