play audio file continuously without gaps

Discussion in 'MATLAB' started by Francesco, Mar 29, 2007.

  1. Francesco

    Francesco Guest

    I'm trying to write a code to play a wav file in a loop.
    I succeeded in doing it (quite easy task,you may say!),but I still
    have a problem: a blank can be heard between one play and the next.
    can anyone help me?
    there is any way to play it continuously without spot when the audio
    file starts again?
    Francesco, Mar 29, 2007
    1. Advertisements

  2. If you read in you wav file into memory you end up with the
    matrix/vector of sound amplitudes.

    You can use size to determine the length of your sound. Create an
    indexing mechanism that counts modulo sound length, then output the
    data from that out to your sound system.

    Data Acquisition Toolbox has some very nice functions that make this
    almost trivial.


    Dave Robinson
    Dave Robinson, Mar 29, 2007
    1. Advertisements

  3. Francesco

    Francesco Guest

    Thank you very much Dave....
    i'll try what you suggested,even if i'm not sure i'll succeed as i'm
    quite a novice!
    Francesco, Mar 29, 2007
  4. Francesco

    Francesco Guest

    Hey Dave,

    sorry if i bother you again,but i tried to do what you suggested to
    me...but i think i did some mistakes as matlab is playing the audio
    files all at the same time.
    this is the code i wrote:




    for i=0:200

    can you or anyone else help me to fix it please?

    thank you
    Francesco, Mar 29, 2007
  5. I don't have time to debug your programme for you, but what I don't
    understand is that you have got the length of your sound array, but I
    can't see it used anywhere. I would have expected to see a mod
    function or something in there - perhaps you have been clever, and I
    am being thick - it is getting late here.

    I think that your sounds all being played at the same time comes
    about from your loop being much faster than the time of play, so you
    start playing the next chunk as soon as you hit sound again.

    I don't have Matlab here so I am running from my memory, which isn't
    all that good these days. But from what I recall, you can also output
    sound from an audioplayer function, which can either operate in a
    nonblocking mode, doing exactly what you have now, or a blocking
    mode, which stops processing until the sound system has finished
    playing you buffer. Which is exactly what you want. This will have
    microscopic delays between buffer loads, but I guess they would be so
    short that you need superhuman ears to hear them. I also vaguely
    remember that you can play a fraction of a sound file by selecting
    start and stop sample numbers. Combining this with your modulo
    addressing might make it very slick indeed.


    Dave Robinson
    Dave Robinson, Mar 29, 2007
  6. Francesco

    Francesco Guest

    Francesco, Mar 29, 2007
  7. Francesco

    Francesco Guest

    Thank you very much again Dave for your precious tips!
    I just noticed that i did only one part of what you suggested to me
    at the beginning as i got the lenght of my sound array but i didn't
    use it.
    If i was clever...and i don't think was only by chance! :)

    thank you again for your help
    Francesco, Mar 29, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.