예제 #1
0
        private void StartButton_Click(object sender, EventArgs e)
        {
            StartButton.Enabled = false;
            try
            {
                recordLength = System.Convert.ToInt32(timeTextBox.Text.ToString());
            }
            catch (Exception _Exception)
            {
                messageTextBox.Text = _Exception.ToString();
                return;
            }

            if (recordLength <= 0)
            {
                messageTextBox.Text = "Please input a valid record time";
                return;
            }

            DateTime CurrTime = DateTime.Now;
            String format = "MMM-ddd-d-HH-mm-ss-yyyy";
            prefix = CurrTime.ToString(format);
            String newPath = System.IO.Path.Combine(prefix);
            System.IO.Directory.CreateDirectory(newPath);

            // Phidgets Sensor
            phidgets = phidgetsCheckBox.Checked;
            if (phidgets)
            {
                // Phidgets Sensor
                spatial = new Spatial();
                //Hook the basic event handlers
                spatial.Attach += new AttachEventHandler(accel_Attach);
                spatial.Detach += new DetachEventHandler(accel_Detach);
                spatial.Error += new Phidgets.Events.ErrorEventHandler(accel_Error);

                //hook the phidget specific event handlers
                spatial.SpatialData += new SpatialDataEventHandler(spatial_SpatialData);

                //open the acclerometer object for device connections
                spatial.open();

                //get the program to wait for an spatial device to be attached
                messageTextBox.Text += "Waiting for spatial to be attached....";

                spatial.waitForAttachment();

                //Set the data rate so the events aren't crazy
                spatial.DataRate = 496; //multiple of 8

                String phidgetTimestamp = System.IO.Path.Combine(newPath, prefix + "-phidget.txt");
                twPhidgetTimestamp = new StreamWriter(phidgetTimestamp);
            }

            // GPS
            if (gpsCheckBox.Checked == true)
            {
                String gpsFileName = System.IO.Path.Combine(newPath, prefix + "-gps.txt");
                readGPS = new ReadGPS("COM" + gpsCom.Text, gpsFileName);
                readGPS.start();
            }

            // Color
            firstColorFrame = true;
            String colorFileName = System.IO.Path.Combine(newPath, prefix + "-color.avi");
            String colorTimestamp = System.IO.Path.Combine(newPath, prefix + "-color.txt");
            aviColorManager = new AviManager(colorFileName, false);
            twColorTimestamp = new StreamWriter(colorTimestamp);

            // Depth
            rawDepth = rawDepthCheckBox.Checked;
            firstDepthFrame = true;
            String depthFileName;
            if (rawDepth)
            {
                depthFileName = System.IO.Path.Combine(newPath, prefix + "-depth.data");
                rawDepthBinaryWriter = new BinaryWriter(File.OpenWrite(depthFileName));
            }
            else
            {
                depthFileName = System.IO.Path.Combine(newPath, prefix + "-depth.avi");
                aviDepthManager = new AviManager(depthFileName, false);
            }
            String depthTimestamp = System.IO.Path.Combine(newPath, prefix + "-depth.txt");
            twDepthTimestamp = new StreamWriter(depthTimestamp);

            kinect.VideoFrameReady += new EventHandler<ImageFrameReadyEventArgs>(kinect_VideoFrameReady);
            kinect.DepthFrameReady += new EventHandler<ImageFrameReadyEventArgs>(kinect_DepthFrameReady);

            kinect.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480, ImageType.Color);
            kinect.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution640x480, ImageType.Depth);

            // Kinect Audio
            String kinectAudioFileName = System.IO.Path.Combine(newPath, prefix + "-kinect-audio.wav");
            String kinectAudioTimestamp = System.IO.Path.Combine(newPath, prefix + "-kinect-audio.txt");
            kinectAudioRecordProcess = new System.Diagnostics.Process();
            //p.StartInfo.WorkingDirectory = @"C:\whatever";
            kinectAudioRecordProcess.StartInfo.FileName = @"AudioCaptureRaw.exe";
            kinectAudioRecordProcess.StartInfo.CreateNoWindow = true;
            kinectAudioRecordProcess.StartInfo.Arguments = recordLength + " " + kinectAudioFileName + " " + kinectAudioTimestamp;
            kinectAudioRecordProcess.Start();

            // Headset Audio
            if (headsetAudioCheckBox.Checked == true)
            {
                String headsetAudioFileName = System.IO.Path.Combine(newPath, prefix + "-headset-audio.wav");
                String headsetAudioTimestamp = System.IO.Path.Combine(newPath, prefix + "-headset-audio.txt");
                headsetAudio = new HeadsetAudio("Shure Digital", headsetAudioFileName);
                tw = new StreamWriter(headsetAudioTimestamp);
                CurrTime = DateTime.Now;
                tw.WriteLine(CurrTime.ToString("yyyy-MM-dd HH:mm:ss.fffffff"));
                headsetAudio.start();
                tw.Close();
            }

            this.startTime = DateTime.Now;
            messageTextBox.Text = "Started";

            this.timer = new System.Windows.Forms.Timer();
            this.timer.Enabled = true;
            this.timer.Interval = 1000;
            this.timer.Tick += new System.EventHandler(this.timer_Tick);
            // one channel audio record
            //audioRecord = true;
            //recordAudioThread = new Thread(new ThreadStart(recordAudio));
            //recordAudioThread.Start();
        }
