Пример #1
0
        Initialize(string inputFile,
                   string outputFile, soundFormat formatType)
        {
            // Setup

            this.inputFile  = inputFile;
            this.outputFile = outputFile;
            this.formatType = formatType;


            // Read in sound file to convert

            pInputFile = sf_open(inputFile,
                                 (int)fileMode.SFM_READ, ref soundInfo);


            // Exit if error was thrown; 0 = NULL pointer

            if ((int)pInputFile == 0)
            {
                return(sf_error(pInputFile));
            }


            // Set the file type for the output file

            soundInfo.format = (int)(formatType);


            // Check that SF_INFO is valid

            if (sf_format_check(ref soundInfo) == 0)
            {
                return(-1);
            }


            // Open output file

            pOutputFile = sf_open(outputFile,
                                  (int)fileMode.SFM_WRITE, ref soundInfo);


            // Exit if error was thrown

            if ((int)pOutputFile == 0)
            {
                return(sf_error(pOutputFile));
            }

            return(0);                  // Success
        }
Пример #2
0
        public SampledSound(FileStream stream, soundFormat format)
        {
            this.stream = stream;
            BinaryReader streamRaw;

            if (format == soundFormat.mp3)
            {
                streamRaw = startMP3();
            }
            else
            {
                streamRaw = startWave();
            }
            read(streamRaw);
        }
Пример #3
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();
        }
Пример #4
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);
        }
        // Initialize() overload:
        // no output filename specified
        public int Initialize(string inputFile, soundFormat formatType)
        {
            string outputFile = inputFile;

            if (formatType >= soundFormat.SF_FORMAT_WAV &&
                    formatType < soundFormat.SF_FORMAT_AIFF)
            {
                outputFile = inputFile + ".wav";
            }
            else if (formatType >= soundFormat.SF_FORMAT_AIFF &&
                    formatType < soundFormat.SF_FORMAT_AU)
            {
                outputFile = inputFile + ".aiff";
            }
            else if (formatType >= soundFormat.SF_FORMAT_AU &&
                    formatType < soundFormat.SF_FORMAT_RAW)
            {
                outputFile = inputFile + ".au";
            }
            else if (formatType >= soundFormat.SF_FORMAT_RAW &&
                    formatType < soundFormat.SF_FORMAT_PAF)
            {
                outputFile = inputFile + ".raw";
            }
            else if (formatType >= soundFormat.SF_FORMAT_PAF &&
                    formatType < soundFormat.SF_FORMAT_SVX)
            {
                outputFile = inputFile + ".paf";
            }
            else if (formatType >= soundFormat.SF_FORMAT_SVX &&
                    formatType < soundFormat.SF_FORMAT_NIST)
            {
                outputFile = inputFile + ".svx";
            }
            else if (formatType >= soundFormat.SF_FORMAT_NIST &&
                    formatType < soundFormat.SF_FORMAT_VOC)
            {
                outputFile = inputFile + ".nist";
            }
            else if (formatType >= soundFormat.SF_FORMAT_VOC &&
                    formatType < soundFormat.SF_FORMAT_IRCAM)
            {
                outputFile = inputFile + ".voc";
            }
            else if (formatType >= soundFormat.SF_FORMAT_IRCAM &&
                    formatType < soundFormat.SF_FORMAT_W64)
            {
                outputFile = inputFile + ".ircam";
            }
            else if (formatType >= soundFormat.SF_FORMAT_W64 &&
                    formatType < soundFormat.SF_FORMAT_MAT4)
            {
                outputFile = inputFile + ".w64";
            }
            else if (formatType >= soundFormat.SF_FORMAT_MAT4 &&
                    formatType < soundFormat.SF_FORMAT_PVF)
            {
                outputFile = inputFile + ".mat4";
            }
            else if (formatType >= soundFormat.SF_FORMAT_PVF &&
                    formatType < soundFormat.SF_FORMAT_XI)
            {
                outputFile = inputFile + ".pvf";
            }
            else if (formatType >= soundFormat.SF_FORMAT_XI &&
                    formatType < soundFormat.SF_FORMAT_HTK)
            {
                outputFile = inputFile + ".xi";
            }
            else if (formatType >= soundFormat.SF_FORMAT_HTK &&
                    formatType < soundFormat.SF_FORMAT_SDS)
            {
                outputFile = inputFile + ".htk";
            }
            else if (formatType >= soundFormat.SF_FORMAT_SDS)
            {
                outputFile = inputFile + ".sds";
            }
            else
            {
                outputFile = inputFile + ".sout";
            }

            return Initialize (inputFile, outputFile, formatType);
        }
        // Performs a conversion between two files with format
        // specified in 'formatType'. Returns -1 on general error,
        // otherwise something from errorCode. 0 return is desired
        public int Initialize(string inputFile, 
            string outputFile, soundFormat formatType)
        {
            // Setup

            this.inputFile = inputFile;
            this.outputFile = outputFile;
            this.formatType = formatType;

            // Read in sound file to convert

            pInputFile = sf_open (inputFile,
                    (int)fileMode.SFM_READ, ref soundInfo);

            // Exit if error was thrown; 0 = NULL pointer

            if ( (int)pInputFile == 0 )
            {
                return sf_error(pInputFile);
            }

            // Set the file type for the output file

            soundInfo.format = (int)(formatType);

            // Check that SF_INFO is valid

            if ( sf_format_check(ref soundInfo) == 0 )
            {
                return -1;
            }

            // Open output file

            pOutputFile = sf_open (outputFile,
                    (int)fileMode.SFM_WRITE, ref soundInfo);

            // Exit if error was thrown

            if ( (int)pOutputFile == 0 )
            {
                return sf_error(pOutputFile);
            }

            return 0;	// Success
        }
