YesNoOk
avatar

Ikemen GO (Read 1255384 times)

Started by K4thos, May 26, 2018, 03:04:27 am
Share this topic:
Re: Ikemen GO Plus
#1081  June 20, 2019, 11:56:09 pm
  • *****
  • Resident Tosspot
  • Pftheh
    • UK
    • plasmoidthunder.neocities.org
Post-processing anti-alias can be resource-intensive, so I'd leave it as an option. Most games do this anyway.

Oh, I want a diagram. I fucking love diagrams.
Re: Ikemen GO Plus
#1082  June 23, 2019, 08:49:27 pm
  • *****
  • Formerly known as HyperClawManiac
  • Competitive MUGEN when?
    • UK
    • sites.google.com/view/ragingrowen/home
I was meant to go over this a month or so ago but you should maybe look into the zoom code on the chars.
I tested Mr.Ansatsuken's 1.1 version of his Broly. These screenshots are of the Camera Zoom on his supers.
Normal (No Zoom):

Zoomed Out to the right of the stage (Training is to the right off screen):

I can probably post a video if you don't understand.
WIP Schedule:
The next Street Fighter All-Stars update
Re: Ikemen GO Plus
#1083  June 27, 2019, 05:58:29 pm
  • *****
  • Resident Tosspot
  • Pftheh
    • UK
    • plasmoidthunder.neocities.org
Tagging @Neat Unsou: because they redid the buffer.

There's an issue with the modified command buffer that I noticed after successfully backporting it to SSZ, wherein a character that has a double-tap input (dash, hop, etc.) will inconsistently perform them with a single tap. At first I thought I'd messed something up, but I encountered the issue in GO as well, so the issue lies with those modifications.

Oh, I want a diagram. I fucking love diagrams.
Re: Ikemen GO Plus
#1084  June 29, 2019, 07:12:47 am
  • ***
  • One of Ikemen GO devs
    • Colombia
I was meant to go over this a month or so ago but you should maybe look into the zoom code on the chars.
I tested Mr.Ansatsuken's 1.1 version of his Broly. These screenshots are of the Camera Zoom on his supers.
Normal (No Zoom):

Zoomed Out to the right of the stage (Training is to the right off screen):

I can probably post a video if you don't understand.

So let me see if I understand.
The first screenshot is when you use the super with the stage zoom option disabled. (So it works as intended)
The second one when you enable stage zoom. (And the bug happens)

I'll download the char to test it myself.

Also I updated the engine again.
Remember that when you loaded a screenpack from a diferent location than the default one it aparear the need to add "font/" at the start of each font to load correctly.
Well now I fixed (Finish my own work) and now it should load correctly from any directory.

And also kidcy added MSAA!

EDIT:
So I made edits to stdout_windows.go for instead of creating a console it attaches to the console it was launched from (If it exist)
So that removes the console on windows but allows output to it. :)
But wait!! We haven't made the Suave Dude character yet!!
Last Edit: June 29, 2019, 08:52:53 am by Gacel
Re: Ikemen GO Plus
#1085  June 29, 2019, 05:23:27 pm
  • ***
  • MvC Adict!!
    • Argentina
    • marvelvscapcomextreme.000webhostapp.com
Guys! keep it up the good work!

Question: Is it possible to elaborate a code/system able to purchase things inside the game? for example with points on every battle that you fought.
Creating a new section that with those points you could purchase more characters, stages, etc.
Marvel vs Capcom Extreme (find the MvC2 characters project right here too!):
marvelvscapcomextreme.000webhostapp.com

Follow the project on:
www.instagram.com/marvelvscapcomextreme/
www.youtube.com/c/MarvelvsCapcomExtreme
www.player.me/marvelvscapcomextreme/

I recieved messages of users that want to donate from paypal or patreon, if you consider that this is a nice and very dedicated project, you can donate any amount that you want right here:
www.paypal.me/marianoemeschini
Re: Ikemen GO Plus
#1086  June 29, 2019, 05:24:19 pm
  • avatar
  • ***
sounds like Marvel vs Capcom 2
Re: Ikemen GO Plus
#1087  June 29, 2019, 09:18:04 pm
  • ****
  • Hey four stars, whatever that means
    • Canada
    • amidweiz.neocities.org
I was testing out the latest version of the windows variant of Ikemen GO plus compared to mugen 1.1 and I decided to record the two with KFM doing the same combo. (if you're curious, yes I had put noko and made KFM heal to max after 100 state ticks afterwords simulating how mugen's training mode works with healing)

Ikemen GO Plus: https://streamable.com/gqndf

Mugen 1.1: https://streamable.com/9ac4g

Few things I had observed with Ikemen GO plus compared to mugen
  • Combo counter doesn't work properly
  • Afterfx seem to be affected by pausetime
  • Damage that is displayed on the lifebar falls more instantly than mugen
  • Sound is clearer in Ikemen than it is in mugen, though not affected by pan currently
  • fall.defence_up seems to actually get applied properly
  • The camera in general seems to operate more harshly than it is in mugen
Re: Ikemen GO Plus
#1088  June 29, 2019, 11:27:30 pm
  • avatar
  • **
Looks like it's counting pausetime as actual time between hits for that reason it ends up resetting combo hits, I think. Looks like pausetime has some issues
Re: Ikemen GO Plus
#1089  July 05, 2019, 02:06:21 am
  • *
    • Brazil
Re: Ikemen GO Plus
#1090  July 05, 2019, 08:01:56 am
  • *****
    • USA
Good luck with this, looks interesting. You make these yourself? Isn't that mugen you are using?
Re: Ikemen GO Plus
#1091  July 11, 2019, 03:24:18 am
  • **
  • The need situation makes the man
    • Mexico
    • www.facebook.com/mike.funkyman
I try to make some commits about fluidsynth, but I need some help

sound.go

Maybe this can be helpful

Showing what is fluidsytnh


Last Edit: July 11, 2019, 03:53:28 am by Mike77154
Re: Ikemen GO Plus
#1092  July 12, 2019, 11:45:57 pm
  • ***
  • One of Ikemen GO devs
    • Colombia
Back again.

About making a in game store.
It's posible but not easy right now there is no score system.
The store fontend could be made in lua and there

It seems that Afterfx and the combo counter time is ignoring pausetime.
Another 2 bugs.

About fluidsytnh...
I have investigated and there are bindings for GO but are undocumented and I have not a single clue on how to use it.
I will try to build a basic command line app that loads a midi to get a hang on it.

EDIT

Also new features by neatunsou.
Quote
MatchRestart
Code:
[state test]
type = MatchRestart
trigger1 = time = 10
p1def = "kfm.def"
p2def = "kfm.def"
Stagedef = "stage0.def"
reload = 1,1
Reset the round and resume. (Same effect as debug key F4)

Set Reload to 1 to reload the file and restart the round from the beginning. (Same effect as the debug key Shift + F4)

One item of Reload specifies whether P1 or 2 item reloads P2. If all 0, do not reload and reset the round.

When the path of def file is specified in P1def, P2def, Stagedef, the file is read when reloading. The pass at that time is based on the execution character.
A interesting one it could be made for a boss that changes stages (And character def) in the second round for example.
But wait!! We haven't made the Suave Dude character yet!!
Last Edit: July 12, 2019, 11:56:11 pm by Gacel
Re: Ikemen GO Plus
#1093  July 13, 2019, 01:44:07 am
  • ***
    • Greece
All i get is a black screen with the new version and ikemen doesnt start at all.
Re: Ikemen GO Plus
#1094  July 13, 2019, 03:25:39 am
  • *
    • rmbase.blog55.fc2.com/
Re: Ikemen GO Plus
#1095  July 13, 2019, 05:00:57 am
  • ***
    • Greece
Maybe MSAA is not compatible with all graphics cards because my pc can definitely run high specs games (I7, 8gb sapphire with 12gb ram).
Re: Ikemen GO Plus
#1096  July 13, 2019, 05:27:24 am
  • **
  • The need situation makes the man
    • Mexico
    • www.facebook.com/mike.funkyman
Back again.

About making a in game store.
It's posible but not easy right now there is no score system.
The store fontend could be made in lua and there

It seems that Afterfx and the combo counter time is ignoring pausetime.
Another 2 bugs.

About fluidsytnh...
I have investigated and there are bindings for GO but are undocumented and I have not a single clue on how to use it.
I will try to build a basic command line app that loads a midi to get a hang on it.

EDIT

Also new features by neatunsou.
Quote
MatchRestart
Code:
[state test]
type = MatchRestart
trigger1 = time = 10
p1def = "kfm.def"
p2def = "kfm.def"
Stagedef = "stage0.def"
reload = 1,1
Reset the round and resume. (Same effect as debug key F4)

Set Reload to 1 to reload the file and restart the round from the beginning. (Same effect as the debug key Shift + F4)

One item of Reload specifies whether P1 or 2 item reloads P2. If all 0, do not reload and reset the round.

When the path of def file is specified in P1def, P2def, Stagedef, the file is read when reloading. The pass at that time is based on the execution character.
A interesting one it could be made for a boss that changes stages (And character def) in the second round for example.



IDK if this is somepart of the basic usage of Fluidsynth but let me share you, the little things do I have:

Standalone mode of fluidsynth
You can simply use fluidsynth to play MIDI files:

Code:
$ fluidsynth -a alsa -m alsa_seq -l -i /usr/share/soundfonts/FluidR3_GM.sf2 example.midi
assuming than you installed soundfont-fluid.

There are many other options to fluidsynth; see manpage or use -h to get help.

One may wish to use pulseaudio instead of alsa as the argument to the -a option.


Tip: The soundfont does not needed to be specified every time if a symbolic link created for the default soundfont, e.g.
Code:
ln -s FluidR3_GM.sf2 /usr/share/soundfonts/default.sf2

ALSA daemon mode
If you want fluidsynth to run as ALSA daemon, edit /etc/conf.d/fluidsynth and add your soundfont along with any other changes you would like to make. For e.g., fluidr3:
Code:
SOUND_FONT=/usr/share/soundfonts/FluidR3_GM.sf2
OTHER_OPTS='-a alsa -m alsa_seq -r 48000'

After that, you can start/enable the fluidsynth service. Note that you can't use root to restart the fluidsynth service, if you're using the pulseaudio driver. Pulseaudio won't allow root to connect, since the pulseaudio server is usually started by the user (and not root). You can solve it by creating a systemd/User service (replacing multi-user.target with default.target in the copied fluidsynth.service).

The following will give you an output software MIDI port (in addition of hardware MIDI ports on your system, if any):

Code:
$ aconnect -o
client 128: 'FLUID Synth (5117)' [type=user]
   0 'Synth input port (5117:0)

An example of usage for this is aplaymidi:
Code:
$ aplaymidi -p128:0 example.midi



SDL_Mixer
To use fluidsynth with programs that use SDL_Mixer, you need to specify the soundfont as:
Code:
 $ SDL_SOUNDFONTS=/usr/share/soundfonts/FluidR3_GM.sf2 ./program



Source  link
https://wiki.archlinux.org/index.php/FluidSynth
http://www.fluidsynth.org/
http://www.fluidsynth.org/api/


Now, let me share you some info about the API (the bad thing is the library is a C library)

Creating and changing the settings

Before you can use the synthesizer, you have to create a settings object. The settings objects is used by many components of the FluidSynth library. It gives a unified API to set the parameters of the audio drivers, the midi drivers, the synthesizer, and so forth. A number of default settings are defined by the current implementation.

All settings have a name that follows the "dotted-name" notation. For example, "synth.polyphony" refers to the number of voices (polyphony) allocated by the synthesizer. The settings also have a type. There are currently three types: strings, numbers (double floats), and integers. You can change the values of a setting using the fluid_settings_setstr(), fluid_settings_setnum(), and fluid_settings_setint() functions. For example:

Code:
#include <fluidsynth.h>
int main(int argc, char** argv)
{
    fluid_settings_t* settings = new_fluid_settings();
    fluid_settings_setint(settings, "synth.polyphony", 128);
    /* ... */
    delete_fluid_settings(settings);
    return 0;
}

The API contains the functions to query the type, the current value, the default value, the range and the "hints" of a setting. The range is the minimum and maximum value of the setting. The hints gives additional information about a setting. For example, whether a string represents a filename. Or whether a number should be interpreted on on a logarithmic scale. Check the settings.h API documentation for a description of all functions.



Creating the synthesizer

