예제 #1
0
        /// <summary>
        /// Initialization method.
        /// </summary>
        /// <param name="handle">Main window handle. Required for the BASS library initialization.</param>
        public static void Init(IntPtr handle)
        {
            // BASS library initialization.
            // -1 is the default audio device.
            // 48000 is the sample rate.
            // The "handle" is the main window's handle to bind the audio device to (for Windows Audio Mixer).
            Bass.BASS_Init(-1, 48000, BASSInit.BASS_DEVICE_DEFAULT, handle);

            // Directory setup.
            dir[TYPE.BGM] = "bgm";
            dir[TYPE.BGS] = "bgs";
            dir[TYPE.ME]  = "me";
            dir[TYPE.VO]  = "vo";
            dir[TYPE.SE]  = "se";

            foreach (TYPE type in Enum.GetValues(typeof(TYPE)))
            {
                try {
                    foreach (string filename in Directory.GetFiles(dir[type]))
                    {
                        // Enable looping for BGMs and BGSs.
                        bool looping = ((type == TYPE.BGM) || (type == TYPE.BGS));

                        // Give several channels to SEs.
                        int channels = (type == TYPE.SE)? 10: 1;

                        if (!audio.ContainsKey(type))
                        {
                            audio[type] = new Dictionary <string, AudioSample>();
                        }
                        audio[type][Negolib.MakeKey(filename)] = new AudioSample(filename, looping, channels);
                    }
                } catch (DirectoryNotFoundException) {
                    Directory.CreateDirectory(dir[type]);
                }

                volume[type] = 1;
            }

            VolumeMaster = 1;
        }
예제 #2
0
 /// <summary>
 /// Rereads the script's directory structure.
 /// </summary>
 void UpdateScriptsDirectory()
 {
     scripts_list.Items.Clear();
     try {
         foreach (string file in Directory.GetFiles(SCRIPTS_DIR))
         {
             if (Negolib.GetExtension(file) == SCRIPT_EXT)
             {
                 scripts_list.Items.Add(Negolib.MakeKey(file));
             }
         }
     } catch (DirectoryNotFoundException) {
         Directory.CreateDirectory(SCRIPTS_DIR);
         var main = File.Create(MakeScriptName(MAIN_SCRIPT));
         main.Close();
         UpdateScriptsDirectory();
     }
     if (scripts_list.SelectedItem == null)
     {
         scripts_list.SelectedIndex = 0;
     }
 }
예제 #3
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="filename">Sample filename.</param>
        /// <param name="_looped">Looping flag.</param>
        /// <param name="channels_max">Maximum channels that this sample can use.</param>
        public AudioSample(string filename, bool _looped = false, int channels_max = 1)
        {
            // Sample loading.
            // First 0 is the starting point.
            // Second 0 is the length (meaning the whole file).
            handle = Bass.BASS_SampleLoad(filename, 0, 0, channels_max, BASSFlag.BASS_DEFAULT);

            // Looping fields initialization.
            // Cannot be moved out of constructor due to "readonly" data modifier.
            looped     = _looped;
            loop_start = -1;
            loop_end   = Double.PositiveInfinity;
            if (looped)
            {
                // Extracting loop timepoints from the tags.
                TAG_INFO tag  = BassTags.BASS_TAG_GetFromFile(filename);
                string   test = tag.NativeTag("loop_start");
                if (test != null)
                {
                    loop_start = Negolib.StringToDouble(test);
                    loop_end   = Negolib.StringToDouble(tag.NativeTag("loop_end"));
                }
            }
        }