The example for outputing audio through only one channle doesn't work for me.. (audioDeviceWriter & audioOscillator)

1 view (last 30 days)
I can't get this example to work at all - it's supposed to play a sine wave in one channle, and a static through the other, but I still get sound from both channles.
I've tried substituting zeros for randn to totally mute the other channel, but it had no effect either.
dev_writer = audioDeviceWriter;
sineGenerator = audioOscillator;
sineGenerator.Frequency = note2Freq(79);
count = 0;
sine = sineGenerator();
static = zeros(length(sine),1);
while count < 1000
dev_writer([sine,static]);
count = count + 1;
end
  5 Comments
Jonathan Sahar
Jonathan Sahar on 28 Sep 2022
Thanks for your answer. Since the sine wave is periodic (i.e. repetitive) doesn't it mean that calling audioOscillator with the same SamplesPerFrame and SampleRate will return the same waveform/frame?
At any rate - I've tested the code again, and can verify that it doesn't work as intended in terms of being one-sided: the channel that's supposed to be the only one working is much louder, but there's definitely sound coming from the other channel as well (same generated sound, not noise).
Could you advise? Thanks!
Walter Roberson
Walter Roberson on 28 Sep 2022
If the samples per frame is not an integer multiple of samples per cycle then the calls to the generator will not return the same result.
For example if you ask for 10000 samples per frame and a sample frequency of 22100 Hz then one frame would be 2.21 cycles, and the second call to the generator would start 0.21 cycles in, not at the beginning of a cycle

Sign in to comment.

Answers (0)

Categories

Find more on Audio I/O and Waveform Generation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!