pcca-matrix / PCCA-Layout

HyperSpin layout for Attract-Mode
GNU General Public License v3.0
7 stars 6 forks source link

Wheel sound being cut #13

Closed ghost closed 4 years ago

ghost commented 4 years ago

I already mentioned this issue in our discord discussions but this is now the place to report bugs. So, when navigating the wheel quickly, the random wheel sounds cut each other. I encountered a similar problem when developing my own themes and here was the solution, for you consideration:

/////////////////////////////////////////////////////////////////////////////////
// Play sound when transitioning to next / previous game on wheel
//
// In order to rapidly play many random sounds without memory leak (calling fe.add_sound() within transition_callback function),
// we are using a relatively large array that each of its members play a sound in its own turn.
// A small array results in sounds being cut by each other since there is not enough "time" for 
// each member to complete the sound playing.
local random_num;
local sound_name="";
local Wheelclick = [];
local i;
for (i=0; i<20; i++)
    Wheelclick.push(fe.add_sound(sound_name));

local sid = 0;

function sound_transitions(ttype, var, ttime) 
{
    if (my_config["enable_random_sound"] != "No")
    {       
        if (my_config["enable_random_sound"] == "Random")
        {
            random_num = floor(((rand() % 1000 ) / 1000.0) * (322 - (1 - 1)) + 1);
            sound_name = FeConfigDirectory+"sounds/GS"+random_num+".mp3";
        }

        if (my_config["enable_random_sound"] == "Click")
            sound_name = FeConfigDirectory+"sounds/click.mp3";

        if (my_config["enable_random_sound"] == "Arcade Joystick")
            sound_name = "joystick.mp3";

        switch(ttype) 
        {
        case Transition.StartLayout:        
        case Transition.EndNavigation:  
            sid++; // next cell in the array
            if (sid > 19) //if reached end of the array go to the beginning
                sid = 0;
            Wheelclick[sid].file_name = sound_name;
            Wheelclick[sid].playing = true;
        break;
        }
    }
    return false;
}
fe.add_transition_callback("sound_transitions");
pcca-matrix commented 4 years ago

I haven't had time to test yet, for the moment it is exactly like hyperspin, but we can modify/improve this part, I would look for that later

ghost commented 4 years ago

I made a video so you can hear it. The first one is a vanilla unzip of HS 1.5.1 - untouched, first launch. The second one is AM with pcca latest release. It is easy to hear the difference - especially pay attention to the longer sounds like "Haaaadukin" how it is cut short in our current version.

The video is unlisted of course: https://youtu.be/83azCwPUepI

pcca-matrix commented 4 years ago

right !

ghost commented 4 years ago

Resolved!