Exemple #1
0
        public static IT.Sample sample_to_brr(IT.Sample sample, int sample_id, string song_name)
        {
            sample.trim();
            sample.expand_ping_loop();

            if (sample.length % 16 != 0 || sample.loop_start % 16 != 0)
            {
                sample = config.resampler.resample(sample, sample.length);                      // Attempt to resample it to same length;
            }
            // resampler will figure out how to achieve
            // nearest multiple of 16 loops/length

            string wav_file = G.TEMP_PATH + sample_id.ToString().PadLeft(2, '0') + ".wav";
            string brr_file = G.TEMP_PATH + sample_id.ToString().PadLeft(2, '0') + ".brr";
            string out_file = G.AMK_SAMPLES_PATH + song_name + "/" + sample_id.ToString().PadLeft(2, '0') + " " + format_filename(sample.name) + ".brr";

            sample.save_to_file(wav_file);
            show_verbose("Converting sample {0} to BRR...", sample_id);
            _run_brr_converter(wav_file, brr_file, sample.loop_start);
            if (!_poll_for_file(brr_file, _calculate_brr_size(sample)))
            {
                throw new FileLoadException("The temp file: \"" + brr_file + "\" was incorrectly generated or missing.");
            }
            _fix_brr_loop(sample, brr_file, out_file);

            return(sample);
        }
Exemple #2
0
        private static bool _initial_block_needed(IT.Sample sample)
        {
            bool initial_block = false;

            for (int i = 0; i < 16; i++)
            {
                initial_block |= sample.sample_data[i].mono != 0;
            }
            return(initial_block);
        }
Exemple #3
0
        private static int _calculate_brr_size(IT.Sample sample)
        {
            //show_debug("{0} {1}", sample.loop_start, sample.length);

            Debug.Assert(sample.length % 16 == 0);
            if (sample.looped)
            {
                Debug.Assert(sample.loop_start % 16 == 0);
                Debug.Assert(sample.loop_end == sample.length);
            }

            if (_initial_block_needed(sample))
            {
                return((config.use_snesbrr) ? 9 * sample.length / 16 : 9 * sample.length / 16 + 9);
            }
            else
            {
                return(9 * sample.length / 16);
            }
        }
Exemple #4
0
        private static void _fix_brr_loop(IT.Sample sample, string brr_file, string new_filename)
        {
            var bytes = new List <byte>();

            byte[] brr_bytes = File.ReadAllBytes(brr_file);

            if (sample.looped)
            {
                int loop_ptr = 9 * sample.loop_start / 16;
                if (!config.use_snesbrr && _initial_block_needed(sample))
                {
                    loop_ptr += 9;
                }

                append_bytes(bytes, to_bytes((ushort)(loop_ptr)));

                for (int i = 0; i < brr_bytes.Length; i++)
                {
                    bytes.Add(brr_bytes[i]);
                }
            }
            else
            {
                append_bytes(bytes, to_bytes((ushort)0));

                for (int i = 0; i < brr_bytes.Length; i++)
                {
                    if (i == brr_bytes.Length - 9)
                    {
                        bytes.Add((byte)(brr_bytes[i] & 0xFD));
                    }
                    else
                    {
                        bytes.Add(brr_bytes[i]);
                    }
                }
            }

            File.WriteAllBytes(new_filename, bytes.ToArray());
        }