Пример #7
0
        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();
        }
Пример #8
0
        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);
        }
Пример #9
0
        Initialize(string inputFile, soundFormat formatType)
        {
            string outputFile = inputFile;

            if (formatType >= soundFormat.SF_FORMAT_WAV &&
                formatType < soundFormat.SF_FORMAT_AIFF)
            {
                outputFile = inputFile + ".wav";
            }
            else if (formatType >= soundFormat.SF_FORMAT_AIFF &&
                     formatType < soundFormat.SF_FORMAT_AU)
            {
                outputFile = inputFile + ".aiff";
            }
            else if (formatType >= soundFormat.SF_FORMAT_AU &&
                     formatType < soundFormat.SF_FORMAT_RAW)
            {
                outputFile = inputFile + ".au";
            }
            else if (formatType >= soundFormat.SF_FORMAT_RAW &&
                     formatType < soundFormat.SF_FORMAT_PAF)
            {
                outputFile = inputFile + ".raw";
            }
            else if (formatType >= soundFormat.SF_FORMAT_PAF &&
                     formatType < soundFormat.SF_FORMAT_SVX)
            {
                outputFile = inputFile + ".paf";
            }
            else if (formatType >= soundFormat.SF_FORMAT_SVX &&
                     formatType < soundFormat.SF_FORMAT_NIST)
            {
                outputFile = inputFile + ".svx";
            }
            else if (formatType >= soundFormat.SF_FORMAT_NIST &&
                     formatType < soundFormat.SF_FORMAT_VOC)
            {
                outputFile = inputFile + ".nist";
            }
            else if (formatType >= soundFormat.SF_FORMAT_VOC &&
                     formatType < soundFormat.SF_FORMAT_IRCAM)
            {
                outputFile = inputFile + ".voc";
            }
            else if (formatType >= soundFormat.SF_FORMAT_IRCAM &&
                     formatType < soundFormat.SF_FORMAT_W64)
            {
                outputFile = inputFile + ".ircam";
            }
            else if (formatType >= soundFormat.SF_FORMAT_W64 &&
                     formatType < soundFormat.SF_FORMAT_MAT4)
            {
                outputFile = inputFile + ".w64";
            }
            else if (formatType >= soundFormat.SF_FORMAT_MAT4 &&
                     formatType < soundFormat.SF_FORMAT_PVF)
            {
                outputFile = inputFile + ".mat4";
            }
            else if (formatType >= soundFormat.SF_FORMAT_PVF &&
                     formatType < soundFormat.SF_FORMAT_XI)
            {
                outputFile = inputFile + ".pvf";
            }
            else if (formatType >= soundFormat.SF_FORMAT_XI &&
                     formatType < soundFormat.SF_FORMAT_HTK)
            {
                outputFile = inputFile + ".xi";
            }
            else if (formatType >= soundFormat.SF_FORMAT_HTK &&
                     formatType < soundFormat.SF_FORMAT_SDS)
            {
                outputFile = inputFile + ".htk";
            }
            else if (formatType >= soundFormat.SF_FORMAT_SDS)
            {
                outputFile = inputFile + ".sds";
            }
            else
            {
                outputFile = inputFile + ".sout";
            }


            return(Initialize(inputFile, outputFile, formatType));
        }