/// <summary>
        /// Play the specified sound file.
        /// </summary>
        /// <param name='fileName'>
        /// true if successful, false if an error occurs
        /// </param>
        public bool StartPlaying(string fileName)
        {
            if (!File.Exists(fileName))
            {
                return(false);
            }
            if (IsPlaying || IsRecording)
            {
                return(false);
            }
            _info = new SF_INFO();
            _hsf  = sf_open(fileName, SF_Mode.READ, ref _info);
            if (_hsf == IntPtr.Zero)
            {
                ShowError(String.Format("Sound player cannot open {0}", fileName));
                return(false);
            }
            _filename   = fileName;
            _fAsyncQuit = false;

            // Create the thread object, passing in the Record method
            // via a ThreadStart delegate. This does not start the thread.
            _playbackThread = new Thread(new ThreadStart(Play));

            // Start the thread
            _playbackThread.Start();

            // Wait for the started thread to become alive:
            while (!_playbackThread.IsAlive)
            {
                ;
            }
            return(true);
        }
Beispiel #2
0
        GetSoundFileType(string filename, ref SF_INFO soundInfo)
        {
            // Open file, pass it reference
            // to SF_INFO structure

            IntPtr errorRef = sf_open(filename,
                                      (int)fileMode.SFM_READ, ref soundInfo);

            int status = sf_error(errorRef);
            int c      = sf_close(errorRef);


            // return success or error

            return(status);
        }
Beispiel #3
0
		/// <summary>
		/// Play the specified sound file.
		/// </summary>
		/// <param name='fileName'>
		/// true if successful, false if an error occurs
		/// </param>
		public bool StartPlaying(string fileName)
		{
			if (!File.Exists(fileName))
				return false;
			if (IsPlaying || IsRecording)
				return false;
			_info = new SF_INFO();
			_hsf = sf_open(fileName, SF_Mode.READ, ref _info);
			if (_hsf == IntPtr.Zero)
			{
				ShowError(String.Format("Sound player cannot open {0}", fileName));
				return false;
			}
			_filename = fileName;
			_fAsyncQuit = false;

			// Create the thread object, passing in the Record method
			// via a ThreadStart delegate. This does not start the thread.
			_playbackThread = new Thread(new ThreadStart(Play));

			// Start the thread
			_playbackThread.Start();

			// Wait for the started thread to become alive:
			while (!_playbackThread.IsAlive)
				;
			return true;
		}
Beispiel #4
0
		internal static extern IntPtr sf_open(string path, SF_Mode mode, ref SF_INFO info);
Beispiel #5
0
//program entry
    static void Main(  )
    {
//declarations
        SF_INFO sfinfo = new SF_INFO();

        float[]    buffer = new float[BUFFER_LEN];
        sf_count_t rcnt;

//set the input file
        string sfn = "input.wav";               //set to a file on YOUR system
        //string sfn = "noexist.wav";   //test with non-existent file

//set the output file
        string ofn = "output.wav";

//read in sound file to convert
        IntPtr infile = sf_open(sfn, (int)lsndf_tf.SFM_READ, ref sfinfo);

//exit if error was thrown
        if ((int)infile == 0)
        {
            Console.WriteLine("Error opening " + sfn);
            Console.WriteLine("Error #" + sf_error(infile));
            return;
        }

//set the file type for the output file
//uncomment one and only one of the statements below to change the output
//file encoding.
        //sfinfo.format = (int)(lsndf_frmts.SF_FORMAT_WAV | lsndf_frmts.SF_FORMAT_PCM_U8);
        //sfinfo.format = (int)(lsndf_frmts.SF_FORMAT_WAV | lsndf_frmts.SF_FORMAT_PCM_16);
        //sfinfo.format = (int)(lsndf_frmts.SF_FORMAT_WAV | lsndf_frmts.SF_FORMAT_MS_ADPCM);
        sfinfo.format = (int)(lsndf_frmts.SF_FORMAT_WAV | lsndf_frmts.SF_FORMAT_IMA_ADPCM);
        //sfinfo.format = (int)(lsndf_frmts.SF_FORMAT_WAV | lsndf_frmts.SF_FORMAT_GSM610);
        /* Soundforge W64. */
        //sfinfo.format = (int)(lsndf_frmts.SF_FORMAT_W64 | lsndf_frmts.SF_FORMAT_PCM_U8);
        //sfinfo.format = (int)(lsndf_frmts.SF_FORMAT_W64 | lsndf_frmts.SF_FORMAT_PCM_16);
        //sfinfo.format = (int)(lsndf_frmts.SF_FORMAT_W64 | lsndf_frmts.SF_FORMAT_MS_ADPCM);
        //sfinfo.format = (int)(lsndf_frmts.SF_FORMAT_W64 | lsndf_frmts.SF_FORMAT_IMA_ADPCM);
        //sfinfo.format = (int)(lsndf_frmts.SF_FORMAT_W64 | lsndf_frmts.SF_FORMAT_GSM610);


//check that SF_INFO is valid
        if (sf_format_check(ref sfinfo) == 0)
        {
            Console.WriteLine("sf_format_check failed. Invalid encoding");
            return;
        }

//open output file
        IntPtr outfile = sf_open(ofn, (int)lsndf_tf.SFM_WRITE, ref sfinfo);

//exit if error was thrown
        if ((int)outfile == 0)
        {
            Console.WriteLine("Error opening " + ofn);
            Console.WriteLine("Error #" + sf_error(outfile));
            return;
        }

//infile -> outfile
        Console.Write(sfn + " -> " + ofn);
        while ((rcnt = sf_read_float(infile, buffer, BUFFER_LEN)) > 0)
        {
            Console.Write(".");
            sf_write_float(outfile, buffer, BUFFER_LEN);
        }
        Console.WriteLine("done.");

//close up shop
        sf_close(infile);
        sf_close(outfile);
    }     //main()
