Пример #1
0
    public override void Initialize(System.IO.BinaryReader reader, RecordHeader header)
    {
        while (reader.BaseStream.Position < header.DataEndPos)
        {
            var subRecordType = (SubRecordType)reader.ReadInt32();
            var size          = reader.ReadInt32();

            switch (subRecordType)
            {
            case SubRecordType.Id:
                name = reader.ReadString(size);
                break;

            case SubRecordType.Data:
                type = (SoundGeneratorType)reader.ReadInt32();
                break;

            case SubRecordType.SoundName:
                sound = Record.GetRecord <SoundRecord>(reader.ReadString(size));
                break;

            case SubRecordType.CreatureName:
                creature = Record.GetRecord <CreatureRecord>(reader.ReadString(size));
                break;

            default:
                throw new NotImplementedException(subRecordType.ToString());
            }
        }
    }
Пример #2
0
        public async Task <IHttpActionResult> PutSoundRecord(int id, SoundRecord soundRecord)
        {
            if (!this.ModelState.IsValid)
            {
                return(BadRequest(this.ModelState));
            }

            if (id != soundRecord.Id)
            {
                return(BadRequest());
            }

            this.db.Entry(soundRecord).State = EntityState.Modified;

            try
            {
                await this.db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SoundRecordExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #3
0
    public override void Initialize(System.IO.BinaryReader reader, RecordHeader header)
    {
        while (reader.BaseStream.Position < header.DataEndPos)
        {
            var type = (SubRecordType)reader.ReadInt32();
            var size = reader.ReadInt32();

            switch (type)
            {
            case SubRecordType.Id:
                name = reader.ReadString(size);
                break;

            case SubRecordType.Model:
                model = reader.ReadString(size);
                break;

            case SubRecordType.Name:
                fullName = reader.ReadString(size);
                break;

            case SubRecordType.Script:
                script = Script.Get(reader.ReadString(size));
                break;

            case SubRecordType.SoundName:
                openSound = Record.GetRecord <SoundRecord>(reader.ReadString(size));
                break;

            case SubRecordType.Anam:
                closeSound = Record.GetRecord <SoundRecord>(reader.ReadString(size));
                break;
            }
        }
    }
Пример #4
0
        public async Task <IHttpActionResult> GetSoundRecord(int id)
        {
            SoundRecord soundRecord = await this.db.SoundRecords.FindAsync(id);

            if (soundRecord == null)
            {
                return(NotFound());
            }

            return(Ok(soundRecord));
        }
Пример #5
0
        public async Task <IHttpActionResult> PostSoundRecord(SoundRecord soundRecord)
        {
            if (!this.ModelState.IsValid)
            {
                return(BadRequest(this.ModelState));
            }

            this.db.SoundRecords.Add(soundRecord);
            await this.db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = soundRecord.Id }, soundRecord));
        }
Пример #6
0
        public async Task <IHttpActionResult> DeleteSoundRecord(int id)
        {
            SoundRecord soundRecord = await this.db.SoundRecords.FindAsync(id);

            if (soundRecord == null)
            {
                return(NotFound());
            }

            this.db.SoundRecords.Remove(soundRecord);
            await this.db.SaveChangesAsync();

            return(Ok(soundRecord));
        }
Пример #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            recorder = new SoundRecord();
            hwCTime  = pfunction.ToShortDate(Request["hwCTime"].Filter());
            stuHwId  = Request["stuHwId"].Filter();
            tqId     = Request["tqId"].Filter();
            string filePath = string.Format("/Upload/Resource/teacherRecording/{0}/{1}/{2}.wav"
                                            , pfunction.ToShortDate(hwCTime), stuHwId, tqId);

            if (File.Exists(Server.MapPath(filePath)))
            {
                recordingPath = filePath + "?" + DateTime.Now.ToString();
            }
        }
