octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GSoC audio callbacks


From: Vytautas Jancauskas
Subject: Re: GSoC audio callbacks
Date: Sun, 18 Aug 2013 00:52:29 +0300

On Tue, Aug 13, 2013 at 8:56 PM, Mike Miller <address@hidden> wrote:
> Hi Vytautas,
>
> I took a look at the latest audio feature you added, callback
> functions for playback and recording [1]. For everyone else following
> along, this is an Octave extension that will allow a user function to
> supply or consume an audio stream in real-time rather than storing the
> entire signal in memory.
>
> [1] 
> http://gsoc2013octaveaudio.blogspot.com/2013/08/writing-portaudio-callbacks-in-octave.html
>
> I had better luck with the playback, and it definitely worked better
> for me than when I tried it the week before. There were still some
> issues with playback, though, and I didn't get much success from
> recording.
>
> Playing audio with a callback:
>
> I created a white noise function and got playback working relatively easily:
>
>   function [y, status] = generate_sound (n)
>     y = randn (n, 1);
>     status = 1;
>   endfunction
>   player = audioplayer (@generate_sound);
>   play (player);
>
> This did run for quite some time with no problem. I couldn't find
> where the status return value was used, so I didn't try different
> values there. Eventually (tens of seconds, maybe a minute or two), the
> sound changed from white noise to a buzz and I got an error about some
> value not being defined. When I tried to stop and play the player
> object again, Octave crashed. I will try to reproduce this and get
> some more debug information.
>

See if this still happens after the latest changes.

> Recording audio to a callback:
>
> I tried to do the same with recording, but for some reason the
> callback function was only called after I called the stop method. I
> did something simple like this:
>
>   function do_record (left, right, n)
>     disp (n);
>   endfunction
>   recorder = audiorecorder (@do_record);
>   record (recorder);
>   stop (recorder);
>
> The number "512" was displayed once, and only after calling stop.
>

This is because you don't return a status value. Return 0 to continue
playback 1 if you want to stop cleanly and 2 if you want to stop
abruptly.

> Do you have a performance reason or use case in mind for separating
> the left and right channels the way it is now? Unless there is a
> compelling reason, I would think it better to be consistent with the
> way audio data is treated now, a single matrix with one column per
> channel for multi-channel audio.
>

Now it uses matrices such as you described them.

> To me it makes more sense if the play callback were simply "data =
> func (nsamples)" and the record callback is "func (data)", since the
> size argument can be inferred from the dimensions of the data matrix.
>

I think it is important that the callback return a status as well.
This allows for graceful handling of errors and other issues inside of
the callback, just return 1 in case of error and portaudio will stop
trying to call the callback.

> Let me know if I'm looking at these callbacks wrong or if you want me
> to try a different way.
>
> As always, great progress on this project.
>
> --
> mike

http://gsoc2013octaveaudio.blogspot.com/2013/08/changes-to-octave-callback-interface.html


reply via email to

[Prev in Thread] Current Thread [Next in Thread]