I’m trying to create two channel audio comprising two discrete sine waves in MATLAB. The sine waves will be identical, except that I want the user to be able to change the phase of one of the sine waves. I posted a full description on Stack Overflow:
I realise it’s poor form to post on two forums. However, I’ve become increasingly concerned that MATLAB won’t be able to do what I want. For example, even with add-ons like the Digital Processing Toolbox and the Audio Toolbox, I worry about MATLAB’s sound handling and the possibility for unexpected behaviour. I thought PsychPortAudio might offer a better solution. If so, I will update the Stack Overflow thread.
For the user-controlled phase changes to a single sine wave, I thought the following might work in PsychPortAudio :
- Generate a single cycle of a sine wave using MATLAB routines (e.g. based on the sine function).
- Pass the single cycle sine wave data to PsychPortAudio in a format in which it can be output by PsychPortAudio.
- Have PsychPortAudio play back the single cycle sine wave infinitely, so that it will loop into a continuous tone.
- Enable user-controlled delays in the PsychPortAudio output. The delays should be fractions of a single cycle of a sine wave. For example, with a 500 Hz sine wave a single cycle is 2 milliseconds. So, the user-controlled delays would be between 0 and 2 milliseconds. These delays will be imperceptible to the user, but will have the effect of altering phase of the sine wave as desired.
Will this work? I’m not sure about steps (2) and (4). For (2), I wonder if the simplest solution is to write the sine wave data to disk (e.g. as a FLAC file) and have PsychPortAudio read it back in? For (4), I thought the Psychtoolbox features for frame buffering might be effective. However, these are generally described with application to screen draw. I wasn’t sure how they’d apply to buffering an audio loop.