Пример #1
0
 public virtual WaveAudio CreateWaveAudio(double fSeconds)
 {
     WaveAudio res = new WaveAudio(SampleRate, 1);
     int nSamples = (int) (fSeconds * res.getSampleRate());
     res.data[0] = this.generate(nSamples);
     return res;
 }
Пример #2
0
        private void freqSketch_onBtnSave(object sender, EventArgs e)
        {
            WaveAudio w = getWaveAudio();

            if (w == null)
            {
                return;
            }
            commonSaveWaveFile(w);
        }
Пример #3
0
        private void vibLab_btnPlay_Click(object sender, EventArgs e)
        {
            WaveAudio w = viblab_Generate();

            if (w == null)
            {
                return;
            }
            pl.Play(w, true); //asynchronous
        }
Пример #4
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            var went = (WsmEntry)entry;

            using (var riff = new MemoryStream(0x2C))
            {
                WaveAudio.WriteRiffHeader(riff, went.Format, entry.Size);
                var input = arc.File.CreateStream(entry.Offset, entry.Size);
                return(new PrefixStream(riff.ToArray(), input));
            }
        }
Пример #5
0
 private void dlgBrowseFile_FileOk(object sender, CancelEventArgs e)
 {
     txtFilePath.Text = dlgBrowseFile.FileName;
     if (txtFilePath.Text.Trim() != "")
     {
         btnExtract.Enabled = true;
         btnHide.Enabled    = true;
         file = new WaveAudio(new FileStream(txtFilePath.Text, FileMode.Open, FileAccess.Read));
         sh   = new StagnoHelper(file);
     }
 }
Пример #6
0
        public static void effectsaudacitytest(AudioPlayer pl)
        {
            WaveAudio w  = new WaveAudio(@"C:\pydev\yalp\Subversion\csaudio\c_audio\simon.wav");
            WaveAudio w2 = Effects.Wahwah(w);

            pl.Play(w2);

            WaveAudio w3 = Effects.Phaser(w);

            pl.Play(w3);
        }
Пример #7
0
 private double getSample(WaveAudio w, int i)
 {
     if (i < 0)
     {
         return(0);
     }
     if (i >= w.data[0].Length)
     {
         return(0);
     }
     return(w.data[0][i]);
 }
Пример #8
0
        private void freqSketch_OnBtnPlay(object sender, EventArgs e)
        {
            // no way to stop during playback, but that's ok, it was interfering with user
            WaveAudio w = getWaveAudio();

            if (w == null)
            {
                return;
            }
            this.pl.Play(w, true);     //play asynchronously
            this.crFeedback_btnPlay.Text = "Stop";
        }
        private void button3_Click(object sender, EventArgs e)
        {
            double d = 0.0;

            if (!InputBoxForm.GetDouble("Enter speed:", 1.0, out d))
            {
                return;
            }
            WaveAudio ww = new WaveAudio(PATH_BACKEND_WAV);

            this.curAudio = Effects.ScalePitchAndDuration(ww, d);
            this.aplayer.Play(this.curAudio, true);
        }
Пример #10
0
        private void btnOpen_Click(object sender, EventArgs e)
        {
            string strFilename, strShortname; WaveAudio w;

            CommonWave.commonLoadWaveFile(out strFilename, out strShortname, out w);
            if (w == null)
            {
                return;
            }
            this.lblFilename.Text = "Loaded: " + strShortname;
            w.setNumChannels(1, true); //convert to mono
            this.m_currentSound = w;
        }
Пример #11
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string sfilename = getSaveFilename();

            if (sfilename != null)
            {
                WaveAudio wout = this.fullcompute();
                if (wout != null)
                {
                    wout.SaveWaveFile(sfilename);
                }
            }
        }
 private void crFeedback_onBtnPlay(object sender, EventArgs e)
 {
     if (this.crFeedback_btnPlay.Text == "Play")
     {
         WaveAudio w = this.objCrFeedback.Generate(double.Parse(this.crFeedbackTxtScale.Text), int.Parse(this.crFeedbackTxtShift.Text));
         this.pl.Play(w, true); //play asynchronously
         this.crFeedback_btnPlay.Text = "Stop";
     }
     else
     {
         this.pl.Stop();
         this.crFeedback_btnPlay.Text = "Play";
     }
 }
