public Mixer(MixerType mixerType) { mMixerType = mixerType; mLines = new MixerLines(); mUserLines = new MixerLines(); mMixerControlChangeHandler = new CallbackWindowControlChangeHandler(PtrMixerControlChange); mMixerLineChangeHandler = new CallbackWindowLineChangeHandler(PtrMixerLineChange); mCallbackWindow = new CallbackWindow(mMixerControlChangeHandler, mMixerLineChangeHandler); DeviceId = -1; }
public Mixer(MixerType mixerType) { mMixerType = mixerType; mLines = new MixerLines(); mUserLines = new MixerLines(); mMixerControlChangeHandler = new CallbackWindowControlChangeHandler(PtrMixerControlChange); mMixerLineChangeHandler = new CallbackWindowLineChangeHandler(PtrMixerLineChange); mCallbackWindow = new CallbackWindow(mMixerControlChangeHandler, mMixerLineChangeHandler); DeviceId = -1; }
public override string ToString() { string volumeValue = Volume.HasValue ? Volume.Value.ToString() : "Null"; string timeValue = Time.HasValue ? Time.Value.ToString() : "Null"; string panValue = Pan.HasValue ? Pan.Value.ToString() : "Null"; string mixerTypeValue = MixerType.ToString(); string pitchValue = Pitch.HasValue ? Pitch.Value.ToString() : "Null"; string spatialBlendValue = SpatialBlend.HasValue ? SpatialBlend.Value.ToString() : "Null"; string minDistanceValue = MinDistance.HasValue ? MinDistance.Value.ToString() : "Null"; string maxDistanceValue = MaxDistance.HasValue ? MaxDistance.Value.ToString() : "Null"; string volumeRolloffTypeValue = VolumeRolloffType.ToString(); return($"{nameof(Volume)}: {volumeValue}, {nameof(Time)}: {timeValue}, {nameof(Pan)}: {panValue}, {nameof(MixerType)}: {mixerTypeValue}, {nameof(Pitch)}: {pitchValue}, {nameof(SpatialBlend)}: {spatialBlendValue}, {nameof(MinDistance)}: {minDistanceValue}, {nameof(MaxDistance)}: {maxDistanceValue}, {nameof(VolumeRolloffType)}: {volumeRolloffTypeValue}"); }
/// <Summary> /// Constructor for the AudioSourceParameters Struct /// </Summary> public AudioSourceParameters(float volume, float time, float pan, float pitch, float spatialBlend, float spread, float minDistance, float maxDistance, MixerType mixerType, VolumeRolloffType volumeRolloffType, bool isMute) { Volume = volume; Time = time; Pan = pan; Pitch = pitch; SpatialBlend = spatialBlend; Spread = spread; MinDistance = minDistance; MaxDistance = maxDistance; MixerType = mixerType; VolumeRolloffType = volumeRolloffType; IsMute = isMute; }
private void LoadValues(MixerType mixerType) { MixerLine line; //Get info about the lines if (mixerType == MixerType.Recording) { mMixers.Recording.DeviceId = ((MixerDetail)comboBoxRecordingDevices.SelectedItem).DeviceId; line = mMixers.Recording.UserLines.GetMixerFirstLineByComponentType(MIXERLINE_COMPONENTTYPE.SRC_MICROPHONE); } else { mMixers.Playback.DeviceId = ((MixerDetail)comboBoxPlaybackDevices.SelectedItem).DeviceId; line = mMixers.Playback.UserLines.GetMixerFirstLineByComponentType(MIXERLINE_COMPONENTTYPE.DST_SPEAKERS); } }
/// <summary> /// Determine which AudioMixerGroup to use based on MixerType enum /// </summary> /// <param name="mixerType">MixterType enum/returns> private AudioMixerGroup CalcAudioMixerGroup(MixerType mixerType) { switch (mixerType) { case MixerType.Music: return(AudioManager.Instance.MusicMixer); case MixerType.Muffled: return(AudioManager.Instance.SFXMuffledMixer); case MixerType.Ambient: return(AudioManager.Instance.AmbientMixer); default: return(AudioManager.Instance.SFXMixer); } }
/// <Summary> /// Constructor for the AudioSourceParameters Struct /// </Summary> public AudioSourceParameters(float pitch = 0, float volume = 0, float time = 0, float pan = 0, float spatialBlend = 0, float spread = 0, float minDistance = 0, float maxDistance = 0, MixerType mixerType = MixerType.Master, VolumeRolloffType volumeRolloffType = VolumeRolloffType.Linear, bool isMute = false) { Pitch = pitch; Volume = volume; Time = time; Pan = pan; SpatialBlend = spatialBlend; Spread = spread; MinDistance = minDistance; MaxDistance = maxDistance; MixerType = mixerType; VolumeRolloffType = volumeRolloffType; IsMute = isMute; }
/// <summary> /// Plays audio clip at. /// </summary> /// <param name="name">The name.</param> /// <param name="worldPos">The world pos.</param> /// <param name="type">The type.</param> public AudioSource PlayAudioClipAt(string name, Vector3 worldPos, MixerType type = MixerType.Game) { AudioClip clip = GetAudioByName(name); if (clip == null) { return(null); } GameObject go = new GameObject("Audio-" + clip.name); AudioSource source = go.AddComponent <AudioSource>(); source.clip = clip; source.loop = false; source.outputAudioMixerGroup = type == MixerType.UI ? UIAudioMixer : GameAudioMixer; source.Play(); Destroy(go, (clip.length + 0.5f)); return(source); }
/// <summary> /// Plays audio clip. /// </summary> /// <param name="name">The name.</param> /// <param name="type">The type.</param> /// <param name="cacheAudio">The cache audio.</param> /// <param name="stopCached">The stop cached.</param> public AudioSource PlayAudioClip(string name, MixerType type = MixerType.UI, bool cacheAudio = false, bool stopCached = false) { AudioClip clip = GetAudioByName(name); if (stopCached && cachedAudioSource != null) { cachedAudioSource.Stop(); } Camera cam = Camera.main; if (cam == null || clip == null) { return(null); } GameObject go = new GameObject("Audio-" + clip.name); go.transform.parent = cam.transform; AudioSource source = go.AddComponent <AudioSource>(); source.clip = clip; source.loop = false; source.outputAudioMixerGroup = type == MixerType.UI ? UIAudioMixer : GameAudioMixer; if (cacheAudio) { cachedAudioSource = source; } source.Play(); Destroy(go, (clip.length + 0.5f)); return(source); }
private AudioDevice GetDefaultDevice(MixerType mixerType) { MMErrors errorCode = 0; IntPtr hWave = IntPtr.Zero; IntPtr hMixer = IntPtr.Zero; try { WAVEFORMATEX waveFormat = WAVEFORMATEX.Empty; waveFormat.formatTag = WaveFormatTag.PCM; waveFormat.nChannels = 1; waveFormat.nSamplesPerSec = 8000; waveFormat.wBitsPerSample = 8; waveFormat.nBlockAlign = (short)(waveFormat.nChannels * (waveFormat.wBitsPerSample / 8)); waveFormat.nAvgBytesPerSec = waveFormat.nSamplesPerSec * waveFormat.nBlockAlign; waveFormat.cbSize = 0; // Get default mixer HWND if (mixerType == MixerType.Recording) { errorCode = (MMErrors)WaveNative.waveInOpen(out hWave, WaveNative.WAVE_MAPPER, ref waveFormat, CallbackForm.Handle, IntPtr.Zero, (int)CallBackFlag.CALLBACK_WINDOW); } else if (mixerType == MixerType.Playback) { errorCode = (MMErrors)WaveNative.waveOutOpen(out hWave, WaveNative.WAVE_MAPPER, ref waveFormat, CallbackForm.Handle, IntPtr.Zero, (int)CallBackFlag.CALLBACK_WINDOW); } if (errorCode != MMErrors.MMSYSERR_NOERROR) { // TODO: Log error!!! //throw new MixerException(errorCode, Audio.GetErrorDescription(FuncName.fnWaveInOpen, errorCode)); return(null); } if (mixerType == MixerType.Recording) { errorCode = (MMErrors)MixerNative.mixerOpen(out hMixer, hWave, IntPtr.Zero, IntPtr.Zero, ((uint)MIXER_OBJECTFLAG.HWAVEIN)); } else if (mixerType == MixerType.Playback) { errorCode = (MMErrors)MixerNative.mixerOpen(out hMixer, hWave, IntPtr.Zero, IntPtr.Zero, ((uint)MIXER_OBJECTFLAG.HWAVEOUT)); } if (errorCode != MMErrors.MMSYSERR_NOERROR) { // TODO: Log error!!! //throw new MixerException(errorCode, Mixers.GetErrorDescription(FuncName.fnMixerOpen, errorCode)); return(null); } int deviceId = -1; errorCode = (MMErrors)MixerNative.mixerGetID(hMixer, ref deviceId, MIXER_OBJECTFLAG.MIXER); if (errorCode != MMErrors.MMSYSERR_NOERROR) { // TODO: Log error!!! //throw new MixerException(errorCode, Mixers.GetErrorDescription(FuncName.fnMixerGetID, errorCode)); return(null); } MIXERCAPS wic = new MIXERCAPS(); errorCode = (MMErrors)MixerNative.mixerGetDevCaps(deviceId, ref wic, Marshal.SizeOf(wic)); if (errorCode != MMErrors.MMSYSERR_NOERROR) { // TODO: Log error!!! //throw new MixerException(errorCode, GetErrorDescription(FuncName.fnMixerGetDevCaps, errorCode)); return(null); } return(GetAudioDeviceByName(wic.szPname, mixerType == MixerType.Playback)); } finally { if (hMixer != IntPtr.Zero) { MixerNative.mixerClose(hMixer); } if (hWave != IntPtr.Zero && mixerType == MixerType.Playback) { WaveNative.waveOutClose(hWave); } if (hWave != IntPtr.Zero && mixerType == MixerType.Recording) { WaveNative.waveInClose(hWave); } } }
/// <summary> /// Plays a SoundSpawn. /// </summary> /// <param name="source">The SoundSpawn to be played</param> /// <param name="polyphonic">Should the sound be played polyphonically</param> /// <param name="global">Does everyone will receive the sound our just nearby players</param> /// <param name="mixerType">The type of mixer to use</param> private void PlaySource(SoundSpawn source, bool polyphonic = false, bool global = true, MixerType mixerType = MixerType.Master) { if (global == false && PlayerManager.LocalPlayer != null && MatrixManager.Linecast(PlayerManager.LocalPlayer.TileWorldPosition().To3Int(), LayerTypeSelection.Walls, layerMask, source.transform.position.To2Int().To3Int()) .ItHit) { source.AudioSource.outputAudioMixerGroup = AudioManager.Instance.SFXMuffledMixer; } if (polyphonic) { source.PlayOneShot(); } else { source.PlayNormally(); } }
private void LoadValues(MixerType mixerType) { MixerLine line; //Get info about the lines if (mixerType == MixerType.Recording) { mMixers.Recording.DeviceId = ((MixerDetail)comboBoxRecordingDevices.SelectedItem).DeviceId; line = mMixers.Recording.UserLines.GetMixerFirstLineByComponentType(MIXERLINE_COMPONENTTYPE.SRC_MICROPHONE); trackBarRecordingVolume.Tag = line; trackBarRecordingBalance.Tag = line; //checkBoxSelectMic.Tag = line; checkBoxRecordingMute.Tag = line; _lastMicVolume = line.Volume; line.Selected = true; this.checkBoxRecordingMute.Checked = line.Volume == 0 ? true : false; } else { mMixers.Playback.DeviceId = ((MixerDetail)comboBoxPlaybackDevices.SelectedItem).DeviceId; line = mMixers.Playback.UserLines.GetMixerFirstLineByComponentType(MIXERLINE_COMPONENTTYPE.DST_SPEAKERS); trackBarPlaybackVolume.Tag = line; trackBarPlaybackBalance.Tag = line; checkBoxPlaybackMute.Tag = line; } //If it is 2 channels then ask both and set the volume to the bigger but keep relation between them (Balance) int volume = 0; float balance = 0; if (line.Channels != 2) volume = line.Volume; else { line.Channel = Channel.Left; int left = line.Volume; line.Channel = Channel.Right; int right = line.Volume; if (left > right) { volume = left; balance = (volume > 0) ? -(1 - (right / (float)left)) : 0; } else { volume = right; balance = (volume > 0) ? (1 - (left / (float)right)) : 0; } } if (mixerType == MixerType.Recording) { if (volume >= 0) this.trackBarRecordingVolume.Value = volume; else this.trackBarRecordingVolume.Enabled = false; //MONO OR MORE THAN 2 CHANNELS, then let disable balance if (line.Channels != 2) this.trackBarRecordingBalance.Enabled = false; else this.trackBarRecordingBalance.Value = (int)(trackBarRecordingBalance.Maximum * balance); } else { if (volume >= 0) this.trackBarPlaybackVolume.Value = volume; else this.trackBarPlaybackVolume.Enabled = false; //MONO OR MORE THAN 2 CHANNELS, then let disable balance if (line.Channels != 2) this.trackBarPlaybackBalance.Enabled = false; else this.trackBarPlaybackBalance.Value = (int)(trackBarPlaybackBalance.Maximum * balance); } // checkbox this.checkBoxPlaybackMute.Checked = line.Mute; //this.checkBoxSelectMic.Checked = line.Selected; }
private void LoadLines(MixerType mixerType) { //Reload Line. Clear old controls if (tBarArray[(int) mixerType] != null) for(int i=0;i<tBarArray[(int) mixerType].Length;i++) { tBarArray[(int) mixerType][i].ValueChanged -= new System.EventHandler(this.tBar_ValueChanged); tBarArray[(int) mixerType][i].Dispose(); tBarBalanceArray[(int) mixerType][i].Dispose(); lblArray[(int) mixerType][i].Dispose(); chkBoxArray[(int) mixerType][i].Dispose(); this.Controls.Remove(tBarArray[(int) mixerType][i]); this.Controls.Remove(tBarBalanceArray[(int) mixerType][i]); this.Controls.Remove(lblArray[(int) mixerType][i]); this.Controls.Remove(chkBoxArray[(int) mixerType][i]); } MixerLines lines; //Get info about the lines if (mixerType == MixerType.Recording) { mMixers.Recording.DeviceId = ((MixerDetail) cboInputDevices.SelectedItem).DeviceId; lines = mMixers.Recording.UserLines; } else { mMixers.Playback.DeviceId = ((MixerDetail) cboOutputDevices.SelectedItem).DeviceId; lines = mMixers.Playback.UserLines; } tBarArray[(int) mixerType] = new TrackBar[lines.Count]; tBarBalanceArray[(int) mixerType] = new TrackBar[lines.Count]; lblArray[(int) mixerType] = new Label[lines.Count]; chkBoxArray[(int) mixerType] = new CheckBox[lines.Count]; //foreach(MixerLine line in lines) for(int i=0;i<lines.Count;i++) { MixerLine line = lines[i]; // TrackBar creation this.tBarArray[(int) mixerType][i] = new System.Windows.Forms.TrackBar(); this.tBarArray[(int) mixerType][i].LargeChange = 10000; this.tBarArray[(int) mixerType][i].Location = new System.Drawing.Point(i * 60 + 10, 120 + (int) mixerType * 225); this.tBarArray[(int) mixerType][i].Maximum = 65535; this.tBarArray[(int) mixerType][i].Name = "tBarArray" + ((int) mixerType).ToString() + i.ToString(); this.tBarArray[(int) mixerType][i].Orientation = Orientation.Vertical; this.tBarArray[(int) mixerType][i].Size = new System.Drawing.Size(45, 100); this.tBarArray[(int) mixerType][i].SmallChange = 6553; this.tBarArray[(int) mixerType][i].TabIndex = i; this.tBarArray[(int) mixerType][i].TickFrequency = 6553; this.tBarArray[(int) mixerType][i].TickStyle = System.Windows.Forms.TickStyle.Both; this.tBarArray[(int) mixerType][i].Tag = line; //If it is 2 channels then ask both and set the volume to the bigger but keep relation between them (Balance) int volume = 0; float balance = 0; if (lines[i].Channels != 2) volume = lines[i].Volume; else { lines[i].Channel = Channel.Left; int left = lines[i].Volume; lines[i].Channel = Channel.Right; int right = lines[i].Volume; if (left > right) { volume = left; balance = (volume > 0) ? -(1 - (right / (float) left)) : 0; } else { volume = right; balance = (volume > 0) ? (1 - (left / (float) right)) : 0; } } if (volume >= 0) this.tBarArray[(int) mixerType][i].Value = volume; else this.tBarArray[(int) mixerType][i].Enabled = false; this.tBarArray[(int) mixerType][i].ValueChanged += new System.EventHandler(this.tBar_ValueChanged); this.Controls.Add(this.tBarArray[(int) mixerType][i]); //TrackBar Balance Creation this.tBarBalanceArray[(int) mixerType][i] = new System.Windows.Forms.TrackBar(); this.tBarBalanceArray[(int) mixerType][i].AutoSize = false; this.tBarBalanceArray[(int) mixerType][i].Location = new System.Drawing.Point(i * 60, 85 + (int) mixerType * 225); this.tBarBalanceArray[(int) mixerType][i].Maximum = 320; this.tBarBalanceArray[(int) mixerType][i].Minimum = -320; this.tBarBalanceArray[(int) mixerType][i].Name = "tBarBalanceArray" + ((int) mixerType).ToString() + i.ToString(); this.tBarBalanceArray[(int) mixerType][i].Size = new System.Drawing.Size(60, 30); this.tBarBalanceArray[(int) mixerType][i].TickFrequency = 320; this.tBarBalanceArray[(int) mixerType][i].TabIndex = i; this.tBarBalanceArray[(int) mixerType][i].SmallChange = 10; this.tBarBalanceArray[(int) mixerType][i].LargeChange = 50; this.tBarBalanceArray[(int) mixerType][i].Tag = line; //MONO OR MORE THAN 2 CHANNELS, then let disable balance if (lines[i].Channels != 2) this.tBarBalanceArray[(int) mixerType][i].Enabled = false; else this.tBarBalanceArray[(int) mixerType][i].Value = (int) (this.tBarBalanceArray[(int) mixerType][i].Maximum * balance); this.tBarBalanceArray[(int) mixerType][i].ValueChanged += new System.EventHandler(this.tBarBalance_ValueChanged); this.Controls.Add(this.tBarBalanceArray[(int) mixerType][i]); //Label Creation this.lblArray[(int) mixerType][i] = new System.Windows.Forms.Label(); this.lblArray[(int) mixerType][i].Location = new System.Drawing.Point(i * 60, 60 + (int) mixerType * 225); this.lblArray[(int) mixerType][i].Name = "lblArray" + ((int) mixerType).ToString() + i.ToString(); this.lblArray[(int) mixerType][i].Size = new System.Drawing.Size(65, 26); this.lblArray[(int) mixerType][i].TabIndex = 10; this.lblArray[(int) mixerType][i].TextAlign = System.Drawing.ContentAlignment.BottomCenter; this.lblArray[(int) mixerType][i].Text = line.Name; this.Controls.Add(this.lblArray[(int) mixerType][i]); //CheckBox Creation this.chkBoxArray[(int) mixerType][i] = new System.Windows.Forms.CheckBox(); this.chkBoxArray[(int) mixerType][i].Location = new System.Drawing.Point(i * 60 + 10, 225 + (int) mixerType * 225); this.chkBoxArray[(int) mixerType][i].Name = "chkMuteSelect" + ((int) mixerType).ToString() + i.ToString(); this.chkBoxArray[(int) mixerType][i].Size = new System.Drawing.Size(60, 16); this.chkBoxArray[(int) mixerType][i].Enabled = false; this.chkBoxArray[(int) mixerType][i].TabIndex = 10; this.chkBoxArray[(int) mixerType][i].Tag = line; if (mixerType == MixerType.Recording) { this.chkBoxArray[(int) mixerType][i].Text = "Select"; if (line.ContainsSelected) { this.chkBoxArray[(int) mixerType][i].Enabled = true; this.chkBoxArray[(int) mixerType][i].Checked = line.Selected; } } else { this.chkBoxArray[(int) mixerType][i].Text = "Mute"; if (line.ContainsMute) { this.chkBoxArray[(int) mixerType][i].Enabled = true; this.chkBoxArray[(int) mixerType][i].Checked = line.Mute; } } this.chkBoxArray[(int) mixerType][i].CheckedChanged += new EventHandler(Form1_CheckedChanged); this.Controls.Add(this.chkBoxArray[(int) mixerType][i]); } }
private void LoadValues(MixerType mixerType) { MixerLine line; //Get info about the lines if (mixerType == MixerType.Recording) { mMixers.Recording.DeviceId = ((MixerDetail)comboBoxRecordingDevices.SelectedItem).DeviceId; line = mMixers.Recording.UserLines.GetMixerFirstLineByComponentType(MIXERLINE_COMPONENTTYPE.SRC_MICROPHONE); } else { mMixers.Playback.DeviceId = ((MixerDetail)comboBoxPlaybackDevices.SelectedItem).DeviceId; line = mMixers.Playback.UserLines.GetMixerFirstLineByComponentType(MIXERLINE_COMPONENTTYPE.DST_SPEAKERS); } }
private void LoadValues(MixerType mixerType) { MixerLine line; //Get info about the lines if (mixerType == MixerType.Recording) { mMixers.Recording.DeviceId = ((MixerDetail)comboBoxRecordingDevices.SelectedItem).DeviceId; line = mMixers.Recording.UserLines.GetMixerFirstLineByComponentType(MIXERLINE_COMPONENTTYPE.SRC_MICROPHONE); trackBarRecordingVolume.Tag = line; trackBarRecordingBalance.Tag = line; //checkBoxSelectMic.Tag = line; checkBoxRecordingMute.Tag = line; _lastMicVolume = line.Volume; line.Selected = true; this.checkBoxRecordingMute.Checked = line.Volume == 0 ? true : false; } else { mMixers.Playback.DeviceId = ((MixerDetail)comboBoxPlaybackDevices.SelectedItem).DeviceId; line = mMixers.Playback.UserLines.GetMixerFirstLineByComponentType(MIXERLINE_COMPONENTTYPE.DST_SPEAKERS); trackBarPlaybackVolume.Tag = line; trackBarPlaybackBalance.Tag = line; checkBoxPlaybackMute.Tag = line; } //If it is 2 channels then ask both and set the volume to the bigger but keep relation between them (Balance) int volume = 0; float balance = 0; if (line.Channels != 2) { volume = line.Volume; } else { line.Channel = Channel.Left; int left = line.Volume; line.Channel = Channel.Right; int right = line.Volume; if (left > right) { volume = left; balance = (volume > 0) ? -(1 - (right / (float)left)) : 0; } else { volume = right; balance = (volume > 0) ? (1 - (left / (float)right)) : 0; } } if (mixerType == MixerType.Recording) { if (volume >= 0) { this.trackBarRecordingVolume.Value = volume; } else { this.trackBarRecordingVolume.Enabled = false; } //MONO OR MORE THAN 2 CHANNELS, then let disable balance if (line.Channels != 2) { this.trackBarRecordingBalance.Enabled = false; } else { this.trackBarRecordingBalance.Value = (int)(trackBarRecordingBalance.Maximum * balance); } } else { if (volume >= 0) { this.trackBarPlaybackVolume.Value = volume; } else { this.trackBarPlaybackVolume.Enabled = false; } //MONO OR MORE THAN 2 CHANNELS, then let disable balance if (line.Channels != 2) { this.trackBarPlaybackBalance.Enabled = false; } else { this.trackBarPlaybackBalance.Value = (int)(trackBarPlaybackBalance.Maximum * balance); } } // checkbox this.checkBoxPlaybackMute.Checked = line.Mute; //this.checkBoxSelectMic.Checked = line.Selected; }