sawass sawass

sawass sawass

  • NA
  • 36
  • 23.6k

listener sound in particular soundcard

May 19 2011 9:53 AM

Hello,

I am a beginner in c #. I have a code that is speaking, the sound output of the computer's sound card. But this code does not allow me to out the sound in a specific external sound card.I have used devicenumber in parameter but the problem is not solved yet.

Has ANYONE can help me improve my code so that it can hear the sound listen an external sound card.

Thank you in advance.

Here is the code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;




namespace PaGa
{
    public partial class StreamingForm : Form{
        

        public StreamingForm()
        {
            InitializeComponent();
            
        }

        /// <summary>
/// Clean up any resources being used.
/// </summary>

/// <summary>
/// The main entry point for the application.
/// </summary>
//[STAThread]

private PaGa.WaveOutPlayer m_Player;
private PaGa.WaveInRecorder m_Recorder;
private PaGa.FifoStream m_Fifo = new PaGa.FifoStream();

private byte[] m_PlayBuffer;
private byte[] m_RecBuffer;

private void Filler(IntPtr data, int size)
{
if (m_PlayBuffer == null || m_PlayBuffer.Length < size)
m_PlayBuffer = new byte[size];
if (m_Fifo.Length >= size)
m_Fifo.Read(m_PlayBuffer, 0, size);
else
for (int i = 0; i < m_PlayBuffer.Length; i++)
m_PlayBuffer[i] = 0;
System.Runtime.InteropServices.Marshal.Copy(m_PlayBuffer, 0, data, size);
}

private void DataArrived(IntPtr data, int size)
{
if (m_RecBuffer == null || m_RecBuffer.Length < size)
m_RecBuffer = new byte[size];
System.Runtime.InteropServices.Marshal.Copy(data, m_RecBuffer, 0, size);
m_Fifo.Write(m_RecBuffer, 0, m_RecBuffer.Length);
}

private void Stop()
{
if (m_Player != null)
try
{
m_Player.Dispose();
}
finally
{
m_Player = null;
}
if (m_Recorder != null)
try
{
m_Recorder.Dispose();
}
finally
{
m_Recorder = null;
}
m_Fifo.Flush(); // clear all pending data
}

private void Start()
{
Stop();
try
{
PaGa.WaveFormatt fmt = new PaGa.WaveFormatt(44100, 16, 2);
m_Player = new PaGa.WaveOutPlayer(-1, fmt, 16384, 3, new PaGa.BufferFillEventHandler(Filler));
m_Recorder = new PaGa.WaveInRecorder(-1, fmt, 16384, 3, new PaGa.BufferDoneEventHandler(DataArrived));
                
                //WaveOut outputDevice = new WaveOut();
               
               // waveOut = outputDevice;
               // outputDevice.DeviceNumber = _deviceNumber;
}
catch
{
Stop();
throw;
}
}

private void StreamingForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Stop();
}

private void StartButton_Click(object sender, System.EventArgs e)
{
Start();
}

private void StopButton_Click(object sender, System.EventArgs e)
{
Stop();
}
       

        


}
}

    


Answers (4)