Beispiel #6
0
 static extern int sf_format_check(ref SF_INFO info);
Beispiel #7
0
 public static extern IntPtr sf_open([MarshalAs(UnmanagedType.LPStr)] string path, int mode, ref SF_INFO sfinfo);
 internal static extern IntPtr sf_open(string path, SF_Mode mode, ref SF_INFO info);
        // Class methods hence
        // Return information about sound file
        public int GetSoundFileType(string filename, ref SF_INFO soundInfo)
        {
            // Open file, pass it reference
            // to SF_INFO structure

            IntPtr errorRef = sf_open (filename,
                    (int)fileMode.SFM_READ, ref soundInfo);

            int status = sf_error(errorRef);
            int c = sf_close(errorRef);

            // return success or error

            return status;
        }
 public static extern IntPtr sf_open_fd(int fd, int mode, 
     ref SF_INFO soundInfo, int close_desc);
 public static extern IntPtr sf_open([MarshalAs(UnmanagedType.LPStr)] string path, 
     int mode,
     ref SF_INFO soundInfo);
 public static extern int sf_format_check(ref SF_INFO info);
Beispiel #13
0
 sf_format_check(ref SF_INFO info);
Beispiel #14
0
 sf_open_fd(int fd, int mode,
            ref SF_INFO soundInfo, int close_desc);
Beispiel #15
0
 sf_open([MarshalAs(UnmanagedType.LPStr)] string path,
         int mode,
         ref SF_INFO soundInfo);
Beispiel #16
0
//program entry
	static void Main(  ) {


//declarations
		SF_INFO sfinfo = new SF_INFO();
		float[] buffer = new float[BUFFER_LEN];
		sf_count_t rcnt;

//set the input file
		string sfn = "input.wav";	//set to a file on YOUR system
		//string sfn = "noexist.wav"; 	//test with non-existent file

//set the output file
		string ofn = "output.wav";

//read in sound file to convert
		IntPtr infile = sf_open (sfn, (int)lsndf_tf.SFM_READ, ref sfinfo);

//exit if error was thrown
		if ( (int)infile == 0 ) {
			Console.WriteLine("Error opening " + sfn);
			Console.WriteLine("Error #" + sf_error(infile));
			return;
		}

//set the file type for the output file
//uncomment one and only one of the statements below to change the output
//file encoding.
		//sfinfo.format = (int)(lsndf_frmts.SF_FORMAT_WAV | lsndf_frmts.SF_FORMAT_PCM_U8);
		//sfinfo.format = (int)(lsndf_frmts.SF_FORMAT_WAV | lsndf_frmts.SF_FORMAT_PCM_16);
		//sfinfo.format = (int)(lsndf_frmts.SF_FORMAT_WAV | lsndf_frmts.SF_FORMAT_MS_ADPCM);
		sfinfo.format = (int)(lsndf_frmts.SF_FORMAT_WAV | lsndf_frmts.SF_FORMAT_IMA_ADPCM);
		//sfinfo.format = (int)(lsndf_frmts.SF_FORMAT_WAV | lsndf_frmts.SF_FORMAT_GSM610);
		/* Soundforge W64. */
		//sfinfo.format = (int)(lsndf_frmts.SF_FORMAT_W64 | lsndf_frmts.SF_FORMAT_PCM_U8);
		//sfinfo.format = (int)(lsndf_frmts.SF_FORMAT_W64 | lsndf_frmts.SF_FORMAT_PCM_16);
		//sfinfo.format = (int)(lsndf_frmts.SF_FORMAT_W64 | lsndf_frmts.SF_FORMAT_MS_ADPCM);
		//sfinfo.format = (int)(lsndf_frmts.SF_FORMAT_W64 | lsndf_frmts.SF_FORMAT_IMA_ADPCM);
		//sfinfo.format = (int)(lsndf_frmts.SF_FORMAT_W64 | lsndf_frmts.SF_FORMAT_GSM610);


//check that SF_INFO is valid
		if ( sf_format_check(ref sfinfo) == 0 ) {
			Console.WriteLine("sf_format_check failed. Invalid encoding");
			return;
		}

//open output file
		IntPtr outfile = sf_open (ofn, (int)lsndf_tf.SFM_WRITE, ref sfinfo);

//exit if error was thrown
		if ( (int)outfile == 0 ) {
			Console.WriteLine("Error opening " + ofn);
			Console.WriteLine("Error #" + sf_error(outfile));
			return;
		}

//infile -> outfile
		Console.Write(sfn + " -> " + ofn);
		while ( (rcnt = sf_read_float (infile, buffer, BUFFER_LEN)) > 0) {
			Console.Write(".");
			sf_write_float (outfile, buffer, BUFFER_LEN);
		}
		Console.WriteLine("done.");

//close up shop
		sf_close(infile);
		sf_close(outfile);


	} //main()