To create the synthesizer, you pass it the settings object, as in the following example:
Code:
#include <fluidsynth.h>
int main(int argc, char** argv)
{
    fluid_settings_t* settings;
    fluid_synth_t* synth;
    settings = new_fluid_settings();
    synth = new_fluid_synth(settings);
    /* Do useful things here */
    delete_fluid_synth(synth);
    delete_fluid_settings(settings);
    return 0;
For a full list of available synthesizer settings, please refer to FluidSettings Documentation.


Creating the Audio Driver

The synthesizer itself does not write any audio to the audio output. This allows application developers to manage the audio output themselves if they wish. The next section describes the use of the synthesizer without an audio driver in more detail.

Creating the audio driver is straightforward: set the audio.driver settings and create the driver object. Because the FluidSynth has support for several audio systems, you may want to change which one you want to use. The list below shows the audio systems that are currently supported. It displays the name, as used by the fluidsynth library, and a description.

jack: JACK Audio Connection Kit (Linux, Mac OS X, Windows)
alsa: Advanced Linux Sound Architecture (Linux)
oss: Open Sound System (Linux, Unix)
pulseaudio: PulseAudio (Linux, Mac OS X, Windows)
coreaudio: Apple CoreAudio (Mac OS X)
dsound: Microsoft DirectSound (Windows)
portaudio: PortAudio Library (Mac OS 9 & X, Windows, Linux)
sndman: Apple SoundManager (Mac OS Classic)
dart: DART sound driver (OS/2)
opensles: OpenSL ES (Android)
oboe: Oboe (Android)
file: Driver to output audio to a file
sdl2*: Simple DirectMedia Layer (Linux, Windows, Mac OS X, iOS, Android, FreeBSD, Haiku, etc.)

The default audio driver depends on the settings with which FluidSynth was compiled. You can get the default driver with fluid_settings_getstr_default(). To get the list of available drivers use the fluid_settings_foreach_option() function. Finally, you can set the driver with fluid_settings_setstr(). In most cases, the default driver should work out of the box.

Additional options that define the audio quality and latency are "audio.sample-format", "audio.period-size", and "audio.periods". The details are described later.

You create the audio driver with the new_fluid_audio_driver() function. This function takes the settings and synthesizer object as arguments. For example:

Code:
void init() 
{
    fluid_settings_t* settings;
    fluid_synth_t* synth;
    fluid_audio_driver_t* adriver;
    settings = new_fluid_settings();
    /* Set the synthesizer settings, if necessary */
    synth = new_fluid_synth(settings);
    fluid_settings_setstr(settings, "audio.driver", "jack");
    adriver = new_fluid_audio_driver(settings, synth);
}

As soon as the audio driver is created, it will start playing. The audio driver creates a separate thread that uses the synthesizer object to generate the audio.

There are a number of general audio driver settings. The audio.driver settings define the audio subsystem that will be used. The audio.periods and audio.period-size settings define the latency and robustness against scheduling delays. There are additional settings for the audio subsystems used. For a full list of available audio driver settings, please refer to FluidSettings Documentation.

*Note: In order to use sdl2 as audio driver, the application is responsible for initializing SDL (e.g. with SDL_Init()). This must be done before the first call to new_fluid_settings()! Also make sure to call SDL_Quit() after all fluidsynth instances have been destroyed.


Using the synthesizer without an audio driver

It is possible to use the synthesizer object without creating an audio driver. This is desirable if the application using FluidSynth manages the audio output itself. The synthesizer has several API functions that can be used to obtain the audio output:

fluid_synth_write_s16() fills two buffers (left and right channel) with samples coded as signed 16 bits (the endian-ness is machine dependent). fluid_synth_write_float() fills a left and right audio buffer with 32 bits floating point samples. The function fluid_synth_process() is the generic interface for synthesizing audio, which is also capable of multi channel audio output.


Loading and managing SoundFonts

Before any sound can be produced, the synthesizer needs a SoundFont.

SoundFonts are loaded with the fluid_synth_sfload() function. The function takes the path to a SoundFont file and a boolean to indicate whether the presets of the MIDI channels should be updated after the SoundFont is loaded. When the boolean value is TRUE, all MIDI channel bank and program numbers will be refreshed, which may cause new instruments to be selected from the newly loaded SoundFont.

The synthesizer can load any number of SoundFonts. The loaded SoundFonts are treated as a stack, where each new loaded SoundFont is placed at the top of the stack. When selecting presets by bank and program numbers, SoundFonts are searched beginning at the top of the stack. In the case where there are presets in different SoundFonts with identical bank and program numbers, the preset from the most recently loaded SoundFont is used. The fluid_synth_program_select() can be used for unambiguously selecting a preset or bank offsets could be applied to each SoundFont with fluid_synth_set_bank_offset(), to try and ensure that each preset has unique bank and program numbers.

The fluid_synth_sfload() function returns the unique identifier of the loaded SoundFont, or -1 in case of an error. This identifier is used in subsequent management functions: fluid_synth_sfunload() removes the SoundFont, fluid_synth_sfreload() reloads the SoundFont. When a SoundFont is reloaded, it retains it's ID and position on the SoundFont stack.

Additional API functions are provided to get the number of loaded SoundFonts and to get a pointer to the SoundFont.



Creating a Real-time MIDI Driver

FluidSynth can process real-time MIDI events received from hardware MIDI ports or other applications. To do so, the client must create a MIDI input driver. It is a very similar process to the creation of the audio driver: you initialize some properties in a settings instance and call the new_fluid_midi_driver() function providing a callback function that will be invoked when a MIDI event is received. The following MIDI drivers are currently supported:

jack: JACK Audio Connection Kit MIDI driver (Linux, Mac OS X)
oss: Open Sound System raw MIDI (Linux, Unix)
alsa_raw: ALSA raw MIDI interface (Linux)
alsa_seq: ALSA sequencer MIDI interface (Linux)
winmidi: Microsoft Windows MM System (Windows)
midishare: MIDI Share (Linux, Mac OS X)
coremidi: Apple CoreMIDI (Mac OS X)

Code:
#include <fluidsynth.h>
int handle_midi_event(void* data, fluid_midi_event_t* event)
{
    printf("event type: %d\n", fluid_midi_event_get_type(event));
}
int main(int argc, char** argv)
{
    fluid_settings_t* settings;
    fluid_midi_driver_t* mdriver;
    settings = new_fluid_settings();
    mdriver = new_fluid_midi_driver(settings, handle_midi_event, NULL);
    /* ... */   
    delete_fluid_midi_driver(mdriver);
    return 0;
}

There are a number of general MIDI driver settings. The midi.driver setting defines the MIDI subsystem that will be used. There are additional settings for the MIDI subsystems used. For a full list of available midi driver settings, please refer to FluidSettings Documentation.


Loading and Playing a MIDI file

FluidSynth can be used to play MIDI files, using the MIDI File Player interface. It follows a high level implementation, though its implementation is currently incomplete. After initializing the synthesizer, create the player passing the synth instance to new_fluid_player(). Then, you can add some SMF file names to the player using fluid_player_add(), and finally call fluid_player_play() to start the playback. You can check if the player has finished by calling fluid_player_get_status(), or wait for the player to terminate using fluid_player_join().

Code:
#include <fluidsynth.h>
int main(int argc, char** argv)
{
    int i;
    fluid_settings_t* settings;
    fluid_synth_t* synth;
    fluid_player_t* player;
    fluid_audio_driver_t* adriver;
    settings = new_fluid_settings();
    synth = new_fluid_synth(settings);
    player = new_fluid_player(synth);
    adriver = new_fluid_audio_driver(settings, synth);
    /* process command line arguments */
    for (i = 1; i < argc; i++) {
        if (fluid_is_soundfont(argv[i])) {
           fluid_synth_sfload(synth, argv[1], 1);
        }
        if (fluid_is_midifile(argv[i])) {
            fluid_player_add(player, argv[i]);
        }
    }
    /* play the midi files, if any */
    fluid_player_play(player);
    /* wait for playback termination */
    fluid_player_join(player);
    /* cleanup */
    delete_fluid_audio_driver(adriver);
    delete_fluid_player(player);
    delete_fluid_synth(synth);
    delete_fluid_settings(settings);
    return 0;
}

A list of available MIDI player settings can be found in FluidSettings Documentation.



Fast file renderer for non-realtime MIDI file rendering

Instead of creating an audio driver as described in section Loading and Playing a MIDI file one may chose to use the file renderer, which is the fastest way to synthesize MIDI files.

Code:
fluid_settings_t* settings;
fluid_synth_t* synth;
fluid_player_t* player;
fluid_file_renderer_t* renderer;
settings = new_fluid_settings();
// specify the file to store the audio to
// make sure you compiled fluidsynth with libsndfile to get a real wave file
// otherwise this file will only contain raw s16 stereo PCM
fluid_settings_setstr(settings, "audio.file.name", "/path/to/output.wav");
// use number of samples processed as timing source, rather than the system timer
fluid_settings_setstr(settings, "player.timing-source", "sample");
// since this is a non-realtime szenario, there is no need to pin the sample data
fluid_settings_setint(settings, "synth.lock-memory", 0);
synth = new_fluid_synth(settings);
// *** loading of a soundfont omitted ***
player = new_fluid_player(synth);
fluid_player_add(player, "/path/to/midifile.mid");
fluid_player_play(player);
renderer = new_fluid_file_renderer (synth);
while (fluid_player_get_status(player) == FLUID_PLAYER_PLAYING)
{
    if (fluid_file_renderer_process_block(renderer) != FLUID_OK)
    {
        break;
    }
}
// just for sure: stop the playback explicitly and wait until finished
fluid_player_stop(player);
fluid_player_join(player);
delete_fluid_file_renderer(renderer);
delete_fluid_player(player);
delete_fluid_synth(synth);
delete_fluid_settings(settings);

Various output files types are supported, if compiled with libsndfile. Those can be specified via the settings object as well. Refer to the FluidSettings Documentation for more audio.file.* options.

So, taking on mind the function of the Fluidsytnh API, now its time to understand the go bindings

So, From squeeky Fluidsyhnth binding, we will take on: Driver.go
Code:
package fluidsynth

// #cgo pkg-config: fluidsynth
// #include <fluidsynth.h>
// #include <stdlib.h>
import "C"

type AudioDriver struct {
ptr *C.fluid_audio_driver_t
}

func NewAudioDriver(settings Settings, synth Synth) AudioDriver {
return AudioDriver{C.new_fluid_audio_driver(settings.ptr, synth.ptr)}
}

func (d *AudioDriver) Delete() {
C.delete_fluid_audio_driver(d.ptr)
}


type FileRenderer struct {
ptr *C.fluid_file_renderer_t
}

func NewFileRenderer(synth Synth) FileRenderer {
return FileRenderer{C.new_fluid_file_renderer(synth.ptr)}
}

func (r *FileRenderer) Delete() {
C.delete_fluid_file_renderer(r.ptr)
}

func (r *FileRenderer) ProcessBlock() bool {
return C.fluid_file_renderer_process_block(r.ptr) == C.FLUID_OK

Now, we instrospect a little on:  sound.go
Code:
import "C"

import (
"os"
"fmt"
"unsafe"
)

type Synth struct {
csettings *C.fluid_settings_t
csynth *C.fluid_synth_t
cdriver *C.fluid_audio_driver_t
ptr *C.fluid_synth_t
}

func NewSynth(settings map[string]interface{}) *Synth {
csettings, _ := C.new_fluid_settings()
for key, value := range settings {
ckey := C.CString(key)
switch value := value.(type) {
case string:
cval := C.CString(value)
C.fluid_settings_setstr(csettings, ckey, cval)
C.free(unsafe.Pointer(cval))
case int:
C.fluid_settings_setint(csettings, ckey, C.int(value))
case float64:
C.fluid_settings_setnum(csettings, ckey, C.double(value))
default:
fmt.Fprintf(os.Stderr, "NewSynth: ignoring setting %s: unhandled type %T\n", key, value)
}
C.free(unsafe.Pointer(ckey))
func cbool(b bool) C.int {
if b {
return 1
}
csynth := C.new_fluid_synth(csettings)
//cdriver := C.new_fluid_audio_driver(csettings, csynth)
return &Synth{csettings, csynth, nil}
return 0
}

func NewSynth(settings Settings) Synth {
return Synth{C.new_fluid_synth(settings.ptr)}
}

func (s *Synth) Delete() {
C.delete_fluid_synth(s.ptr)
}

func (s *Synth) SFLoad(path string, resetPresets bool) int {
cpath := C.CString(path)
defer C.free(unsafe.Pointer(cpath))
creset := C.int(1)
if !resetPresets {
creset = 0
}
cfont_id, _ := C.fluid_synth_sfload(s.csynth, cpath, creset)
creset := cbool(resetPresets)
cfont_id, _ := C.fluid_synth_sfload(s.ptr, cpath, creset)
return int(cfont_id)
}

/* XXX can this be run automatically on gc? */
func (s *Synth) Delete() {
//C.delete_fluid_audio_driver(s.cdriver)
C.delete_fluid_synth(s.csynth)
C.delete_fluid_settings(s.csettings)
}

func (s *Synth) NoteOn(channel, note, velocity uint8) {
C.fluid_synth_noteon(s.csynth, C.int(channel), C.int(note), C.int(velocity))
C.fluid_synth_noteon(s.ptr, C.int(channel), C.int(note), C.int(velocity))
}

func (s *Synth) NoteOff(channel, note uint8) {
C.fluid_synth_noteoff(s.csynth, C.int(channel), C.int(note))
C.fluid_synth_noteoff(s.ptr, C.int(channel), C.int(note))
}

func (s *Synth) ProgramChange(channel, program uint8) {
C.fluid_synth_program_change(s.csynth, C.int(channel), C.int(program))
C.fluid_synth_program_change(s.ptr, C.int(channel), C.int(program))
}

func (s *Synth) WriteFrames_int16(dst []int16) {
if len(dst) % 2 != 0 {
panic("dst not disivible by 2")
/* WriteS16 synthesizes signed 16-bit samples. It will fill as much of the provided
slices as it can without overflowing 'left' or 'right'. For interleaved stereo, have both
'left' and 'right' share a backing array and use lstride = rstride = 2. ie:
    synth.WriteS16(samples, samples[1:], 2, 2)
*/
func (s *Synth) WriteS16(left, right []int16, lstride, rstride int) {
nframes := (len(left) + lstride - 1) / lstride
rframes := (len(right) + rstride - 1) / rstride
if rframes < nframes {
nframes = rframes
}
cbuf := unsafe.Pointer(&dst[0])
C.fluid_synth_write_s16(s.csynth, C.int(len(dst)/2), cbuf, 0, 2, cbuf, 1, 2)
C.fluid_synth_write_s16(s.ptr, C.int(nframes), unsafe.Pointer(&left[0]), 0, C.int(lstride), unsafe.Pointer(&right[0]), 0, C.int(rstride))
}

func (s *Synth) WriteFloat(left, right []float32, lstride, rstride int) {
nframes := (len(left) + lstride - 1) / lstride
rframes := (len(right) + rstride - 1) / rstride
if rframes < nframes {
nframes = rframes
}
C.fluid_synth_write_float(s.ptr, C.int(nframes), unsafe.Pointer(&left[0]), 0, C.int(lstride), unsafe.Pointer(&right[0]), 0, C.int(rstride))
}

type TuningId struct {
Bank, Program uint8
}

/* ActivateKeyTuning creates/modifies a specific tuning bank/program */
func (s *Synth) ActivateKeyTuning(id TuningId, name string, tuning [128]float64, apply bool) {
n := C.CString(name)
defer C.free(unsafe.Pointer(n))
C.fluid_synth_activate_key_tuning(s.ptr, C.int(id.Bank), C.int(id.Program), n, (*C.double)(&tuning[0]), cbool(apply))
}

/* ActivateTuning switches a midi channel onto the specified tuning bank/program */
func (s *Synth) ActivateTuning(channel uint8, id TuningId, apply bool) {
C.fluid_synth_activate_tuning(s.ptr, C.int(channel), C.int(id.Bank), C.int(id.Program), cbool(apply))


And no less important, settings.go

Code:
package fluidsynth

// #cgo pkg-config: fluidsynth
// #include <fluidsynth.h>
// #include <stdlib.h>
import "C"

import (
"unsafe"
)

var settingNames map[string]*C.char
var nSettings = 0

type Settings struct {
ptr *C.fluid_settings_t
}

func NewSettings() Settings {
if settingNames == nil {
settingNames = make(map[string]*C.char)
}
nSettings++
return Settings{ptr: C.new_fluid_settings()}
}

func (s *Settings) Delete() {
nSettings--
if nSettings == 0 {
settingNames = nil
}
C.delete_fluid_settings(s.ptr)
}

func cname(name string) *C.char {
if cname, ok := settingNames[name]; ok {
return cname
}
cname := C.CString(name)
settingNames[name] = cname
return cname
}

/* IsRealtime returns true if changing the specified setting immediately affects an associated Synth */
func (s *Settings) IsRealtime(name string) bool {
return C.fluid_settings_is_realtime(s.ptr, cname(name)) == 1
}

func (s *Settings) SetInt(name string, val int) bool {
return C.fluid_settings_setint(s.ptr, cname(name), C.int(val)) == 1
}

func (s *Settings) SetNum(name string, val float64) bool {
return C.fluid_settings_setnum(s.ptr, cname(name), C.double(val)) == 1
}

func (s *Settings) SetString(name, val string) bool {
cval := C.CString(val)
defer C.free(unsafe.Pointer(cval))
return C.fluid_settings_setstr(s.ptr, cname(name), cval) == 1

}

func (s *Settings) GetInt(name string, val *int) bool {
return C.fluid_settings_getint(s.ptr, cname(name), (*C.int)(unsafe.Pointer(val))) == 1
}

func (s *Settings) GetNum(name string, val *float64) bool {
return C.fluid_settings_getnum(s.ptr, cname(name), (*C.double)(unsafe.Pointer(val))) == 1
}

func (s *Settings) GetString(name string, val *string) bool {
var cstr *C.char
ok := (C.fluid_settings_getstr(s.ptr, cname(name), &cstr) == 1)
if ok {
*val = C.GoString(cstr)
}
return ok
}



So, Having this on mind, lets analize main.go and sound.go


So, We begin on Main.go

Code:
package main

import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"regexp"
"runtime"
"strconv"
"strings"

"github.com/go-gl/glfw/v3.2/glfw"
"github.com/yuin/gopher-lua"
)

func init() {
runtime.LockOSThread()
}
func chk(err error) {
if err != nil {
panic(err)
}
}
func createLog(p string) *os.File {
//fmt.Println("Creating log")
f, err := os.Create(p)
if err != nil {
panic(err)
}
return f
}
func closeLog(f *os.File) {
//fmt.Println("Closing log")
f.Close()
}
func main() {
if len(os.Args[1:]) > 0 {
sys.cmdFlags = make(map[string]string)
key := ""
player := 1
for _, a := range os.Args[1:] {
match, _ := regexp.MatchString("^-", a)
if match {
help, _ := regexp.MatchString("^-[h%?]", a)
if help {
fmt.Println("I.K.E.M.E.N\nOptions (case sensitive):")
fmt.Println(" -h -?               Help")
fmt.Println(" -log <logfile>      Records match data to <logfile>")
fmt.Println(" -r <sysfile>        Loads motif <sysfile>. eg. -r motifdir or -r motifdir/system.def")
fmt.Println("\nQuick VS Options:")
fmt.Println(" -p<n> <playername>  Loads player n, eg. -p3 kfm")
fmt.Println(" -p<n>.ai <level>    Set player n's AI to <level>, eg. -p1.ai 8")
fmt.Println(" -p<n>.color <col>   Set player n's color to <col>")
fmt.Println(" -p<n>.life <life>   Sets player n's life to <life>")
fmt.Println(" -p<n>.power <power> Sets player n's power to <power>")
fmt.Println(" -rounds <num>       Plays for <num> rounds, and then quits")
fmt.Println(" -s <stagename>      Loads stage <stagename>")
fmt.Println("\nPress ENTER to exit.")
var s string
fmt.Scanln(&s)
os.Exit(0)
}
sys.cmdFlags[a] = ""
key = a
} else if key == "" {
sys.cmdFlags[fmt.Sprintf("-p%v", player)] = a
player += 1
} else {
sys.cmdFlags[key] = a
key = ""
}
}
}
chk(glfw.Init())
defer glfw.Terminate()
defcfg := []byte(strings.Join(strings.Split(`{
  "HelperMax":56,
  "PlayerProjectileMax":256,
  "ExplodMax":512,
  "AfterImageMax":128,
  "MasterVolume":80,
  "WavVolume":80,
  "BgmVolume":80,
  "Attack.LifeToPowerMul":0.7,
  "GetHit.LifeToPowerMul":0.6,
  "Width":640,
  "Height":480,
  "Super.TargetDefenceMul":1.5,
  "LifebarFontScale":1,
  "System":"script/main.lua",
  "KeyConfig":[{
      "Joystick":-1,
      "Buttons":["UP","DOWN","LEFT","RIGHT","z","x","c","a","s","d","RETURN","q","w"]
    },{
      "Joystick":-1,
      "Buttons":["t","g","f","h","j","k","l","u","i","o","RSHIFT","LEFTBRACKET","RIGHTBRACKET"]
    }],
  "JoystickConfig":[{
      "Joystick":0,
      "Buttons":["-7","-8","-5","-6","0","1","4","2","3","5","7","6","8"]
    },{
      "Joystick":1,
      "Buttons":["-7","-8","-5","-6","0","1","4","2","3","5","7","6","8"]
    }],
  "Motif":"data/system.def",
  "CommonAir":"data/common.air",
  "CommonCmd":"data/common.cmd",
  "SimulMode":true,
  "LifeMul":100,
  "Team1VS2Life":120,
  "TurnsRecoveryRate":300,
  "ZoomActive":false,
  "ZoomMin":0.75,
  "ZoomMax":1.1,
  "ZoomSpeed":1,
  "RoundTime":99,
  "NumTurns":4,
  "NumSimul":4,
  "NumTag":4,
  "Difficulty":8,
  "Credits":10,
  "ListenPort":7500,
  "ContSelection":true,
  "AIRandomColor":true,
  "AIRamping":true,
  "AutoGuard":false,
  "TeamPowerShare":false,
  "TeamLifeShare":false,
  "Fullscreen":false,
  "AudioDucking":false,
  "QuickLaunch":0,
  "AllowDebugKeys":true,
  "PostProcessingShader": 0,
  "LocalcoordScalingType": 1,
  "IP":{
  }
}
`, "\n"), "\r\n"))
tmp := struct {
HelperMax              int32
PlayerProjectileMax    int
ExplodMax              int
AfterImageMax          int32
MasterVolume           int
WavVolume              int
BgmVolume              int
Attack_LifeToPowerMul  float32 `json:"Attack.LifeToPowerMul"`
GetHit_LifeToPowerMul  float32 `json:"GetHit.LifeToPowerMul"`
Width                  int32
Height                 int32
Super_TargetDefenceMul float32 `json:"Super.TargetDefenceMul"`
LifebarFontScale       float32
System                 string
KeyConfig              []struct {
Joystick int
Buttons  []interface{}
}
JoystickConfig []struct {
Joystick int
Buttons  []interface{}
}
NumTag                int
TeamLifeShare         bool
AIRandomColor         bool
Fullscreen            bool
AudioDucking          bool
AllowDebugKeys        bool
PostProcessingShader  int32
LocalcoordScalingType int32
CommonAir             string
CommonCmd             string
QuickLaunch           int
}{}
chk(json.Unmarshal(defcfg, &tmp))
const configFile = "data/config.json"
if bytes, err := ioutil.ReadFile(configFile); err != nil {
f, err := os.Create(configFile)
chk(err)
f.Write(defcfg)
chk(f.Close())
} else {
if len(bytes) >= 3 &&
bytes[0] == 0xef && bytes[1] == 0xbb && bytes[2] == 0xbf {
bytes = bytes[3:]
}
chk(json.Unmarshal(bytes, &tmp))
}
sys.helperMax = tmp.HelperMax
sys.playerProjectileMax = tmp.PlayerProjectileMax
sys.explodMax = tmp.ExplodMax
sys.afterImageMax = tmp.AfterImageMax
sys.attack_LifeToPowerMul = tmp.Attack_LifeToPowerMul
sys.getHit_LifeToPowerMul = tmp.GetHit_LifeToPowerMul
sys.super_TargetDefenceMul = tmp.Super_TargetDefenceMul
sys.lifebarFontScale = tmp.LifebarFontScale
sys.quickLaunch = tmp.QuickLaunch
sys.masterVolume = tmp.MasterVolume
sys.wavVolume = tmp.WavVolume
sys.bgmVolume = tmp.BgmVolume
sys.AudioDucking = tmp.AudioDucking
stoki := func(key string) int {
return int(StringToKey(key))
}
Atoi := func(key string) int {
var i int
i, _ = strconv.Atoi(key)
return i
}
for a := 0; a < tmp.NumTag; a++ {
for _, kc := range tmp.KeyConfig {
b := kc.Buttons
if kc.Joystick < 0 {
sys.keyConfig = append(sys.keyConfig, KeyConfig{kc.Joystick,
stoki(b[0].(string)), stoki(b[1].(string)),
stoki(b[2].(string)), stoki(b[3].(string)),
stoki(b[4].(string)), stoki(b[5].(string)), stoki(b[6].(string)),
stoki(b[7].(string)), stoki(b[8].(string)), stoki(b[9].(string)),
stoki(b[10].(string)), stoki(b[11].(string)), stoki(b[12].(string))})
}
}
for _, jc := range tmp.JoystickConfig {
b := jc.Buttons
if jc.Joystick >= 0 {
sys.JoystickConfig = append(sys.JoystickConfig, KeyConfig{jc.Joystick,
Atoi(b[0].(string)), Atoi(b[1].(string)),
Atoi(b[2].(string)), Atoi(b[3].(string)),
Atoi(b[4].(string)), Atoi(b[5].(string)), Atoi(b[6].(string)),
Atoi(b[7].(string)), Atoi(b[8].(string)), Atoi(b[9].(string)),
Atoi(b[10].(string)), Atoi(b[11].(string)), Atoi(b[12].(string))})
}
}
}
sys.teamLifeShare = tmp.TeamLifeShare
sys.fullscreen = tmp.Fullscreen
sys.PostProcessingShader = tmp.PostProcessingShader
sys.LocalcoordScalingType = tmp.LocalcoordScalingType
sys.aiRandomColor = tmp.AIRandomColor
sys.allowDebugKeys = tmp.AllowDebugKeys
air, err := ioutil.ReadFile(tmp.CommonAir)
if err != nil {
fmt.Print(err)
}
sys.commonAir = string("\n") + string(air)
cmd, err := ioutil.ReadFile(tmp.CommonCmd)
if err != nil {
fmt.Print(err)
}
sys.commonCmd = string("\n") + string(cmd)
//os.Mkdir("debug", os.ModeSticky|0755)
log := createLog("Ikemen.txt")
defer closeLog(log)
l := sys.init(tmp.Width, tmp.Height)
if err := l.DoFile(tmp.System); err != nil {
fmt.Fprintln(log, err)
switch err.(type) {
case *lua.ApiError:
errstr := strings.Split(err.Error(), "\n")[0]
if len(errstr) < 10 || errstr[len(errstr)-10:] != "<game end>" {
panic(err)
}
default:
panic(err)
}
}
if !sys.gameEnd {
sys.gameEnd = true
}
<-sys.audioClose



Now, lets make some commits

Code:
package main

import (
        "C"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"regexp"
"runtime"
"strconv"
"strings"
        "path/filepath"

"github.com/go-gl/glfw/v3.2/glfw"
"github.com/yuin/gopher-lua"
        "github.com/x42/avldrums.lv2/tree/master/fluidsynth"
)

func init() {
runtime.LockOSThread()
}
func chk(err error) {
if err != nil {
panic(err)
}
}
func createLog(p string) *os.File {
//fmt.Println("Creating log")
f, err := os.Create(p)
if err != nil {
panic(err)
}
return f
}
func closeLog(f *os.File) {
//fmt.Println("Closing log")
f.Close()
}
func (s *Synth) SFLoad(path string, resetPresets bool) int {
cpath := C.CString(path)
defer C.free(unsafe.Pointer(cpath))
creset := C.int(1)
if !resetPresets {
creset = 0
}
cfont_id, _ := C.fluid_synth_sfload("data/gamesoundfont.sf2")
creset := cbool(resetPresets)
cfont_id, _ := C.fluid_synth_sfload("data/gamesoundfont.sf2")
return int(cfont_id)
}
func main() {
if len(os.Args[1:]) > 0 {
sys.cmdFlags = make(map[string]string)
key := ""
player := 1
for _, a := range os.Args[1:] {
match, _ := regexp.MatchString("^-", a)
if match {
help, _ := regexp.MatchString("^-[h%?]", a)
if help {
fmt.Println("I.K.E.M.E.N\nOptions (case sensitive):")
fmt.Println(" -h -?               Help")
fmt.Println(" -log <logfile>      Records match data to <logfile>")
fmt.Println(" -r <sysfile>        Loads motif <sysfile>. eg. -r motifdir or -r motifdir/system.def")
fmt.Println("\nQuick VS Options:")
fmt.Println(" -p<n> <playername>  Loads player n, eg. -p3 kfm")
fmt.Println(" -p<n>.ai <level>    Set player n's AI to <level>, eg. -p1.ai 8")
fmt.Println(" -p<n>.color <col>   Set player n's color to <col>")
fmt.Println(" -p<n>.life <life>   Sets player n's life to <life>")
fmt.Println(" -p<n>.power <power> Sets player n's power to <power>")
fmt.Println(" -rounds <num>       Plays for <num> rounds, and then quits")
fmt.Println(" -s <stagename>      Loads stage <stagename>")
fmt.Println("\nPress ENTER to exit.")
var s string
fmt.Scanln(&s)
os.Exit(0)
}
sys.cmdFlags[a] = ""
key = a
} else if key == "" {
sys.cmdFlags[fmt.Sprintf("-p%v", player)] = a
player += 1
} else {
sys.cmdFlags[key] = a
key = ""
}
}
}
chk(glfw.Init())
defer glfw.Terminate()
defcfg := []byte(strings.Join(strings.Split(`{
  "HelperMax":56,
  "PlayerProjectileMax":256,
  "ExplodMax":512,
  "AfterImageMax":128,
  "MasterVolume":80,
  "WavVolume":80,
  "BgmVolume":80,
  "Attack.LifeToPowerMul":0.7,
  "GetHit.LifeToPowerMul":0.6,
  "Width":640,
  "Height":480,
  "Super.TargetDefenceMul":1.5,
  "LifebarFontScale":1,
  "System":"script/main.lua",
  "KeyConfig":[{
      "Joystick":-1,
      "Buttons":["UP","DOWN","LEFT","RIGHT","z","x","c","a","s","d","RETURN","q","w"]
    },{
      "Joystick":-1,
      "Buttons":["t","g","f","h","j","k","l","u","i","o","RSHIFT","LEFTBRACKET","RIGHTBRACKET"]
    }],
  "JoystickConfig":[{
      "Joystick":0,
      "Buttons":["-7","-8","-5","-6","0","1","4","2","3","5","7","6","8"]
    },{
      "Joystick":1,
      "Buttons":["-7","-8","-5","-6","0","1","4","2","3","5","7","6","8"]
    }],
  "Motif":"data/system.def",
  "CommonAir":"data/common.air",
  "CommonCmd":"data/common.cmd",
  "SFLoad":"data/gamesoundfont.sf2"
  "SimulMode":true,
  "LifeMul":100,
  "Team1VS2Life":120,
  "TurnsRecoveryRate":300,
  "ZoomActive":false,
  "ZoomMin":0.75,
  "ZoomMax":1.1,
  "ZoomSpeed":1,
  "RoundTime":99,
  "NumTurns":4,
  "NumSimul":4,
  "NumTag":4,
  "Difficulty":8,
  "Credits":10,
  "ListenPort":7500,
  "ContSelection":true,
  "AIRandomColor":true,
  "AIRamping":true,
  "AutoGuard":false,
  "TeamPowerShare":false,
  "TeamLifeShare":false,
  "Fullscreen":false,
  "AudioDucking":false,
  "QuickLaunch":0,
  "AllowDebugKeys":true,
  "PostProcessingShader": 0,
  "LocalcoordScalingType": 1,
  "IP":{
  }
}
`, "\n"), "\r\n"))
tmp := struct {
HelperMax              int32
PlayerProjectileMax    int
ExplodMax              int
AfterImageMax          int32
MasterVolume           int
WavVolume              int
BgmVolume              int
Attack_LifeToPowerMul  float32 `json:"Attack.LifeToPowerMul"`
GetHit_LifeToPowerMul  float32 `json:"GetHit.LifeToPowerMul"`
Width                  int32
Height                 int32
Super_TargetDefenceMul float32 `json:"Super.TargetDefenceMul"`
LifebarFontScale       float32
System                 string
KeyConfig              []struct {
Joystick int
Buttons  []interface{}
}
JoystickConfig []struct {
Joystick int
Buttons  []interface{}
}
NumTag                int
TeamLifeShare         bool
AIRandomColor         bool
Fullscreen            bool
AudioDucking          bool
AllowDebugKeys        bool
PostProcessingShader  int32
LocalcoordScalingType int32
CommonAir             string
CommonCmd             string
QuickLaunch           int
}{}
chk(json.Unmarshal(defcfg, &tmp))
const configFile = "data/config.json"
if bytes, err := ioutil.ReadFile(configFile); err != nil {
f, err := os.Create(configFile)
chk(err)
f.Write(defcfg)
chk(f.Close())
} else {
if len(bytes) >= 3 &&
bytes[0] == 0xef && bytes[1] == 0xbb && bytes[2] == 0xbf {
bytes = bytes[3:]
}
chk(json.Unmarshal(bytes, &tmp))
}
sys.helperMax = tmp.HelperMax
sys.playerProjectileMax = tmp.PlayerProjectileMax
sys.explodMax = tmp.ExplodMax
sys.afterImageMax = tmp.AfterImageMax
sys.attack_LifeToPowerMul = tmp.Attack_LifeToPowerMul
sys.getHit_LifeToPowerMul = tmp.GetHit_LifeToPowerMul
sys.super_TargetDefenceMul = tmp.Super_TargetDefenceMul
sys.lifebarFontScale = tmp.LifebarFontScale
sys.quickLaunch = tmp.QuickLaunch
sys.masterVolume = tmp.MasterVolume
sys.wavVolume = tmp.WavVolume
sys.bgmVolume = tmp.BgmVolume
sys.AudioDucking = tmp.AudioDucking
stoki := func(key string) int {
return int(StringToKey(key))
}
Atoi := func(key string) int {
var i int
i, _ = strconv.Atoi(key)
return i
}
for a := 0; a < tmp.NumTag; a++ {
for _, kc := range tmp.KeyConfig {
b := kc.Buttons
if kc.Joystick < 0 {
sys.keyConfig = append(sys.keyConfig, KeyConfig{kc.Joystick,
stoki(b[0].(string)), stoki(b[1].(string)),
stoki(b[2].(string)), stoki(b[3].(string)),
stoki(b[4].(string)), stoki(b[5].(string)), stoki(b[6].(string)),
stoki(b[7].(string)), stoki(b[8].(string)), stoki(b[9].(string)),
stoki(b[10].(string)), stoki(b[11].(string)), stoki(b[12].(string))})
}
}
for _, jc := range tmp.JoystickConfig {
b := jc.Buttons
if jc.Joystick >= 0 {
sys.JoystickConfig = append(sys.JoystickConfig, KeyConfig{jc.Joystick,
Atoi(b[0].(string)), Atoi(b[1].(string)),
Atoi(b[2].(string)), Atoi(b[3].(string)),
Atoi(b[4].(string)), Atoi(b[5].(string)), Atoi(b[6].(string)),
Atoi(b[7].(string)), Atoi(b[8].(string)), Atoi(b[9].(string)),
Atoi(b[10].(string)), Atoi(b[11].(string)), Atoi(b[12].(string))})
}
}
}
sys.teamLifeShare = tmp.TeamLifeShare
sys.fullscreen = tmp.Fullscreen
sys.PostProcessingShader = tmp.PostProcessingShader
sys.LocalcoordScalingType = tmp.LocalcoordScalingType
sys.aiRandomColor = tmp.AIRandomColor
sys.allowDebugKeys = tmp.AllowDebugKeys
air, err := ioutil.ReadFile(tmp.CommonAir)
if err != nil {
fmt.Print(err)
}
sys.commonAir = string("\n") + string(air)
cmd, err := ioutil.ReadFile(tmp.CommonCmd)
if err != nil {
fmt.Print(err)
}
sys.commonCmd = string("\n") + string(cmd)
//os.Mkdir("debug", os.ModeSticky|0755)
log := createLog("Ikemen.txt")
defer closeLog(log)
l := sys.init(tmp.Width, tmp.Height)
if err := l.DoFile(tmp.System); err != nil {
fmt.Fprintln(log, err)
switch err.(type) {
case *lua.ApiError:
errstr := strings.Split(err.Error(), "\n")[0]
if len(errstr) < 10 || errstr[len(errstr)-10:] != "<game end>" {
panic(err)
}
default:
panic(err)
}
}
if !sys.gameEnd {
sys.gameEnd = true
}
<-sys.audioClose

Last Edit: July 15, 2019, 06:16:49 pm by Mike77154
Re: Ikemen GO Plus
#1097  July 13, 2019, 08:58:43 am
  • ***
  • One of Ikemen GO devs
    • Colombia
Thanks for the info about fluidsynth!

All i get is a black screen with the new version and ikemen doesnt start at all.

Possibly due to the MSAA implementation.
This will need to be an option.
Maybe MSAA is not compatible with all graphics cards because my pc can definitely run high specs games (I7, 8gb sapphire with 12gb ram).

Better be safe than sorry. I'll implement the old rendering pre MSSA rendering as a option by tomorrow. (It will be the default one)
But wait!! We haven't made the Suave Dude character yet!!
Re: Ikemen GO Plus
#1098  July 13, 2019, 09:31:15 am
  • ****
  • Hoping for the best, prepared for the worst.
  • 2D Fighting games forever!
    • Brazil
Glad to see you're back man.
Lasagna
Re: Ikemen GO Plus
#1099  July 14, 2019, 03:41:00 am
  • **
  • The need situation makes the man
    • Mexico
    • www.facebook.com/mike.funkyman
about my mod suggestions on main.go, maybe this can be the failures

Code:
jdoodle.go:15:2: cannot find package "github.com/go-gl/glfw/v3.2/glfw" in any of:
/usr/lib/go/src/github.com/go-gl/glfw/v3.2/glfw (from $GOROOT)
/root/go/src/github.com/go-gl/glfw/v3.2/glfw (from $GOPATH)
jdoodle.go:18:5: cannot find package "github.com/sqweek/fluidsynth" in any of:
/usr/lib/go/src/github.com/sqweek/fluidsynth (from $GOROOT)
/root/go/src/github.com/sqweek/fluidsynth (from $GOPATH)
jdoodle.go:17:5: cannot find package "github.com/x42/avldrums.lv2/tree/master/fluidsynth" in any of:
/usr/lib/go/src/github.com/x42/avldrums.lv2/tree/master/fluidsynth (from $GOROOT)
/root/go/src/github.com/x42/avldrums.lv2/tree/master/fluidsynth (from $GOPATH)
jdoodle.go:16:2: cannot find package "github.com/yuin/gopher-lua" in any of:
/usr/lib/go/src/github.com/yuin/gopher-lua (from $GOROOT)
/root/go/src/github.com/yuin/gopher-lua (from $GOPATH)
Command exited with non-zero status 1


Code:
$go run main.go
main.go:15:2: cannot find package "github.com/go-gl/glfw/v3.2/glfw" in any of:
/usr/lib/golang/src/github.com/go-gl/glfw/v3.2/glfw (from $GOROOT)
/home/cg/root/1773287/go/src/github.com/go-gl/glfw/v3.2/glfw (from $GOPATH)
main.go:18:9: cannot find package "github.com/sqweek/fluidsynth" in any of:
/usr/lib/golang/src/github.com/sqweek/fluidsynth (from $GOROOT)
/home/cg/root/1773287/go/src/github.com/sqweek/fluidsynth (from $GOPATH)
main.go:17:9: cannot find package "github.com/x42/avldrums.lv2/tree/master/fluidsynth" in any of:
/usr/lib/golang/src/github.com/x42/avldrums.lv2/tree/master/fluidsynth (from $GOROOT)
/home/cg/root/1773287/go/src/github.com/x42/avldrums.lv2/tree/master/fluidsynth (from $GOPATH)
main.go:16:2: cannot find package "github.com/yuin/gopher-lua" in any of:
/usr/lib/golang/src/github.com/yuin/gopher-lua (from $GOROOT)
/home/cg/root/1773287/go/src/github.com/yuin/gopher-lua (from $GOPATH)


And for last take, let me make some experiments on sound.go

Code:
package main

import (
"encoding/binary"
"fmt"
"math"
"os"
"path/filepath"

"github.com/timshannon/go-openal/openal"

"github.com/faiface/beep"
"github.com/faiface/beep/effects"
"github.com/faiface/beep/flac"
"github.com/faiface/beep/mp3"
"github.com/faiface/beep/speaker"
"github.com/faiface/beep/vorbis"
)

const (
audioOutLen    = 2048
audioFrequency = 48000
)

// ------------------------------------------------------------------
// Audio Source

// AudioSource structure.
// It contains OpenAl's sound destination and buffer
type AudioSource struct {
Src  openal.Source
bufs openal.Buffers
}

func NewAudioSource() (s *AudioSource) {
s = &AudioSource{Src: openal.NewSource(), bufs: openal.NewBuffers(2)}
for i := range s.bufs {
s.bufs[i].SetDataInt16(openal.FormatStereo16, sys.nullSndBuf[:],
audioFrequency)
}
s.Src.QueueBuffers(s.bufs)
if err := openal.Err(); err != nil {
println(err.Error())
}
return
}
func (s *AudioSource) Delete() {
for s.Src.BuffersQueued() > 0 {
s.Src.UnqueueBuffer()
}
s.bufs.Delete()
s.Src.Delete()
}

// ------------------------------------------------------------------
// Mixer

type Mixer struct {
buf        [audioOutLen * 2]float32
sendBuf    []int16
out        chan []int16
normalizer *Normalizer
}

func newMixer() *Mixer {
return &Mixer{out: make(chan []int16, 1), normalizer: NewNormalizer()}
}
func (m *Mixer) bufClear() {
for i := range m.buf {
m.buf[i] = 0
}
}
func (m *Mixer) write() bool {
if m.sendBuf == nil {
m.sendBuf = make([]int16, len(m.buf))
for i := 0; i <= len(m.sendBuf)-2; i += 2 {
l, r := m.normalizer.Process(m.buf[i], m.buf[i+1])
m.sendBuf[i] = int16(32767 * l)
m.sendBuf[i+1] = int16(32767 * r)
}
}
select {
case m.out <- m.sendBuf:
default:
return false
}
m.sendBuf = nil
m.bufClear()
return true
}
func (m *Mixer) Mix(wav []byte, fidx float64, bytesPerSample, channels int,
sampleRate float64, loop bool, volume float32) float64 {
fidxadd := sampleRate / audioFrequency
if fidxadd > 0 {
switch bytesPerSample {
case 1:
switch channels {
case 1:
for i := 0; i <= len(m.buf)-2; i += 2 {
iidx := int(fidx)
if iidx >= len(wav) {
if !loop {
break
}
iidx, fidx = 0, 0
}
sam := volume * (float32(wav[iidx]) - 128) / 128
m.buf[i] += sam
m.buf[i+1] += sam
fidx += fidxadd
}
return fidx
case 2:
for i := 0; i <= len(m.buf)-2; i += 2 {
iidx := 2 * int(fidx)
if iidx > len(wav)-2 {
if !loop {
break
}
iidx, fidx = 0, 0
}
m.buf[i] += volume * (float32(wav[iidx]) - 128) / 128
m.buf[i+1] += volume * (float32(wav[iidx+1]) - 128) / 128
fidx += fidxadd
}
return fidx
}
case 2:
switch channels {
case 1:
for i := 0; i <= len(m.buf)-2; i += 2 {
iidx := 2 * int(fidx)
if iidx > len(wav)-2 {
if !loop {
break
}
iidx, fidx = 0, 0
}
sam := volume *
float32(int(wav[iidx])|int(int8(wav[iidx+1]))<<8) / (1 << 15)
m.buf[i] += sam
m.buf[i+1] += sam
fidx += fidxadd
}
return fidx
case 2:
for i := 0; i <= len(m.buf)-2; i += 2 {
iidx := 4 * int(fidx)
if iidx > len(wav)-4 {
if !loop {
break
}
iidx, fidx = 0, 0
}
m.buf[i] += volume *
float32(int(wav[iidx])|int(int8(wav[iidx+1]))<<8) / (1 << 15)
m.buf[i+1] += volume *
float32(int(wav[iidx+2])|int(int8(wav[iidx+3]))<<8) / (1 << 15)
fidx += fidxadd
}
return fidx
}
}
}
return float64(len(wav))
}

// ------------------------------------------------------------------
// Normalizer

type Normalizer struct {
mul  float64
l, r *NormalizerLR
}

func NewNormalizer() *Normalizer {
return &Normalizer{mul: 4, l: &NormalizerLR{1, 0, 1, 1 / 32.0, 0, 0},
r: &NormalizerLR{1, 0, 1, 1 / 32.0, 0, 0}}
}
func (n *Normalizer) Process(l, r float32) (float32, float32) {
lmul := n.l.process(n.mul, &l)
rmul := n.r.process(n.mul, &r)
if sys.AudioDucking {
if lmul < rmul {
n.mul = lmul
} else {
n.mul = rmul
}
if n.mul > 16 {
n.mul = 16
}
} else {
n.mul = 0.5 * (float64(sys.wavVolume) * float64(sys.masterVolume) * 0.0001)
}
return l, r
}

type NormalizerLR struct {
heri, herihenka, fue, heikin, katayori, katayori2 float64
}

func (n *NormalizerLR) process(bai float64, sam *float32) float64 {
n.katayori = (n.katayori*audioFrequency/110 + float64(*sam)) /
(audioFrequency/110.0 + 1)
n.katayori2 = (n.katayori2*audioFrequency/112640 + float64(*sam)) /
(audioFrequency/112640.0 + 1)
s := (n.katayori2 - n.katayori) * bai
if math.Abs(s) > 1 {
bai *= math.Pow(1/math.Abs(s), n.heri)
n.herihenka += 32 * (1 - n.heri) / float64(audioFrequency+32)
if s < 0 {
s = -1
} else {
s = 1
}
} else {
tmp := (1 - math.Pow(1-math.Abs(s), 64)) * math.Pow(0.5-math.Abs(s), 3)
bai += bai * (n.heri*(1/32.0-n.heikin)/n.fue + tmp*n.fue*(1-n.heri)/32) /
(audioFrequency*2/8.0 + 1)
n.herihenka -= (0.5 - n.heikin) * n.heri / (audioFrequency * 2)
}
n.fue += (32*n.fue*(1/n.fue-math.Abs(s)) - n.fue) /
(32 * audioFrequency * 2)
n.heikin += (math.Abs(s) - n.heikin) / (audioFrequency * 2)
n.heri += n.herihenka
if n.heri < 0 {
n.heri = 0
} else if n.heri > 0 {
n.heri = 1
}
*sam = float32(s)
return bai
}

// ------------------------------------------------------------------
// Bgm

type Bgm struct {
filename string
ctrl     *beep.Ctrl
}

func newBgm() *Bgm {
return &Bgm{}
}

func (bgm *Bgm) IsVorbis() bool {
return bgm.IsFormat(".ogg")
}

func (bgm *Bgm) IsMp3() bool {
return bgm.IsFormat(".mp3")
}

func (bgm *Bgm) IsFLAC() bool {
return bgm.IsFormat(".flac")
}

func (bgm *Bgm) IsFormat(extension string) bool {
return filepath.Ext(bgm.filename) == extension
}

func (bgm *Bgm) Open(filename string) {

if filepath.Base(bgm.filename) == filepath.Base(filename) {
return
}

bgm.filename = filename
speaker.Clear()

if bgm.IsVorbis() {
bgm.ReadVorbis()
} else if bgm.IsMp3() {
bgm.ReadMp3()
} else if bgm.IsFLAC() {
bgm.ReadFLAC()
}

}

func (bgm *Bgm) ReadMp3() {
f, _ := os.Open(bgm.filename)
s, format, err := mp3.Decode(f)
if err != nil {
return
}
bgm.ReadFormat(s, format)
}

func (bgm *Bgm) ReadFLAC() {
f, _ := os.Open(bgm.filename)
s, format, err := flac.Decode(f)
if err != nil {
return
}
bgm.ReadFormat(s, format)
}

func (bgm *Bgm) ReadVorbis() {
f, _ := os.Open(bgm.filename)
s, format, err := vorbis.Decode(f)
if err != nil {
return
}
bgm.ReadFormat(s, format)
}

func (bgm *Bgm) ReadFormat(s beep.StreamSeekCloser, format beep.Format) {
streamer := beep.Loop(-1, s)
volume := -5 + float64(sys.bgmVolume)*0.06*(float64(sys.masterVolume)/100)
streamer = &effects.Volume{Streamer: streamer, Base: 2, Volume: volume, Silent: volume <= -5}
resample := beep.Resample(int(3), format.SampleRate, beep.SampleRate(Mp3SampleRate), streamer)
bgm.ctrl = &beep.Ctrl{Streamer: resample}
speaker.Play(bgm.ctrl)
}

func (bgm *Bgm) Pause() {
speaker.Lock()
bgm.ctrl.Paused = true
speaker.Unlock()
return
}

// ------------------------------------------------------------------
// Wave

type Wave struct {
SamplesPerSec  uint32
Channels       uint16
BytesPerSample uint16
Wav            []byte
}

func ReadWave(f *os.File, ofs int64) (*Wave, error) {
buf := make([]byte, 4)
n, err := f.Read(buf)
if err != nil {
return nil, err
}
if string(buf[:n]) != "RIFF" {
return nil, Error("RIFFではありません")
}
read := func(x interface{}) error {
return binary.Read(f, binary.LittleEndian, x)
}
var riffSize uint32
if err := read(&riffSize); err != nil {
return nil, err
}
riffSize += 8
if n, err = f.Read(buf); err != nil {
return nil, err
}
if string(buf[:n]) != "WAVE" {
return &Wave{SamplesPerSec: 11025, Channels: 1, BytesPerSample: 1}, nil
}
fmtSize, dataSize := uint32(0), uint32(0)
w := Wave{}
riffend := ofs + 16 + int64(riffSize)
ofs += 28
for (fmtSize == 0 || dataSize == 0) && ofs < riffend {
if n, err = f.Read(buf); err != nil {
return nil, err
}
var size uint32
if err := read(&size); err != nil {
return nil, err
}
switch string(buf[:n]) {
case "fmt ":
fmtSize = size
var fmtID uint16
if err := read(&fmtID); err != nil {
return nil, err
}
if fmtID != 1 {
return nil, Error("リニアPCMではありません")
}
if err := read(&w.Channels); err != nil {
return nil, err
}
if w.Channels < 1 || w.Channels > 2 {
return nil, Error("チャンネル数が不正です")
}
if err := read(&w.SamplesPerSec); err != nil {
return nil, err
}
if w.SamplesPerSec < 1 || w.SamplesPerSec >= 0xfffff {
return nil, Error(fmt.Sprintf("周波数が不正です %d", w.SamplesPerSec))
}
var musi uint32
if err := read(&musi); err != nil {
return nil, err
}
var mushi uint16
if err := read(&mushi); err != nil {
return nil, err
}
if err := read(&w.BytesPerSample); err != nil {
return nil, err
}
if w.BytesPerSample != 8 && w.BytesPerSample != 16 {
return nil, Error("bit数が不正です")
}
w.BytesPerSample >>= 3
case "data":
dataSize = size
w.Wav = make([]byte, dataSize)
if err := binary.Read(f, binary.LittleEndian, w.Wav); err != nil {
return nil, err
}
}
ofs += int64(size) + 8
f.Seek(ofs, 0)
}
if fmtSize == 0 {
if dataSize > 0 {
return nil, Error("fmt がありません")
}
return nil, nil
}
return &w, nil
}

// ------------------------------------------------------------------
// Snd

type Snd struct {
table     map[[2]int32]*Wave
ver, ver2 uint16
}

func newSnd() *Snd {
return &Snd{table: make(map[[2]int32]*Wave)}
}

func LoadSnd(filename string) (*Snd, error) {
s := newSnd()
f, err := os.Open(filename)
if err != nil {
return nil, err
}
defer func() { chk(f.Close()) }()
buf := make([]byte, 12)
var n int
if n, err = f.Read(buf); err != nil {
return nil, err
}
if string(buf[:n]) != "ElecbyteSnd\x00" {
return nil, Error("ElecbyteSndではありません")
}
read := func(x interface{}) error {
return binary.Read(f, binary.LittleEndian, x)
}
if err := read(&s.ver); err != nil {
return nil, err
}
if err := read(&s.ver2); err != nil {
return nil, err
}
var numberOfSounds uint32
if err := read(&numberOfSounds); err != nil {
return nil, err
}
var subHeaderOffset uint32
if err := read(&subHeaderOffset); err != nil {
return nil, err
}
for i := uint32(0); i < numberOfSounds; i++ {
f.Seek(int64(subHeaderOffset), 0)
var nextSubHeaderOffset uint32
if err := read(&nextSubHeaderOffset); err != nil {
return nil, err
}
var subFileLenght uint32
if err := read(&subFileLenght); err != nil {
return nil, err
}
var num [2]int32
if err := read(&num); err != nil {
return nil, err
}
if num[0] >= 0 && num[1] >= 0 {
_, ok := s.table[num]
if !ok {
tmp, err := ReadWave(f, int64(subHeaderOffset))
if err != nil {
return nil, err
}
s.table[num] = tmp
}
}
subHeaderOffset = nextSubHeaderOffset
}
return s, nil
}
func (s *Snd) Get(gn [2]int32) *Wave {
return s.table[gn]
}
func (s *Snd) play(gn [2]int32) bool {
c := sys.sounds.GetChannel()
if c == nil {
return false
}
c.sound = s.Get(gn)
return c.sound != nil
}

// ------------------------------------------------------------------
// Sound

type Sound struct {
sound   *Wave
volume  int16
loop    bool
freqmul float32
fidx    float64
}

func (s *Sound) mix() {
if s.sound == nil {
return
}
s.fidx = sys.mixer.Mix(s.sound.Wav, s.fidx,
int(s.sound.BytesPerSample), int(s.sound.Channels),
float64(s.sound.SamplesPerSec)*float64(s.freqmul), s.loop,
float32(s.volume)/256)
if int(s.fidx) >= len(s.sound.Wav)/
int(s.sound.BytesPerSample*s.sound.Channels) {
s.sound = nil
s.fidx = 0
}
}
func (s *Sound) SetVolume(vol int32) {
if vol < 0 {
s.volume = 0
} else if vol > 512 {
s.volume = 512
} else {
s.volume = int16(vol)
}
}
func (s *Sound) SetPan(pan float32, offset *float32) {
// 未実装
}

type Sounds []Sound

func newSounds(size int) (s Sounds) {
s = make(Sounds, size)
for i := range s {
s[i] = Sound{volume: 256, freqmul: 1}
}
return
}
func (s Sounds) GetChannel() *Sound {
for i := range s {
if s[i].sound == nil {
return &s[i]
}
}
return nil
}
func (s Sounds) mixSounds() {
for i := range s {
s[i].mix()
}
}


And lets mess with this

Code:
package main

import (
        "C"
"encoding/binary"
"fmt"
"math"
"os"
"path/filepath"

"github.com/timshannon/go-openal/openal"

"github.com/faiface/beep"
"github.com/faiface/beep/effects"
"github.com/faiface/beep/flac"
"github.com/faiface/beep/mp3"
"github.com/faiface/beep/speaker"
"github.com/faiface/beep/vorbis"

        "github.com/x42/avldrums.lv2/tree/master/fluidsynth"
         "github.com/sqweek/fluidsynth"
)

const (
audioOutLen    = 2048
audioFrequency = 48000
)

// ------------------------------------------------------------------
// Audio Source

// AudioSource structure.
// It contains OpenAl's sound destination and buffer
type AudioSource struct {
Src  openal.Source
bufs openal.Buffers
}

func NewAudioSource() (s *AudioSource) {
s = &AudioSource{Src: openal.NewSource(), bufs: openal.NewBuffers(2)}
for i := range s.bufs {
s.bufs[i].SetDataInt16(openal.FormatStereo16, sys.nullSndBuf[:],
audioFrequency)
}
s.Src.QueueBuffers(s.bufs)
if err := openal.Err(); err != nil {
println(err.Error())
}
return
}
func (s *AudioSource) Delete() {
for s.Src.BuffersQueued() > 0 {
s.Src.UnqueueBuffer()
}
s.bufs.Delete()
s.Src.Delete()
}

// ------------------------------------------------------------------
//MIDI HANDLING (FLUIDSYNTH)
type AudioDriver struct {
ptr *C.fluid_audio_driver_t
}

func NewAudioDriver(settings Settings, synth Synth) AudioDriver {
return AudioDriver{C.new_fluid_audio_driver(settings.ptr, synth.ptr)}
}

func (d *AudioDriver) Delete() {
C.delete_fluid_audio_driver(d.ptr)
}


type FileRenderer struct {
ptr *C.fluid_file_renderer_t
}

func NewFileRenderer(synth Synth) FileRenderer {
return FileRenderer{C.new_fluid_file_renderer(synth.ptr)}
}

func (r *FileRenderer) Delete() {
C.delete_fluid_file_renderer(r.ptr)
}

func (r *FileRenderer) ProcessBlock() bool {
return C.fluid_file_renderer_process_block(r.ptr) == C.FLUID_OK
}

func NewSettings() Settings {
if settingNames == nil {
settingNames = make(map[string]*C.char)
}
nSettings++
return Settings{ptr: C.new_fluid_settings()}
}

func (s *Settings) Delete() {
nSettings--
if nSettings == 0 {
settingNames = nil
}
C.delete_fluid_settings(s.ptr)
}

func cname(name string) *C.char {
if cname, ok := settingNames[name]; ok {
return cname
}
cname := C.CString(name)
settingNames[name] = cname
return cname
}

/* IsRealtime returns true if changing the specified setting immediately affects an associated Synth */
func (s *Settings) IsRealtime(name string) bool {
return C.fluid_settings_is_realtime(s.ptr, cname(name)) == 1
}

func (s *Settings) SetInt(name string, val int) bool {
return C.fluid_settings_setint(s.ptr, cname(name), C.int(val)) == 1
}

func (s *Settings) SetNum(name string, val float64) bool {
return C.fluid_settings_setnum(s.ptr, cname(name), C.double(val)) == 1
}

func (s *Settings) SetString(name, val string) bool {
cval := C.CString(val)
defer C.free(unsafe.Pointer(cval))
return C.fluid_settings_setstr(s.ptr, cname(name), cval) == 1

}

func (s *Settings) GetInt(name string, val *int) bool {
return C.fluid_settings_getint(s.ptr, cname(name), (*C.int)(unsafe.Pointer(val))) == 1
}

func (s *Settings) GetNum(name string, val *float64) bool {
return C.fluid_settings_getnum(s.ptr, cname(name), (*C.double)(unsafe.Pointer(val))) == 1
}

func (s *Settings) GetString(name string, val *string) bool {
var cstr *C.char
ok := (C.fluid_settings_getstr(s.ptr, cname(name), &cstr) == 1)
if ok {
*val = C.GoString(cstr)
}
return ok
}

type Synth struct {
ptr *C.fluid_synth_t
}

func cbool(b bool) C.int {
if b {
return 1
}
return 0
}

func NewSynth(settings Settings) Synth {
return Synth{C.new_fluid_synth(settings.ptr)}
}

func (s *Synth) Delete() {
C.delete_fluid_synth(s.ptr)
}
func (s *Synth) NoteOn(channel, note, velocity uint8) {
C.fluid_synth_noteon(s.ptr, C.int(channel), C.int(note), C.int(velocity))
}

func (s *Synth) NoteOff(channel, note uint8) {
C.fluid_synth_noteoff(s.ptr, C.int(channel), C.int(note))
}

func (s *Synth) ProgramChange(channel, program uint8) {
C.fluid_synth_program_change(s.ptr, C.int(channel), C.int(program))
}

/* WriteS16 synthesizes signed 16-bit samples. It will fill as much of the provided
slices as it can without overflowing 'left' or 'right'. For interleaved stereo, have both
'left' and 'right' share a backing array and use lstride = rstride = 2. ie:
    synth.WriteS16(samples, samples[1:], 2, 2)
*/
func (s *Synth) WriteS16(left, right []int16, lstride, rstride int) {
nframes := (len(left) + lstride - 1) / lstride
rframes := (len(right) + rstride - 1) / rstride
if rframes < nframes {
nframes = rframes
}
C.fluid_synth_write_s16(s.ptr, C.int(nframes), unsafe.Pointer(&left[0]), 0, C.int(lstride), unsafe.Pointer(&right[0]), 0, C.int(rstride))
}

func (s *Synth) WriteFloat(left, right []float32, lstride, rstride int) {
nframes := (len(left) + lstride - 1) / lstride
rframes := (len(right) + rstride - 1) / rstride
if rframes < nframes {
nframes = rframes
}
C.fluid_synth_write_float(s.ptr, C.int(nframes), unsafe.Pointer(&left[0]), 0, C.int(lstride), unsafe.Pointer(&right[0]), 0, C.int(rstride))
}

type TuningId struct {
Bank, Program uint8
}

/* ActivateKeyTuning creates/modifies a specific tuning bank/program */
func (s *Synth) ActivateKeyTuning(id TuningId, name string, tuning [128]float64, apply bool) {
n := C.CString(name)
defer C.free(unsafe.Pointer(n))
C.fluid_synth_activate_key_tuning(s.ptr, C.int(id.Bank), C.int(id.Program), n, (*C.double)(&tuning[0]), cbool(apply))
}

/* ActivateTuning switches a midi channel onto the specified tuning bank/program */
func (s *Synth) ActivateTuning(channel uint8, id TuningId, apply bool) {
C.fluid_synth_activate_tuning(s.ptr, C.int(channel), C.int(id.Bank), C.int(id.Program), cbool(apply))
}
// ------------------------------------------------------------------
// Mixer

type Mixer struct {
buf        [audioOutLen * 2]float32
sendBuf    []int16
out        chan []int16
normalizer *Normalizer
}

func newMixer() *Mixer {
return &Mixer{out: make(chan []int16, 1), normalizer: NewNormalizer()}
}
func (m *Mixer) bufClear() {
for i := range m.buf {
m.buf[i] = 0
}
}
func (m *Mixer) write() bool {
if m.sendBuf == nil {
m.sendBuf = make([]int16, len(m.buf))
for i := 0; i <= len(m.sendBuf)-2; i += 2 {
l, r := m.normalizer.Process(m.buf[i], m.buf[i+1])
m.sendBuf[i] = int16(32767 * l)
m.sendBuf[i+1] = int16(32767 * r)
}
}
select {
case m.out <- m.sendBuf:
default:
return false
}
m.sendBuf = nil
m.bufClear()
return true
}
func (m *Mixer) Mix(wav []byte, fidx float64, bytesPerSample, channels int,
sampleRate float64, loop bool, volume float32) float64 {
fidxadd := sampleRate / audioFrequency
if fidxadd > 0 {
switch bytesPerSample {
case 1:
switch channels {
case 1:
for i := 0; i <= len(m.buf)-2; i += 2 {
iidx := int(fidx)
if iidx >= len(wav) {
if !loop {
break
}
iidx, fidx = 0, 0
}
sam := volume * (float32(wav[iidx]) - 128) / 128
m.buf[i] += sam
m.buf[i+1] += sam
fidx += fidxadd
}
return fidx
case 2:
for i := 0; i <= len(m.buf)-2; i += 2 {
iidx := 2 * int(fidx)
if iidx > len(wav)-2 {
if !loop {
break
}
iidx, fidx = 0, 0
}
m.buf[i] += volume * (float32(wav[iidx]) - 128) / 128
m.buf[i+1] += volume * (float32(wav[iidx+1]) - 128) / 128
fidx += fidxadd
}
return fidx
}
case 2:
switch channels {
case 1:
for i := 0; i <= len(m.buf)-2; i += 2 {
iidx := 2 * int(fidx)
if iidx > len(wav)-2 {
if !loop {
break
}
iidx, fidx = 0, 0
}
sam := volume *
float32(int(wav[iidx])|int(int8(wav[iidx+1]))<<8) / (1 << 15)
m.buf[i] += sam
m.buf[i+1] += sam
fidx += fidxadd
}
return fidx
case 2:
for i := 0; i <= len(m.buf)-2; i += 2 {
iidx := 4 * int(fidx)
if iidx > len(wav)-4 {
if !loop {
break
}
iidx, fidx = 0, 0
}
m.buf[i] += volume *
float32(int(wav[iidx])|int(int8(wav[iidx+1]))<<8) / (1 << 15)
m.buf[i+1] += volume *
float32(int(wav[iidx+2])|int(int8(wav[iidx+3]))<<8) / (1 << 15)
fidx += fidxadd
}
return fidx
}
}
}
return float64(len(wav))
}

// ------------------------------------------------------------------
// Normalizer

type Normalizer struct {
mul  float64
l, r *NormalizerLR
}

func NewNormalizer() *Normalizer {
return &Normalizer{mul: 4, l: &NormalizerLR{1, 0, 1, 1 / 32.0, 0, 0},
r: &NormalizerLR{1, 0, 1, 1 / 32.0, 0, 0}}
}
func (n *Normalizer) Process(l, r float32) (float32, float32) {
lmul := n.l.process(n.mul, &l)
rmul := n.r.process(n.mul, &r)
if sys.AudioDucking {
if lmul < rmul {
n.mul = lmul
} else {
n.mul = rmul
}
if n.mul > 16 {
n.mul = 16
}
} else {
n.mul = 0.5 * (float64(sys.wavVolume) * float64(sys.masterVolume) * 0.0001)
}
return l, r
}

type NormalizerLR struct {
heri, herihenka, fue, heikin, katayori, katayori2 float64
}

func (n *NormalizerLR) process(bai float64, sam *float32) float64 {
n.katayori = (n.katayori*audioFrequency/110 + float64(*sam)) /
(audioFrequency/110.0 + 1)
n.katayori2 = (n.katayori2*audioFrequency/112640 + float64(*sam)) /
(audioFrequency/112640.0 + 1)
s := (n.katayori2 - n.katayori) * bai
if math.Abs(s) > 1 {
bai *= math.Pow(1/math.Abs(s), n.heri)
n.herihenka += 32 * (1 - n.heri) / float64(audioFrequency+32)
if s < 0 {
s = -1
} else {
s = 1
}
} else {
tmp := (1 - math.Pow(1-math.Abs(s), 64)) * math.Pow(0.5-math.Abs(s), 3)
bai += bai * (n.heri*(1/32.0-n.heikin)/n.fue + tmp*n.fue*(1-n.heri)/32) /
(audioFrequency*2/8.0 + 1)
n.herihenka -= (0.5 - n.heikin) * n.heri / (audioFrequency * 2)
}
n.fue += (32*n.fue*(1/n.fue-math.Abs(s)) - n.fue) /
(32 * audioFrequency * 2)
n.heikin += (math.Abs(s) - n.heikin) / (audioFrequency * 2)
n.heri += n.herihenka
if n.heri < 0 {
n.heri = 0
} else if n.heri > 0 {
n.heri = 1
}
*sam = float32(s)
return bai
}

// ------------------------------------------------------------------
// Bgm

type Bgm struct {
filename string
ctrl     *beep.Ctrl
}

func newBgm() *Bgm {
return &Bgm{}
}

func (bgm *Bgm) IsVorbis() bool {
return bgm.IsFormat(".ogg")
}

func (bgm *Bgm) IsMp3() bool {
return bgm.IsFormat(".mp3")
}

func (bgm *Bgm) IsFLAC() bool {
return bgm.IsFormat(".flac")
}
func (bgm *Bgm) IsMIDI() bool {
return bgm.IsFormat(".mid")
}


func (bgm *Bgm) IsFormat(extension string) bool {
return filepath.Ext(bgm.filename) == extension
}

func (bgm *Bgm) Open(filename string) {

if filepath.Base(bgm.filename) == filepath.Base(filename) {
return
}

bgm.filename = filename
speaker.Clear()

if bgm.IsVorbis() {
bgm.ReadVorbis()
} else if bgm.IsMp3() {
bgm.ReadMp3()
} else if bgm.IsFLAC() {
bgm.ReadFLAC()
}else if bgm.IsMIDI() {
                C.new_fluid_player()
bgm.ReadMIDI()
                C.fluid_player_play()
}
}

func (bgm *Bgm) ReadMp3() {
f, _ := os.Open(bgm.filename)
s, format, err := mp3.Decode(f)
if err != nil {
return
}
bgm.ReadFormat(s, format)
}

func (bgm *Bgm) ReadFLAC() {
f, _ := os.Open(bgm.filename)
s, format, err := flac.Decode(f)
if err != nil {
return
}
bgm.ReadFormat(s, format)
}

func (bgm *Bgm) ReadVorbis() {
f, _ := os.Open(bgm.filename)
s, format, err := vorbis.Decode(f)
if err != nil {
return
}
bgm.ReadFormat(s, format)
}
func (bgm *Bgm) ReadMIDI() {
f, _ := os.Open(bgm.filename)
s, format, err := C.fluid_player_play(f)
if err != nil {
return
}
bgm.ReadFormat(s, format)
}

func (bgm *Bgm) ReadFormat(s beep.StreamSeekCloser, format beep.Format) {
streamer := beep.Loop(-1, s)
volume := -5 + float64(sys.bgmVolume)*0.06*(float64(sys.masterVolume)/100)
streamer = &effects.Volume{Streamer: streamer, Base: 2, Volume: volume, Silent: volume <= -5}
resample := beep.Resample(int(3), format.SampleRate, beep.SampleRate(Mp3SampleRate), streamer)
bgm.ctrl = &beep.Ctrl{Streamer: resample}
speaker.Play(bgm.ctrl)
}

func (bgm *Bgm) Pause() {
speaker.Lock()
bgm.ctrl.Paused = true
speaker.Unlock()
return
}

// ------------------------------------------------------------------
// Wave

type Wave struct {
SamplesPerSec  uint32
Channels       uint16
BytesPerSample uint16
Wav            []byte
}

func ReadWave(f *os.File, ofs int64) (*Wave, error) {
buf := make([]byte, 4)
n, err := f.Read(buf)
if err != nil {
return nil, err
}
if string(buf[:n]) != "RIFF" {
return nil, Error("RIFFではありません")
}
read := func(x interface{}) error {
return binary.Read(f, binary.LittleEndian, x)
}
var riffSize uint32
if err := read(&riffSize); err != nil {
return nil, err
}
riffSize += 8
if n, err = f.Read(buf); err != nil {
return nil, err
}
if string(buf[:n]) != "WAVE" {
return &Wave{SamplesPerSec: 11025, Channels: 1, BytesPerSample: 1}, nil
}
fmtSize, dataSize := uint32(0), uint32(0)
w := Wave{}
riffend := ofs + 16 + int64(riffSize)
ofs += 28
for (fmtSize == 0 || dataSize == 0) && ofs < riffend {
if n, err = f.Read(buf); err != nil {
return nil, err
}
var size uint32
if err := read(&size); err != nil {
return nil, err
}
switch string(buf[:n]) {
case "fmt ":
fmtSize = size
var fmtID uint16
if err := read(&fmtID); err != nil {
return nil, err
}
if fmtID != 1 {
return nil, Error("リニアPCMではありません")
}
if err := read(&w.Channels); err != nil {
return nil, err
}
if w.Channels < 1 || w.Channels > 2 {
return nil, Error("チャンネル数が不正です")
}
if err := read(&w.SamplesPerSec); err != nil {
return nil, err
}
if w.SamplesPerSec < 1 || w.SamplesPerSec >= 0xfffff {
return nil, Error(fmt.Sprintf("周波数が不正です %d", w.SamplesPerSec))
}
var musi uint32
if err := read(&musi); err != nil {
return nil, err
}
var mushi uint16
if err := read(&mushi); err != nil {
return nil, err
}
if err := read(&w.BytesPerSample); err != nil {
return nil, err
}
if w.BytesPerSample != 8 && w.BytesPerSample != 16 {
return nil, Error("bit数が不正です")
}
w.BytesPerSample >>= 3
case "data":
dataSize = size
w.Wav = make([]byte, dataSize)
if err := binary.Read(f, binary.LittleEndian, w.Wav); err != nil {
return nil, err
}
}
ofs += int64(size) + 8
f.Seek(ofs, 0)
}
if fmtSize == 0 {
if dataSize > 0 {
return nil, Error("fmt がありません")
}
return nil, nil
}
return &w, nil
}

// ------------------------------------------------------------------
// Snd

type Snd struct {
table     map[[2]int32]*Wave
ver, ver2 uint16
}

func newSnd() *Snd {
return &Snd{table: make(map[[2]int32]*Wave)}
}

func LoadSnd(filename string) (*Snd, error) {
s := newSnd()
f, err := os.Open(filename)
if err != nil {
return nil, err
}
defer func() { chk(f.Close()) }()
buf := make([]byte, 12)
var n int
if n, err = f.Read(buf); err != nil {
return nil, err
}
if string(buf[:n]) != "ElecbyteSnd\x00" {
return nil, Error("ElecbyteSndではありません")
}
read := func(x interface{}) error {
return binary.Read(f, binary.LittleEndian, x)
}
if err := read(&s.ver); err != nil {
return nil, err
}
if err := read(&s.ver2); err != nil {
return nil, err
}
var numberOfSounds uint32
if err := read(&numberOfSounds); err != nil {
return nil, err
}
var subHeaderOffset uint32
if err := read(&subHeaderOffset); err != nil {
return nil, err
}
for i := uint32(0); i < numberOfSounds; i++ {
f.Seek(int64(subHeaderOffset), 0)
var nextSubHeaderOffset uint32
if err := read(&nextSubHeaderOffset); err != nil {
return nil, err
}
var subFileLenght uint32
if err := read(&subFileLenght); err != nil {
return nil, err
}
var num [2]int32
if err := read(&num); err != nil {
return nil, err
}
if num[0] >= 0 && num[1] >= 0 {
_, ok := s.table[num]
if !ok {
tmp, err := ReadWave(f, int64(subHeaderOffset))
if err != nil {
return nil, err
}
s.table[num] = tmp
}
}
subHeaderOffset = nextSubHeaderOffset
}
return s, nil
}
func (s *Snd) Get(gn [2]int32) *Wave {
return s.table[gn]
}
func (s *Snd) play(gn [2]int32) bool {
c := sys.sounds.GetChannel()
if c == nil {
return false
}
c.sound = s.Get(gn)
return c.sound != nil
}

// ------------------------------------------------------------------
// Sound

type Sound struct {
sound   *Wave
volume  int16
loop    bool
freqmul float32
fidx    float64
}

func (s *Sound) mix() {
if s.sound == nil {
return
}
s.fidx = sys.mixer.Mix(s.sound.Wav, s.fidx,
int(s.sound.BytesPerSample), int(s.sound.Channels),
float64(s.sound.SamplesPerSec)*float64(s.freqmul), s.loop,
float32(s.volume)/256)
if int(s.fidx) >= len(s.sound.Wav)/
int(s.sound.BytesPerSample*s.sound.Channels) {
s.sound = nil
s.fidx = 0
}
}
func (s *Sound) SetVolume(vol int32) {
if vol < 0 {
s.volume = 0
} else if vol > 512 {
s.volume = 512
} else {
s.volume = int16(vol)
}
}
func (s *Sound) SetPan(pan float32, offset *float32) {
// 未実装
}

type Sounds []Sound

func newSounds(size int) (s Sounds) {
s = make(Sounds, size)
for i := range s {
s[i] = Sound{volume: 256, freqmul: 1}
}
return
}
func (s Sounds) GetChannel() *Sound {
for i := range s {
if s[i].sound == nil {
return &s[i]
}
}
return nil
}
func (s Sounds) mixSounds() {
for i := range s {
s[i].mix()
}
}

possible failures
Code:
jdoodle.go:13:2: cannot find package "github.com/faiface/beep" in any of:
/usr/lib/go/src/github.com/faiface/beep (from $GOROOT)
/root/go/src/github.com/faiface/beep (from $GOPATH)
jdoodle.go:14:2: cannot find package "github.com/faiface/beep/effects" in any of:
/usr/lib/go/src/github.com/faiface/beep/effects (from $GOROOT)
/root/go/src/github.com/faiface/beep/effects (from $GOPATH)
jdoodle.go:15:2: cannot find package "github.com/faiface/beep/flac" in any of:
/usr/lib/go/src/github.com/faiface/beep/flac (from $GOROOT)
/root/go/src/github.com/faiface/beep/flac (from $GOPATH)
jdoodle.go:16:2: cannot find package "github.com/faiface/beep/mp3" in any of:
/usr/lib/go/src/github.com/faiface/beep/mp3 (from $GOROOT)
/root/go/src/github.com/faiface/beep/mp3 (from $GOPATH)
jdoodle.go:17:2: cannot find package "github.com/faiface/beep/speaker" in any of:
/usr/lib/go/src/github.com/faiface/beep/speaker (from $GOROOT)
/root/go/src/github.com/faiface/beep/speaker (from $GOPATH)
jdoodle.go:18:2: cannot find package "github.com/faiface/beep/vorbis" in any of:
/usr/lib/go/src/github.com/faiface/beep/vorbis (from $GOROOT)
/root/go/src/github.com/faiface/beep/vorbis (from $GOPATH)
jdoodle.go:21:10: cannot find package "github.com/sqweek/fluidsynth" in any of:
/usr/lib/go/src/github.com/sqweek/fluidsynth (from $GOROOT)
/root/go/src/github.com/sqweek/fluidsynth (from $GOPATH)
jdoodle.go:11:2: cannot find package "github.com/timshannon/go-openal/openal" in any of:
/usr/lib/go/src/github.com/timshannon/go-openal/openal (from $GOROOT)
/root/go/src/github.com/timshannon/go-openal/openal (from $GOPATH)
jdoodle.go:20:9: cannot find package "github.com/x42/avldrums.lv2/tree/master/fluidsynth" in any of:
/usr/lib/go/src/github.com/x42/avldrums.lv2/tree/master/fluidsynth (from $GOROOT)
/root/go/src/github.com/x42/avldrums.lv2/tree/master/fluidsynth (from $GOPATH)
Command exited with non-zero status 1

Code:
$go run main.go
main.go:13:2: cannot find package "github.com/faiface/beep" in any of:
/usr/lib/golang/src/github.com/faiface/beep (from $GOROOT)
/home/cg/root/1773287/go/src/github.com/faiface/beep (from $GOPATH)
main.go:14:2: cannot find package "github.com/faiface/beep/effects" in any of:
/usr/lib/golang/src/github.com/faiface/beep/effects (from $GOROOT)
/home/cg/root/1773287/go/src/github.com/faiface/beep/effects (from $GOPATH)
main.go:15:2: cannot find package "github.com/faiface/beep/flac" in any of:
/usr/lib/golang/src/github.com/faiface/beep/flac (from $GOROOT)
/home/cg/root/1773287/go/src/github.com/faiface/beep/flac (from $GOPATH)
main.go:16:2: cannot find package "github.com/faiface/beep/mp3" in any of:
/usr/lib/golang/src/github.com/faiface/beep/mp3 (from $GOROOT)
/home/cg/root/1773287/go/src/github.com/faiface/beep/mp3 (from $GOPATH)
main.go:17:2: cannot find package "github.com/faiface/beep/speaker" in any of:
/usr/lib/golang/src/github.com/faiface/beep/speaker (from $GOROOT)
/home/cg/root/1773287/go/src/github.com/faiface/beep/speaker (from $GOPATH)
main.go:18:2: cannot find package "github.com/faiface/beep/vorbis" in any of:
/usr/lib/golang/src/github.com/faiface/beep/vorbis (from $GOROOT)
/home/cg/root/1773287/go/src/github.com/faiface/beep/vorbis (from $GOPATH)
main.go:21:10: cannot find package "github.com/sqweek/fluidsynth" in any of:
/usr/lib/golang/src/github.com/sqweek/fluidsynth (from $GOROOT)
/home/cg/root/1773287/go/src/github.com/sqweek/fluidsynth (from $GOPATH)
main.go:11:2: cannot find package "github.com/timshannon/go-openal/openal" in any of:
/usr/lib/golang/src/github.com/timshannon/go-openal/openal (from $GOROOT)
/home/cg/root/1773287/go/src/github.com/timshannon/go-openal/openal (from $GOPATH)
main.go:20:9: cannot find package "github.com/x42/avldrums.lv2/tree/master/fluidsynth" in any of:
/usr/lib/golang/src/github.com/x42/avldrums.lv2/tree/master/fluidsynth (from $GOROOT)
/home/cg/root/1773287/go/src/github.com/x42
Last Edit: July 14, 2019, 04:03:59 am by Mike77154
Re: Ikemen GO Plus
#1100  July 14, 2019, 04:09:43 am
  • **
  • The need situation makes the man
    • Mexico
    • www.facebook.com/mike.funkyman
Sorry four doubleposting, but is the only thing can I do, for keep the order on my posts without failures

So Here is the Suggestion for Adding Fluidsynth and Midi compatibility for Ikemen Go

Main.go revisited
Code:
package main
// #include <stdio.h>
// #include <fluidsynth.h>
import (
        "C"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"regexp"
"runtime"
"strconv"
"strings"
        "path/filepath"

"github.com/go-gl/glfw/v3.2/glfw"
"github.com/yuin/gopher-lua"
        "github.com/x42/avldrums.lv2/tree/master/fluidsynth"
)

func init() {
runtime.LockOSThread()
}
func chk(err error) {
if err != nil {
panic(err)
}
}
func createLog(p string) *os.File {
//fmt.Println("Creating log")
f, err := os.Create(p)
if err != nil {
panic(err)
}
return f
}
func closeLog(f *os.File) {
//fmt.Println("Closing log")
f.Close()
}
func (s *Synth) SFLoad(path string, resetPresets bool) int {
cpath := C.CString(path)
defer C.free(unsafe.Pointer(cpath))
creset := C.int(1)
if !resetPresets {
creset = 0
}
cfont_id, _ := C.fluid_synth_sfload("data/gamesoundfont.sf2")
creset := cbool(resetPresets)
cfont_id, _ := C.fluid_synth_sfload("data/gamesoundfont.sf2")
return int(cfont_id)
}
func main() {
if len(os.Args[1:]) > 0 {
sys.cmdFlags = make(map[string]string)
key := ""
player := 1
for _, a := range os.Args[1:] {
match, _ := regexp.MatchString("^-", a)
if match {
help, _ := regexp.MatchString("^-[h%?]", a)
if help {
fmt.Println("I.K.E.M.E.N\nOptions (case sensitive):")
fmt.Println(" -h -?               Help")
fmt.Println(" -log <logfile>      Records match data to <logfile>")
fmt.Println(" -r <sysfile>        Loads motif <sysfile>. eg. -r motifdir or -r motifdir/system.def")
fmt.Println("\nQuick VS Options:")
fmt.Println(" -p<n> <playername>  Loads player n, eg. -p3 kfm")
fmt.Println(" -p<n>.ai <level>    Set player n's AI to <level>, eg. -p1.ai 8")
fmt.Println(" -p<n>.color <col>   Set player n's color to <col>")
fmt.Println(" -p<n>.life <life>   Sets player n's life to <life>")
fmt.Println(" -p<n>.power <power> Sets player n's power to <power>")
fmt.Println(" -rounds <num>       Plays for <num> rounds, and then quits")
fmt.Println(" -s <stagename>      Loads stage <stagename>")
fmt.Println("\nPress ENTER to exit.")
var s string
fmt.Scanln(&s)
os.Exit(0)
}
sys.cmdFlags[a] = ""
key = a
} else if key == "" {
sys.cmdFlags[fmt.Sprintf("-p%v", player)] = a
player += 1
} else {
sys.cmdFlags[key] = a
key = ""
}
}
}
chk(glfw.Init())
defer glfw.Terminate()
defcfg := []byte(strings.Join(strings.Split(`{
  "HelperMax":56,
  "PlayerProjectileMax":256,
  "ExplodMax":512,
  "AfterImageMax":128,
  "MasterVolume":80,
  "WavVolume":80,
  "BgmVolume":80,
  "Attack.LifeToPowerMul":0.7,
  "GetHit.LifeToPowerMul":0.6,
  "Width":640,
  "Height":480,
  "Super.TargetDefenceMul":1.5,
  "LifebarFontScale":1,
  "System":"script/main.lua",
  "KeyConfig":[{
      "Joystick":-1,
      "Buttons":["UP","DOWN","LEFT","RIGHT","z","x","c","a","s","d","RETURN","q","w"]
    },{
      "Joystick":-1,
      "Buttons":["t","g","f","h","j","k","l","u","i","o","RSHIFT","LEFTBRACKET","RIGHTBRACKET"]
    }],
  "JoystickConfig":[{
      "Joystick":0,
      "Buttons":["-7","-8","-5","-6","0","1","4","2","3","5","7","6","8"]
    },{
      "Joystick":1,
      "Buttons":["-7","-8","-5","-6","0","1","4","2","3","5","7","6","8"]
    }],
  "Motif":"data/system.def",
  "CommonAir":"data/common.air",
  "CommonCmd":"data/common.cmd",
  "SFLoad":"data/gamesoundfont.sf2"
  "SimulMode":true,
  "LifeMul":100,
  "Team1VS2Life":120,
  "TurnsRecoveryRate":300,
  "ZoomActive":false,
  "ZoomMin":0.75,
  "ZoomMax":1.1,
  "ZoomSpeed":1,
  "RoundTime":99,
  "NumTurns":4,
  "NumSimul":4,
  "NumTag":4,
  "Difficulty":8,
  "Credits":10,
  "ListenPort":7500,
  "ContSelection":true,
  "AIRandomColor":true,
  "AIRamping":true,
  "AutoGuard":false,
  "TeamPowerShare":false,
  "TeamLifeShare":false,
  "Fullscreen":false,
  "AudioDucking":false,
  "QuickLaunch":0,
  "AllowDebugKeys":true,
  "PostProcessingShader": 0,
  "LocalcoordScalingType": 1,
  "IP":{
  }
}
`, "\n"), "\r\n"))
tmp := struct {
HelperMax              int32
PlayerProjectileMax    int
ExplodMax              int
AfterImageMax          int32
MasterVolume           int
WavVolume              int
BgmVolume              int
Attack_LifeToPowerMul  float32 `json:"Attack.LifeToPowerMul"`
GetHit_LifeToPowerMul  float32 `json:"GetHit.LifeToPowerMul"`
Width                  int32
Height                 int32
Super_TargetDefenceMul float32 `json:"Super.TargetDefenceMul"`
LifebarFontScale       float32
System                 string
KeyConfig              []struct {
Joystick int
Buttons  []interface{}
}
JoystickConfig []struct {
Joystick int
Buttons  []interface{}
}
NumTag                int
TeamLifeShare         bool
AIRandomColor         bool
Fullscreen            bool
AudioDucking          bool
AllowDebugKeys        bool
PostProcessingShader  int32
LocalcoordScalingType int32
CommonAir             string
CommonCmd             string
QuickLaunch           int
}{}
chk(json.Unmarshal(defcfg, &tmp))
const configFile = "data/config.json"
if bytes, err := ioutil.ReadFile(configFile); err != nil {
f, err := os.Create(configFile)
chk(err)
f.Write(defcfg)
chk(f.Close())
} else {
if len(bytes) >= 3 &&
bytes[0] == 0xef && bytes[1] == 0xbb && bytes[2] == 0xbf {
bytes = bytes[3:]
}
chk(json.Unmarshal(bytes, &tmp))
}
sys.helperMax = tmp.HelperMax
sys.playerProjectileMax = tmp.PlayerProjectileMax
sys.explodMax = tmp.ExplodMax
sys.afterImageMax = tmp.AfterImageMax
sys.attack_LifeToPowerMul = tmp.Attack_LifeToPowerMul
sys.getHit_LifeToPowerMul = tmp.GetHit_LifeToPowerMul
sys.super_TargetDefenceMul = tmp.Super_TargetDefenceMul
sys.lifebarFontScale = tmp.LifebarFontScale
sys.quickLaunch = tmp.QuickLaunch
sys.masterVolume = tmp.MasterVolume
sys.wavVolume = tmp.WavVolume
sys.bgmVolume = tmp.BgmVolume
sys.AudioDucking = tmp.AudioDucking
stoki := func(key string) int {
return int(StringToKey(key))
}
Atoi := func(key string) int {
var i int
i, _ = strconv.Atoi(key)
return i
}
for a := 0; a < tmp.NumTag; a++ {
for _, kc := range tmp.KeyConfig {
b := kc.Buttons
if kc.Joystick < 0 {
sys.keyConfig = append(sys.keyConfig, KeyConfig{kc.Joystick,
stoki(b[0].(string)), stoki(b[1].(string)),
stoki(b[2].(string)), stoki(b[3].(string)),
stoki(b[4].(string)), stoki(b[5].(string)), stoki(b[6].(string)),
stoki(b[7].(string)), stoki(b[8].(string)), stoki(b[9].(string)),
stoki(b[10].(string)), stoki(b[11].(string)), stoki(b[12].(string))})
}
}
for _, jc := range tmp.JoystickConfig {
b := jc.Buttons
if jc.Joystick >= 0 {
sys.JoystickConfig = append(sys.JoystickConfig, KeyConfig{jc.Joystick,
Atoi(b[0].(string)), Atoi(b[1].(string)),
Atoi(b[2].(string)), Atoi(b[3].(string)),
Atoi(b[4].(string)), Atoi(b[5].(string)), Atoi(b[6].(string)),
Atoi(b[7].(string)), Atoi(b[8].(string)), Atoi(b[9].(string)),
Atoi(b[10].(string)), Atoi(b[11].(string)), Atoi(b[12].(string))})
}
}
}
sys.teamLifeShare = tmp.TeamLifeShare
sys.fullscreen = tmp.Fullscreen
sys.PostProcessingShader = tmp.PostProcessingShader
sys.LocalcoordScalingType = tmp.LocalcoordScalingType
sys.aiRandomColor = tmp.AIRandomColor
sys.allowDebugKeys = tmp.AllowDebugKeys
air, err := ioutil.ReadFile(tmp.CommonAir)
if err != nil {
fmt.Print(err)
}
sys.commonAir = string("\n") + string(air)
cmd, err := ioutil.ReadFile(tmp.CommonCmd)
if err != nil {
fmt.Print(err)
}
sys.commonCmd = string("\n") + string(cmd)
//os.Mkdir("debug", os.ModeSticky|0755)
log := createLog("Ikemen.txt")
defer closeLog(log)
l := sys.init(tmp.Width, tmp.Height)
if err := l.DoFile(tmp.System); err != nil {
fmt.Fprintln(log, err)
switch err.(type) {
case *lua.ApiError:
errstr := strings.Split(err.Error(), "\n")[0]
if len(errstr) < 10 || errstr[len(errstr)-10:] != "<game end>" {
panic(err)
}
default:
panic(err)
}
}
if !sys.gameEnd {
sys.gameEnd = true
}
<-sys.audioClose


Sound.go revisited

Code:
package main

// #include <stdio.h>
// #include <fluidsynth.h>
import (
        "C"
"encoding/binary"
"fmt"
"math"
"os"
"path/filepath"

"github.com/timshannon/go-openal/openal"

"github.com/faiface/beep"
"github.com/faiface/beep/effects"
"github.com/faiface/beep/flac"
"github.com/faiface/beep/mp3"
"github.com/faiface/beep/speaker"
"github.com/faiface/beep/vorbis"

        "github.com/x42/avldrums.lv2/tree/master/fluidsynth"
         "github.com/sqweek/fluidsynth"
)

const (
audioOutLen    = 2048
audioFrequency = 48000
)

// ------------------------------------------------------------------
// Audio Source

// AudioSource structure.
// It contains OpenAl's sound destination and buffer
type AudioSource struct {
Src  openal.Source
bufs openal.Buffers
}

func NewAudioSource() (s *AudioSource) {
s = &AudioSource{Src: openal.NewSource(), bufs: openal.NewBuffers(2)}
for i := range s.bufs {
s.bufs[i].SetDataInt16(openal.FormatStereo16, sys.nullSndBuf[:],
audioFrequency)
}
s.Src.QueueBuffers(s.bufs)
if err := openal.Err(); err != nil {
println(err.Error())
}
return
}
func (s *AudioSource) Delete() {
for s.Src.BuffersQueued() > 0 {
s.Src.UnqueueBuffer()
}
s.bufs.Delete()
s.Src.Delete()
}

// ------------------------------------------------------------------
//MIDI HANDLING (FLUIDSYNTH)
type AudioDriver struct {
ptr *C.fluid_audio_driver_t
}

func NewAudioDriver(settings Settings, synth Synth) AudioDriver {
return AudioDriver{C.new_fluid_audio_driver(settings.ptr, synth.ptr)}
}

func (d *AudioDriver) Delete() {
C.delete_fluid_audio_driver(d.ptr)
}


type FileRenderer struct {
ptr *C.fluid_file_renderer_t
}

func NewFileRenderer(synth Synth) FileRenderer {
return FileRenderer{C.new_fluid_file_renderer(synth.ptr)}
}

func (r *FileRenderer) Delete() {
C.delete_fluid_file_renderer(r.ptr)
}

func (r *FileRenderer) ProcessBlock() bool {
return C.fluid_file_renderer_process_block(r.ptr) == C.FLUID_OK
}

func NewSettings() Settings {
if settingNames == nil {
settingNames = make(map[string]*C.char)
}
nSettings++
return Settings{ptr: C.new_fluid_settings()}
}

func (s *Settings) Delete() {
nSettings--
if nSettings == 0 {
settingNames = nil
}
C.delete_fluid_settings(s.ptr)
}

func cname(name string) *C.char {
if cname, ok := settingNames[name]; ok {
return cname
}
cname := C.CString(name)
settingNames[name] = cname
return cname
}

/* IsRealtime returns true if changing the specified setting immediately affects an associated Synth */
func (s *Settings) IsRealtime(name string) bool {
return C.fluid_settings_is_realtime(s.ptr, cname(name)) == 1
}

func (s *Settings) SetInt(name string, val int) bool {
return C.fluid_settings_setint(s.ptr, cname(name), C.int(val)) == 1
}

func (s *Settings) SetNum(name string, val float64) bool {
return C.fluid_settings_setnum(s.ptr, cname(name), C.double(val)) == 1
}

func (s *Settings) SetString(name, val string) bool {
cval := C.CString(val)
defer C.free(unsafe.Pointer(cval))
return C.fluid_settings_setstr(s.ptr, cname(name), cval) == 1

}

func (s *Settings) GetInt(name string, val *int) bool {
return C.fluid_settings_getint(s.ptr, cname(name), (*C.int)(unsafe.Pointer(val))) == 1
}

func (s *Settings) GetNum(name string, val *float64) bool {
return C.fluid_settings_getnum(s.ptr, cname(name), (*C.double)(unsafe.Pointer(val))) == 1
}

func (s *Settings) GetString(name string, val *string) bool {
var cstr *C.char
ok := (C.fluid_settings_getstr(s.ptr, cname(name), &cstr) == 1)
if ok {
*val = C.GoString(cstr)
}
return ok
}

type Synth struct {
ptr *C.fluid_synth_t
}

func cbool(b bool) C.int {
if b {
return 1
}
return 0
}

func NewSynth(settings Settings) Synth {
return Synth{C.new_fluid_synth(settings.ptr)}
}

func (s *Synth) Delete() {
C.delete_fluid_synth(s.ptr)
}
func (s *Synth) NoteOn(channel, note, velocity uint8) {
C.fluid_synth_noteon(s.ptr, C.int(channel), C.int(note), C.int(velocity))
}

func (s *Synth) NoteOff(channel, note uint8) {
C.fluid_synth_noteoff(s.ptr, C.int(channel), C.int(note))
}

func (s *Synth) ProgramChange(channel, program uint8) {
C.fluid_synth_program_change(s.ptr, C.int(channel), C.int(program))
}

/* WriteS16 synthesizes signed 16-bit samples. It will fill as much of the provided
slices as it can without overflowing 'left' or 'right'. For interleaved stereo, have both
'left' and 'right' share a backing array and use lstride = rstride = 2. ie:
    synth.WriteS16(samples, samples[1:], 2, 2)
*/
func (s *Synth) WriteS16(left, right []int16, lstride, rstride int) {
nframes := (len(left) + lstride - 1) / lstride
rframes := (len(right) + rstride - 1) / rstride
if rframes < nframes {
nframes = rframes
}
C.fluid_synth_write_s16(s.ptr, C.int(nframes), unsafe.Pointer(&left[0]), 0, C.int(lstride), unsafe.Pointer(&right[0]), 0, C.int(rstride))
}

func (s *Synth) WriteFloat(left, right []float32, lstride, rstride int) {
nframes := (len(left) + lstride - 1) / lstride
rframes := (len(right) + rstride - 1) / rstride
if rframes < nframes {
nframes = rframes
}
C.fluid_synth_write_float(s.ptr, C.int(nframes), unsafe.Pointer(&left[0]), 0, C.int(lstride), unsafe.Pointer(&right[0]), 0, C.int(rstride))
}

type TuningId struct {
Bank, Program uint8
}

/* ActivateKeyTuning creates/modifies a specific tuning bank/program */
func (s *Synth) ActivateKeyTuning(id TuningId, name string, tuning [128]float64, apply bool) {
n := C.CString(name)
defer C.free(unsafe.Pointer(n))
C.fluid_synth_activate_key_tuning(s.ptr, C.int(id.Bank), C.int(id.Program), n, (*C.double)(&tuning[0]), cbool(apply))
}

/* ActivateTuning switches a midi channel onto the specified tuning bank/program */
func (s *Synth) ActivateTuning(channel uint8, id TuningId, apply bool) {
C.fluid_synth_activate_tuning(s.ptr, C.int(channel), C.int(id.Bank), C.int(id.Program), cbool(apply))
}
// ------------------------------------------------------------------
// Mixer

type Mixer struct {
buf        [audioOutLen * 2]float32
sendBuf    []int16
out        chan []int16
normalizer *Normalizer
}

func newMixer() *Mixer {
return &Mixer{out: make(chan []int16, 1), normalizer: NewNormalizer()}
}
func (m *Mixer) bufClear() {
for i := range m.buf {
m.buf[i] = 0
}
}
func (m *Mixer) write() bool {
if m.sendBuf == nil {
m.sendBuf = make([]int16, len(m.buf))
for i := 0; i <= len(m.sendBuf)-2; i += 2 {
l, r := m.normalizer.Process(m.buf[i], m.buf[i+1])
m.sendBuf[i] = int16(32767 * l)
m.sendBuf[i+1] = int16(32767 * r)
}
}
select {
case m.out <- m.sendBuf:
default:
return false
}
m.sendBuf = nil
m.bufClear()
return true
}
func (m *Mixer) Mix(wav []byte, fidx float64, bytesPerSample, channels int,
sampleRate float64, loop bool, volume float32) float64 {
fidxadd := sampleRate / audioFrequency
if fidxadd > 0 {
switch bytesPerSample {
case 1:
switch channels {
case 1:
for i := 0; i <= len(m.buf)-2; i += 2 {
iidx := int(fidx)
if iidx >= len(wav) {
if !loop {
break
}
iidx, fidx = 0, 0
}
sam := volume * (float32(wav[iidx]) - 128) / 128
m.buf[i] += sam
m.buf[i+1] += sam
fidx += fidxadd
}
return fidx
case 2:
for i := 0; i <= len(m.buf)-2; i += 2 {
iidx := 2 * int(fidx)
if iidx > len(wav)-2 {
if !loop {
break
}
iidx, fidx = 0, 0
}
m.buf[i] += volume * (float32(wav[iidx]) - 128) / 128
m.buf[i+1] += volume * (float32(wav[iidx+1]) - 128) / 128
fidx += fidxadd
}
return fidx
}
case 2:
switch channels {
case 1:
for i := 0; i <= len(m.buf)-2; i += 2 {
iidx := 2 * int(fidx)
if iidx > len(wav)-2 {
if !loop {
break
}
iidx, fidx = 0, 0
}
sam := volume *
float32(int(wav[iidx])|int(int8(wav[iidx+1]))<<8) / (1 << 15)
m.buf[i] += sam
m.buf[i+1] += sam
fidx += fidxadd
}
return fidx
case 2:
for i := 0; i <= len(m.buf)-2; i += 2 {
iidx := 4 * int(fidx)
if iidx > len(wav)-4 {
if !loop {
break
}
iidx, fidx = 0, 0
}
m.buf[i] += volume *
float32(int(wav[iidx])|int(int8(wav[iidx+1]))<<8) / (1 << 15)
m.buf[i+1] += volume *
float32(int(wav[iidx+2])|int(int8(wav[iidx+3]))<<8) / (1 << 15)
fidx += fidxadd
}
return fidx
}
}
}
return float64(len(wav))
}

// ------------------------------------------------------------------
// Normalizer

type Normalizer struct {
mul  float64
l, r *NormalizerLR
}

func NewNormalizer() *Normalizer {
return &Normalizer{mul: 4, l: &NormalizerLR{1, 0, 1, 1 / 32.0, 0, 0},
r: &NormalizerLR{1, 0, 1, 1 / 32.0, 0, 0}}
}
func (n *Normalizer) Process(l, r float32) (float32, float32) {
lmul := n.l.process(n.mul, &l)
rmul := n.r.process(n.mul, &r)
if sys.AudioDucking {
if lmul < rmul {
n.mul = lmul
} else {
n.mul = rmul
}
if n.mul > 16 {
n.mul = 16
}
} else {
n.mul = 0.5 * (float64(sys.wavVolume) * float64(sys.masterVolume) * 0.0001)
}
return l, r
}

type NormalizerLR struct {
heri, herihenka, fue, heikin, katayori, katayori2 float64
}

func (n *NormalizerLR) process(bai float64, sam *float32) float64 {
n.katayori = (n.katayori*audioFrequency/110 + float64(*sam)) /
(audioFrequency/110.0 + 1)
n.katayori2 = (n.katayori2*audioFrequency/112640 + float64(*sam)) /
(audioFrequency/112640.0 + 1)
s := (n.katayori2 - n.katayori) * bai
if math.Abs(s) > 1 {
bai *= math.Pow(1/math.Abs(s), n.heri)
n.herihenka += 32 * (1 - n.heri) / float64(audioFrequency+32)
if s < 0 {
s = -1
} else {
s = 1
}
} else {
tmp := (1 - math.Pow(1-math.Abs(s), 64)) * math.Pow(0.5-math.Abs(s), 3)
bai += bai * (n.heri*(1/32.0-n.heikin)/n.fue + tmp*n.fue*(1-n.heri)/32) /
(audioFrequency*2/8.0 + 1)
n.herihenka -= (0.5 - n.heikin) * n.heri / (audioFrequency * 2)
}
n.fue += (32*n.fue*(1/n.fue-math.Abs(s)) - n.fue) /
(32 * audioFrequency * 2)
n.heikin += (math.Abs(s) - n.heikin) / (audioFrequency * 2)
n.heri += n.herihenka
if n.heri < 0 {
n.heri = 0
} else if n.heri > 0 {
n.heri = 1
}
*sam = float32(s)
return bai
}

// ------------------------------------------------------------------
// Bgm

type Bgm struct {
filename string
ctrl     *beep.Ctrl
}

func newBgm() *Bgm {
return &Bgm{}
}

func (bgm *Bgm) IsVorbis() bool {
return bgm.IsFormat(".ogg")
}

func (bgm *Bgm) IsMp3() bool {
return bgm.IsFormat(".mp3")
}

func (bgm *Bgm) IsFLAC() bool {
return bgm.IsFormat(".flac")
}
func (bgm *Bgm) IsMIDI() bool {
return bgm.IsFormat(".mid")
}


func (bgm *Bgm) IsFormat(extension string) bool {
return filepath.Ext(bgm.filename) == extension
}

func (bgm *Bgm) Open(filename string) {

if filepath.Base(bgm.filename) == filepath.Base(filename) {
return
}

bgm.filename = filename
speaker.Clear()

if bgm.IsVorbis() {
bgm.ReadVorbis()
} else if bgm.IsMp3() {
bgm.ReadMp3()
} else if bgm.IsFLAC() {
bgm.ReadFLAC()
}else if bgm.IsMIDI() {
                C.new_fluid_player()
bgm.ReadMIDI()
                C.fluid_player_play()
}
}

func (bgm *Bgm) ReadMp3() {
f, _ := os.Open(bgm.filename)
s, format, err := mp3.Decode(f)
if err != nil {
return
}
bgm.ReadFormat(s, format)
}

func (bgm *Bgm) ReadFLAC() {
f, _ := os.Open(bgm.filename)
s, format, err := flac.Decode(f)
if err != nil {
return
}
bgm.ReadFormat(s, format)
}

func (bgm *Bgm) ReadVorbis() {
f, _ := os.Open(bgm.filename)
s, format, err := vorbis.Decode(f)
if err != nil {
return
}
bgm.ReadFormat(s, format)
}
func (bgm *Bgm) ReadMIDI() {
f, _ := os.Open(bgm.filename)
s, format, err := C.fluid_player_play(f)
if err != nil {
return
}
bgm.ReadFormat(s, format)
}

func (bgm *Bgm) ReadFormat(s beep.StreamSeekCloser, format beep.Format) {
streamer := beep.Loop(-1, s)
volume := -5 + float64(sys.bgmVolume)*0.06*(float64(sys.masterVolume)/100)
streamer = &effects.Volume{Streamer: streamer, Base: 2, Volume: volume, Silent: volume <= -5}
resample := beep.Resample(int(3), format.SampleRate, beep.SampleRate(Mp3SampleRate), streamer)
bgm.ctrl = &beep.Ctrl{Streamer: resample}
speaker.Play(bgm.ctrl)
}

func (bgm *Bgm) Pause() {
speaker.Lock()
bgm.ctrl.Paused = true
speaker.Unlock()
return
}

// ------------------------------------------------------------------
// Wave

type Wave struct {
SamplesPerSec  uint32
Channels       uint16
BytesPerSample uint16
Wav            []byte
}

func ReadWave(f *os.File, ofs int64) (*Wave, error) {
buf := make([]byte, 4)
n, err := f.Read(buf)
if err != nil {
return nil, err
}
if string(buf[:n]) != "RIFF" {
return nil, Error("RIFFではありません")
}
read := func(x interface{}) error {
return binary.Read(f, binary.LittleEndian, x)
}
var riffSize uint32
if err := read(&riffSize); err != nil {
return nil, err
}
riffSize += 8
if n, err = f.Read(buf); err != nil {
return nil, err
}
if string(buf[:n]) != "WAVE" {
return &Wave{SamplesPerSec: 11025, Channels: 1, BytesPerSample: 1}, nil
}
fmtSize, dataSize := uint32(0), uint32(0)
w := Wave{}
riffend := ofs + 16 + int64(riffSize)
ofs += 28
for (fmtSize == 0 || dataSize == 0) && ofs < riffend {
if n, err = f.Read(buf); err != nil {
return nil, err
}
var size uint32
if err := read(&size); err != nil {
return nil, err
}
switch string(buf[:n]) {
case "fmt ":
fmtSize = size
var fmtID uint16
if err := read(&fmtID); err != nil {
return nil, err
}
if fmtID != 1 {
return nil, Error("リニアPCMではありません")
}
if err := read(&w.Channels); err != nil {
return nil, err
}
if w.Channels < 1 || w.Channels > 2 {
return nil, Error("チャンネル数が不正です")
}
if err := read(&w.SamplesPerSec); err != nil {
return nil, err
}
if w.SamplesPerSec < 1 || w.SamplesPerSec >= 0xfffff {
return nil, Error(fmt.Sprintf("周波数が不正です %d", w.SamplesPerSec))
}
var musi uint32
if err := read(&musi); err != nil {
return nil, err
}
var mushi uint16
if err := read(&mushi); err != nil {
return nil, err
}
if err := read(&w.BytesPerSample); err != nil {
return nil, err
}
if w.BytesPerSample != 8 && w.BytesPerSample != 16 {
return nil, Error("bit数が不正です")
}
w.BytesPerSample >>= 3
case "data":
dataSize = size
w.Wav = make([]byte, dataSize)
if err := binary.Read(f, binary.LittleEndian, w.Wav); err != nil {
return nil, err
}
}
ofs += int64(size) + 8
f.Seek(ofs, 0)
}
if fmtSize == 0 {
if dataSize > 0 {
return nil, Error("fmt がありません")
}
return nil, nil
}
return &w, nil
}

// ------------------------------------------------------------------
// Snd

type Snd struct {
table     map[[2]int32]*Wave
ver, ver2 uint16
}

func newSnd() *Snd {
return &Snd{table: make(map[[2]int32]*Wave)}
}

func LoadSnd(filename string) (*Snd, error) {
s := newSnd()
f, err := os.Open(filename)
if err != nil {
return nil, err
}
defer func() { chk(f.Close()) }()
buf := make([]byte, 12)
var n int
if n, err = f.Read(buf); err != nil {
return nil, err
}
if string(buf[:n]) != "ElecbyteSnd\x00" {
return nil, Error("ElecbyteSndではありません")
}
read := func(x interface{}) error {
return binary.Read(f, binary.LittleEndian, x)
}
if err := read(&s.ver); err != nil {
return nil, err
}
if err := read(&s.ver2); err != nil {
return nil, err
}
var numberOfSounds uint32
if err := read(&numberOfSounds); err != nil {
return nil, err
}
var subHeaderOffset uint32
if err := read(&subHeaderOffset); err != nil {
return nil, err
}
for i := uint32(0); i < numberOfSounds; i++ {
f.Seek(int64(subHeaderOffset), 0)
var nextSubHeaderOffset uint32
if err := read(&nextSubHeaderOffset); err != nil {
return nil, err
}
var subFileLenght uint32
if err := read(&subFileLenght); err != nil {
return nil, err
}
var num [2]int32
if err := read(&num); err != nil {
return nil, err
}
if num[0] >= 0 && num[1] >= 0 {
_, ok := s.table[num]
if !ok {
tmp, err := ReadWave(f, int64(subHeaderOffset))
if err != nil {
return nil, err
}
s.table[num] = tmp
}
}
subHeaderOffset = nextSubHeaderOffset
}
return s, nil
}
func (s *Snd) Get(gn [2]int32) *Wave {
return s.table[gn]
}
func (s *Snd) play(gn [2]int32) bool {
c := sys.sounds.GetChannel()
if c == nil {
return false
}
c.sound = s.Get(gn)
return c.sound != nil
}

// ------------------------------------------------------------------
// Sound

type Sound struct {
sound   *Wave
volume  int16
loop    bool
freqmul float32
fidx    float64
}

func (s *Sound) mix() {
if s.sound == nil {
return
}
s.fidx = sys.mixer.Mix(s.sound.Wav, s.fidx,
int(s.sound.BytesPerSample), int(s.sound.Channels),
float64(s.sound.SamplesPerSec)*float64(s.freqmul), s.loop,
float32(s.volume)/256)
if int(s.fidx) >= len(s.sound.Wav)/
int(s.sound.BytesPerSample*s.sound.Channels) {
s.sound = nil
s.fidx = 0
}
}
func (s *Sound) SetVolume(vol int32) {
if vol < 0 {
s.volume = 0
} else if vol > 512 {
s.volume = 512
} else {
s.volume = int16(vol)
}
}
func (s *Sound) SetPan(pan float32, offset *float32) {
// 未実装
}

type Sounds []Sound

func newSounds(size int) (s Sounds) {
s = make(Sounds, size)
for i := range s {
s[i] = Sound{volume: 256, freqmul: 1}
}
return
}
func (s Sounds) GetChannel() *Sound {
for i := range s {
if s[i].sound == nil {
return &s[i]
}
}
return nil
}
func (s Sounds) mixSounds() {
for i := range s {
s[i].mix()
}
}


So, feel free to modify my commits, or correct the synthax, remember is only a suggestion
Last Edit: July 14, 2019, 04:32:14 am by Mike77154