示例#1
0
        // Conversion routine overload
        // (madlldlib)
        //
        // Convert() routine overload for
        // MP3 decoding using madlldlib.
        // Expects 'inputFile' to be MP3.
        //
        // Note: Calling this method in
        // your code requires you to
        // release your code under GPL
        // terms. See the readme.txt
        // file in this distribution
        // for details.
        public void Convert(string inputFile, string outputFile, 
            soundFormat convertTo, MadlldlibWrapper.Callback updateStatus)
        {
            // Handle incorrect output types

            if ( !(convertTo == soundFormat.WAV) &&
                   !(convertTo == soundFormat.RAW) )
            {
                throw new Exception(
                        "Cannot convert from MP3 to this format directly: " +
                        convertTo);
            }

            // Check that file is MP3
            // Search through .5 of file
            // before quitting

            MP3Check verifyMP3 = new MP3Check(inputFile, 2);

            if (!verifyMP3.Check())
            {
                throw new Exception("Not a valid MP3 file: " +
                        inputFile);
            }

            // Convert to short pathnames

            inputFilePath.Capacity = MAX_STRLEN;
            outputFilePath.Capacity = MAX_STRLEN;
            GetShortPathName(inputFile, inputFilePath, MAX_STRLEN);
            GetShortPathName(outputFile, outputFilePath, MAX_STRLEN);

            // Assign if returned path is not zero:

            if (inputFilePath.Length > 0)
                inputFile = inputFilePath.ToString();

            if (outputFilePath.Length > 0)
                outputFile = outputFilePath.ToString();

            // status/error message reporting.
            // String length must be set
            // explicitly

            StringBuilder status = new StringBuilder();
            status.Capacity=256;

            // call the decoding function

            if (convertTo == soundFormat.WAV)
            {
                MadlldlibWrapper.DecodeMP3(inputFile, outputFile,
                        MadlldlibWrapper.DEC_WAV, status, updateStatus);
            }

            else

            // Convert to PCM (raw):

            {
                MadlldlibWrapper.DecodeMP3(inputFile, outputFile,
                        MadlldlibWrapper.DEC_PCM, status, updateStatus);
            }

            // this prevents garbage collection
            // from occurring on callback

            GC.KeepAlive(updateStatus);
        }
示例#2
0
        // Conversion routine overload
        // (madNPObjectsrv)
        //
        // Convert() routine overload for
        // MP3 decoding using madnpsrv.
        // Expects 'inputFile' to be MP3
        public void Convert(string inputFile, string outputFile, 
            soundFormat convertTo, MadnpsrvWrapper.Callback updateStatus)
        {
            // Handle incorrect output types

            if ( !(convertTo == soundFormat.WAV) &&
                   !(convertTo == soundFormat.RAW) )
            {
                throw new Exception(
                        "Cannot convert from MP3 to this format directly: " +
                        convertTo);
            }

            // Check that file is MP3
            // Search through 1/2 of file
            // before quitting

            MP3Check verifyMP3 = new MP3Check(inputFile, 2);

            if (!verifyMP3.Check())
            {
                throw new Exception("Not a valid MP3 file: " + inputFile);
            }

            // Create class instance

            MadnpsrvWrapper madNPObject = new MadnpsrvWrapper();

            // call the decoding function

            if (convertTo == soundFormat.WAV)
            {
                // Startup pipe server:
                madNPObject.StartPipe(inputFile,
                        outputFile, MadnpsrvWrapper.DEC_WAV);
            }

            else

            // Convert to PCM (raw):

            {
                // Startup pipe server:
                madNPObject.StartPipe(inputFile,
                        outputFile, MadnpsrvWrapper.DEC_PCM);
            }

            // Call read function (passing delegate
            // function)

            madNPObject.ReadPipe(updateStatus);

            // Kill the pipe server,
            // just in case it is still
            // running

            madNPObject.StopPipe();
        }
示例#3
0
        // Given a file, return
        // the sound file format
        public soundFormat CheckSoundFormat(string inputFile)
        {
            // Verify existence of inputFilenm, throw
            // exception if not exist

            if (!System.IO.File.Exists(inputFile))
            {
                throw new FileNotFoundException(
                        "Cannot find file " + inputFile);
            }

            // Check for non-MP3 sound file

            LibsndfileWrapper libSndFile = new LibsndfileWrapper();
            LibsndfileWrapper.SF_INFO soundInfo =
                new LibsndfileWrapper.SF_INFO();

            int i = libSndFile.GetSoundFileType(inputFile, ref soundInfo);

            // First check to see if it's an audio
            // format !MP3. Then check for MP3.
            // If no valid format found, throw
            // exception.

            if (soundInfo.format != 0)
            {
                return (soundFormat)soundInfo.format;
            }
            else
            {

                MP3Check verifyMP3 = new MP3Check(inputFile, 2);

                if (!verifyMP3.Check())
                {
                    throw new Exception("Cannot determine sound file type: " +
                        inputFile);

                }
                else
                {
                    return soundFormat.MP3;
                }

            }
        }