Inheritance: MonoBehaviour
Esempio n. 1
0
 // creates a snippet along with its new AudioData object based on the filename
 public Segment(int id, AudioData audioData)
 {
     init();
     this.AudioData = audioData;
     Id = id;
     this.Name = System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetFileName(audioData.FilePathRelativeToProjectDir));
 }
Esempio n. 2
0
 public override void ReadBlock(FlvContext context)
 {
     base.ReadBlock(context);
     var br = context.Reader;
     var dat = br.ReadBytes((int)this.Header.DataLength);
     data = new AudioData(dat);
     this.Size += this.Header.DataLength;
     context.CurrentPostion += this.Size;
 }
Esempio n. 3
0
 internal int Set(string key, AudioData bmp)
 {
     int id = GetId(key);
     if (id != -1)
     {
         values[id] = bmp;
         return id;
     }
     for (int i = 0; i < max; i++)
     {
         if (keys[i] == null)
         {
             keys[i] = key;
             values[i] = bmp;
             return i;
         }
     }
     return -1;
 }
 public static AudioData[] EditAudioDataArray(GameObject gameObject,
                                              AudioData[] AudioDataArray)
 {
     if (GUILayout.Button ("Add Audio Data")) {
         AudioData audioData = new AudioData ();
         AudioDataArray = Util.AddToArray<AudioData> (audioData, AudioDataArray);
     }
     for(int i=0; i<AudioDataArray.Length; i++)
     {
         AudioData audio = AudioDataArray [i];
         EditorGUILayout.LabelField ("------------------------ " + audio.Name);
         audio.Name = EditorGUILayout.TextField (new GUIContent ("Name", ""), audio.Name);
         audio.randomAudioClips = EditorCommon.EditObjectArray<AudioClip>("Edit Audio clips:", audio.randomAudioClips);
         //Delete this audio data
         if (GUILayout.Button ("Delete AduioData:" + audio.Name)) {
             AudioDataArray = Util.CloneExcept<AudioData> (AudioDataArray, audio);
         }
     }
     EditorGUILayout.Space ();
     return AudioDataArray;
 }
 private static PcmFormat FilterSetup(AudioData from, List<FilterBase> filters)
 {
     var fmt = new PcmFormat(from.meta.channels, from.meta.sampleRate, from.meta.totalSamples);
     foreach (var f in filters) {
         fmt = f.Setup(fmt);
     }
     return fmt;
 }
Esempio n. 6
0
 public int EnqueueSamples(AudioData audioData)
 {
     return EnqueueSamples(audioData.Channels, audioData.Rate, audioData.Samples, audioData.Frames);
 }
Esempio n. 7
0
	void EncodingUpdate()
	{		
		if(Microphone.devices.Length != 0)
		{
			if(m_bRecording == false)
			{
				//if(Input.GetKeyDown(KeyCode.LeftAlt))
				{
					m_acVoiceInput = Microphone.Start(Microphone.devices[0], true, m_kiRecordTime, 44000);
					
					//start timer
					m_fRecordingTimer = 0.0f; 
					m_bRecording = true;
				}
			}			
			else if(m_bRecording)
			{
				m_fRecordingTimer += Time.deltaTime;
								
				if(m_fRecordingTimer >= (float)m_kiRecordTime)
				{
					Microphone.End(Microphone.devices[0]);
					
					// Calculate sound size (To the nearest frame size)
					int iAudioDataSize = m_acVoiceInput.samples * m_acVoiceInput.channels * sizeof(float);
					iAudioDataSize -= iAudioDataSize % m_iFrameSize;
									
					// Extract audio data through the bum
					float[] fAudioData = new float[iAudioDataSize / sizeof(float)];
					m_acVoiceInput.GetData(fAudioData, 0);
					
					// Convert to short
					short[] saAudioData = new short[fAudioData.Length];
			
					for (int i = 0; i < fAudioData.Length; ++i)
					{
						saAudioData[i] = (short)(fAudioData[i] * 32767.0f);
					}					
								
					AudioData voiceData = new AudioData();
					voiceData.iAudioDataSize = iAudioDataSize;
					voiceData.iFrequency = m_acVoiceInput.frequency;
					voiceData.saData = saAudioData;				
					
					m_bEncoding = true;
					
					m_EncodeThread = new Thread(new ParameterizedThreadStart(EncodeAudio));
					m_EncodeThread.Start((object)voiceData);
					
					m_bRecording = false;
				}
			}
		}		
		
		if(!m_EncodeThread.IsAlive && m_bEncoding)
		{
			m_bEncoding = false;
			CNetwork.Connection.TransmitMicrophoneAudio(s_AudioPacket);
			
			s_AudioPacket.Clear();
		}		
	}
