コード例 #1
0
        public void GetAllFormats()
        {
            Pcm16Format pcm   = GenerateAudio.GeneratePcmSineWave(100, 1, 48000);
            var         audio = new AudioData(pcm);

            Assert.Collection(audio.GetAllFormats(), x => Assert.True(x is Pcm16Format));

            audio.GetFormat <GcAdpcmFormat>();
            Assert.Collection(audio.GetAllFormats(), x => Assert.True(x is Pcm16Format), x => Assert.True(x is GcAdpcmFormat));
        }
コード例 #2
0
        public void LoadFile(AudioData audioData, IFileFormat fileFormat)
        {
            AudioFileFormats.Add(fileFormat);

            //Load Channel Info
            AudioFile file = new AudioFile();

            file.Title = fileFormat.FileName;
            if (fileFormat is VGAdudioFile)
            {
                file.vgAdudioFile = (VGAdudioFile)fileFormat;
            }

            //Loop through each channel and set it's own
            var format = audioData.GetAllFormats().ToArray()[0];

            for (int c = 0; c < format.ChannelCount; c++)
            {
                using (var memWav = new MemoryStream())
                {
                    AudioChannel audioChannel = new AudioChannel();
                    audioChannel.Name = $"Channel [{c}]";
                    file.Channels.Add(audioChannel);

                    //Load data and write to stream
                    var audio  = format.GetChannels(c).ToPcm16();
                    var writer = new WaveWriter();
                    writer.WriteToStream(audio, memWav);
                    audioChannel.Data = memWav.ToArray();

                    memWav.Position = 0;

                    //Load the player
                    audioChannel.audioPlayer.Open(new MemoryStream(audioChannel.Data), "wav", activeDevice);

                    /*     OpenFileDialog openFileDialog = new OpenFileDialog();
                     *   if (openFileDialog.ShowDialog() == DialogResult.OK)
                     *   {
                     *       audioChannel.audioPlayer.Open(openFileDialog.FileName, activeDevice);
                     *   }*/


                    audioChannel.audioPlayer.PlaybackStopped += (s, args) =>
                    {
                        //WasapiOut uses SynchronizationContext.Post to raise the event
                        //There might be already a new WasapiOut-instance in the background when the async Post method brings the PlaybackStopped-Event to us.
                        if (audioChannel.audioPlayer.PlaybackState != PlaybackState.Stopped)
                        {
                        }
                    };
                }
            }

            audioListView.AddObject(file);

            if (audioListView.Items.Count != 0)
            {
                audioListView.SelectedIndex = 0;
            }
        }
コード例 #3
0
        public static PCM16Audio FromAudioData(AudioData a)
        {
            byte[] data = new WaveWriter().GetFile(a);
            var    w    = FromByteArray(data);

            if (!a.GetAllFormats().Any(f => f.Looping))
            {
                w.NonLooping = true;
            }
            w.OriginalAudioData = a;
            return(w);
        }
コード例 #4
0
        public void AddDifferentFormats()
        {
            Pcm16Format   pcm    = GenerateAudio.GeneratePcmSineWave(100, 1, 48000);
            GcAdpcmFormat adpcm  = GenerateAudio.GenerateAdpcmSineWave(100, 1, 48000);
            var           audio  = new AudioData(pcm);
            var           audio2 = new AudioData(adpcm);

            AudioData combined = AudioData.Combine(audio, audio2);

            Assert.Collection(combined.GetAllFormats(), x => Assert.True(x is Pcm16Format));
            var pcmCombined = combined.GetFormat <Pcm16Format>();

            Assert.Same(pcm.Channels[0], pcmCombined.Channels[0]);
            Assert.Equal(2, pcmCombined.ChannelCount);
        }
コード例 #5
0
        public void AddSameFormatsAfterEncodingChoosesEncodedFormat()
        {
            Pcm16Format pcm    = GenerateAudio.GeneratePcmSineWave(100, 1, 48000);
            Pcm16Format pcm2   = GenerateAudio.GeneratePcmSineWave(100, 1, 48000);
            var         audio  = new AudioData(pcm);
            var         audio2 = new AudioData(pcm2);

            var adpcm  = audio.GetFormat <GcAdpcmFormat>();
            var adpcm2 = audio2.GetFormat <GcAdpcmFormat>();

            AudioData combined = AudioData.Combine(audio, audio2);

            Assert.Collection(combined.GetAllFormats(), x => Assert.True(x is GcAdpcmFormat));
            var pcmCombined   = combined.GetFormat <Pcm16Format>();
            var adpcmCombined = combined.GetFormat <GcAdpcmFormat>();

            Assert.Same(adpcm.Channels[0].GetAdpcmAudio(), adpcmCombined.Channels[0].GetAdpcmAudio());
            Assert.Same(adpcm2.Channels[0].GetAdpcmAudio(), adpcmCombined.Channels[1].GetAdpcmAudio());
            Assert.NotSame(pcm.Channels[0], pcmCombined.Channels[0]);
            Assert.NotSame(pcm2.Channels[0], pcmCombined.Channels[1]);
            Assert.Equal(2, adpcmCombined.ChannelCount);
        }
コード例 #6
0
        public void AddDifferentFormatsMultipleInputs()
        {
            Pcm16Format pcmFormat = GenerateAudio.GeneratePcmSineWave(100, 4, 48000);
            Pcm16Format pcm0      = pcmFormat.GetChannels(0);
            Pcm16Format pcm1      = pcmFormat.GetChannels(1, 2);
            Pcm16Format pcm2      = pcmFormat.GetChannels(3);
            var         audio0    = new AudioData(pcm0);
            var         audio1    = new AudioData(pcm1);
            var         audio2    = new AudioData(pcm2);

            audio0.GetFormat <GcAdpcmFormat>();
            audio2.GetFormat <GcAdpcmFormat>();

            AudioData combined = AudioData.Combine(audio0, audio1, audio2);

            Assert.Collection(combined.GetAllFormats(), x => Assert.True(x is Pcm16Format));
            var pcmCombined = combined.GetFormat <Pcm16Format>();

            Assert.Equal(4, pcmCombined.ChannelCount);
            Assert.Same(pcm0.Channels[0], pcmCombined.Channels[0]);
            Assert.Same(pcm1.Channels[0], pcmCombined.Channels[1]);
            Assert.Same(pcm1.Channels[1], pcmCombined.Channels[2]);
            Assert.Same(pcm2.Channels[0], pcmCombined.Channels[3]);
        }