Find the answer to your Linux question:
Results 1 to 6 of 6
I have a program that reads the input from the sound card (mic) and writes that same data to the output of the card in real time. What would be ...
  1. #1
    Just Joined!
    Join Date
    Dec 2003
    Posts
    41

    sound delay

    I have a program that reads the input from the sound card (mic) and writes that same data to the output of the card in real time. What would be the best option for me not to do this in real time. I mean like add something like a 200 msec delay?

    Thanks.

  2. #2
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    That depends on what you mean by "I have a program". Martin Luther King said "I have a dream," but you have more than a dream here.

    If you mean that you wrote the program, then construct a ring buffer to hold the data, perhaps one tenth of a second per buffer, and work out the logic yourself.

    If you mean that you have the source of the program, then get familiar with the source, change it as above, and go!

    If you mean that you have no source and can't get it, then if the documentation for the program doesn't answer the question, you might be stuck.

    I know this doesn't help much, but in the first two cases it's at least a start.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  3. #3
    Just Joined!
    Join Date
    Dec 2003
    Posts
    41
    I actually have the source. In fact, the program is my own.

    Could you elaborate on the "ring buffer' concept?

    Thanks.

  4. #4
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    I misspoke myself; not ring buffer, but buffer ring.

    You have a "circle" of buffers; each points to the next, and the final one points to the first one.

    Is it possible to store a tenth of a second of data in each buffer, and then move along to the next? And play nothing for the first 20 seconds?

    Then, asynchronously continue storing a tenth of a second of sound in each buffer after that, and start consuming buffers from the beginning, outputting the sound?

    I feel like I'm blowing smoke here, but does this work?
    --
    Bill

    Old age and treachery will overcome youth and skill.

  5. #5
    Just Joined!
    Join Date
    Dec 2003
    Posts
    41
    Quote Originally Posted by wje_lf View Post
    I misspoke myself; not ring buffer, but buffer ring.

    You have a "circle" of buffers; each points to the next, and the final one points to the first one.

    Is it possible to store a tenth of a second of data in each buffer, and then move along to the next? And play nothing for the first 20 seconds?

    Then, asynchronously continue storing a tenth of a second of sound in each buffer after that, and start consuming buffers from the beginning, outputting the sound?

    I feel like I'm blowing smoke here, but does this work?
    Hi!

    Your idea makes some sense. Perhaps I can post the block of code that copies data from input to output. I'm using the JACK audio connection kit if you're familiar with it.

    Code:
    jack_default_audio_sample_t *out = 
                    (jack_default_audio_sample_t *) 
                    jack_port_get_buffer (output_port, nframes);
    	jack_default_audio_sample_t *in = 
                    (jack_default_audio_sample_t *) 
                    jack_port_get_buffer (input_port, nframes);
    
    	memcpy (out, in, sizeof (jack_default_audio_sample_t) * nframes);
    This above block of code merely copies the data from the input buffer (in) to the output (out). jack_default_audio_sample_t is used to hold audio data. As is obvious, memcpy() is the important part because it does the actual copy. Function description are here:
    JACK-AUDIO-CONNECTION-KIT: jack.h File Reference

  6. #6
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    Seems straightforward to me. Don't have a simple input buffer and output buffer; have a ring of buffers, and choose a small value of nframes.
    --
    Bill

    Old age and treachery will overcome youth and skill.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...