Пример #8
0
        private static SoundRecord GetSoundLevel()
        {
            int venueId       = _rnd.Next(1, 13);
            int sectionNumber = _rnd.Next(1, 11);
            int seatSectionId = ((venueId - 1) * 10) + sectionNumber;

            // Read SeatCount from SeatSection table for calculated SectionId
            int seatCount = _seatSectionRepository.GetSeatCount(seatSectionId);

            // Generate a SeatNumber between 1 and SeatCount read above
            int seatNumber = _rnd.Next(1, seatCount + 1);
            int deviceId   = seatNumber + _seatSectionRepository.CalculateSum(venueId, seatSectionId);

            DateTime currentDateTime = DateTime.UtcNow;
            int      decibelLevel    = GetDecibelLevel(currentDateTime.Minute, deviceId);

            decimal longitude = 0;
            decimal latitude  = 0;

            // Get venue details from repo
            var venueModel = _venueRepository.GetVenueInformation(venueId);

            if (venueModel != null)
            {
                longitude = venueModel.Longitude;
                latitude  = venueModel.Latitude;
            }

            SoundRecord soundRecord = new SoundRecord
            {
                DateTime = currentDateTime.ToString("o"),
                Location = new SoundRecord.GeoLocation()
                {
                    Type        = "Point",
                    Coordinates = new List <decimal>()
                    {
                        longitude,
                        latitude
                    }
                },
                DecibelLevel = decibelLevel,
                DeviceId     = deviceId,
                VenueId      = venueId,
                Seat         = seatNumber,
                SeatSection  = sectionNumber
            };

            return(soundRecord);
        }
Пример #9
0
        public static string StopRecording()
        {
            try
            {
                recorder.RecStop();
                recorder = null;
                recorder = new SoundRecord();

                return("0");
            }
            catch (Exception)
            {
                return("1");
            }
        }
Пример #10
0
        public void SendInfo(SoundRecord soundRecord)
        {
            var eventHubClient = EventHubClient.CreateFromConnectionString(CloudConfiguration.EventHubConnString, CloudConfiguration.EventHubName);

            try
            {
                var jsonData = JsonConvert.SerializeObject(soundRecord);
                Console.WriteLine("{0} > Sending message to Event Hub: {1}", DateTime.Now, jsonData);
                eventHubClient.Send(new EventData(Encoding.UTF8.GetBytes(jsonData)));
            }
            catch (Exception exception)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("{0} > Exception: {1}", DateTime.Now, exception.Message);
                Console.ResetColor();
            }
        }
Пример #11
0
        public async void SendInfo(SoundRecord soundRecord)
        {
            Uri    endpointUri      = new Uri(CloudConfiguration.DocumentDbUri);
            string authorizationKey = CloudConfiguration.DocumentDbKey;

            _documentClient = new DocumentClient(endpointUri, authorizationKey);

            var collection = await GetDocumentCollection();

            try
            {
                Console.WriteLine("{0} > Sending message to Document DB: {1}", DateTime.Now, soundRecord);
                var result = await _documentClient.CreateDocumentAsync(collection.SelfLink, soundRecord);
            }
            catch (Exception exception)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("{0} > Exception: {1}", DateTime.Now, exception.Message);
                Console.ResetColor();
            }
        }
Пример #12
0
    public SoundName(System.IO.BinaryReader reader, int size)
    {
        var bytes = reader.ReadBytes(32);

        // Has lots of junk after string, so find the first null character
        int index = 32;

        for (var i = 0; i < bytes.Length; i++)
        {
            if (bytes[i] == 0)
            {
                index = i;
                break;
            }
        }

        var sound = System.Text.Encoding.ASCII.GetString(bytes, 0, index);

        this.sound = Record.GetRecord <SoundRecord>(sound);
        chance     = reader.ReadByte();
    }
Пример #13
0
        public override void Initialize(System.IO.BinaryReader reader, RecordHeader header)
        {
            while (reader.BaseStream.Position < header.DataEndPos)
            {
                var type = (SubRecordType)reader.ReadInt32();
                var size = reader.ReadInt32();

                switch (type)
                {
                case SubRecordType.Id:
                    name = reader.ReadString(size);
                    break;

                case SubRecordType.Model:
                    model = reader.ReadString(size);
                    break;

                case SubRecordType.Name:
                    fullName = reader.ReadString(size);
                    break;

                case SubRecordType.Script:
                    script = Script.Get(reader.ReadString(size));
                    break;

                case SubRecordType.ItemTexture:
                    CreateSprite(reader.ReadString(size));
                    break;

                case SubRecordType.LightData:
                    data = new LightRecordData(reader);
                    break;

                case SubRecordType.SoundName:
                    sound = Record.GetRecord <SoundRecord>(reader.ReadString(size));
                    break;
                }
            }
        }
