public Listener(System.Windows.Forms.Form form, Object3D object_listening) { m_listener = object_listening; Sound.BufferDescription description = new Sound.BufferDescription(); Sound.WaveFormat fmt = new Sound.WaveFormat(); description.PrimaryBuffer = true; description.Control3D = true; Sound.Buffer buff = null; fmt.FormatTag = Sound.WaveFormatTag.Pcm; fmt.Channels = 2; fmt.SamplesPerSecond = 22050; fmt.BitsPerSample = 16; fmt.BlockAlign = (short)(fmt.BitsPerSample / 8 * fmt.Channels); fmt.AverageBytesPerSecond = fmt.SamplesPerSecond * fmt.BlockAlign; applicationDevice.SetCooperativeLevel(form, Sound.CooperativeLevel.Priority); // Get the primary buffer and set the format. buff = new Buffer(description, Device); buff.Format = fmt; applicationListener = new Listener3D(buff); listenerParameters = applicationListener.AllParameters; }
private void trackBar1_Scroll(object sender, System.EventArgs e) { if (ApplicationBuffer != null) { ApplicationBuffer.Frequency = trackBar1.Value; } if (bufferx != null) { BufferCaps cap; cap = bufferx.Caps; //bufferx.Pan = 10000; //cap.ControlFrequency = true; //int xxx = cap.BufferBytes / sps; int xxx1 = cap.PlayCpuOverhead; //label5.Text = xxx.ToString() + " " + xxx1.ToString(); bufferx.Frequency = trackBar1.Value; Microsoft.DirectX.DirectSound.WaveFormat wfm = buffer_desc.Format; int bps = wfm.BitsPerSample; sps = wfm.AverageBytesPerSecond; //Play Buffer. //bufferx.Play(0,BufferPlayFlags.Default); //bufferx = buffer; //wfm.AverageBytesPerSecond = trackBar1.Value; //bufferx.Frequency =trackBar1.Value; } //if (trackBar1.Value != Convert.ToInt16(label1.Text)) label1.Text = trackBar1.Value.ToString(); }
private WaveFormat CreateWaveFormat() { WaveFormat format = new Microsoft.DirectX.DirectSound.WaveFormat(); format.AverageBytesPerSecond = 192000; format.BitsPerSample = 16; format.BlockAlign = 4; format.Channels = 2; format.FormatTag = WaveFormatTag.Pcm; format.SamplesPerSecond = 48000; return(format); }
public DSoundPlayer(Control owner, PullAudio pullAudio, Qaryan.Audio.WaveFormat format) { this.pullAudio = pullAudio; this.soundDevice = new Device(); this.soundDevice.SetCooperativeLevel(owner, CooperativeLevel.Normal); // Set up our wave format to 44,100Hz, with 16 bit resolution DirectSound.WaveFormat wf = ConvertWaveFormat(format); // wf.FormatTag = DirectSound.WaveFormatTag.Pcm; // wf.SamplesPerSecond = 44100; // wf.BitsPerSample = 16; // wf.Channels = channels; // wf.BlockAlign = (short)(wf.Channels * wf.BitsPerSample / 8); // wf.AverageBytesPerSecond = wf.SamplesPerSecond * wf.BlockAlign; this.samplesPerUpdate = 1024; // Create a buffer with 5 seconds of sample data bufferDesc = new BufferDescription(wf); bufferDesc.BufferBytes = this.samplesPerUpdate * wf.BlockAlign * 5; bufferDesc.ControlPositionNotify = true; bufferDesc.GlobalFocus = true; this.soundBuffer = new SecondaryBuffer(bufferDesc, this.soundDevice); Notify notify = new Notify(this.soundBuffer); fillEvent[0] = new AutoResetEvent(false); fillEvent[1] = new AutoResetEvent(false); // Set up two notification events, one at halfway, and one at the end of the buffer BufferPositionNotify[] posNotify = new BufferPositionNotify[2]; posNotify[0] = new BufferPositionNotify(); posNotify[0].Offset = bufferDesc.BufferBytes / 2 - 1; posNotify[0].EventNotifyHandle = fillEvent[0].SafeWaitHandle.DangerousGetHandle(); posNotify[1] = new BufferPositionNotify(); posNotify[1].Offset = bufferDesc.BufferBytes - 1; posNotify[1].EventNotifyHandle = fillEvent[1].SafeWaitHandle.DangerousGetHandle(); notify.SetNotificationPositions(posNotify); this.thread = new Thread(new ThreadStart(SoundPlayback)); this.thread.SetApartmentState(ApartmentState.STA); this.thread.Name = "SoundPlayback"; this.thread.Priority = ThreadPriority.Highest; this.Pause(); this.running = true; this.thread.Start(); }
private void button3_Click(object sender, System.EventArgs e) { //Create and setup the sound device. Device dev = new Device(); devx = dev; dev.SetCooperativeLevel(this, CooperativeLevel.Normal); //Create and setup the buffer description. buffer_desc = new BufferDescription(); buffer_desc.ControlEffects = true; //this has to be true to use effects. buffer_desc.GlobalFocus = true; //play sound even if application loses focus. buffer_desc.ControlFrequency = true; //Create and setup the buffer for playing the sound. SecondaryBuffer buffer = new SecondaryBuffer( //@"C:\WINDOWS\Media\ding.wav", @"Z:\My Documents\My Programming\Pong\qbytespong.wav", buffer_desc, dev); timer1.Enabled = true; //Create an array of effects descriptions, //set the effect objects to echo and chorus and //set it in the buffer. EffectDescription[] effects = new EffectDescription[3]; //effects[0].GuidEffectClass = DSoundHelper.StandardEchoGuid; effects[1].GuidEffectClass = DSoundHelper.StandardChorusGuid; effects[0].GuidEffectClass = DSoundHelper.StandardFlangerGuid; effects[2].GuidEffectClass = DSoundHelper.StandardParamEqGuid; buffer.SetEffects(effects); //public class EchoEffect : System.MarshalByRefObject // Member of Microsoft.DirectX.DirectSound //System.IntPtr lp=Application.lp; //EchoEffect efx = new EchoEffect(lp,buffer); //efx. Microsoft.DirectX.DirectSound.WaveFormat wfm = buffer_desc.Format; int bps = wfm.BitsPerSample; sps = wfm.AverageBytesPerSecond; msps = wfm.SamplesPerSecond; //Play Buffer. buffer.Play(0, BufferPlayFlags.Default); bufferx = buffer; trackBar1.Value = msps; label1.Text = trackBar1.Value.ToString(); }
/// <summary> /// Helper function for creating WaveFormat instances /// </summary> /// <param name="sr">Sampling rate</param> /// <param name="bps">Bits per sample</param> /// <param name="ch">Channels</param> /// <returns></returns> public static Microsoft.DirectX.DirectSound.WaveFormat CreateWaveFormat(int sr, short bps, short ch) { Microsoft.DirectX.DirectSound.WaveFormat wfx = new Microsoft.DirectX.DirectSound.WaveFormat(); wfx.FormatTag = WaveFormatTag.Pcm; wfx.SamplesPerSecond = sr; wfx.BitsPerSample = bps; wfx.Channels = ch; wfx.BlockAlign = (short)(wfx.Channels * (wfx.BitsPerSample / 8)); wfx.AverageBytesPerSecond = wfx.SamplesPerSecond * wfx.BlockAlign; return(wfx); }
private void SetBufferAndWave(int samplesPerSecond) { waveFormat = new Microsoft.DirectX.DirectSound.WaveFormat(); waveFormat.SamplesPerSecond = samplesPerSecond; waveFormat.Channels = 2; waveFormat.FormatTag = WaveFormatTag.Pcm; waveFormat.BitsPerSample = 16; waveFormat.BlockAlign = (short)(waveFormat.Channels * waveFormat.BitsPerSample / 8); waveFormat.AverageBytesPerSecond = waveFormat.BlockAlign * waveFormat.SamplesPerSecond; bufferDesc = new BufferDescription(waveFormat); bufferDesc.DeferLocation = true; bufferDesc.ControlEffects = false; bufferDesc.ControlFrequency = true; bufferDesc.ControlPan = true; bufferDesc.ControlVolume = true; bufferDesc.ControlPositionNotify = true; bufferDesc.GlobalFocus = true; bufferDesc.BufferBytes = m_StreamBufferSize; }
private void Play(Int16[] data) { WaveFormat format = new Microsoft.DirectX.DirectSound.WaveFormat(); format.AverageBytesPerSecond = bitspersample / 8 * samplerate; format.BitsPerSample = bitspersample; format.BlockAlign = bitspersample / 8; format.Channels = 1; format.FormatTag = WaveFormatTag.Pcm; format.SamplesPerSecond = samplerate; BufferDescription desc = new BufferDescription(format); desc.BufferBytes = (int)(bitspersample / 8 * data.Length); desc.ControlVolume = true; desc.GlobalFocus = true; buffer = new SecondaryBuffer(desc, dev); buffer.Write(0, data, LockFlag.None); buffer.Play(0, BufferPlayFlags.Default); }
public StreamingPlayer(Control owner, Device device, Microsoft.DirectX.DirectSound.WaveFormat format) { m_Device = device; if (m_Device == null) { m_Device = new Device(); m_Device.SetCooperativeLevel(owner, CooperativeLevel.Normal); m_OwnsDevice = true; } BufferDescription desc = new BufferDescription(format); desc.BufferBytes = format.AverageBytesPerSecond; desc.ControlVolume = true; desc.GlobalFocus = true; m_Buffer = new SecondaryBuffer(desc, m_Device); m_BufferBytes = m_Buffer.Caps.BufferBytes; m_Timer = new System.Timers.Timer(BytesToMs(m_BufferBytes) / 6); m_Timer.Enabled = false; m_Timer.Elapsed += new System.Timers.ElapsedEventHandler(Timer_Elapsed); }
public StreamingPlayer(Control owner, Microsoft.DirectX.DirectSound.WaveFormat format) : this(owner, null, format) { }
public PlayerClass(AudioBookConverterMain Caller, string filename) { if (GetSourceExt(filename) != "mp3") { return; } file = filename; Parent = Caller; Microsoft.DirectX.DirectSound.WaveFormat format = new Microsoft.DirectX.DirectSound.WaveFormat(); WmaStream wmastr = new WmaStream(filename); format.BlockAlign = wmastr.Format.nBlockAlign; format.Channels = wmastr.Format.nChannels; format.SamplesPerSecond = wmastr.Format.nSamplesPerSec; format.BitsPerSample = wmastr.Format.wBitsPerSample; format.AverageBytesPerSecond = format.BlockAlign * format.SamplesPerSecond; wmastr.Dispose(); BufferDescription desc = new BufferDescription(format); desc.ControlPan = true; desc.GlobalFocus = true; desc.BufferBytes = 262144; desc.ControlPositionNotify = true; desc.CanGetCurrentPosition = true; desc.ControlVolume = true; desc.StickyFocus = true; desc.LocateInSoftware = true; desc.ControlEffects = false; desc.LocateInHardware = false; desc.Control3D = false; //MemoryStream bufferstream = new MemoryStream(262144); Device device = new Device(); device.SetCooperativeLevel(Parent, CooperativeLevel.Priority); sound = new SecondaryBuffer(desc, device); sound.SetCurrentPosition(1); sound.Volume = 0; sound.Pan = 0; BufferNotificationEvent = new AutoResetEvent(false); BufferNotify = new Notify(sound); BufferPositionNotify[] BufferPositions = new BufferPositionNotify[2]; BufferPositions[0].Offset = 0; BufferPositions[0].EventNotifyHandle = BufferNotificationEvent.Handle; BufferPositions[1].Offset = (desc.BufferBytes / 2); BufferPositions[1].EventNotifyHandle = BufferNotificationEvent.Handle; BufferNotify.SetNotificationPositions(BufferPositions); DataTransferThread = new Thread(new ThreadStart(WMDataFill)); //if (GetSourceExt(filename) =="mp4") DataTransferThread = new Thread(new ThreadStart(FaadDataFill)); //if (GetSourceExt(filename) =="flac") DataTransferThread = new Thread(new ThreadStart(FlacDataFill)); //if (GetSourceExt(filename) =="ogg") DataTransferThread = new Thread(new ThreadStart(OggDataFill)); DataTransferThread.Name = "BufferFill"; DataTransferThread.Priority = ThreadPriority.Highest; DataTransferThread.Start(); }
/// <summary> /// Helper function for creating WaveFormat instances /// </summary> /// <param name="sr">Sampling rate</param> /// <param name="bps">Bits per sample</param> /// <param name="ch">Channels</param> /// <returns></returns> public static Microsoft.DirectX.DirectSound.WaveFormat CreateWaveFormat(int sr, short bps, short ch) { Microsoft.DirectX.DirectSound.WaveFormat wfx = new Microsoft.DirectX.DirectSound.WaveFormat(); wfx.FormatTag = WaveFormatTag.Pcm; wfx.SamplesPerSecond = sr; wfx.BitsPerSample = bps; wfx.Channels = ch; wfx.BlockAlign = (short)(wfx.Channels * (wfx.BitsPerSample / 8)); wfx.AverageBytesPerSecond = wfx.SamplesPerSecond * wfx.BlockAlign; return wfx; }