Exemplo n.º 1
0
		public static AudioDevice CreateDevice (string name) {
			AudioDevice dev;

			dev = TryAlsa (name);
			/* if no option is found, return a silent device */
			if (dev == null)
				dev = new AudioDevice ();
			return dev;
		}
Exemplo n.º 2
0
		public abstract void Play (AudioDevice dev);
Exemplo n.º 3
0
		public override void Play (AudioDevice dev) {
						int    fragment_played = 0;
			int    total_data_played = 0;
			int    chunk_size        = (int)dev.ChunkSize;
			int    count             = data_len;
			byte[] buffer            = new byte [data_len];
			byte[] chunk_to_play     = new byte [chunk_size];
			
			// Read only Au data, don't care about file header here !
			stream.Position = 0; //(long)data_offset;
			stream.Read (buffer, 0, data_len); 
			
			while (!IsStopped && count >= 0){
				// Copy one chunk from buffer
				Buffer.BlockCopy(buffer, total_data_played, chunk_to_play, 0, chunk_size);
				// play that chunk, !!! the size pass to alsa the number of fragment, a fragment is a sample per channel !!!
				fragment_played = dev.PlaySample (chunk_to_play, chunk_size / (frame_divider * channels));
				
				// If alsa played something, inc the total data played and dec the data to be played
				if (fragment_played > 0) {
					total_data_played  += (fragment_played * frame_divider * channels);
					count              -= (fragment_played * frame_divider * channels);
				}
			}
		}
Exemplo n.º 4
0
		public virtual void Setup (AudioDevice dev) {
			dev.SetFormat (Format, Channels, Rate);
		}
Exemplo n.º 5
0
		public void Load ()
		{
			// can this be reused to load the same file again without re-setting the location?
			if (load_completed)
				return;
			if (audiostream != null) {
				LoadFromStream (audiostream);
			} else {
				LoadFromUri (sound_location);
			}

			// force recreate for new stream
			adata = null;
			adev = null;

			load_completed = true;
			AsyncCompletedEventArgs e = new AsyncCompletedEventArgs (null, false, this);
			OnLoadCompleted (e);
			if (LoadCompleted != null)
				LoadCompleted (this, e);

			if (use_win32_player) {
				if (win32_player == null)
					win32_player = new Win32SoundPlayer (mstream);
				else 
					win32_player.Stream = mstream;
			}
		}
Exemplo n.º 6
0
		public void PlaySync ()
		{
			Start ();

			if (mstream == null) {
				SystemSounds.Beep.Play ();
				return;
			}

			if (!use_win32_player) {
				try {
					if (adata == null)
						adata = new WavData (mstream);
					if (adev == null)
						adev = AudioDevice.CreateDevice (null);
					if (adata != null) {
						adata.Setup (adev);
						adata.Play (adev);
					}
				} catch {
				}
			} else {
				win32_player.PlaySync ();
			}
		}
Exemplo n.º 7
0
		public override void Play(AudioDevice dev) {
			int fragment_played = 0;
			int total_data_played = 0;
			int chunk_size = (int)dev.ChunkSize;
			int count = data_len;
			byte[] buffer = new byte[data_len];
			byte[] chunk_to_play = new byte[chunk_size];

			// Read only wave data, don't care about file header here !
			stream.Position = data_offset;
			stream.Read(buffer, 0, data_len);

			while (!IsStopped && count >= 0) {
				//Console.WriteLine(stream.Position + " - " + DateTime.Now.ToString());
				// Copy one chunk from buffer
				var readSize = buffer.Length - total_data_played < chunk_size ? buffer.Length - total_data_played : chunk_size;
				if (readSize == 0) return;
				Buffer.BlockCopy(buffer, total_data_played, chunk_to_play, 0, readSize);
				// play that chunk, !!! the size pass to alsa the number of fragment, a fragment is a sample per channel !!!
				fragment_played = dev.PlaySample(chunk_to_play, readSize / (frame_divider * channels));

				// If alsa played something, inc the total data played and dec the data to be played
				if (fragment_played > 0) {
					total_data_played += (fragment_played * frame_divider * channels);
					count -= (fragment_played * frame_divider * channels);
				}
			}
		}
Exemplo n.º 8
0
		public override void Play (AudioDevice dev) {
			int read;
			int count = data_len;
			byte[] buffer = new byte [buffer_size];
			stream.Position = 0;
			while (!IsStopped && count >= 0 && (read = stream.Read (buffer, 0, System.Math.Min (buffer.Length, count))) > 0) {
				// FIXME: account for leftover bytes
				dev.PlaySample (buffer, read/frame_divider);
				count -= read;
			}
		}
Exemplo n.º 9
0
 public abstract void Play(AudioDevice dev);
Exemplo n.º 10
0
 public virtual void Setup(AudioDevice dev)
 {
     dev.SetFormat(Format, Channels, Rate);
 }
Exemplo n.º 11
0
		public TAudioPlayer() {
			adev = Mono.Audio.AudioDevice.CreateDevice(null);
			th = new Thread(mainLoop);
			th.Start();
		}