// Prepares for recording and sets the state that the audio thread stream callback is monitoring void StartRecording(int numSamples) { if (_leftData != null) // We've already recorded something, let's free the data { _leftData.Release(); // Note that releasing data won't stop playback, as the player retains it too. _rightData.Release(); // Also note that Release() only has an effect if it was allocated in G-Audio's virtual memory. } if (_useManagedMemory) { _leftData = GATManager.GetDataContainer(numSamples); //Ask the manager for an empty container of appropriate size _rightData = GATManager.GetDataContainer(numSamples); } else { _leftData = new GATData(new float[numSamples]); // Make the container ourselves, allocating float arrays manually. _rightData = new GATData(new float[numSamples]); } _leftData.Retain(); // Retain the data, otherwise the player will free it at the end of playback. _rightData.Retain(); // Just as Release, this has no effect on manually allocated arrays. _recOffset = 0; // reset the offset _state = State.Recording; // update state }
protected override void ButtonClicked(int buttonIndex) { string sampleName = ButtonLabels[buttonIndex]; //since the button labels are the sample names, we can just grab the string at buttonIndex float gain = SliderValues[buttonIndex]; //and the gain value according to the corresponding slider's value //Get the audio data from the bank GATData sampleData = sampleBank.GetAudioData(sampleName); // And play it through the default player, at track TrackNb, and specified gain. GATManager.DefaultPlayer.PlayData(sampleData, TrackNb, gain); }
protected override void ButtonClicked(int buttonIndex) { //Simple, unprocessed playback through the selected track. We'll focus on recording, not processing. string sampleName = ButtonLabels[buttonIndex]; float gain = SliderValues[buttonIndex]; //Grab the audio data from the bank GATData sampleData = sampleBank.GetAudioData(sampleName); // And play it through the default player, at track _trackNb, and specified gain. GATManager.DefaultPlayer.PlayData(sampleData, TrackNb, gain); }
public RecInfo(int numSamples, int numChannels, int itrackNb) { int i; data = new GATData[numChannels]; for (i = 0; i < numChannels; i++) { data[i] = new GATData(new float[numSamples]); } trackNb = itrackNb; Track = GATManager.DefaultPlayer.GetTrack(trackNb); }
protected override void ButtonClicked(int buttonIndex) { if (_realTimeSample != null) { if (_realTimeSample.PlayingStatus == GATRealTimeSample.Status.Playing) // If a sample is already playing, we stop it { _realTimeSample.FadeOutAndStop(.5d); //fade occurs at buffer level, no coroutines, no pops. } } string sampleName = ButtonLabels[buttonIndex]; // get the name of the clicked sample float pitch = SliderValues[buttonIndex]; // and the value of the corresponding slider GATData sampleData = sampleBank.GetAudioData(sampleName); // grab the audio data from the bank _realTimeSample = new GATRealTimeSample(sampleData); // wrap in a GATRealTimeSample for realtime monitoring and control _realTimeSample.Loop = true; _realTimeSample.Pitch = pitch; // set pitch _realTimeSample.PlayThroughTrack(TrackNb); // and play. Note that we ask the GATRealTimeInstance to play directly. There are many overloaded // Play methods - this is the simplest and routes playback through the default player. _playingSampleIndex = buttonIndex; // cache the index of the sample for easy monitoring of sliders ( see below ) }
public override void OnInspectorGUI() { int i; GATSoundBank soundBank; base.OnInspectorGUI(); if (_sampleBank == null) { return; } GUILayout.Space(5f); EditorGUIUtility.fieldWidth = 70f; for (i = 0; i < _sampleBank.SoundBanks.Count; i++) { soundBank = _sampleBank.SoundBanks[i]; GUILayout.BeginHorizontal(); _sampleBank.SoundBanks[i] = EditorGUILayout.ObjectField(soundBank, typeof(GATSoundBank), false, GUILayout.ExpandWidth(false)) as GATSoundBank; if (GUI.changed) { CheckBanks(_sampleBank.SoundBanks[i], i); } if (soundBank != null) { GUILayout.Label(soundBank.SampleRate.ToString() + " khz", GUILayout.Width(60f)); } else { GUILayout.Space(64f); } if (i > 0) { GUI.color = Color.red; if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.Width(20f))) { _sampleBank.SoundBanks.RemoveAt(i); _sampleBank.EditorUpdateSoundBank(); break; } GUI.color = Color.white; } GUILayout.EndHorizontal(); } if (GUILayout.Button("Add Bank", GUILayout.Width(65f))) { _sampleBank.SoundBanks.Add(null); } if (_sampleBank.IsLoaded == false) { _sampleBank.extraCapacity = EditorGUILayout.IntField("Extra Capacity", _sampleBank.extraCapacity, GUILayout.ExpandWidth(false)); } if (_sampleBank.SoundBank != null) { if (_sampleBank.IsLoaded) { GUI.enabled = false; } EditorGUIUtility.labelWidth = 100f; EditorGUIUtility.fieldWidth = 80f; GUILayout.BeginHorizontal(); _sampleBank.AllocationMode = ( GATDataAllocationMode )EditorGUILayout.EnumPopup("Allocation Mode:", _sampleBank.AllocationMode, GUILayout.ExpandWidth(false)); GUI.enabled = true; if (_sampleBank.IsLoaded == false) { GUI.color = Color.green; if (GUILayout.Button("Load", __buttonOptions)) { _sampleBank.LoadAll(); } } else { GUI.color = Color.red; if (GUILayout.Button("Unload", __buttonOptions)) { _sampleBank.UnloadAll(); _sampleBank.AutoLoadInEditMode = false; } } GUILayout.EndHorizontal(); GUI.color = Color.white; _sampleBank.LoadInAwake = GUILayout.Toggle(_sampleBank.LoadInAwake, "Load in Awake", GUILayout.Width(120f)); bool autoLoad = _sampleBank.AutoLoadInEditMode; _sampleBank.AutoLoadInEditMode = GUILayout.Toggle(_sampleBank.AutoLoadInEditMode, "Auto Load in Edit Mode", GUILayout.Width(150f)); if (Application.isPlaying == false && autoLoad != _sampleBank.AutoLoadInEditMode) { if (autoLoad) { if (_sampleBank.IsLoaded) { _sampleBank.UnloadAll(); } } else { if (_sampleBank.IsLoaded == false) { _sampleBank.LoadAll(); } } } if (_sampleBank.IsLoaded == false) { return; } GUI.color = __purpleColor; string[] allNames = _sampleBank.AllSampleNames; foreach (string sampleName in allNames) { if (GUILayout.Button(sampleName, __largeButtonOptions)) { GATData data = _sampleBank.GetAudioData(sampleName); GATManager.DefaultPlayer.PlayData(data, 0); } } } else { EditorGUILayout.HelpBox(string.Format("None of the specified SoundBanks match your current {0}kHz sample rate.", GATInfo.OutputSampleRate), MessageType.Warning); } }
void OnRecEnd( GATData[] caches, bool willLoop ) { if( willLoop == false ) { _state = State.IdleRecInMemory; } }
void UnitSounds() { while (GATManager.DefaultPlayer.NbOfTracks < 4) { GATManager.DefaultPlayer.AddTrack <GATTrack>(); } List <string> notes = new List <string>(); foreach (UnitScript u in units) { int register; switch (u.currType) { case PuppetType.TREBLE: register = Random.Range(3, 4); break; case PuppetType.BASS: register = Random.Range(1, 2); break; default: register = 3; break; } if (u == null || u.gameObject == null) { continue; } switch (u.currAction) { case ConstFile.Actions.MOVE_ENEMY: for (int i = 0; i < numNotes; i++) { if (midzoneArr[i].InZone(u.gameObject.transform.position.y)) { float arenaWidth = right.position.x - left.position.x; float percent = (u.gameObject.transform.position.x - left.position.x) / arenaWidth; int trackNumber = 0; string noteName; if (u.team == 0) { noteName = midzoneArr[(i + 2) % numNotes].name; } else { noteName = midzoneArr[i].name; percent = 1 - percent; } noteName = string.Format(noteName, register); if (!notes.Contains(noteName)) { GATData mySampleData = sampleBank.GetAudioData(string.Format(noteName, register)); GATManager.DefaultPlayer.PlayData(mySampleData, trackNumber, percent); notes.Add(noteName); } } } break; case ConstFile.Actions.MOVE_BACK: for (int i = 0; i < numNotes; i++) { if (midzoneArr[i].InZone(u.gameObject.transform.position.y)) { float arenaWidth = right.position.x - left.position.x; float percent = (u.gameObject.transform.position.x - left.position.x) / arenaWidth; int trackNumber = 1; string noteName; if (u.team == 0) { noteName = midzoneArr[(i + 2) % numNotes].name; } else { noteName = midzoneArr[i].name; percent = 1 - percent; } noteName = string.Format(noteName, register); if (!notes.Contains(noteName)) { GATData mySampleData = sampleBank.GetAudioData(string.Format(noteName, register)); GATManager.DefaultPlayer.PlayData(mySampleData, trackNumber, percent); notes.Add(noteName); } } } break; case ConstFile.Actions.MOVE_FORWARD: for (int i = 0; i < numNotes; i++) { if (midzoneArr[i].InZone(u.gameObject.transform.position.y)) { float arenaWidth = right.position.x - left.position.x; float percent = (u.gameObject.transform.position.x - left.position.x) / arenaWidth; int trackNumber = 2; string noteName; if (u.team == 0) { noteName = midzoneArr[(i + 2) % numNotes].name; } else { noteName = midzoneArr[i].name; percent = 1 - percent; } noteName = string.Format(noteName, register); if (!notes.Contains(noteName)) { GATData mySampleData = sampleBank.GetAudioData(string.Format(noteName, register)); GATManager.DefaultPlayer.PlayData(mySampleData, trackNumber, percent); notes.Add(noteName); } } } break; case ConstFile.Actions.ATTACK: for (int i = 0; i < numNotes; i++) { if (midzoneArr[i].InZone(u.gameObject.transform.position.y)) { float arenaWidth = right.position.x - left.position.x; float percent = (u.gameObject.transform.position.x - left.position.x) / arenaWidth; int trackNumber = 3; string noteName; if (u.team == 0) { noteName = midzoneArr[(i + 2) % numNotes].name; } else { noteName = midzoneArr[i].name; percent = 1 - percent; } GATData mySampleData = sampleBank.GetAudioData(string.Format(noteName, register + 1)); GATManager.DefaultPlayer.PlayData(mySampleData, trackNumber, percent); } } break; case ConstFile.Actions.REST: // no sound break; } } }
public RecInfo( int numSamples, int numChannels, int itrackNb ) { int i; data = new GATData[ numChannels ]; for( i = 0; i < numChannels; i++ ) { data[ i ] = new GATData( new float[ numSamples ] ); } trackNb = itrackNb; Track = GATManager.DefaultPlayer.GetTrack( trackNb ); }
// delegate method called by streamToCache void RecAtEnd( GATData[] caches, bool willLoop ) { _recState = RecState.Idle; }