Audio mix

Contenu du snippet

Voici une table de mixage très basique. Avec cette table on a la possibilité d'ouvrir 2 fichiers son différents et de les mixers. Il me reste à revoir le disign, créer un systeme d'echo...., et à rajouter qlq fonctionnalité.

Source / Exemple :


using System;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;

namespace sound2
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public class MainForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.TrackBar trackBar3;
		private System.Windows.Forms.TrackBar trackBar2;
		private System.Windows.Forms.TrackBar trackBar1;
		private System.Windows.Forms.Button button3;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.TrackBar trackBar4;
		private System.Windows.Forms.TextBox textBox8;
		private System.Windows.Forms.Button button7;
		private System.Windows.Forms.Button button6;
		private System.Windows.Forms.Button button5;
		private System.Windows.Forms.Button button4;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.TextBox textBox6;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.Button button8;
		private System.Windows.Forms.TextBox textBox2;
		private System.Windows.Forms.TrackBar trackBar5;
		private System.Windows.Forms.TextBox textBox5;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.TextBox textBox4;
		private System.Windows.Forms.TextBox textBox7;
		private System.Windows.Forms.TextBox textBox3;
		
		public FileDialog fileDlg = new OpenFileDialog();
		public Thread t1;
		public Thread t2;		
		
		private Microsoft.DirectX.AudioVideoPlayback.Audio monAudio;
		private Microsoft.DirectX.AudioVideoPlayback.Audio monAudio2;		
	
			
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			initaudio();
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
		}
		
		[STAThread]
		public static void Main(string[] args)
		{
			Application.Run(new MainForm());
		}
		
		#region Windows Forms Designer generated code
		/// <summary>
		/// This method is required for Windows Forms designer support.
		/// Do not change the method contents inside the source code editor. The Forms designer might
		/// not be able to load this method if it was changed manually.
		/// </summary>
		private void InitializeComponent() {
			this.textBox3 = new System.Windows.Forms.TextBox();
			this.textBox7 = new System.Windows.Forms.TextBox();
			this.textBox4 = new System.Windows.Forms.TextBox();
			this.button1 = new System.Windows.Forms.Button();
			this.textBox5 = new System.Windows.Forms.TextBox();
			this.trackBar5 = new System.Windows.Forms.TrackBar();
			this.textBox2 = new System.Windows.Forms.TextBox();
			this.button8 = new System.Windows.Forms.Button();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.textBox6 = new System.Windows.Forms.TextBox();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.button4 = new System.Windows.Forms.Button();
			this.button5 = new System.Windows.Forms.Button();
			this.button6 = new System.Windows.Forms.Button();
			this.button7 = new System.Windows.Forms.Button();
			this.textBox8 = new System.Windows.Forms.TextBox();
			this.trackBar4 = new System.Windows.Forms.TrackBar();
			this.button2 = new System.Windows.Forms.Button();
			this.button3 = new System.Windows.Forms.Button();
			this.trackBar1 = new System.Windows.Forms.TrackBar();
			this.trackBar2 = new System.Windows.Forms.TrackBar();
			this.trackBar3 = new System.Windows.Forms.TrackBar();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			((System.ComponentModel.ISupportInitialize)(this.trackBar5)).BeginInit();
			this.groupBox1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.trackBar4)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.trackBar1)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.trackBar2)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.trackBar3)).BeginInit();
			this.groupBox2.SuspendLayout();
			this.SuspendLayout();
			// 
			// textBox3
			// 
			this.textBox3.Location = new System.Drawing.Point(16, 24);
			this.textBox3.Name = "textBox3";
			this.textBox3.Size = new System.Drawing.Size(200, 26);
			this.textBox3.TabIndex = 6;
			this.textBox3.Text = "";
			// 
			// textBox7
			// 
			this.textBox7.Location = new System.Drawing.Point(112, 88);
			this.textBox7.Name = "textBox7";
			this.textBox7.Size = new System.Drawing.Size(72, 26);
			this.textBox7.TabIndex = 9;
			this.textBox7.Text = "";
			// 
			// textBox4
			// 
			this.textBox4.Location = new System.Drawing.Point(16, 24);
			this.textBox4.Name = "textBox4";
			this.textBox4.Size = new System.Drawing.Size(192, 26);
			this.textBox4.TabIndex = 0;
			this.textBox4.Text = "";
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(16, 56);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(80, 23);
			this.button1.TabIndex = 0;
			this.button1.Text = "play";
			this.button1.Click += new System.EventHandler(this.Button1Click);
			// 
			// textBox5
			// 
			this.textBox5.Location = new System.Drawing.Point(16, 88);
			this.textBox5.Name = "textBox5";
			this.textBox5.Size = new System.Drawing.Size(72, 26);
			this.textBox5.TabIndex = 5;
			this.textBox5.Text = "";
			// 
			// trackBar5
			// 
			this.trackBar5.Location = new System.Drawing.Point(112, 200);
			this.trackBar5.Maximum = 100;
			this.trackBar5.Name = "trackBar5";
			this.trackBar5.Size = new System.Drawing.Size(528, 45);
			this.trackBar5.TabIndex = 10;
			this.trackBar5.Value = 50;
			this.trackBar5.Scroll += new System.EventHandler(this.TrackBar5Scroll);
			// 
			// textBox2
			// 
			this.textBox2.Location = new System.Drawing.Point(200, 88);
			this.textBox2.Name = "textBox2";
			this.textBox2.Size = new System.Drawing.Size(80, 26);
			this.textBox2.TabIndex = 4;
			this.textBox2.Text = "";
			// 
			// button8
			// 
			this.button8.Location = new System.Drawing.Point(192, 56);
			this.button8.Name = "button8";
			this.button8.Size = new System.Drawing.Size(72, 23);
			this.button8.TabIndex = 4;
			this.button8.Text = "pause";
			this.button8.Click += new System.EventHandler(this.Button8Click);
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(16, 88);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(80, 26);
			this.textBox1.TabIndex = 2;
			this.textBox1.Text = "";
			// 
			// textBox6
			// 
			this.textBox6.Location = new System.Drawing.Point(192, 88);
			this.textBox6.Name = "textBox6";
			this.textBox6.Size = new System.Drawing.Size(72, 26);
			this.textBox6.TabIndex = 6;
			this.textBox6.Text = "";
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.textBox7);
			this.groupBox1.Controls.Add(this.textBox3);
			this.groupBox1.Controls.Add(this.button1);
			this.groupBox1.Controls.Add(this.button2);
			this.groupBox1.Controls.Add(this.textBox1);
			this.groupBox1.Controls.Add(this.button3);
			this.groupBox1.Controls.Add(this.textBox2);
			this.groupBox1.Controls.Add(this.trackBar1);
			this.groupBox1.Controls.Add(this.button4);
			this.groupBox1.Controls.Add(this.trackBar3);
			this.groupBox1.Font = new System.Drawing.Font("Comic Sans MS", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.groupBox1.ForeColor = System.Drawing.SystemColors.ControlLightLight;
			this.groupBox1.Location = new System.Drawing.Point(16, 16);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(352, 176);
			this.groupBox1.TabIndex = 8;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "groupBox1";
			// 
			// button4
			// 
			this.button4.Location = new System.Drawing.Point(224, 24);
			this.button4.Name = "button4";
			this.button4.Size = new System.Drawing.Size(56, 23);
			this.button4.TabIndex = 7;
			this.button4.Text = "add";
			this.button4.Click += new System.EventHandler(this.Button4Click);
			// 
			// button5
			// 
			this.button5.Location = new System.Drawing.Point(216, 24);
			this.button5.Name = "button5";
			this.button5.Size = new System.Drawing.Size(48, 23);
			this.button5.TabIndex = 1;
			this.button5.Text = "add";
			this.button5.Click += new System.EventHandler(this.Button5Click);
			// 
			// button6
			// 
			this.button6.Location = new System.Drawing.Point(16, 56);
			this.button6.Name = "button6";
			this.button6.Size = new System.Drawing.Size(72, 23);
			this.button6.TabIndex = 2;
			this.button6.Text = "play";
			this.button6.Click += new System.EventHandler(this.Button6Click);
			// 
			// button7
			// 
			this.button7.Location = new System.Drawing.Point(104, 56);
			this.button7.Name = "button7";
			this.button7.Size = new System.Drawing.Size(72, 23);
			this.button7.TabIndex = 3;
			this.button7.Text = "stop";
			this.button7.Click += new System.EventHandler(this.Button7Click);
			// 
			// textBox8
			// 
			this.textBox8.Location = new System.Drawing.Point(104, 88);
			this.textBox8.Name = "textBox8";
			this.textBox8.Size = new System.Drawing.Size(72, 26);
			this.textBox8.TabIndex = 11;
			this.textBox8.Text = "";
			// 
			// trackBar4
			// 
			this.trackBar4.Location = new System.Drawing.Point(272, 24);
			this.trackBar4.Maximum = 20;
			this.trackBar4.Name = "trackBar4";
			this.trackBar4.Orientation = System.Windows.Forms.Orientation.Vertical;
			this.trackBar4.Size = new System.Drawing.Size(45, 136);
			this.trackBar4.TabIndex = 10;
			this.trackBar4.Value = 20;
			this.trackBar4.Scroll += new System.EventHandler(this.TrackBar4Scroll);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(112, 56);
			this.button2.Name = "button2";
			this.button2.TabIndex = 1;
			this.button2.Text = "stop";
			this.button2.Click += new System.EventHandler(this.Button2Click);
			// 
			// button3
			// 
			this.button3.Location = new System.Drawing.Point(200, 56);
			this.button3.Name = "button3";
			this.button3.Size = new System.Drawing.Size(80, 23);
			this.button3.TabIndex = 3;
			this.button3.Text = "pause";
			this.button3.Click += new System.EventHandler(this.Button3Click);
			// 
			// trackBar1
			// 
			this.trackBar1.Location = new System.Drawing.Point(16, 120);
			this.trackBar1.Maximum = 100;
			this.trackBar1.Name = "trackBar1";
			this.trackBar1.Size = new System.Drawing.Size(264, 45);
			this.trackBar1.TabIndex = 5;
			this.trackBar1.Scroll += new System.EventHandler(this.TrackBar1Scroll);
			// 
			// trackBar2
			// 
			this.trackBar2.Location = new System.Drawing.Point(16, 120);
			this.trackBar2.Maximum = 100;
			this.trackBar2.Name = "trackBar2";
			this.trackBar2.Size = new System.Drawing.Size(248, 45);
			this.trackBar2.TabIndex = 7;
			this.trackBar2.Scroll += new System.EventHandler(this.TrackBar2Scroll);
			// 
			// trackBar3
			// 
			this.trackBar3.Location = new System.Drawing.Point(288, 24);
			this.trackBar3.Maximum = 20;
			this.trackBar3.Name = "trackBar3";
			this.trackBar3.Orientation = System.Windows.Forms.Orientation.Vertical;
			this.trackBar3.Size = new System.Drawing.Size(45, 136);
			this.trackBar3.TabIndex = 8;
			this.trackBar3.Value = 20;
			this.trackBar3.Scroll += new System.EventHandler(this.TrackBar3Scroll);
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.Add(this.textBox8);
			this.groupBox2.Controls.Add(this.trackBar2);
			this.groupBox2.Controls.Add(this.textBox6);
			this.groupBox2.Controls.Add(this.button8);
			this.groupBox2.Controls.Add(this.button7);
			this.groupBox2.Controls.Add(this.button6);
			this.groupBox2.Controls.Add(this.button5);
			this.groupBox2.Controls.Add(this.textBox4);
			this.groupBox2.Controls.Add(this.trackBar4);
			this.groupBox2.Controls.Add(this.textBox5);
			this.groupBox2.Font = new System.Drawing.Font("Comic Sans MS", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.groupBox2.ForeColor = System.Drawing.SystemColors.ControlLightLight;
			this.groupBox2.Location = new System.Drawing.Point(384, 16);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(336, 176);
			this.groupBox2.TabIndex = 9;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "groupBox2";
			// 
			// MainForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.BackColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.ClientSize = new System.Drawing.Size(736, 238);
			this.Controls.Add(this.trackBar5);
			this.Controls.Add(this.groupBox2);
			this.Controls.Add(this.groupBox1);
			this.Name = "MainForm";
			this.Text = "MiX_#";
			((System.ComponentModel.ISupportInitialize)(this.trackBar5)).EndInit();
			this.groupBox1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.trackBar4)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.trackBar2)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.trackBar3)).EndInit();
			this.groupBox2.ResumeLayout(false);
			this.ResumeLayout(false);
		}
		#endregion
		void initaudio()
		{
		}
		void stop(object sender, System.EventArgs e)
		{
			t1.Abort();
			this.textBox1.Text = "wait...";
			this.textBox7.Text = "wait...";			
		}
		void play(object sender, System.EventArgs e)
		{
			t1 = new Thread(new ThreadStart(curentime));
    	   	t1.Start();
	       	this.textBox2.Text = monAudio.Duration.ToString();
		}		
		void Button1Click(object sender, System.EventArgs e)
		{
			if ( monAudio != null )
			{			
				monAudio.Play();				
			}
			else {
				MessageBox.Show("Tu doit entré le fichier que tu veux joué");
			}
		}
		
		void Button2Click(object sender, System.EventArgs e)
		{
			if ( monAudio != null )
			{
				monAudio.Stop();				
			}
		}
		
		void Button3Click(object sender, System.EventArgs e)
		{
			if ( monAudio != null )
			{
				monAudio.Pause();				
			}
		}
		void curentime()
		{
			while ( ( monAudio != null ) && ( monAudio.Duration > monAudio.CurrentPosition ) )
			{
				double n = monAudio.Duration - monAudio.CurrentPosition;
				this.textBox7.Text = n.ToString();
				this.textBox1.Text = monAudio.CurrentPosition.ToString();
				n = 100 / monAudio.Duration * monAudio.CurrentPosition;
				this.trackBar1.Value = System.Convert.ToInt16(n);
				
				Thread.Sleep(500);	
			}
		}
		
		void TrackBar1Scroll(object sender, System.EventArgs e)
		{
			if ( monAudio != null ) {
				double n = monAudio.Duration / 100 * this.trackBar1.Value;
				//this.textBox3.Text = n.ToString();
				monAudio.CurrentPosition = n;
			}
			else {
				this.trackBar1.Value = 0;
			}
		}
	
		void Button4Click(object sender, System.EventArgs e)
		{
                fileDlg.Filter = "Music File (*.mp3;*.wma;*.wav)|*.mp3;*.wma;*.wav";
                fileDlg.RestoreDirectory = true ;
                if(fileDlg.ShowDialog() == DialogResult.OK)
                {
                	this.textBox3.Text = fileDlg.FileName;
           			monAudio = new Microsoft.DirectX.AudioVideoPlayback.Audio(fileDlg.FileName);
					monAudio.Stopping += new System.EventHandler(stop);
					monAudio.Pausing += new System.EventHandler(stop);	
					monAudio.Starting += new System.EventHandler(play);	
					monAudio.Ending += new System.EventHandler(stop);
                }
		}
		
		void Button5Click(object sender, System.EventArgs e)
		{
                fileDlg.Filter = "Music File (*.mp3;*.wma;*.wav)|*.mp3;*.wma;*.wav";
                fileDlg.RestoreDirectory = true ;
                if(fileDlg.ShowDialog() == DialogResult.OK)
                {
                	this.textBox4.Text = fileDlg.FileName;
                	monAudio2 = new Microsoft.DirectX.AudioVideoPlayback.Audio(fileDlg.FileName);
					monAudio2.Stopping += new System.EventHandler(stop2);
					monAudio2.Pausing += new System.EventHandler(stop2);	
					monAudio2.Starting += new System.EventHandler(play2);	
					monAudio2.Ending += new System.EventHandler(stop2);
                }			
		}
		void stop2(object sender, System.EventArgs e)
		{
			t2.Abort();
			this.textBox5.Text = "wait...";
			this.textBox8.Text = "wait...";			
		}
		void play2(object sender, System.EventArgs e)
		{
			t2 = new Thread(new ThreadStart(curentime2));
    	   	t2.Start();
	       	this.textBox6.Text = monAudio2.Duration.ToString();
		}		
		void Button6Click(object sender, System.EventArgs e)
		{
			if ( monAudio2 != null )
			{
				monAudio2.Play();			
			}
			else {
				MessageBox.Show("Tu doit entré le fichier que tu veux joué");
			}					
		}
		void curentime2()
		{
			while ( ( monAudio2 != null ) && ( monAudio2.Duration > monAudio2.CurrentPosition ) )
			{
				double n = monAudio2.Duration - monAudio2.CurrentPosition;
				this.textBox8.Text = n.ToString();
				this.textBox5.Text = monAudio2.CurrentPosition.ToString();
				n = 100 / monAudio2.Duration * monAudio2.CurrentPosition;
				this.trackBar2.Value = System.Convert.ToInt16(n);
				Thread.Sleep(500);				
			}
		}		
		
		void Button7Click(object sender, System.EventArgs e)
		{
			if ( monAudio2 != null )
			{
				monAudio2.Stop();				
			}		
		}
		
		void Button8Click(object sender, System.EventArgs e)
		{
			if ( monAudio2 != null )
			{
				monAudio2.Pause();				
			}			
		}
		
		void TrackBar2Scroll(object sender, System.EventArgs e)
		{
			if ( monAudio != null ) {
				double n = monAudio2.Duration / 100 * this.trackBar2.Value;
				//this.textBox5.Text = n.ToString();
				monAudio2.CurrentPosition = n;	
			}
			else {
				this.trackBar2.Value = 0;
			}			
		}
		
		void TrackBar3Scroll(object sender, System.EventArgs e)
		{
			if ( monAudio != null )
			{
				monAudio.Volume = 0-(10000-10000 / 20 * this.trackBar3.Value);
			}
		}	
		void TrackBar4Scroll(object sender, System.EventArgs e)
		{
			if ( monAudio2 != null )
			{
				monAudio2.Volume = 0-(10000-10000 / 20 * this.trackBar4.Value);
			}
		}
		
		void TrackBar5Scroll(object sender, System.EventArgs e)
		{
			if ( ( monAudio2 != null ) && ( monAudio != null ) )
				{
				if ( this.trackBar5.Value == 50 ) 
				{
					monAudio.Volume = 0;
					monAudio2.Volume = 0;
				}
				else if ( this.trackBar5.Value < 50 ) 
				{
					monAudio.Volume = 0;
					monAudio2.Volume = 0-(5000-5000 / 50 * this.trackBar5.Value);
				}
				else if ( this.trackBar5.Value > 50 ) 
				{
					monAudio2.Volume = 0;
					monAudio.Volume = 0-(5000-5000 / 50 * (100-this.trackBar5.Value));
				}
				int n = 20 * (10000 + monAudio.Volume) / 10000;
				this.trackBar3.Value = n;
				n = 20 * (10000 + monAudio2.Volume) / 10000;
				this.trackBar4.Value = n;				
			}
			else {
				this.trackBar5.Value = 50;
			}
		}
		
	}
}

Conclusion :


by abdoulax

Have Fun

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.