Esempio n. 8
0
 public AudioData GetClone()
 {
     AudioData clone = new AudioData();
     clone.Name = this.Name;
     clone.randomAudioClips = randomAudioClips;
     return clone;
 }
 public bool Register(string name, AudioData data)
 {
     if (sounds.ContainsKey (name)) {
         return false;
     }
     sounds.Add (name, data);
     return true;
 }
Esempio n. 10
0
 public override AudioCi AudioCreate(AudioData data)
 {
     return audio.CreateAudio((AudioDataCs)data);
 }
Esempio n. 11
0
    /// <summary>
    /// Initializes this emitter. This is either called from the audio engine if the emitter is static, or from a game object in the world if it's spawned dynamically.
    /// </summary>
    public void Initialize(bool dynamic)
    {
        if (!string.IsNullOrEmpty(audioDataFileName))
        {
            audioData = AudioBank.GetAudioData(audioDataFileName);
            outputRateFactor = (float)audioData.Frequency / AudioSettings.outputSampleRate;
            isCreatedDynamically = dynamic;

            if (is3DSound)
            {
                leftPan = 0.0f;
                rightPan = 0.0f;
            }
        }
    }
        private int SetupResultPcm(AudioData from, out AudioData to, FileFormatType toFileFormat)
        {
            to = new AudioData();
            to.fileFormat = toFileFormat;

            var fmt = FilterSetup(from, mFilters);

            to.meta = new WWFlacRWCS.Metadata(from.meta);
            to.meta.sampleRate = fmt.SampleRate;
            to.meta.totalSamples = fmt.NumSamples;
            to.meta.channels = fmt.Channels;

            switch (toFileFormat) {
            case FileFormatType.FLAC:
            #if true
                to.meta.bitsPerSample = 24;
            #endif
                break;
            case FileFormatType.DSF:
                to.meta.bitsPerSample = 1;
                break;
            }

            if (from.picture != null) {
                to.picture = new byte[from.picture.Length];
                System.Array.Copy(from.picture, to.picture, to.picture.Length);
            }

            // allocate "to" pcm data
            to.pcm = new List<AudioDataPerChannel>();
            for (int ch=0; ch < to.meta.channels; ++ch) {
                byte [] data;

                // set silent sample values to output buffer
                switch (toFileFormat) {
                case FileFormatType.DSF:
                    if (0x7FFFFFC7 < (to.meta.totalSamples + 7) / 8) {
                        return (int)WWFlacRWCS.FlacErrorCode.OutputFileTooLarge;
                    }
                    data = new byte[(to.meta.totalSamples + 7) / 8];
                    for (long i=0; i < data.LongLength; ++i) {
                        data[i] = 0x69;
                    }
                    break;
                case FileFormatType.FLAC:
                    if (0x7FFFFFC7 < to.meta.totalSamples * (to.meta.bitsPerSample / 8)) {
                        return (int)WWFlacRWCS.FlacErrorCode.OutputFileTooLarge;
                    }
                    data = new byte[to.meta.totalSamples * (to.meta.bitsPerSample / 8)];
                    break;
                default:
                    System.Diagnostics.Debug.Assert(false);
                    data = null;
                    break;
                }

                var adp = new AudioDataPerChannel();
                adp.data = data;
                adp.bitsPerSample = to.meta.bitsPerSample;
                adp.totalSamples = to.meta.totalSamples;
                to.pcm.Add(adp);
            }
            return 0;
        }
