2

I want to play sound "on-demand". A simple drum machine is what I want to program.

Is it possible to make DirectShow read from a memory buffer ?(object created by c++)

I am thinking:

Create a buffer of, lets say, 40000 positions, type double (I don't know the actual data type to use as sound, so I might be wrong with double).

40000 positions can be 1 second of playback.

The DirectShow object is supposed to read this buffer position by position, over and over again. and the buffer will contain the actual value of the output of the sound. For example (a sine-looking output):

{0, 0.4, 0.7, 0.9, 0.99, 0.9, 0.7, 0.4, 0, -0,4, -0.7, -0.9, -0.99, -0.9, -0.7, -0.4, 0}

The resolution of this sound sequence is probably not that good, but it is only to display what I mean.

Is this possible? I cannot find any examples or information about it on Google.

edit: When working on DirectShow and streaming video (UBS camera), I used something called Sample Grabber. Which called a method for every frame from the cam. I am looking for something similar, but for music, and something that is called before the music is played. Thanks

Roman R.
  • 68,205
  • 6
  • 94
  • 158
Easyrider
  • 3,199
  • 5
  • 22
  • 32
  • I have a Buffer Source filter (32-bit only). It is a source filter that contains a COM interface you can call to put data into it. If you want it, let me know. – Stephen Chung Mar 20 '15 at 09:13

1 Answers1

1

You want to stream your data through and injecting data into DirectShow pipeline is possible.

By design, outer DirectShow interface does not provide access to streamed data. Controlling code builds the topology, connects filters, sets them up and controls the state of the pipeline. All data is streamed behind the scenes, filters are passing pieces of data one to another and this adds up into data streaming.

Sample Grabber is the helper filter that allows to grab a copy of data being passed through certain graph point. Because otherwise payload data is not available to controlling code, Sample Grabber gained popularity, esp. for grabbing video frames out the the "inaccessible" stream, live or file backed playback.

Now when you want to do the opposite, put your own data into pipeline, the Sample Grabber concept does not work. Taking a copy of data is one thing, and proactive putting your own data into the stream is a different one.

To inject your own data you typically put your own custom filter into the pipeline that generates the data. You want to generate PCM audio data. You are choose where you take it from - generation, reading from file, memory, network, looping whatsoever. You fill buffers, you add time stamps and you deliver the audio buffers to the downstream filters. A typical starting point is PushSource Filters Sample which introduces the concept of a filter producing video data. In a similar way you want to produce PCM audio data.

A related question:

Community
  • 1
  • 1
Roman R.
  • 68,205
  • 6
  • 94
  • 158