Пример #13
0
        public static void effectstest(AudioPlayer pl)
        {
            WaveAudio w = new WaveAudio(mediadir + "d44k16bit2ch.wav");

            pl.Play(Effects.Derivative(w));
            pl.Play(Effects.Flange(w));
            pl.Play(Effects.Reverse(w));
            pl.Play(Effects.ScalePitchAndDuration(w, 0.75));
            pl.Play(Effects.ScalePitchAndDuration(w, 1.25));
            pl.Play(Effects.Tremolo(w, 1.0, 1.0));
            pl.Play(Effects.Vibrato(w, 0.2, 0.5));

            w.setSampleRate(22050);
            pl.Play(w); // should sound "normal"
        }
Пример #14
0
        // Test between 20Hz and 500Hz. This works very well, although it is hard to eliminate octave errors
        // This test will play original, then a sine at the frequency it detected. The two should line up.
        private static void pitchdetectwav(AudioPlayer pl, string strFilename, PitchDetection.PitchDetectAlgorithm algorithm)
        {
            string    strInstdir = mediadir + @"pitchdetect\";
            WaveAudio w          = new WaveAudio(strInstdir + strFilename);

            if (w.getNumChannels() != 1)
            {
                w.setNumChannels(1, true);
            }
            double    dfreq     = PitchDetection.DetectPitch(w, 50, 500, algorithm);
            WaveAudio testPitch = new Triangle(dfreq, 0.7).CreateWaveAudio(1.0);

            pl.Play(w);
            pl.Play(testPitch);
        }
Пример #15
0
        internal ALSound(WaveAudio waveAudio)
        {
            WaveAudio = waveAudio;

            BufferHandle = AL.GenBuffer();
            ALHelper.CheckLastError();

            AL.BufferData(BufferHandle,
                          ALHelper.GetSoundFormat(WaveAudio.WaveInfo.Channels, WaveAudio.WaveInfo.BitDepth),
                          ref WaveAudio.WaveData[0],
                          WaveAudio.WaveData.Length,
                          WaveAudio.WaveInfo.SampleRate);
            ALHelper.CheckLastError();

            Duration = WaveAudio.Duration;
        }
Пример #16
0
 private WaveAudio getWaveAudio()
 {
     double[] freqs, weights;
     getFrequenciesFromInputImage(out freqs, out weights);
     if (freqs != null)
     {
         this.freqSketch_btnPlay.Enabled = false;
         this.freqSketch_btnPlay.Invalidate();
         WaveAudio res = this.objFreqSketch.Generate(freqs, weights, (double)this.freqSketch_flipSeconds.Value, this.sketchFreq_chkFFT.Checked, this.sketchFreq_chkRandomPhases.Checked);
         this.freqSketch_btnPlay.Enabled = true;
         return(res);
     }
     else
     {
         return(null);
     }
 }
        internal static void commonSaveWaveFile(WaveAudio w)
        {
            string strFilename = getSaveFilename();

            if (strFilename == null || strFilename == "")
            {
                return;
            }
            try
            {
                w.SaveWaveFile(strFilename);
            }
            catch (Exception er)
            {
                MessageBox.Show("Error when saving wave file: " + er.Message);
                return;
            }
        }
Пример #18
0
    public void Play(WaveAudio a, bool bAsync)
    {
        m  = new MemoryStream();
        bw = new BinaryWriter(m);
        a.SaveWaveFile(bw);

        pl = new SoundPlayer(m);
        pl.Stream.Position = 0;     // This line is necessary

        if (bAsync)
        {
            pl.Play();
        }
        else
        {
            pl.PlaySync();
        }
    }
Пример #19
0
        public static void padsynthtests(AudioPlayer pl)
        {
            WaveAudio menchoir = new PadSynthesisChoir(110.0, 0.7, 1.0).CreateWaveAudio(4.0);

            pl.Play(menchoir);

            WaveAudio ww01 = new PadSynthesisEnsemble(Sine.FrequencyFromMidiNote(59), 0.7).CreateWaveAudio(4.0);
            WaveAudio ww02 = new PadSynthesisEnsemble(Sine.FrequencyFromMidiNote(64), 0.7).CreateWaveAudio(4.0);
            WaveAudio ww03 = new PadSynthesisEnsemble(Sine.FrequencyFromMidiNote(67), 0.7).CreateWaveAudio(4.0);
            WaveAudio ww04 = new PadSynthesisEnsemble(Sine.FrequencyFromMidiNote(69 + 12), 0.7).CreateWaveAudio(4.0);

            pl.Play(WaveAudio.Mix(new WaveAudio[] { ww01, ww02, ww03, ww04 }));

            WaveAudio guitar1 = new PadSynthesisExtended(110.0, 0.7).CreateWaveAudio(4.0);
            WaveAudio guitar2 = new PadSynthesisExtended(110.0 * 1.5, 0.7).CreateWaveAudio(4.0);

            pl.Play(WaveAudio.Mix(guitar1, guitar2));
        }
Пример #20
0
        private WaveAudio Go(WaveAudio win)
        {
            WaveAudio wout = new WaveAudio(44100, 1);

            wout.LengthInSamples = win.LengthInSamples;

            List <ControlFeed> activeFeeds = new List <ControlFeed>();

            foreach (ControlFeed feed in this.controlArray)
            {
                if (!feed.IsDisabled())
                {
                    activeFeeds.Add(feed);
                }
            }
            ControlFeed[] feeds = activeFeeds.ToArray();

            //get delays... actually not too efficient in terms of mem. use to precalc this...
            int[][] delays = new int[feeds.Length][];
            for (int i = 0; i < feeds.Length; i++)
            {
                delays[i] = feeds[i].Go(wout.LengthInSamples);
            }

            // now do this
            for (int i = 0; i < wout.LengthInSamples; i++)
            {
                double val = 0;
                for (int j = 0; j < feeds.Length; j++)
                {
                    int    index       = i - delays[j][i];
                    double scaleFactor = feeds[j].GetMultiply();
                    val += getSample(win, index) * scaleFactor;     // !!! !! !!!!

                    // weird stuff here!!!
                    //if (j==0) val += getSample(win, index) * scaleFactor;
                    //else val += (getSample(win, index) * scaleFactor) + 0.7*getSample(wout, index) * scaleFactor;
                }
                wout.data[0][i] = val;
            }


            return(wout);
        }
Пример #21
0
        private void button1_Click(object sender, EventArgs e)
        {
            WaveAudio test = new WaveAudio(44100, 1);

            test.LengthInSamples = 44100 * 7;
            double freq             = 100;                     //300;
            PeriodicAlternative osc = new PAChangeSquare(4.0); //new PASin();

            for (int i = 0; i < test.LengthInSamples; i++)
            {
                test.data[0][i] = 0.9 * osc.GetValue(i * freq * 2.0 * Math.PI / (double)44100.0);
            }
            //player.Play(test, true);

            WaveAudio win    = new WaveAudio(strMedia + "acoust.wav");
            WaveAudio wmixed = WaveAudio.Mix(WaveAudio.Modulate(test, win), 0.7, win, 0.3);

            player.Play(wmixed, true);
        }
Пример #22
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            var went = entry as MgsEntry;

            if (null == went || went.Format != 0)
            {
                return(arc.File.CreateStream(entry.Offset, entry.Size));
            }
            var format = new WaveFormat {
                FormatTag        = 1,
                Channels         = (ushort)(went.Channels & 0x7FFF),
                SamplesPerSecond = went.SamplesPerSecond,
            };
            Stream pcm;
            uint   pcm_size;

            if (0 != (went.Channels & 0x8000))
            {
                format.BitsPerSample = 0x10;
                var decoder = new PcmDecoder(went);
                using (var input = arc.File.CreateStream(entry.Offset, entry.Size))
                {
                    var data = decoder.Decode(input);
                    pcm      = new MemoryStream(data);
                    pcm_size = (uint)data.Length;
                }
            }
            else
            {
                format.BitsPerSample = went.BitsPerSample;
                pcm      = arc.File.CreateStream(entry.Offset, entry.Size);
                pcm_size = entry.Size;
            }
            using (var riff = new MemoryStream(0x2C))
            {
                ushort align = (ushort)(format.Channels * format.BitsPerSample / 8);
                format.AverageBytesPerSecond = went.SamplesPerSecond * align;
                format.BlockAlign            = align;
                WaveAudio.WriteRiffHeader(riff, format, pcm_size);
                return(new PrefixStream(riff.ToArray(), pcm));
            }
        }
 internal static void commonLoadWaveFile(out string strFilename, out string strShortname, out WaveAudio w)
 {
     w           = null; strShortname = null;
     strFilename = getOpenFilename();
     if (strFilename == null || strFilename == "")
     {
         return;
     }
     try
     {
         w = new WaveAudio(strFilename);
     }
     catch (Exception er)
     {
         MessageBox.Show("Error when loading wave file: " + er.Message);
         return;
     }
     string[] pathsplit = strFilename.Split(new char[] { '\\' });
     strShortname = pathsplit[pathsplit.Length - 1];
 }
Пример #24
0
        public static void operations_test(AudioPlayer pl)
        {
            WaveAudio noteLongLow = new Triangle(Triangle.FrequencyFromMidiNote(60), 0.5).CreateWaveAudio(1.0);
            WaveAudio noteShortHi = new Triangle(Triangle.FrequencyFromMidiNote(64), 0.5).CreateWaveAudio(0.5);

            pl.Play(WaveAudio.Concatenate(noteLongLow, noteShortHi));
            pl.Play(WaveAudio.Concatenate(noteShortHi, noteLongLow));
            pl.Play(WaveAudio.Mix(noteShortHi, noteLongLow));
            pl.Play(WaveAudio.Mix(noteLongLow, noteShortHi));
            WaveAudio tmp = new Sine(200, 1.0).CreateWaveAudio(4.0);

            tmp.setNumChannels(2, true);
            pl.Play(WaveAudio.Modulate(new WaveAudio(mediadir + "d44k16bit2ch.wav"), tmp));

            WaveAudio cp;

            cp = noteLongLow.Clone(); cp.FadeIn(0.3); pl.Play(cp);
            cp = noteLongLow.Clone(); cp.FadeOut(0.3); pl.Play(cp);
            cp = noteLongLow.Clone(); cp.Amplify(0.5); pl.Play(cp);
            cp = noteLongLow.Clone(); cp.Amplify(2.0); pl.Play(cp);
        }
Пример #25
0
        static void iotests_perfile(string strFilename, int nBits, int nChannels, int nRate)
        {
            WaveAudio w01 = new WaveAudio(strFilename);

            asserteq(w01.getNumChannels(), nChannels);
            asserteq(w01.getSampleRate(), nRate, "011");
            asserteqf(w01.LengthInSamples, 90725 * (nRate / 22050), 1.0, "012"); //note give 1.0 tolerance
            asserteqf(w01.LengthInSeconds, 4.1145124, "013");

            asserteq(w01.data.Length, nChannels);
            asserteq(w01.data[0].Length, w01.LengthInSamples);
            for (int i = 0; i < nChannels; i++)
            {
                asserteq(w01.data[i].Length, w01.LengthInSamples);
            }

            // test converting to other rates / quality
            w01.SaveWaveFile(mediadir + "ttout\\o_" + nRate + "_" + nBits + "_" + nRate + "_" + nChannels + ".wav", nBits);
            nBits = (nBits == 8) ? 16 : 8;
            w01.SaveWaveFile(mediadir + "ttout\\ot_" + nRate + "_" + nBits + "_" + nRate + "_" + nChannels + ".wav", nBits);
        }
        public WaveAudio Generate(double timeScale, int timeShift)
        {
            if (wLast != null && timeScale == this.timeScaleLast && timeShift == this.timeShiftLast && !bNeedUpdate)
            {
                return(wLast);
            }

            WaveAudio w = wInput.Clone();

            for (int ch = 0; ch < w.getNumChannels(); ch++)
            {
                for (int i = 0; i < w.data[ch].Length; i++)
                {
                    w.data[ch][i] = w.data[ch][i] + w.data[ch][((int)(i * timeScale) + timeShift) % w.data[ch].Length];
                }
            }
            this.timeScaleLast = timeScale;
            this.timeShiftLast = timeShift;
            this.wLast         = w;
            this.bNeedUpdate   = false;
            return(w);
        }
Пример #27
0
        public static void propertytests()
        {
            // these aren't the best tests.
            WaveAudio w1 = new WaveAudio(44100, 2);

            asserteq(w1.data.Length, 2, "channels");
            asserteq(w1.getNumChannels(), 2, "channels");
            assert(w1.data[0] != null && w1.data[1] != null, "channels");
            assert(w1.data[0].Length == 1 && w1.data[1].Length == 1, "004");
            asserteq(w1.getSampleRate(), 44100, "005");

            WaveAudio w1m = new WaveAudio(22050, 1);

            asserteq(w1m.data.Length, 1, "channels");
            assert(w1m.data[0] != null, "channels");
            asserteq(w1m.data[0].Length, 1, "004");
            asserteq(w1m.getSampleRate(), 22050, "005");

            // now set some properties
            w1m.LengthInSamples = 100;
            asserteq(w1m.data[0].Length, 100);
            asserteqf(w1m.LengthInSeconds, 100 / (double)w1m.getSampleRate(), 0.001);
        }