Пример #14
0
 void FixedUpdate()
 {
     if (listener.soundMemory.Count > 0)
     {
         SoundRecord maxSound = null;
         foreach (SoundRecord sound in listener.soundMemory)
         {
             if (maxSound == null || sound.soundType.CompareTo(maxSound.soundType) > 0)
             {
                 maxSound = sound;
             }
             if (sound.soundType.CompareTo(maxSound.soundType) == 0 && sound.effectiveSoundLevel > maxSound.effectiveSoundLevel)
             {
                 maxSound = sound;
             }
         }
         if (maxSound != null)
         {
             control.moveTargetPoint = maxSound.location;
             listener.soundMemory.Clear();
         }
     }
 }
Пример #15
0
 private static SoundRecord recorder = null;    // 录音
 protected void Page_Load(object sender, EventArgs e)
 {
     recorder = new SoundRecord();
 }
Пример #16
0
 private void button2_Click(object sender, EventArgs e)
 {
     recorder.RecStop();
     recorder = null;
     string inputFile =Application.StartupPath + "\\__record__.wav";
     string outputFile =Application.StartupPath + "\\data\\"+this.hashName+"_"+bm.CurrentVal()+"_"+0+".mp3";
     compress(inputFile, outputFile);
 }
Пример #17
0
 private void button3_Click(object sender, EventArgs e)
 {
     if (recorder == null)
         recorder = new SoundRecord();
     string wavfile = Application.StartupPath + "\\__record__.wav";
     recorder.SetFileName(wavfile);
     recorder.RecStart();
 }
    //##############################################################################################
    // Iterate over the sounds, cleaning up finished sounds, and applying occlusion where necessary
    // This is done in late update, in the hopes that most objects are done moving around by then.
    //##############################################################################################
    void LateUpdate()
    {
        float deltaTime = Time.deltaTime;

        for (int i = 0, c = usedSources.Count; i < c; ++i)
        {
            if (usedSources[i].isPlaying)
            {
                SoundRecord record = records[i];

                // Place the sound in the correct position
                if (record.parent)
                {
                    usedSources[i].transform.position = record.parent.transform.position;
                }

                if ((record.features & SoundFeatures.ThreeDimensional) != 0)
                {
                    // Simualate the dynamic reverb if update time elapsed
                    if ((record.features & SoundFeatures.DynamicSimulatedReverb) != 0)
                    {
                        record.timeUntilReverbUpdate -= deltaTime;

                        if (record.timeUntilReverbUpdate <= 0.0f)
                        {
                            record.previousVolumeNormalized = record.physicalVolumeNormalized;

                            float physicalVolumeNormalized = CalculatePhysicalVolumeNormalized(record.parent);
                            record.physicalVolumeNormalized = physicalVolumeNormalized;

                            record.timeUntilReverbUpdate = REVERB_UPDATE_TIME;
                        }

                        float physicalVolume = CustomMath.StepToTarget(
                            record.previousVolumeNormalized,
                            record.physicalVolumeNormalized,
                            (1 / REVERB_UPDATE_TIME) * deltaTime
                            );

                        ApplyReverbFromPhysicalVolume(record.reverb, physicalVolume);
                    }

                    // Simualate the dynamic occlusion if update time elapsed
                    if ((record.features & SoundFeatures.DynamicOcclusion) != 0)
                    {
                        record.timeUntilOcclusionUpdate -= deltaTime;

                        if (record.timeUntilOcclusionUpdate <= 0.0f)
                        {
                            record.previousOcclusion = record.currentOcclusion;
                            record.currentOcclusion  = Occluded(record.parent);

                            record.timeUntilOcclusionUpdate = OCCLUSION_UPDATE_TIME;
                        }

                        float occlusion = CustomMath.StepToTarget(
                            record.previousOcclusion,
                            record.currentOcclusion,
                            (1 / OCCLUSION_UPDATE_TIME) * deltaTime
                            );

                        record.previousOcclusion = occlusion;

                        ApplyOcclusion(record.lowPassFilter, occlusion);
                    }
                }
            }
            else
            {
                // If source is not playing, return to the unused sources
                usedSources[i].Stop();
                unusedSources.Enqueue(usedSources[i]);

                usedSources.RemoveAt(i);
                records.RemoveAt(i);

                c = usedSources.Count;
            }
        }

        #if UNITY_EDITOR
        if (usedSources.Count != records.Count)
        {
            Logger.Error("Mismatched used sources and records count!");
        }
        #endif // UNITY_EDITOR
    }
    //##############################################################################################
    // This is the primary function for how a sound is set up and played TODO TODO
    //
    // This function returns the sound id of the record, for reference later. For example, a loop
    // can be started and the id cached, then stopped at a later time, using that id.
    //##############################################################################################
    public int PlaySoundInternal(SoundAsset asset, GameObject transformObject)
    {
        if (asset == null || asset.clip == null || asset.volume <= 0.0f)
        {
            return(INVALID_SOUND);
        }

        int index = GetValidSoundIndex(asset.priority);

        if (index != INVALID_SOUND)
        {
            AudioSource        source        = usedSources[index];
            AudioReverbFilter  reverb        = source.GetComponent <AudioReverbFilter>();
            AudioLowPassFilter lowPassFilter = source.GetComponent <AudioLowPassFilter>();

            // Setup source
            source.Stop();
            source.clip = asset.clip;
            source.loop = (asset.count == SoundCount.Looping);

            // Randomize the pitch if needed
            if (asset.pitchBend > 0.0f)
            {
                source.pitch = 1.0f + (Random.value * asset.pitchBend) - (asset.pitchBend * 0.5f);
            }
            else
            {
                source.pitch = 1.0f;
            }

            // Apply volume
            source.volume = asset.volume * globalVolume;

            // Position immediately before next update
            source.gameObject.transform.position = transformObject == null ? Vector3.zero : transformObject.transform.position;

            // setup records
            SoundRecord record = records[index];
            record.volume   = asset.volume;
            record.features = asset.features;
            record.priority = asset.priority;
            record.soundId  = soundIdIndex;
            record.parent   = transformObject;

            record.reverb        = reverb;
            record.lowPassFilter = lowPassFilter;

            soundIdIndex++;

            // Set defaults for advanced features
            bool delayed = false;
            reverb.reverbPreset           = AudioReverbPreset.Off;
            lowPassFilter.cutoffFrequency = SoundConstants.LPF_CLEAR;
            source.spatialBlend           = SoundConstants.SPATIAL_BLEND_TWO_D;

            // Advanced features require three-dimensional spatialization and a valid transform
            if ((asset.features & SoundFeatures.ThreeDimensional) != 0)
            {
                if (transformObject != null)
                {
                    source.spatialBlend = SoundConstants.SPATIAL_BLEND_THREE_D;

                    if ((asset.features & SoundFeatures.SimulatedReverb) != 0)
                    {
                        float physicalVolumeNormalized = CalculatePhysicalVolumeNormalized(record.parent);
                        ApplyReverbFromPhysicalVolume(reverb, physicalVolumeNormalized);

                        record.timeUntilReverbUpdate    = REVERB_UPDATE_TIME;
                        record.previousVolumeNormalized = physicalVolumeNormalized;
                        record.physicalVolumeNormalized = physicalVolumeNormalized;
                    }

                    if ((asset.features & SoundFeatures.Occlusion) != 0)
                    {
                        // Mark previous occlusion as invalid to immediately apply
                        record.currentOcclusion  = Occluded(transformObject);
                        record.previousOcclusion = record.currentOcclusion;

                        record.timeUntilOcclusionUpdate = OCCLUSION_UPDATE_TIME;

                        ApplyOcclusion(lowPassFilter, record.currentOcclusion);
                    }

                    if ((asset.features & SoundFeatures.DistanceDelayed) != 0)
                    {
                        delayed = true;
                    }

                    if ((asset.features & SoundFeatures.EmitsSlapbacks) != 0)
                    {
                        // TODO Shoot ray away from listener, and create delayed slapback at that point?
                    }

                    if ((asset.features & SoundFeatures.Doppler) != 0)
                    {
                        source.dopplerLevel = SoundConstants.DOPPLER_ON;
                    }
                    else
                    {
                        source.dopplerLevel = SoundConstants.DOPPLER_OFF;
                    }
                }

                if (transformObject == null && asset.features != 0)
                {
                    Logger.Error("All Sound Assets with Sound Features require a transform object as an argument.");
                    record.features = 0;
                }
            }

            // play the sound unless delayed
            if (!delayed)
            {
                source.Play();
            }

            return(records[index].soundId);
        }
        else
        {
            Logger.Warning("Failed to play " + asset.clip + " with priority " + asset.priority);
            return(INVALID_SOUND);
        }
    }