How can I split and pipe multiple NAudio stream

Jean-Philippe Encausse

I have a C# project working with input audio Stream from Kinect 1, Kinect 2, Microphone or anything else.

waveIn.DataAvailable += (object sender, WaveInEventArgs e) => {
  lock(buffer){
    var pos = buffer.Position;
              buffer.Write(e.Buffer, 0, e.BytesRecorded);
              buffer.Position = pos;
  }
};

The buffer variable is a Stream from component A that will be processed by a SpeechRecognition component B working on Streams.

I will add new components C, D, E, working on Streams to compute pitch, detect sound, do finger printing, or anything else ...

How can I duplicate that Stream for components C, D, E ?

  • Component A send an Event "I have a Stream do what you want" I don't want to reverse the logic by an Event "Give me your streams"

  • I'm looking for a "MultiStream" that could give me a Stream instance and will handle the job

Component A

var MultiStream buffer = new MultiStream()
...
SendMyEventWith(buffer)

Component B, C, D, E

public void HandleMyEvent(MultiStream buffer){
  var stream = buffer.GetNewStream();
  var engine = new EngineComponentB()
      engine.SetStream(stream);
}
  • The MultiStream must be a Stream to wrap Write() method (because Stream do not have data available mechanics) ?
  • If a Stream is Dispose() by Component B the MultiStream should remove it from it's array ?
  • The MultiStream must throw an exception on Read() to require use of GetNewStream()

EDIT: Kinect 1 provide a Stream itself ... :-( should I use a Thread to pumpit into the MultiStream ?

Did anybody have that kind of MultiStream Class ?

Thanks

caesay

I'm not sure if this is the best way to do it or that it's better than the previous answer, and I'm not guaranteeing that this code is perfect, but I coded something that is literally what you asked for because it was fun - a MultiStream class.

You can find the code for the class here: http://pastie.org/10289142

Usage Example:

MultiStream ms = new MultiStream();

Stream copy1 = ms.CloneStream();
ms.Read( ... );

Stream copy2 = ms.CloneStream();
ms.Read( ... );

copy1 and copy2 will contain identical data after the example is ran, and they will continue to get updated as the MultiStream is written to. You can read, update position, and dispose of the cloned streams individually. If disposed the cloned streams will get removed from MultiStream, and disposing of Multistream will close all related and cloned streams (you can change this if it's not the behavior you want). Trying to write to the cloned streams will throw a not supported exception.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I implement pipe for multiple commands?

From Dev

Node - how can i pipe to a new READABLE stream?

From Dev

How can I split a pipe into 16 byte sequences?

From Dev

How can I use volumeSlider in NAudio?

From Dev

How do I resample an in-memory audio stream (byte[]) with NAudio?

From Dev

How do I resample an in-memory audio stream (byte[]) with NAudio?

From Dev

How can I tail multiple files and pipe their output to an SSH connection

From Dev

How can I time a pipe?

From Dev

How can you pipe a readable stream to another readable stream?

From Dev

How can you pipe a readable stream to another readable stream?

From Dev

How can I split a string separated with pipe symbol using jQuery regex

From Dev

How can I merge multiple Streams into a higher level Stream?

From Dev

How can I build a stream/feed from multiple objects?

From Dev

How can I stream the same music to multiple computers?

From Dev

How can I split a string into multiple parts in python?

From Dev

How can I split an ItemGroup's Excludes into multiple lines?

From Dev

How can I split my file into multiple files?

From Dev

How can I split an expression onto multiple lines in Python

From Dev

How can i split a single tuple into multiple using python?

From Dev

How can I split a character string in a dataframe into multiple columns

From Dev

How can I split a text file into multiple text files?

From Dev

How can I split my linux file into multiple files?

From Dev

How can I split Openbox `rc.xml` into multiple files?

From Dev

How can I split my Ethernet line into multiple?

From Dev

SqlDataReader prints multiple rows, how can I split?

From Dev

How can I split a character string in a dataframe into multiple columns

From Dev

How can I split a file based on multiple column values

From Dev

How can I split test methods for reuse in multiple case with Minitest?

From Dev

How can I use regexes to split strings by multiple delimiters, with a limit?

Related Related

  1. 1

    How can I implement pipe for multiple commands?

  2. 2

    Node - how can i pipe to a new READABLE stream?

  3. 3

    How can I split a pipe into 16 byte sequences?

  4. 4

    How can I use volumeSlider in NAudio?

  5. 5

    How do I resample an in-memory audio stream (byte[]) with NAudio?

  6. 6

    How do I resample an in-memory audio stream (byte[]) with NAudio?

  7. 7

    How can I tail multiple files and pipe their output to an SSH connection

  8. 8

    How can I time a pipe?

  9. 9

    How can you pipe a readable stream to another readable stream?

  10. 10

    How can you pipe a readable stream to another readable stream?

  11. 11

    How can I split a string separated with pipe symbol using jQuery regex

  12. 12

    How can I merge multiple Streams into a higher level Stream?

  13. 13

    How can I build a stream/feed from multiple objects?

  14. 14

    How can I stream the same music to multiple computers?

  15. 15

    How can I split a string into multiple parts in python?

  16. 16

    How can I split an ItemGroup's Excludes into multiple lines?

  17. 17

    How can I split my file into multiple files?

  18. 18

    How can I split an expression onto multiple lines in Python

  19. 19

    How can i split a single tuple into multiple using python?

  20. 20

    How can I split a character string in a dataframe into multiple columns

  21. 21

    How can I split a text file into multiple text files?

  22. 22

    How can I split my linux file into multiple files?

  23. 23

    How can I split Openbox `rc.xml` into multiple files?

  24. 24

    How can I split my Ethernet line into multiple?

  25. 25

    SqlDataReader prints multiple rows, how can I split?

  26. 26

    How can I split a character string in a dataframe into multiple columns

  27. 27

    How can I split a file based on multiple column values

  28. 28

    How can I split test methods for reuse in multiple case with Minitest?

  29. 29

    How can I use regexes to split strings by multiple delimiters, with a limit?

HotTag

Archive