Esempio n. 13
0
 /** 
     @brief Lock to access the internal storage of a specified format. 
     @param[in]  access		The access mode.
     @param[out] data		The sample data storage, to be returned.
     @return PXCM_STATUS_NO_ERROR	Successful execution.
 */
 public pxcmStatus AcquireAccess(Access access, out AudioData data)
 {
     return AcquireAccess(access, (AudioFormat)0, out data);
 }
Esempio n. 14
0
 public void registerAudioData(Audio_Type type, AudioData data)
 {
     AudioDatas.Add(type, data);
 }
        private static int ReadFlacFile(string path, out AudioData ad)
        {
            ad = new AudioData();

            ad.fileFormat = FileFormatType.FLAC;

            var flac = new WWFlacRWCS.FlacRW();
            int rv = flac.DecodeAll(path);
            if (rv < 0) {
                return rv;
            }

            rv = flac.GetDecodedMetadata(out ad.meta);
            if (rv < 0) {
                return rv;
            }

            rv = flac.GetDecodedPicture(out ad.picture, ad.meta.pictureBytes);
            if (rv < 0) {
                return rv;
            }

            ad.pcm = new List<AudioDataPerChannel>();
            for (int ch=0; ch < ad.meta.channels; ++ch) {
                byte [] data;
                long lrv = flac.GetDecodedPcmBytes(ch, 0, out data, ad.meta.totalSamples * (ad.meta.bitsPerSample / 8));
                if (lrv < 0) {
                    return (int)lrv;
                }

                var adp = new AudioDataPerChannel();
                adp.data = data;
                adp.offsBytes = 0;
                adp.bitsPerSample = ad.meta.bitsPerSample;
                adp.totalSamples = ad.meta.totalSamples;
                ad.pcm.Add(adp);
            }

            flac.DecodeEnd();

            return 0;
        }
Esempio n. 16
0
        /** 
        @brief Unlock the previously acquired buffer.
        @param[in] data		The sample data storage previously acquired.
        @return PXCM_STATUS_NO_ERROR	Successful execution.
        */
        public pxcmStatus ReleaseAccess(AudioData data)
        {
            AudioDataNative dataNative = data as AudioDataNative;
            if (dataNative == null) return pxcmStatus.PXCM_STATUS_HANDLE_INVALID;
            if (dataNative.native == IntPtr.Zero) return pxcmStatus.PXCM_STATUS_HANDLE_INVALID;

            Marshal.WriteInt32(dataNative.native, Marshal.OffsetOf(typeof(AudioData), "dataSize").ToInt32(), unchecked((Int32)data.dataSize));
            pxcmStatus sts = PXCMAudio_ReleaseAccess(instance, dataNative.native);
            Marshal.FreeHGlobal(dataNative.native);
            dataNative.native = IntPtr.Zero;
            return sts;
        }
Esempio n. 17
0
        /** 
        @brief Lock to access the internal storage of a specified format. The function will perform format conversion if unmatched. 
        @param[in]  access		The access mode.
        @param[in]  format		The requested smaple format.
        @param[in]  options     The option flags
        @param[out] data		The sample data storage, to be returned.
        @return PXC_STATUS_NO_ERROR	Successful execution.
        */
        public pxcmStatus AcquireAccess(Access access, AudioFormat format, Option options, out AudioData data)
        {
            AudioDataNative dataNative = new AudioDataNative();
            dataNative.native = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(AudioDataNative)));
            data = dataNative;

            pxcmStatus sts = PXCMAudio_AcquireAccess(instance, access, format, options, dataNative.native);
            if (sts >= pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
                IntPtr native = dataNative.native;
                Marshal.PtrToStructure(dataNative.native, dataNative);
                dataNative.native = native;
            }
            else
            {
                Marshal.FreeHGlobal(dataNative.native);
                dataNative.native = IntPtr.Zero;
            }
            return sts;
        }
 public void AddAudioData(string name, AudioData audioData)
 {
     audioDatas.Add(name, audioData);
 }