예제 #2
0
 /// <summary>Add a wave audio stream from another file to this file</summary>
 /// <param name="waveFileName">Name of the wave file to add</param>
 /// <param name="startAtFrameIndex">Index of the video frame at which the sound is going to start</param>
 public void AddAudioStream(String waveFileName, int startAtFrameIndex)
 {
     AviManager audioManager = new AviManager(waveFileName, true);
     AudioStream newStream = audioManager.GetWaveStream();
     AddAudioStream(newStream, startAtFrameIndex);
     audioManager.Close();
 }
예제 #3
0
        /// <summary>Copy all frames into a new file</summary>
        /// <param name="fileName">Name of the new file</param>
        /// <param name="recompress">true: Compress the new stream</param>
        /// <returns>AviManager for the new file</returns>
        /// <remarks>Use this method if you want to append frames to an existing, compressed stream</remarks>
        public AviManager DecompressToNewFile(String fileName, bool recompress, out VideoStream newStream2)
        {
            AviManager newFile = new AviManager(fileName, false);

            this.GetFrameOpen();

            Bitmap frame = GetBitmap(0);
            VideoStream newStream = newFile.AddVideoStream(recompress, frameRate, frame);
            frame.Dispose();

            for(int n=1; n<countFrames; n++){
                frame = GetBitmap(n);
                newStream.AddFrame(frame);
                frame.Dispose();
            }

            this.GetFrameClose();

            newStream2 = newStream;
            return newFile;
        }
예제 #4
0
        /// <summary>Copy a piece of video and wave sound int a new file</summary>
        /// <param name="newFileName">File name</param>
        /// <param name="startAtSecond">Start copying at second x</param>
        /// <param name="stopAtSecond">Stop copying at second y</param>
        /// <returns>AviManager for the new video</returns>
        public AviManager CopyTo(String newFileName, float startAtSecond, float stopAtSecond)
        {
            AviManager newFile = new AviManager(newFileName, false);

            try {
                //copy video stream

                VideoStream videoStream = GetVideoStream();

                int startFrameIndex = (int)(videoStream.FrameRate * startAtSecond);
                int stopFrameIndex = (int)(videoStream.FrameRate * stopAtSecond);

                videoStream.GetFrameOpen();
                Bitmap bmp = videoStream.GetBitmap(startFrameIndex);
                VideoStream newStream = newFile.AddVideoStream(false, videoStream.FrameRate, bmp);
                for (int n = startFrameIndex + 1; n <= stopFrameIndex; n++) {
                    bmp = videoStream.GetBitmap(n);
                    newStream.AddFrame(bmp);
                }
                videoStream.GetFrameClose();

                //copy audio stream

                AudioStream waveStream = GetWaveStream();

                Avi.AVISTREAMINFO streamInfo = new Avi.AVISTREAMINFO();
                Avi.PCMWAVEFORMAT streamFormat = new Avi.PCMWAVEFORMAT();
                int streamLength = 0;
                IntPtr ptrRawData = waveStream.GetStreamData(
                    ref streamInfo,
                    ref streamFormat,
                    ref streamLength);

                int startByteIndex = (int)( startAtSecond * (float)(waveStream.CountSamplesPerSecond * streamFormat.nChannels * waveStream.CountBitsPerSample) / 8);
                int stopByteIndex = (int)( stopAtSecond * (float)(waveStream.CountSamplesPerSecond * streamFormat.nChannels * waveStream.CountBitsPerSample) / 8);

                IntPtr ptrWavePart = new IntPtr(ptrRawData.ToInt32() + startByteIndex);

                byte[] rawData = new byte[stopByteIndex - startByteIndex];
                Marshal.Copy(ptrWavePart, rawData, 0, rawData.Length);
                Marshal.FreeHGlobal(ptrRawData);

                streamInfo.dwLength = rawData.Length;
                streamInfo.dwStart = 0;

                IntPtr unmanagedRawData = Marshal.AllocHGlobal(rawData.Length);
                Marshal.Copy(rawData, 0, unmanagedRawData, rawData.Length);
                newFile.AddAudioStream(unmanagedRawData, streamInfo, streamFormat, rawData.Length);
                Marshal.FreeHGlobal(unmanagedRawData);
            } catch (Exception ex) {
                newFile.Close();
                throw ex;
            }

            return newFile;
        }