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

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 Commenti

not sure about your set-up, but this seems to work (silence in one ear, sine in the other). If you want to hear the actual sine wave progressing, you will need to move the call to inside the for loop though:
dev_writer = audioDeviceWriter;
sineGenerator = audioOscillator;
sineGenerator.Frequency = note2Freq(79);
count = 0;
static = zeros(length(sine),1);
while count < 1000
sine = sineGenerator();
dev_writer([sine,static]);
count = count + 1;
end
Thanks!
What do you mean by hearing the sine wave progressing? I thought that the generator just returns the same sine wave each time you call it to get a sine from it..
Hi Jonathan,
audioOscillator does not return the same sine wave each time you call it. When you call it, it will give you a frame of the sine wave (controlled by value of SamplesPerFrame). When you call it again, you get the next sine wave frame in time. If you stitch/plot consecutive outputs of the oscillator, you get the repeating sine wave. One output of the oscillator might just be a small part of the sine wave period, or could include multiple periods: that all depends on SamplesPerFrame and SampleRate.
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!
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

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Audio I/O and Waveform Generation in Centro assistenza e File Exchange

Richiesto:

il 13 Set 2022

Commentato:

il 28 Set 2022

Community Treasure Hunt

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

Start Hunting!

Translated by