Ejemplo n.º 1
0
 private void PlayFileForm_Load(object sender, EventArgs e)
 {
     if (Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, Handle))
     {
         fileName         = String.Empty;
         streamHandle     = 0;
         waveStreamHandle = 0;
         fileStream       = null;
         waveForm         = null;
         soundStream      = new BASS_FILEPROCS(
             new FILECLOSEPROC(closeFile),
             new FILELENPROC(getFileLen),
             new FILEREADPROC(readFile),
             new FILESEEKPROC(setSeekCur)
             );
     }
 }
Ejemplo n.º 2
0
        private void buttonPlay_Click(object sender, EventArgs e)
        {
            // svuoto sempre lo stream prima di crearne uno nuovo
            Bass.BASS_StreamFree(streamHandle);
            Bass.BASS_StreamFree(waveStreamHandle);
            // controllo che il file di cui creare lo stream esista
            if (fileName != String.Empty)
            {
                // apro il file
                fileStream = File.OpenRead(fileName);
                // creo un handle per lo streaming dal file
                //streamHandle = Bass.BASS_StreamCreateFileUser(BASSStreamSystem.STREAMFILE_NOBUFFER, BASSFlag.BASS_DEFAULT | BASSFlag.BASS_MUSIC_PRESCAN, soundStream, IntPtr.Zero);
                streamHandle = Bass.BASS_StreamCreateFile(fileName, 0, fileStream.Length, BASSFlag.BASS_DEFAULT);

                //waveForm = new WaveForm(fileName, new WAVEFORMPROC(WaveChunkLoad), null);
                waveForm = new WaveForm("prova");
                waveForm.FrameResolution = 0.01f;
                //waveForm.RenderStart(true, BASSFlag.BASS_DEFAULT);
                waveForm.RenderStart(streamHandle, true, false);
                waveForm.CallbackFrequency = 5;

                //waveForm.RenderStartRecording(streamHandle, 5, 5);
                //myRecProc = new RECORDPROC(MyRecoring);
                //recHandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_RECORD_PAUSE, myRecProc, );


                if (streamHandle != 0 && Bass.BASS_ChannelPlay(streamHandle, false))
                {
                    Thread t = new Thread(updateFrames);
                    t.Start();

                    buttonPause.Enabled = true;
                    buttonStop.Enabled  = true;
                    buttonPlay.Enabled  = false;
                    buttonOpen.Enabled  = false;
                }
                else
                {
                    buttonOpen.Enabled  = true;
                    buttonPlay.Enabled  = false;
                    buttonPause.Enabled = false;
                    buttonStop.Enabled  = false;
                }
            }
        }
Ejemplo n.º 3
0
        public static double waveForm90(WaveForm wf, double p)
        {
            switch (wf)
            {
            case WaveForm.Sine:
                return(Math.Cos(p * 2 * Math.PI));

            case WaveForm.Saw:
                return(saw90(p));

            case WaveForm.Triangle:
                return(tri90(p));

            case WaveForm.Pulse:
                return(pulse90(p));
            }
            return(0);
        }
Ejemplo n.º 4
0
        public static double waveForm(WaveForm wf, double p, double pwm)
        {
            switch (wf)
            {
            case WaveForm.Sine:
                return(Math.Sin(p * 2 * Math.PI));

            case WaveForm.Saw:
                return(saw(p));

            case WaveForm.Triangle:
                return(tri(p, pwm));

            case WaveForm.Pulse:
                return(pulse(p, pwm));
            }
            return(0);
        }
Ejemplo n.º 5
0
        public static double waveForm90(WaveForm wf, double p, double pwm)
        {
            switch (wf)
            {
            case WaveForm.Sine:
                return(Math.Cos(p * 2 * Math.PI));

            case WaveForm.Saw:
                return(saw90(p));

            case WaveForm.Triangle:
                return(tri((p < 0.75) ? (p + 0.25) : (p - 0.75), pwm));

            case WaveForm.Pulse:
                return(pulse((p < 0.75) ? (p + 0.25) : (p - 0.75), pwm));
            }
            return(0);
        }
