Ejemplo n.º 1
0
        // Use this as an alternative to inject an extra silent channel into the stream
        public static IProducer <AudioBuffer> AddSilentChannel(this IProducer <AudioBuffer> audioStream)
        {
            byte[] audioWithExtraChannel = null;

            return(audioStream.Select(
                       audio =>
            {
                int bytesPerChannel = audio.Length / audio.Format.Channels;
                int bytesPerSample = audio.Format.BitsPerSample / 8;
                if (audioWithExtraChannel?.Length != audio.Length + bytesPerChannel)
                {
                    audioWithExtraChannel = new byte[audio.Length + bytesPerChannel];
                }

                for (int i = 0, j = 0; i < audio.Data.Length;)
                {
                    for (int k = 0; k < audio.Format.Channels; k++)
                    {
                        for (int l = 0; l < bytesPerSample; l++)
                        {
                            audioWithExtraChannel[j++] = audio.Data[i++];
                        }
                    }

                    // inject silent sample
                    for (int l = 0; l < bytesPerSample; l++)
                    {
                        audioWithExtraChannel[j++] = 0;
                    }
                }

                var newFormat = WaveFormat.Create16BitPcm((int)audio.Format.SamplesPerSec, audio.Format.Channels + 1);
                return new AudioBuffer(audioWithExtraChannel, newFormat);
            }));
        }
Ejemplo n.º 2
0
 private void ButtonCreate16BitPcm_Click(object sender, RoutedEventArgs e)
 {
     Update(WaveFormat.Create16BitPcm((int)Format.SamplesPerSec, Format.Channels));
 }