Esempio n. 19
0
    /// <summary>
    /// Attempts loading an audio file with a specified filename.
    /// Will throw an exception if the file could not be read for some reason.
    /// This function does only read 16-bit .wav files with no metadata. If the file is not valid then it could lead to corrupt data,
    /// or unhandled exceptions.
    /// </summary>
    /// <param name="filename">The path to the file to be read.</param>
    /// <returns>AudioData, or null.</returns>
    public static AudioData LoadFromFile(string filename)
    {
        AudioData audioData = null;

        using (BinaryReader reader = new BinaryReader(File.OpenRead(filename)))
        {
            Debug.Log("Reading wav: " + filename);

            reader.BaseStream.Seek(22, SeekOrigin.Begin);
            ushort channels = reader.ReadUInt16();
            //Debug.Log("Channels: " + channels);
            uint sampleRate = reader.ReadUInt32();
            //Debug.Log("Sample rate: " + sampleRate);
            reader.BaseStream.Seek(34, SeekOrigin.Begin);
            ushort bitsPerSample = reader.ReadUInt16();
            //Debug.Log("Bits per sample: " + bitsPerSample);
            reader.BaseStream.Seek(40, SeekOrigin.Begin);
            uint numberOfBytes = reader.ReadUInt32();
            //Debug.Log("Number of bytes: " + numberOfBytes);
            uint numberOfSamples = numberOfBytes * 8 / bitsPerSample;
            //Debug.Log("Number of samples: " + numberOfSamples);

            float maxAmplitude = 0.0f;
            float[] data = new float[numberOfSamples * channels];
            //short[] shortData = new short[numberOfSamples * channels];
            byte[] buffer = new byte[numberOfBytes];

            if (bitsPerSample / 8 == 2)
            {

                reader.BaseStream.Seek(44, SeekOrigin.Begin);
                buffer = reader.ReadBytes((int)numberOfBytes);

                int bufferStep = 0;
                for (int i = 0; i < numberOfSamples && bufferStep < buffer.Length; i++)
                {
                    float sample = (float)BitConverter.ToInt16(buffer, bufferStep) / Int16.MaxValue;

                    float abs = Mathf.Abs(sample);
                    if (abs > maxAmplitude)
                        maxAmplitude = abs;

                    data[i] = sample;
                    bufferStep += 2;
                }
            }
            else
                Debug.LogWarning(filename + "is not a 16-bit wav.");

            audioData = new AudioData(data, (int)channels, (int)sampleRate, maxAmplitude, (int)numberOfSamples / (int)channels);
        }

        return audioData;
    }
Esempio n. 20
0
 public override bool AudioDataLoaded(AudioData data)
 {
     return true;
 }
        private static int WriteFlacFile(ref AudioData ad, string path)
        {
            int rv;
            var flac = new WWFlacRWCS.FlacRW();
            rv = flac.EncodeInit(ad.meta);
            if (rv < 0) {
                return rv;
            }

            rv = flac.EncodeSetPicture(ad.picture);
            if (rv < 0) {
                flac.EncodeEnd();
                return rv;
            }

            for (int ch=0; ch < ad.meta.channels; ++ch) {
                long lrv = flac.EncodeAddPcm(ch, ad.pcm[ch].data);
                if (lrv < 0) {
                    flac.EncodeEnd();
                    return (int)lrv;
                }
            }

            rv = flac.EncodeRun(path);
            if (rv < 0) {
                flac.EncodeEnd();
                return rv;
            }

            flac.EncodeEnd();
            return 0;
        }
Esempio n. 22
0
 public abstract AudioCi AudioCreate(AudioData data);
Esempio n. 23
0
 public abstract bool AudioDataLoaded(AudioData data);
Esempio n. 24
0
 /** 
     @brief Lock to access the internal storage of a specified format. The function will perform format conversion if unmatched. 
     @param[in]  access		The access mode.
     @param[in]  format		The requested smaple format.
     @param[out] data		The sample data storage, to be returned.
     @return PXCM_STATUS_NO_ERROR	Successful execution.
 */
 public pxcmStatus AcquireAccess(Access access, AudioFormat format, out AudioData data)
 {
     return AcquireAccess(access, format, 0, out data);
 }