Ejemplo n.º 6
0
        private static WaveForm GetNewWaveForm(bool isStereo)
        {
            var ColorBackground = Color.FromArgb(192, 192, 192);
            var ColorWaveForm   = Color.FromArgb(50, 50, 200);
            var ColorLine       = Color.FromArgb(50, 50, 200);
            var WaveImage       = new WaveForm
            {
                FrameResolution   = 0.01f,
                CallbackFrequency = 2000,
                ColorBackground   = ColorBackground,
                ColorLeft         = ColorWaveForm,
                ColorRight        = ColorWaveForm,
                ColorMiddleLeft   = ColorLine,
                ColorMiddleRight  = ColorLine,
                DrawWaveForm      = isStereo ? WaveForm.WAVEFORMDRAWTYPE.Stereo : WaveForm.WAVEFORMDRAWTYPE.Mono
            };

            return(WaveImage);
        }
        private void buttonPlay_Click(object sender, EventArgs e)
        {
            wfdrawer = null;
            try
            {
                if (player == null)
                {
                    player = new Player(MFM.fileName, MFM.fileStream.Length, MFM.fileStream);
                }
                //waveForm = new WaveForm(fileName, new WAVEFORMPROC(WaveChunkLoad), null);
                if (waveForm == null)
                {
                    waveForm = new WaveForm();
                }
                waveForm.FrameResolution = 0.01f;
                //waveForm.RenderStart(true, BASSFlag.BASS_DEFAULT);
                waveForm.RenderStart(player.streamHandle, true, false);
                // waveForm.CallbackFrequency = 5;
                //waveForm.RenderStartRecording(streamHandle, 5, 5);
                //myRecProc = new RECORDPROC(MyRecoring);
                //recHandle = Bass.BASS_RecordStart(44100, 2, BASSFlag.BASS_RECORD_PAUSE, myRecProc, );
                wfdrawer = new WaveformDrawer(waveForm, player.streamHandle, pictureBoxWave);

                if (player.play())
                {
                    wfdrawer.startDrawing();
                    buttonPause.Enabled = true;
                    buttonStop.Enabled  = true;
                    buttonPlay.Enabled  = false;
                    buttonOpen.Enabled  = false;
                }
                else
                {
                    buttonOpen.Enabled  = true;
                    buttonPlay.Enabled  = false;
                    buttonPause.Enabled = false;
                    buttonStop.Enabled  = false;
                }
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 8
0
        public static void waveForm(WaveForm wf, ref double zero, ref double ninety, double p, double pwm)
        {
            switch (wf)
            {
            case WaveForm.Sine:
                zero   = Math.Sin(p * 2 * Math.PI);
                ninety = Math.Cos(p * 2 * Math.PI);
                return;

            case WaveForm.Saw:
                zero   = saw(p);
                ninety = saw90(p);
                return;

            case WaveForm.Triangle:
                if (pwm != 0)
                {
                    zero   = tri(p, pwm);
                    ninety = tri((p < 0.75) ? (p + 0.25) : (p - 0.75), pwm);
                }
                else
                {
                    zero   = tri(p);
                    ninety = tri90(p);
                }
                return;

            case WaveForm.Pulse:
                if (pwm != 0)
                {
                    zero   = pulse(p, pwm);
                    ninety = pulse((p < 0.75) ? (p + 0.25) : (p - 0.75), pwm);
                }
                else
                {
                    zero   = pulse(p);
                    ninety = pulse90(p);
                }
                return;
            }
            zero = ninety = 0.0;
        }
Ejemplo n.º 9
0
        public Staff(Clef c, WaveForm w, int inst, int totalStaffNumber, int staffNumber)
        {
            LINE_SPACING = 30 * Song._SCALE;
            LENGTH       = Song.PAGE_WIDTH - Song.LEFT_MARGIN - Song.RIGHT_MARGIN;
            HEIGHT       = 4 * LINE_SPACING;

            mTotalInstrumentNumber = inst;
            mTotalStaffNumber      = totalStaffNumber;

            mYPosition = mTotalInstrumentNumber * Song.INSTRUMENT_SPACING + mTotalStaffNumber * (HEIGHT + Song.STAFF_SPACING);

            mClef     = c;
            mWaveForm = w;
            mMeasures = new List <Measure>();
            AddMeasure();

            keySignature = new List <RectangleF>();

            area         = new RectangleF();
            mStaffNumber = staffNumber;

            Song.TOTAL_STAVES++;
            Song.SELECTABLES.Add(this);
            switch (mClef)
            {
            case Clef.Treble:
                Song.LASTNOTES[inst][staffNumber] = new Note(Pitch.G, Accidental.Natural, Duration.Quarter, 4);
                break;

            case Clef.Alto:
                Song.LASTNOTES[inst][staffNumber] = new Note(Pitch.G, Accidental.Natural, Duration.Quarter, 4);
                break;

            case Clef.Bass:
                Song.LASTNOTES[inst][staffNumber] = new Note(Pitch.D, Accidental.Natural, Duration.Quarter, 3);
                break;

            case Clef.Tenor:
                Song.LASTNOTES[inst][staffNumber] = new Note(Pitch.G, Accidental.Natural, Duration.Quarter, 4);
                break;
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Play a note for length ms.
 /// </summary>
 /// <param name="wave">Wave form to play.</param>
 /// <param name="freq">Frequency.</param>
 /// <param name="length">Length in ms.</param>
 /// <remarks>If length is negative, play until told to stop.</remarks>
 public void Play(WaveForm wave, int freq, int length)
 {
     lock (_mutex)
     {
         _wave       = wave;
         _oscLength  = Rate / freq;
         _oscSamples = 0;
         if (length == -1)
         {
             _remainingSamples = 1;
             _playForever      = true;
         }
         else
         {
             _remainingSamples = (Rate * length) / 1000;
             _playForever      = false;
         }
         _mixedSamples = 0;
     }
 }
        public MainWindow()
        {
            InitializeComponent();

            // Init Controls
            btnConn.IsEnabled      = false;
            btnApply.IsEnabled     = false;
            IsSending              = false;
            cmbPortSel.ItemsSource = SerialPort.GetPortNames();
            optSqr.IsChecked       = true;
            this.Closed           += new EventHandler(window_Closed);

            // Init Parameters
            IsConnected = false;
            IsSending   = false;
            wfMode      = WaveForm.Sqr;

            // Init Thread
            thrSendFunc = new ThreadStart(ContinuousSerialSend);
        }
Ejemplo n.º 12
0
    public override void ExtendedControl()
    {
        base.ExtendedControl();
        float dt = Time.deltaTime;

        float x1 = NAInput.GetAxis(NAControl.MoveHorizontal);
        float y1 = NAInput.GetAxis(NAControl.MoveVertical);
        float x2 = NAInput.GetAxis(NAControl.ViewHorizontal);
        float y2 = NAInput.GetAxis(NAControl.ViewVertical);

        bool buttonAction = NAInput.GetControlDown(NAControl.Action);
        bool buttonJump   = NAInput.GetControlDown(NAControl.Jump);
        bool buttonCamera = NAInput.GetControlDown(NAControl.Camera);
        bool buttonMenu   = NAInput.GetControlDown(NAControl.Menu);

        frequency += x1 * dt * 100f;
        duration  += y1 * dt;

        duration = Mathf.Clamp(duration, 0.1f, 10);


        if (buttonJump)
        {
            Generate();
            //Play();
        }

        float padx = NAInput.GetAxis(NAControl.PadHorizontal);
        float pady = NAInput.GetAxis(NAControl.PadVertical);

        if (NAInput.PadHorizontalPressed && padx > 0)
        {
            waveform = waveform++;
        }
        else if (NAInput.PadHorizontalPressed && padx < 0)
        {
            waveform = waveform--;
        }
    }
Ejemplo n.º 13
0
        /// <summary>
        ///     Loads the wave data for the current track
        /// </summary>
        private void LoadTrackWaveData()
        {
            _waveRendered = false;

            if (!File.Exists(Filename))
            {
                return;
            }

            Wave = new WaveForm(Filename, WaveForm_Callback, this)
            {
                FrameResolution    = 0.001f,
                CallbackFrequency  = 30000,
                ColorBackground    = Color.Black,
                ColorLeft          = Color.Navy,
                ColorLeftEnvelope  = Color.LightGray,
                ColorRight         = Color.Navy,
                ColorRightEnvelope = Color.LightGray,
                ColorMarker        = Color.Gold,
                ColorBeat          = Color.LightSkyBlue,
                ColorVolume        = Color.White,
                DrawEnvelope       = false,
                DrawWaveForm       = WaveForm.WAVEFORMDRAWTYPE.Mono,
                DrawMarker         =
                    WaveForm.MARKERDRAWTYPE.Line | WaveForm.MARKERDRAWTYPE.Name | WaveForm.MARKERDRAWTYPE.NameBoxFilled,
                MarkerLength = 0.9f
            };


            Wave.RenderStart(true, BASSFlag.BASS_DEFAULT);

            SetMarkers();

            while (!_waveRendered)
            {
                Application.DoEvents();
                Thread.Sleep(100);
            }
        }
Ejemplo n.º 14
0
        private short[] GetWave(WaveForm waveForm, float frequency)
        {
            short[] wave = new short[SAMPLE_RATE];

            switch (waveForm)
            {
            case WaveForm.Noise:
                return(WaveFormGenerator.Noise(SAMPLE_RATE));

            case WaveForm.Square:
                return(WaveFormGenerator.Square(frequency, SAMPLE_RATE));

            case WaveForm.Saw:
                return(WaveFormGenerator.Saw(frequency, SAMPLE_RATE));

            case WaveForm.Triangle:
                return(WaveFormGenerator.Triangle((short)frequency, SAMPLE_RATE));

            case WaveForm.Sine:
            default:
                return(WaveFormGenerator.Sine(frequency, SAMPLE_RATE));
            }
        }
Ejemplo n.º 15
0
        public Measure(Clef clef, WaveForm wave, float yPosition, int measureNumber)
        {
            mMeasureNumber = measureNumber;
            mClef          = clef;
            mWaveForm      = wave;
            mChords        = new List <Chord>();
            Song.SELECTABLES.Add(this);
            if (Song.CHORD_POSITIONS.Count <= mMeasureNumber)
            {
                int last = Song.CHORD_POSITIONS.Count;
                switch (Song.TIME)
                {
                case Time.NineEight:
                    Song.CHORD_POSITIONS.Add(new float[18]);
                    break;

                case Time.SixEight:
                case Time.ThreeFour:
                    Song.CHORD_POSITIONS.Add(new float[12]);
                    break;

                case Time.ThreeEight:
                case Time.FourFour:
                    Song.CHORD_POSITIONS.Add(new float[16]);
                    break;

                case Time.TwoFour:
                    Song.CHORD_POSITIONS.Add(new float[8]);
                    break;
                }
                for (int i = 0; i < Song.CHORD_POSITIONS[last].Length; i++)
                {
                    Song.CHORD_POSITIONS[last][i] = 0;
                }
            }
            Song.TOTAL_MEASURES++;
        }
Ejemplo n.º 16
0
 public WaveSource()
 {
     form = WaveForm.Sin;
     Amp  = 1;
     Freq = 10000;
 }
Ejemplo n.º 17
0
        public WaveFormScrollView()
        {
            WaveFormView = new WaveForm();
            WaveFormView.OnChangePosition += (position) => OnChangePosition(position);
            WaveFormView.OnChangeSecondaryPosition += (position) => OnChangeSecondaryPosition(position);
            WaveFormView.MinHeight = 60;
            WaveFormScaleView = new WaveFormScale();

            _lblZoom = new Label();
            _lblZoom.Background = new SolidColorBrush(Color.FromArgb(140, 32, 40, 46));
            _lblZoom.Foreground = new SolidColorBrush(Colors.White);
            _lblZoom.Padding = new Thickness(4);
            _lblZoom.Content = "100%";
            _lblZoom.FontFamily = new FontFamily("Roboto");
            _lblZoom.FontSize = 11;
            _lblZoom.Width = Double.NaN;
            _lblZoom.Height = Double.NaN;

            _stackPanelZoom = new StackPanel();
            _stackPanelZoom.HorizontalAlignment = HorizontalAlignment.Center;
            _stackPanelZoom.VerticalAlignment = VerticalAlignment.Center;
            _stackPanelZoom.Children.Add(_lblZoom);

            _gridWaveForm = new Grid();
            _gridWaveForm.Height = Double.NaN;
            _gridWaveForm.Children.Add(WaveFormView);
            _gridWaveForm.Children.Add(_stackPanelZoom);

            _grid = new Grid();
            _rowScale = new RowDefinition();
            _rowScale.Height = new GridLength(22);
            _rowWaveForm = new RowDefinition();
            //_rowWaveForm.Height = GridLength.Auto;
            _grid.RowDefinitions.Add(_rowScale);
            _grid.RowDefinitions.Add(_rowWaveForm);
            _grid.Children.Add(WaveFormScaleView);
            _grid.Children.Add(_gridWaveForm);
            Grid.SetRow(WaveFormScaleView, 0);
            Grid.SetRow(_gridWaveForm, 1);
            Children.Add(_grid);

            _timerFadeOutZoomLabel = new Timer(100);
            _timerFadeOutZoomLabel.Elapsed += HandleTimerFadeOutZoomLabelElapsed;
            _timerFadeOutZoomLabel.Start();

            CreateContextualMenu();
        }
Ejemplo n.º 18
0
 public static Oscillator SetWaveForm(this Oscillator oscillator, WaveForm waveForm)
 {
     oscillator.WaveFormType = waveForm;
     return oscillator;
 }
Ejemplo n.º 19
0
        public static Oscillator FrequencyModulate(this Oscillator oscillator, FrameworkElement frequencyTarget, DependencyProperty frequencyProperty, FrameworkElement amplitudeTarget, DependencyProperty amplitudeProperty, WaveForm waveForm)
        {
            oscillator.FrequencyModulator.WaveForm = waveForm;

            if (frequencyProperty != null && frequencyTarget != null)
            {
                Binding frequencyBinding = new Binding();
                frequencyBinding.Mode = BindingMode.TwoWay;
                frequencyBinding.Source = oscillator.FrequencyModulator;
                frequencyBinding.Path = new PropertyPath("ModulationFrequency");
                frequencyTarget.SetBinding(frequencyProperty, frequencyBinding);
            }

            if (amplitudeProperty != null && amplitudeTarget != null)
            {
                Binding amplitudeBinding = new Binding();
                amplitudeBinding.Mode = BindingMode.TwoWay;
                amplitudeBinding.Source = oscillator.FrequencyModulator;
                amplitudeBinding.Path = new PropertyPath("Amplitude");
                amplitudeTarget.SetBinding(amplitudeProperty, amplitudeBinding);
            }

            return oscillator;
        }
Ejemplo n.º 20
0
 public static Oscillator SetWaveForm(this Oscillator oscillator, WaveForm waveForm)
 {
     oscillator.WaveFormType = waveForm;
     return(oscillator);
 }
Ejemplo n.º 21
0
        /// <summary>
        ///     Loads the wave data for the current track
        /// </summary>
        private void LoadTrackWaveData()
        {
            _waveRendered = false;

            if (!File.Exists(Filename)) return;

            Wave = new WaveForm(Filename, WaveForm_Callback, this)
            {
                FrameResolution = 0.001f,
                CallbackFrequency = 30000,
                ColorBackground = Color.Black,
                ColorLeft = Color.Navy,
                ColorLeftEnvelope = Color.LightGray,
                ColorRight = Color.Navy,
                ColorRightEnvelope = Color.LightGray,
                ColorMarker = Color.Gold,
                ColorBeat = Color.LightSkyBlue,
                ColorVolume = Color.White,
                DrawEnvelope = false,
                DrawWaveForm = WaveForm.WAVEFORMDRAWTYPE.Mono,
                DrawMarker =
                    WaveForm.MARKERDRAWTYPE.Line | WaveForm.MARKERDRAWTYPE.Name | WaveForm.MARKERDRAWTYPE.NameBoxFilled,
                MarkerLength = 0.9f
            };


            Wave.RenderStart(true, BASSFlag.BASS_DEFAULT);

            SetMarkers();

            while (!_waveRendered)
            {
                Application.DoEvents();
                Thread.Sleep(100);
            }
        }
Ejemplo n.º 22
0
        private void loadDeckB_Click(object sender, EventArgs e)
        {
            if (mix.running())
            {
                string item = getItem();
                if (!item.Equals(string.Empty) || item != null)
                {
                    if (mix.loadDeckB(item))
                    {
                        WFRight = new WaveForm(item, new Un4seen.Bass.Misc.WAVEFORMPROC(RightCallback), deckAOsc);
                        WFRight.CallbackFrequency = 500; // every 10 seconds rendered
                        WFRight.ColorBackground = Color.Black;
                        WFRight.ColorBeat = Color.Lime;
                        WFRight.ColorVolume = Color.Red;
                        WFRight.RenderStart(true, BASSFlag.BASS_DEFAULT);

                        deckBLabel.Text = item.Split(sep).Last();
                        timeDeckB.Text = mix.getTimeDeck('B');
                        mix.computeCrossFade();
                    }
                }
                else
                {
                    Console.WriteLine("Could not load into Deck A");
                }
            }
        }
 public static float[] GetWaveTable(WaveForm form)
 {
     return(waveTables[form]);
 }
Ejemplo n.º 24
0
 public RTDrawableWaveform(WaveForm _waveform, double _modulation)
 {
     waveform   = _waveform;
     modulation = _modulation;
     rand       = new Random();
 }
Ejemplo n.º 25
0
        static void Main(string[] args)
        {
            AnalysisParam A = new AnalysisParam();

            A.ESPCalibrationX  = "x";
            A.ESPCalibrationY  = "x";
            A.WaveCalibrationX = "x";
            A.WaveCalibrationY = "x";
            A.WaveThreshold    = 150;
            A.nmax             = 10;
            A.ESPMaxResolution = 0.2;

            //EnergySP e = new EnergySP();
            WaveForm     w        = new WaveForm();
            String       filepath = "a.dat";
            int          a;
            FileStream   fs = new FileStream(filepath, FileMode.Open, FileAccess.ReadWrite);
            BinaryReader br = new BinaryReader(fs);

            a = br.ReadInt32();
            int[] cnt = new int[a];
            for (int i = 0; i < a; i++)
            {
                cnt[i] = br.ReadInt32();
            }
            fs.Close();
            double[] wav = new double[a];
            for (int i = 0; i < a; i++)
            {
                wav[i] = -1;
                if (i % 2 == 0)
                {
                    wav[i] = 1;
                }
                wav[i] = cnt[i];
            }
            w.SampleValue = wav;
            //e.Count = cnt;
            //e.Analysis_De_LM_EM(A);
            //for (int i = 0; i < e.AnalysisResultLength; i++)
            //{
            //    Console.WriteLine(e.AnalysisResult[i].Peak);
            //}

            bool bl = w.Analysis(A);

            Console.WriteLine(bl);
            for (int i = 0; i < w.AnalysisResultLength; i++)
            {
                Console.WriteLine(w.AnalysisResult[i].TimeofMax);
            }
            Structedfile sf = new Structedfile();

            sf.ReadFile("", "1234");
            Structedfile sf2 = new Structedfile();

            sf2 = sf;
            w   = sf2.Wav[0].Transf();
            sf2.WriteFile("", "ABCDEFG");

            //Byte[] Frame = { 0x55, 0xAA,
            //    0x14,0x01,0xFD,0x00,0x01,0x00,0x04,
            //    19,10,31,15,30,00,
            //    0xEB,0x90,0xA1,0x0A,0x01,
            //    0,
            //    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
            //    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
            //    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
            //    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
            //    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
            //    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
            //    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
            //    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
            //    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
            //    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
            //    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
            //    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
            //    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
            //    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
            //    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
            //    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
            //    0xC1,0xA1,
            //    0xEE
            //};
            //Rawdatafile raw = new Rawdatafile();
            //unsafe
            //{
            //    Byte* FrameESP = stackalloc Byte[280];
            //    for (int j = 0; j < 32; j++)
            //    {
            //        for (int i = 0; i < 280; i++)
            //        {

            //            FrameESP[i] = Frame[i];
            //            FrameESP[i] = (Byte)i;
            //        }
            //        raw.WriteFrame((IntPtr)FrameESP);
            //    }
            //}
            //raw.Run = 1000;

            //Structedfile strf = new Structedfile();
            //strf = raw.AnalysisFrameCache();


            Console.ReadLine();
        }
Ejemplo n.º 26
0
    public void HandleWaves()
    {
        if (moveMesh == true)
        {
            if (Application.isPlaying)
            {
                if (useGPU == true)
                {
                    GetComponent <Renderer>().sharedMaterials[0].SetFloat("_GameTime", now);
                    if (waveForms.Count > 1)
                    {
                        WaveForm wForm1 = waveForms[0];
                        WaveForm wForm2 = waveForms[1];
                        GetComponent <Renderer>().materials[0].SetInt("_UseGPU", 2);
                        GetComponent <Renderer>().materials[0].SetVector("_WaveSpeed", new Vector4(wForm1.speed.x, wForm1.speed.y, wForm2.speed.x, wForm2.speed.y));
                        GetComponent <Renderer>().materials[0].SetVector("_Wavelength", new Vector4(wForm1.waveLength.x, wForm1.waveLength.y, wForm2.waveLength.x, wForm2.waveLength.y));
                        GetComponent <Renderer>().materials[0].SetVector("_WaveOffset", new Vector4(wForm1.offset.x, wForm1.offset.y, wForm2.offset.x, wForm2.offset.y));
                        GetComponent <Renderer>().materials[0].SetVector("_WaveGain", new Vector4(wForm1.waveGain.x, wForm1.waveGain.y, wForm2.waveGain.x, wForm2.waveGain.y));
                        GetComponent <Renderer>().materials[0].SetFloat("_WaveScale1", wForm1.scale);
                        GetComponent <Renderer>().materials[0].SetFloat("_WaveScale2", wForm2.scale);
                    }
                    else if (waveForms.Count == 1)
                    {
                        WaveForm wForm = waveForms[0];
                        GetComponent <Renderer>().materials[0].SetInt("_UseGPU", 1);
                        GetComponent <Renderer>().materials[0].SetVector("_WaveSpeed", new Vector4(wForm.speed.x, wForm.speed.y, 0, 0));
                        GetComponent <Renderer>().materials[0].SetVector("_Wavelength", new Vector4(wForm.waveLength.x, wForm.waveLength.y, 0, 0));
                        GetComponent <Renderer>().materials[0].SetVector("_WaveOffset", new Vector4(wForm.offset.x, wForm.offset.y, 0, 0));
                        GetComponent <Renderer>().materials[0].SetVector("_WaveGain", new Vector4(wForm.waveGain.x, wForm.waveGain.y, 0, 0));
                        GetComponent <Renderer>().materials[0].SetFloat("_WaveScale1", wForm.scale);
                    }
                }
                else
                {
                    GetComponent <Renderer>().materials[0].SetInt("_UseGPU", 0);
                }
            }
            else
            {
                if (useGPU == true)
                {
                    GetComponent <Renderer>().sharedMaterials[0].SetFloat("_GameTime", now);
                    if (waveForms.Count > 1)
                    {
                        WaveForm wForm1 = waveForms[0];
                        WaveForm wForm2 = waveForms[1];
                        GetComponent <Renderer>().sharedMaterials[0].SetInt("_UseGPU", 2);
                        GetComponent <Renderer>().sharedMaterials[0].SetVector("_WaveSpeed", new Vector4(wForm1.speed.x, wForm1.speed.y, wForm2.speed.x, wForm2.speed.y));
                        GetComponent <Renderer>().sharedMaterials[0].SetVector("_Wavelength", new Vector4(wForm1.waveLength.x, wForm1.waveLength.y, wForm2.waveLength.x, wForm2.waveLength.y));
                        GetComponent <Renderer>().sharedMaterials[0].SetVector("_WaveOffset", new Vector4(wForm1.offset.x, wForm1.offset.y, wForm2.offset.x, wForm2.offset.y));
                        GetComponent <Renderer>().sharedMaterials[0].SetVector("_WaveGain", new Vector4(wForm1.waveGain.x, wForm1.waveGain.y, wForm2.waveGain.x, wForm2.waveGain.y));
                        GetComponent <Renderer>().sharedMaterials[0].SetFloat("_WaveScale1", wForm1.scale);
                        GetComponent <Renderer>().sharedMaterials[0].SetFloat("_WaveScale2", wForm2.scale);
                    }
                    else if (waveForms.Count == 1)
                    {
                        WaveForm wForm = waveForms[0];
                        GetComponent <Renderer>().sharedMaterials[0].SetInt("_UseGPU", 1);
                        GetComponent <Renderer>().sharedMaterials[0].SetVector("_WaveSpeed", new Vector4(wForm.speed.x, wForm.speed.y, 0, 0));
                        GetComponent <Renderer>().sharedMaterials[0].SetVector("_Wavelength", new Vector4(wForm.waveLength.x, wForm.waveLength.y, 0, 0));
                        GetComponent <Renderer>().sharedMaterials[0].SetVector("_WaveOffset", new Vector4(wForm.offset.x, wForm.offset.y, 0, 0));
                        GetComponent <Renderer>().sharedMaterials[0].SetVector("_WaveGain", new Vector4(wForm.waveGain.x, wForm.waveGain.y, 0, 0));
                        GetComponent <Renderer>().sharedMaterials[0].SetFloat("_WaveScale1", wForm.scale);
                    }
                }
                else
                {
                    GetComponent <Renderer>().sharedMaterials[0].SetInt("_UseGPU", 0);
                }
            }

            if (useGPU == false || (waveForms.Count > 2))
            {
                float offsetY = 0.0f;
                float offsetX = 0.0f;
                for (int j = 0; j < vertices.Length; j++)
                {
                    offsetX = 0f;
                    offsetY = 0f;
                    Vector3 vertex = vertices[j];
                    Vector3 v      = transform.TransformPoint(vertex);
                    int     run    = 1;
                    foreach (WaveForm waveForm in waveForms)
                    {
                        if (useGPU == true && run < 2)
                        {
                            run++;
                            continue;
                        }
                        offsetY += waveForm.scale * Mathf.Cos((now * (waveForm.speed.y) * twopi) + ((v.z * twopi) / waveForm.waveLength.y) + waveForm.offset.y);
                        offsetX += waveForm.scale * Mathf.Cos((now * (waveForm.speed.x) * twopi) + ((v.x * twopi) / waveForm.waveLength.x) + waveForm.offset.x);
                    }
                    vertices[j].y = offsetX + offsetY;
                }
            }

            if ((useGPU == true && waveForms.Count > 2) || useGPU == false)
            {
                m.vertices = vertices;
                m.RecalculateNormals();
            }
        }
    }
Ejemplo n.º 27
0
 public WaveFormGenerator(WaveForm waveForm, NumericScale scale)
 {
     _waveForm = waveForm;
     _scale    = scale;
 }
        public void Load(string file)
        {
            if (file == null || !File.Exists(file))
            {
                return;
            }

            Bass.BASS_StreamFree(streamID);
            Bass.BASS_StreamFree(streamFileID);

            if (lastFile != file)
            {
                lastFile = file;

                WaveModel?.Dispose();

                var wf = new WaveForm(file);
                wf.FrameResolution = 0.005;

                if (wf.RenderStart(false, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_PRESCAN | BASSFlag.BASS_FX_FREESOURCE))
                {
                    var samples = new float[wf.Wave.data.Length];

                    var maxPeak = 0f;

                    for (int i = 0; i < wf.Wave.data.Length; i++)
                    {
                        var sample = wf.Wave.data[i];

                        var peakLeft  = sample.left / (float)short.MaxValue;
                        var peakRight = sample.right / (float)short.MaxValue;

                        var peak = Math.Max(Math.Abs(peakLeft), Math.Abs(peakRight));

                        maxPeak = Math.Max(peak, maxPeak);

                        samples[i] = peak;
                    }

                    var vertexes = new Queue <float>();

                    // averaging values
                    for (int i = 0; i < samples.Length; i++)
                    {
                        if (maxPeak > 0.001)
                        {
                            samples[i] /= maxPeak;
                        }
                        samples[i] *= 0.9f;

                        vertexes.Enqueue(i / (float)samples.Length * 100000);
                        vertexes.Enqueue(samples[i]);
                    }

                    WaveModel = ModelManager.LoadModel2ToVao(vertexes.ToArray());
                    wf.Reset();
                }
            }

            var stream = Bass.BASS_StreamCreateFile(file, 0, 0, BASSFlag.BASS_STREAM_DECODE | BASSFlag.BASS_STREAM_PRESCAN | BASSFlag.BASS_FX_FREESOURCE);
            var tempo  = Tempo;

            streamFileID = stream;
            streamID     = BassFx.BASS_FX_TempoCreate(streamFileID, BASSFlag.BASS_STREAM_PRESCAN);

            Tempo = tempo;

            Bass.BASS_ChannelGetAttribute(streamID, BASSAttribute.BASS_ATTRIB_TEMPO_FREQ, ref originval);

            Reset();
        }
Ejemplo n.º 29
0
 /// <summary>
 /// Play a note for length ms.
 /// </summary>
 /// <param name="wave">Wave form to play.</param>
 /// <param name="freq">Frequency.</param>
 /// <param name="length">Length in ms.</param>
 /// <remarks>If length is negative, play until told to stop.</remarks>
 public void Play(WaveForm wave, int freq, int length)
 {
     lock (_mutex)
     {
         _wave = wave;
         _oscLength = Rate / freq;
         _oscSamples = 0;
         if (length == -1)
         {
             _remainingSamples = 1;
             _playForever = true;
         }
         else
         {
             _remainingSamples = (Rate * length) / 1000;
             _playForever = false;
         }
         _mixedSamples = 0;
     }
 }
Ejemplo n.º 30
0
        static public float EvalWave(float phase, float frequency, float amplitude, float baseStart, WaveForm waveForm, float polynomial)
        {
            float x = (Time.time + phase) * frequency;
            float y = 0f;

            x = x - Mathf.Floor(x);//ensure x is between 0 and 1
            switch (waveForm)
            {
            case WaveForm.invertedSaw:
                y = 1f + x * -2;
                break;

            case WaveForm.noise:
                //TODO: slow down returns based on frequency
                y = 1f - Random.value * 2;
                break;

            case WaveForm.saw:
                y = -1f + x * 2;
                break;

            case WaveForm.sin:
                y = Mathf.Sin(x * 2 * Mathf.PI);
                break;

            case WaveForm.square:
                if (x < 0.5f)
                {
                    y = 1f;
                }
                else
                {
                    y = -1f;
                }
                break;

            case WaveForm.triangle:
                if (x < 0.5f)
                {
                    y = 4f * x - 1f;
                }
                else
                {
                    y = -4f * x + 3f;
                }
                break;

            case WaveForm.polynomial:
                y = Mathf.Pow(1 - 2 * x, Mathf.Abs(polynomial));
                break;

            default:
                Debug.LogError("Missing waveform in WaveMathHelper");
                break;
            }
            return(y * amplitude + baseStart);
        }
Ejemplo n.º 31
0
        public void Evaluate(int SpreadMax)
        {
            if (this.FPinInFile.PinIsChanged)
            {
                string path;
                this.FPinInFile.GetString(0, out path);
                if (File.Exists(path))
                {
                    this.FWaveForm = new WaveForm(path, new WAVEFORMPROC(MyWaveFormCallback), this);
                    this.FWaveForm.FrameResolution    = 0.01f; // 10ms are nice
                    this.FWaveForm.CallbackFrequency  = 2000;  // every 30 seconds rendered (3000*10ms=30sec)
                    this.FWaveForm.ColorBackground    = Color.WhiteSmoke;
                    this.FWaveForm.ColorLeft          = Color.Gainsboro;
                    this.FWaveForm.ColorLeftEnvelope  = Color.Gray;
                    this.FWaveForm.ColorRight         = Color.LightGray;
                    this.FWaveForm.ColorRightEnvelope = Color.DimGray;
                    this.FWaveForm.ColorMarker        = Color.DarkBlue;
                    this.FWaveForm.DrawWaveForm       = WaveForm.WAVEFORMDRAWTYPE.Stereo;
                    this.FWaveForm.DrawMarker         = WaveForm.MARKERDRAWTYPE.Line;
                    this.FWaveForm.MarkerLength       = 1f;

                    this.FWaveForm.RenderStart(true, BASSFlag.BASS_DEFAULT);
                }
            }

            #region Start / End
            if (this.FPinInStart.PinIsChanged || this.FPinInEnd.PinIsChanged)
            {
                double start, end;
                this.FPinInStart.GetValue(0, out start);
                this.FPinInEnd.GetValue(0, out end);

                if (this.FWaveForm != null)
                {
                    if (start <= 0)
                    {
                        this.FFrameStart = -1;
                    }
                    else
                    {
                        this.FFrameStart = this.FWaveForm.Position2Frames(start);
                    }


                    if (end <= 0 || end <= start)
                    {
                        this.FFrameEnd = -1;
                    }
                    else
                    {
                        this.FFrameEnd = this.FWaveForm.Position2Frames(end);
                    }
                    this.RedrawWF();
                }
            }
            #endregion

            #region Position Marker
            if (this.FPinInCurrentPosition.PinIsChanged || this.FPinInMarkers.PinIsChanged)
            {
                if (this.FWaveForm != null)
                {
                    double markerpos;
                    this.FWaveForm.ClearAllMarker();
                    for (int i = 0; i < this.FPinInMarkers.SliceCount; i++)
                    {
                        this.FPinInMarkers.GetValue(i, out markerpos);

                        if (markerpos > 0)
                        {
                            this.FWaveForm.AddMarker("Marker" + i.ToString(), markerpos);
                        }
                    }

                    double position;
                    this.FPinInCurrentPosition.GetValue(0, out position);

                    if (position < 0)
                    {
                        this.FWaveForm.RemoveMarker("Position");
                    }
                    else
                    {
                        this.FWaveForm.AddMarker("Position", position);
                    }
                    this.RedrawWF();
                }
            }
            #endregion
        }
Ejemplo n.º 32
0
 public static Oscillator SetFrequencyModulationWaveForm(this Oscillator oscillator, WaveForm waveForm)
 {
     oscillator.FrequencyModulator.WaveForm = waveForm;
     return oscillator;
 }
Ejemplo n.º 33
0
 public void PlayEffectReg2(WaveForm waveForm, ulong freq, ulong pulseWidth, uint attackDecay, uint sustain, bool pulse)
 {
 }
Ejemplo n.º 34
0
 public static Oscillator FrequencyModulate(this Oscillator oscillator, double frequency, short amplitude, WaveForm waveForm)
 {
     oscillator.FrequencyModulator.ModulationFrequency = frequency;
     oscillator.FrequencyModulator.Amplitude = amplitude;
     oscillator.FrequencyModulator.WaveForm = waveForm;
     return oscillator;
 }
Ejemplo n.º 35
0
 public RTDrawableWaveform(WaveForm _waveform) : this(_waveform, 0)
 {
 }
Ejemplo n.º 36
0
 public void SetDummyWaveForm(AnalogChannel channel, WaveForm w)
 {
     ChannelConfig[channel].waveform = w;
 }
        public SynthesizedSound(int sampleRate = 44100, int length = 1, float frequenzy = 440f, WaveForm form = WaveForm.Sine)
        {
            random = new Random((int)frequenzy);
            int s = sizeof(short);

            byte[] waveByteData = new byte[sampleRate * s * length];

            for (int i = 0; i < sampleRate * length; i++)
            {
                byte[] sampleBytes;
                switch (form)
                {
                case WaveForm.Sine: sampleBytes = GetSineWave(frequenzy, sampleRate, i); break;

                case WaveForm.Square: sampleBytes = GetSquareWave(frequenzy, sampleRate, i); break;

                case WaveForm.Noise: sampleBytes = GetNoiseWave(frequenzy, sampleRate, i); break;

                default: sampleBytes = GetSineWave(frequenzy, sampleRate, i); break;
                }
                waveByteData[i * s]     = sampleBytes[0];
                waveByteData[i * s + 1] = sampleBytes[1];
            }

            Sound = new SoundEffect(waveByteData, sampleRate, AudioChannels.Mono);
        }
Ejemplo n.º 38
0
 public void setWaveForm(WaveForm waveForm)
 {
     waveFormGenerator.waveForm = waveForm;
 }
Ejemplo n.º 39
0
        private void GetWave()
        {
            this.wf = new Un4seen.Bass.Misc.WaveForm(this.track, new WAVEFORMPROC(this.WaveFormCallback), null);
            this.wf.FrameResolution = 0.01f; //// neccesarry to fit the angle increase
            this.wf.CallbackFrequency = 250;
            this.wf.ColorBackground = System.Drawing.Color.FromArgb(0, System.Drawing.Color.White); //// transparent

            ////wf.ColorBackground = System.Drawing.Color.Black;
            this.wf.ColorLeft = System.Drawing.Color.White;

            this.wf.ColorLeftEnvelope = System.Drawing.Color.White;
            this.wf.ColorRight = System.Drawing.Color.White;
            this.wf.ColorRightEnvelope = System.Drawing.Color.White;

            this.wf.DrawWaveForm = WaveForm.WAVEFORMDRAWTYPE.Stereo;
            this.wf.RenderStart(true, BASSFlag.BASS_DEFAULT);
        }
Ejemplo n.º 40
0
 public static Oscillator Create(double frequency, WaveForm waveForm)
 {
     return new Oscillator() { Frequency = frequency, WaveFormType = waveForm };
 }
Ejemplo n.º 41
0
 public ISignalGenerator WithWaveForm(WaveForm waveForm)
 {
     _WaveForm = waveForm;
     return(this);
 }