Thread: How can I work with sound in a C Console Application

  1. #1
    Registered User
    Join Date
    Mar 2010

    How can I work with sound in a C Console Application

    I'm not writing a game, but the Forum description indicated that sound libraries are in this domain, so here goes.

    I have developed a C Console Application (Visual Studio 2008 Express) that, at this point, is ANSI C99 compliant. What it does is allow the programmer to write custom processing blocks and then use my framework engine to assemble the blocks and connect them together to form what I call a "radio" since the main purpose is to explore Software Defined Radio. But it's a lot more general than that - for instance, the first radio I constructed implemented a Caesar Shift Cipher.

    The basic idea is that each block takes data from an input port, performs a bit of processing, and then passes data to an output port. The overall engine repeatedly cycles through all the blocks, with each block expected to perform just a tiny amount on each pass.

    Source Blocks get their data from someplace other than another block (such as a file) while Sink Blocks send their data someplace other than another block (such as a file).

    I would like to develop two blocks that do the following:

    Sound Source Block: Gets data from the PC microphone and pushes it out to other blocks.

    Sound Sink Block: Pulls data from a block and sends it to the PC speaker.

    The data itself would simply be sound samples.

    What I envision for the Sound Source block is that, every time it is called, checks to see if there is a new block of data available from the microphone (and I don't care if a block is one sample or a thousand samples, I can work with either) and pushes out one sample to the next block. If the data from the microphone is availble in 100 sample chunks, then most of the time the block will not have anything to read from the microphone but will usually have data from the last block stored internally to push out.

    What I envision for the Sound Sink block is very similar. Every time it is called it pulls a sample value from the block preceding it and stores in internally. It then checks if the speaker is ready to accept another block of data. If so, it pushes the next block of data to it.

    One thing that is very important is that the stream of data either from the microphone or to the speaker be continuous - assuming that the engine is able to keep up with the demand (if it can't then that's my problem).

    So what I need is a means of, from a C program (Console App, not a Windows program) is a way of interfacing with the microphone and speaker that is compatible with these goals. Note that, while I want to keep the framework engine C99 compliant, I don't care if individual blocks are not compliant.

    Any recommendations?


  2. #2
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    I honestly don't know how, but you could probably stream input/output with VLC in the command line. I can do it via the gui, but don't know the switches you need to make it work.
    Consider this post signed

  3. #3
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    You can use windows.h to gain access to windows PlaySound() function that lets you play certain file formats, so the console ability to "see" sound is there.

    Try out libraries like fmod, SndLib, PortAudio, Bass... I never tried to incorporate sound on my console applications other than the odd Beep. But you did ask what can you do. I suppose you could find anything useful in there.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  4. #4
    Or working on it anyways mramazing's Avatar
    Join Date
    Dec 2005
    Lehi, UT
    You can use FMOD I'm pretty sure. just google it.
    -- Will you show me how to c++?

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    OpenAL will work as well.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using System.ServiceProcess in console application
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 06-18-2008, 11:36 PM
  2. Adding sound to console apps
    By DarkMortar in forum C Programming
    Replies: 16
    Last Post: 05-24-2006, 11:53 PM
  3. Low latency sound effects
    By VirtualAce in forum Game Programming
    Replies: 0
    Last Post: 12-21-2004, 01:58 AM
  4. sound in console
    By subflood in forum Linux Programming
    Replies: 2
    Last Post: 08-23-2004, 07:27 PM
  5. Run vbscript from C++ console application
    By dp_goose in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2003, 09:00 AM