Пример #1
0
        public static float[] DecodeUsingMplayer(string fileIn, int srate)
        {
            lock (_locker) {
                using (Process towav = new Process())
                {
                    fileIn = Regex.Replace(fileIn, "%20", " ");
                    DbgTimer t = new DbgTimer();
                    t.Start();
                    String curdir = System.Environment.CurrentDirectory;
                    Dbg.WriteLine("Decoding: " + fileIn);
                    String tempFile = System.IO.Path.GetTempFileName();
                    String wav      = tempFile + ".wav";
                    Dbg.WriteLine("Temporary wav file: " + wav);

                    towav.StartInfo.FileName               = "./NativeLibraries\\mplayer\\mplayer.exe";
                    towav.StartInfo.Arguments              = " -quiet -ao pcm:fast:waveheader \"" + fileIn + "\" -format floatle -af resample=" + srate + ":0:2,pan=1:0.5:0.5 -channels 1 -vo null -vc null -ao pcm:file=\\\"" + wav + "\\\"";
                    towav.StartInfo.UseShellExecute        = false;
                    towav.StartInfo.RedirectStandardOutput = true;
                    towav.StartInfo.RedirectStandardError  = true;
                    towav.Start();
                    towav.WaitForExit();

                    int exitCode = towav.ExitCode;
                    // 0 = succesfull
                    // 1 = partially succesful
                    // 2 = failed
                    if (exitCode != 0)
                    {
                        string standardError = towav.StandardError.ReadToEnd();
                        Console.Out.WriteLine(standardError);
                        return(null);
                    }

                                        #if DEBUG
                    string standardOutput = towav.StandardOutput.ReadToEnd();
                    Console.Out.WriteLine(standardOutput);
                                        #endif

                    RiffRead riff = new RiffRead(wav);
                    riff.Process();
                    float[] floatBuffer = riff.SoundData[0];
                    try
                    {
                        File.Delete(tempFile);
                        //File.Delete(wav);
                    }
                    catch (IOException io)
                    {
                        Console.WriteLine(io);
                    }

                    Dbg.WriteLine("Decoding Execution Time: " + t.Stop().TotalMilliseconds + " ms");
                    return(floatBuffer);
                }
            }
        }
Пример #2
0
    public static double[][] ReadWaveFile(String wavfile, ref int channels, ref int samplecount, ref int samplerate)
    {
        RiffRead riffRead = new RiffRead(wavfile);

        riffRead.Process();
        channels    = riffRead.Channels;
        samplecount = riffRead.SampleCount;
        samplerate  = riffRead.SampleRate;
        return(riffRead.SoundData);
    }