Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting started #3

Open
veso266 opened this issue Mar 4, 2018 · 7 comments
Open

Getting started #3

veso266 opened this issue Mar 4, 2018 · 7 comments

Comments

@veso266
Copy link

veso266 commented Mar 4, 2018

Hi do you think you could tell me simply how to play a mod or s3m file with this library

I've tried like this

ModPlayer.SetFixedRandom = true;
            int result = 0;
            int iterations = 0;
            String modName = null;
            DateTime startTime = DateTime.Now;
            Module mod;
            ModDriver.LoadDriver<NoAudio>();
            ModDriver.MikMod_Init("");
            mod = ModuleLoader.Load("Music1.mod");
            modName = "Music1.mod";
            int lookingForByte = -1;
            int byteCount = 44; // wav header
            DateTime loadTime = DateTime.Now;
            ModPlayer.Player_Start(mod);

            // Trap for wrapping mods.
            while (ModPlayer.Player_Active() && iterations < 5000)
            {
                if (lookingForByte > 0)
                {
                    int test = byteCount + (int)WavDriver.BUFFERSIZE;
                    if (test > lookingForByte)
                    {
                        Debug.WriteLine("Will fail on the next pass, at {0} byes in", (lookingForByte - byteCount));
                    }
                }

                ModPlayer.Player_HandleTick();
                byteCount += (int)WavDriver.BUFFERSIZE;
                iterations++;
            }

but when I run the program I can't hear anything

Thanks for Anwsering and Best Regards

@thegouldfish
Copy link
Owner

thegouldfish commented Mar 4, 2018

If you don't have anything already playing audio then you can do this.

First add the NAudio.dll (from the lib folder) as a reference in your project, and also make sure the NAudioDriver has been included in as well.

you code will look like this

Module mod;
ModDriver.LoadDriver<NAudio>();
ModDriver.MikMod_Init("");
mod = ModuleLoader.Load("Location of mod files"); // Change to the path of the .s3m or .mod file
ModPlayer.Player_Start(mod);

while (ModPlayer.Player_Active())
{
    ModPlayer.Player_HandleTick();
}

If you look at the WindowsTest project it will give you an idea of how to set it up.

If you aren't on windows, or need to play the audio via another method then you will need to write a write a "driver" check the Wiki on how to do that.

@veso266
Copy link
Author

veso266 commented Mar 5, 2018

Hi tried wiki example and it works great for saving wav files but I would like to play it direcly from my speakers so I tried

MikMod player;
            player = new MikMod();
            player.Init<NAudio>(); (the line error is at)

            Module mod = null;
            mod = player.LoadModule("Music1.mod");

            if (mod != null)
            {
                player.Play(mod);
                // Depending on the driver you might need to call update
                // if update is not need calling update will not break anything
                // Please note that some mods can loop indefiniatly so might never end.
                while (player.IsPlaying())
                {
                    player.Update();
                }
                //player.Stop();

                // Calling unload will clear out any loaded samples and the mod data.
                // Its fine to then load another module after unloading one.
                //player.UnLoadModule(mod);
            }
            else
            {
                // Failed to load the mod
                if (player.HasError)
                {
                    Console.WriteLine("Failed to load mod for reason:");
                }
            }

but I get
NAudio is a namespace but is used like a type
not sure what is wrong

also tried your example but I stil get this error

I've included NAudio.dll and SharpMikNAudio.dll (not sure what is the diference between SharpMikNAudio.dll and SharpMik.dll but if I can't include both

Thanks for Anwsering and Best Regards

@thegouldfish
Copy link
Owner

thegouldfish commented Mar 5, 2018

NAudio.dll is a audio playing library for C# (https://github.com/naudio/NAudio)
SharpMikNAudio.dll is SharpMik with the SharpMik NAudio driver included, so you will need both.

Try changing the code to this

player.Init<NaudioDriver>();

I really need to find some time to tidy the wiki and the codebase up.

@veso266
Copy link
Author

veso266 commented Mar 6, 2018

works like a charm thank you

PS: not sure why

                while (player.IsPlaying())
                {
                    player.Update();
                }

is needed (because my WinForm does open if its there
if I remove this while statment everything works fine

@thegouldfish
Copy link
Owner

Great to hear it worked.

The player.update() is needed for some of the audio drivers as you need to push data to them (the write to wav driver for example).

Others like the NAudio Driver (or XNA driver) pull the data when they need it.

So yeah in this instance it wasn't needed.

As the core of the library is just a module decoder, its then up to the audio drivers to do something with that processed byte array.

I hope that makes sense.

@veso266
Copy link
Author

veso266 commented Mar 6, 2018

Thanks again
a last question: how can I loop a mod file when it comes to the end without a gap?

Thanks for Anwsering and Best Regards

@thegouldfish
Copy link
Owner

after you load the mod you can set the wrap flag.

mod = player.LoadModule("Music1.mod");
mod.wrap = true;

and the mod should repeat from its set repeat point or the start if its not been set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants