public void ReadMonoFromFileTest()
 {
     using (BassAudioService bass = new BassAudioService())
     {
         string tempFile = Path.GetTempPath() + "\\" + 0 + ".wav";
         bass.RecodeTheFile(PathToMp3, tempFile, 5512);
         float[] samples = bass.ReadMonoFromFile(PathToMp3, SampleRate);
         FileInfo info = new FileInfo(tempFile);
         long expectedSize = info.Length - WaveHeader;
         long actualSize = samples.Length * (BitsPerSample / 8);
         Assert.AreEqual(expectedSize, actualSize);
     }
 }
        public void ReadMonoFromFileUsingBothProxiesTest()
        {
            string name = MethodBase.GetCurrentMethod().Name;
            using (BassAudioService bassAudioService = new BassAudioService())
            {
                using (DirectSoundAudioService directSoundAudioService = new DirectSoundAudioService())
                {
                    float[] bdata = bassAudioService.ReadMonoFromFile(PathToMp3, 5512);
                    float[] ddata = directSoundAudioService.ReadMonoFromFile(PathToWav, 5512);

                    for (int i = 0; i < bdata.Length; i++)
                    {
                        if ((Math.Abs(bdata[i] - ddata[i]) / int.MaxValue) > 1)
                        {
                            Assert.Fail("Data arrays are different: " + bdata[i] + ":" + ddata[i] + " at " + i);
                        }
                    }

                    Assert.AreEqual(bdata.Length, ddata.Length);
                }
            }
        }
        private void BtnDrawSignalClick(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(_tbPathToFile.Text))
            {
                MessageBox.Show(
                    Resources.SelectAPathToBeDrawn,
                    Resources.SelectFile,
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
                return;
            }

            if (!File.Exists(Path.GetFullPath(_tbPathToFile.Text)))
            {
                MessageBox.Show(
                    Resources.NoSuchFile, Resources.NoSuchFile, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            SaveFileDialog sfd = new SaveFileDialog
                {
                    Filter = Resources.FileFilterJPeg,
                    FileName = Path.GetFileNameWithoutExtension(_tbPathToFile.Text) + "_signal_" + ".jpg"
                };

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                string fullpath = Path.GetFullPath(_tbPathToFile.Text);
                FadeControls(false);
                Action action = () =>
                    {
                        using (IAudioService proxy = new BassAudioService())
                        {
                            float[] data = proxy.ReadMonoFromFile(
                                fullpath, new DefaultFingerprintingConfiguration().SampleRate, 0, 0);
                            Bitmap image = Imaging.GetSignalImage(data, (int)_nudWidth.Value, (int)_nudHeight.Value);
                            image.Save(sfd.FileName, ImageFormat.Jpeg);
                            image.Dispose();
                        }
                    };

                action.BeginInvoke(
                    (result) =>
                        {
                            FadeControls(true);
                            action.EndInvoke(result);
                            MessageBox.Show(
                                Resources.ImageIsDrawn,
                                Resources.Finished,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                        },
                    null);
            }
        }