Playrec - Forum

Multi-channel Matlab Audio

You are not logged in.

#1 2010-05-29 09:19:02

Visne
New member
Registered: 2010-05-29
Posts: 2

playing a wav sample

Hi Rob,

Thank tou very much, Playrec is a very useful tool! You did a really good work.

I'm trying to implement a pitchTracking program, that can analyze your voice, token from mic or a wav sample.
In the second case, I'm able to get the file open and analyzed, but when i want to play this sample, i get some trouble:
I'd like to play the whole sample, and while playing drawing some graphs in real time.

I'm able to do that when I rec, but no idea about play! Is there a function like playrec('getRec',...) that I can use on play?

I tried dividing the sample in windows, and playng the sample window by window: this way graphs are ok, but play is not 'nice to ear' because of a latency between windows, due to while condition evaluation.

while counter+2*windowLength < length(audioSample)
    if counter == 1
        frame =audioSample(counter : counter+windowLength-1);
    else
        frame = nextFrame;
    end
    set(timeLineSegnale, 'YData', frame);
    set(timeLineAutocorr,'YData', autocorrelation);
    drawnow;   
    while(playrec('isFinished') == 0);end;                        <- This is to coordinate graphs and play
    playrec('play',frame,1);
    counter = counter+windowLength;
    nextFrame = audioSample(counter : counter+windowLength-1);   
end

Is it possible to use a playrec function (such as 'getRec') to do it better? Can you suggest me something?

Thank you very much!!!

Valerio

Offline

 

#2 2010-05-29 11:25:40

Rob
Administrator
Registered: 2007-12-23
Posts: 54

Re: playing a wav sample

What you want to do is possible, you will just need to be slightly clever in how you do it!

The Playrec command 'play' returns a unique page number that is associated with the frame of audio that you supplied.  The 'isFinished' command can take an optional parameter which is a page number.  When a page number is supplied it tells you whether that page (or frame as you're calling them) of samples has finished.  The 'block' command is similar in that it can be made to wait until a particular page has finished rather than all pages queued up.

Here's a rough flow to get you going:

1) Send multiple frames to Playrec one after the other (don't wait for them to complete).  As you are only playing this can be any number (maybe try 10 or so initially), just make sure it's large enough to avoid glitches (found through trial and error!).  Keep a record of the page number returned for each frame.

2) Display the graph for the first frame of samples

3) Wait for the first page to complete (this is why you need to keep track of the page numbers returned!).

4) Send Playrec the next frame of samples continuing from where you got to, again keeping a record of the page number returned.

5) Loop back to (2) but this time display the graph for the second frame of samples.

Note how you're displaying graphs for frames you sent to Playrec a little while previously.  Playrec needs to have the next frame of samples before the previous frame finishes to avoid audible glitches...but this doesn't mean you have to display the graph for that frame!

If you look at the play_wav.m file in the example scripts download then this shows how to play a wav file using multiple pages. It waits for the first page in the list of pages sent to Playrec to finish before sending another one to add to the end of the list.  You could potentially use this file as a starting point, modifying it as follows:

    if(length(pageNumList) > pageBufCount)
        if(runMaxSpeed)
            while(playrec('isFinished', pageNumList(1)) == 0)
            end
        else       
            playrec('block', pageNumList(1));
        end

        pageNumList = pageNumList(2:end);

<Add your code here to display the graphs.  The first time this code is run you should display the graph for the SECOND frame - the first frame should be displayed before the outer for loop starts.  The next time the code is run it should display the graph for the 3rd frame and so on.>

    end

I hope this helps - please let me know how you get on.

Offline

 

#3 2010-05-29 14:59:43

Visne
New member
Registered: 2010-05-29
Posts: 2

Re: playing a wav sample

Ops, sorry, i didn't notice that example... With the file 'play_wav.m' and your suggestions I was able to solve my problem! big_smile


Thank you so much for the fast answer and for your essential help!

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2008 PunBB