Пример #28
0
        public override Stream OpenEntry(ArcFile arc, Entry entry)
        {
            var oent = entry as OdnEntry;

            if (oent != null && oent.IsEncrypted)
            {
                byte key  = (byte)~entry.Offset;
                var  data = arc.File.View.ReadBytes(entry.Offset, entry.Size);
                Decrypt(data, data.Length, key);
                return(new BinMemoryStream(data));
            }
            if (AudioNameRe.IsMatch(entry.Name))
            {
                using (var wav = new MemoryStream(0x2C))
                {
                    var format = new WaveFormat {
                        FormatTag        = 1,
                        Channels         = 1,
                        SamplesPerSecond = AudioSampleRate.Get <uint>(),
                        BlockAlign       = 2,
                        BitsPerSample    = 16,
                    };
                    format.SetBPS();
                    WaveAudio.WriteRiffHeader(wav, format, entry.Size);
                    var header = wav.ToArray();
                    var data   = arc.File.CreateStream(entry.Offset, entry.Size);
                    return(new PrefixStream(header, data));
                }
            }
            var input = arc.File.CreateStream(entry.Offset, entry.Size);

            if (0x5E6A6A42 == input.Signature)
            {
                return(new XoredStream(input, 0xD));
            }
            return(input);
        }
Пример #29
0
 Stream OpenAudio(ArcFile arc, Entry entry)
 {
     using (var input = arc.File.CreateStream(entry.Offset, entry.Size))
     {
         var header      = input.ReadHeader(0x20);
         int header_size = header.ToUInt16(10);
         var format      = new WaveFormat {
             FormatTag             = header.ToUInt16(0x10),
             Channels              = header.ToUInt16(0x12),
             SamplesPerSecond      = header.ToUInt32(0x14),
             AverageBytesPerSecond = header.ToUInt32(0x18),
             BlockAlign            = header.ToUInt16(0x1C),
             BitsPerSample         = header.ToUInt16(0x1E),
         };
         input.Position = header_size + 0x10;
         var data = new byte[header.ToInt32(0)];
         KTool.Unpack(input, data, header[8]);
         var output = new MemoryStream(data.Length);
         WaveAudio.WriteRiffHeader(output, format, (uint)data.Length);
         output.Write(data, 0, data.Length);
         output.Position = 0;
         return(output);
     }
 }
Пример #30
0
        public Form1()
        {
            InitializeComponent();
            this.m_audioPlayer = new AudioPlayer();

            this.savedNum    = SetKeyState.GetNumState();
            this.savedScroll = SetKeyState.GetScrollState();
            this.savedCaps   = SetKeyState.GetCapsState();

            if (File.Exists(@"..\..\cis.wav"))
            {
                this.m_currentSound = new WaveAudio(@"..\..\cis.wav");
            }
            else if (File.Exists(@"cis.wav"))
            {
                this.m_currentSound = new WaveAudio(@"cis.wav");
            }

            if (m_currentSound != null)
            {
                this.m_currentSound.setNumChannels(1, true);
                this.lblFilename.Text = "Loaded: cis.wav";
            }
        }
Пример #31
0
 public void Play(WaveAudio a)
 {
     Play(a, false);
 }
Пример #32
0
 private void dlgBrowseFile_FileOk(object sender, CancelEventArgs e)
 {
     txtFilePath.Text = dlgBrowseFile.FileName;
     if (txtFilePath.Text.Trim() != "")
     {
         btnExtract.Enabled = true;
         btnHide.Enabled = true;
         file = new WaveAudio(new FileStream(txtFilePath.Text, FileMode.Open, FileAccess.Read));
         sh = new StagnoHelper(file);
     }
 }
Пример #33
0
 private void dlgSaveFile_FileOk(object sender, CancelEventArgs e)
 {
     file.WriteFile(dlgSaveFile.FileName);
     file = new WaveAudio(new FileStream(txtFilePath.Text, FileMode.Open, FileAccess.Read));
     sh = new StagnoHelper(file);
 }