フィルターのクリア

Play a sound at certain frequency and recording it simultaneously

13 ビュー (過去 30 日間)
Andrew Moss
Andrew Moss 2019 年 2 月 28 日
コメント済み: Walter Roberson 2020 年 4 月 12 日
Hello,
I am a novice and I need your help
The code below helps me to generate a sound at certain frequency for a certain duration, how to I record simultaneously and write it
to a file?
Fs = 44100; % Samples per second. 48000 is also a good choice
toneFreq = 22000; % Tone frequency, in Hertz. must be less than .5 * Fs.
nSeconds = 10; % Duration of the sound
a = sin(linspace(0, nSeconds*toneFreq*2*pi, round(nSeconds*Fs)));
sound(a,Fs); % Play sound at sampling rate Fs
  2 件のコメント
alon cohen
alon cohen 2020 年 4 月 12 日
why did you choose specificly Fs=44100 (or 48000) ?
how does changing Fs affect the real frequency i hear out of my computer?
thanks.
Walter Roberson
Walter Roberson 2020 年 4 月 12 日
44100 is the standard for CDs. It was a compromise based upon what available electronic circuits could affordably do at the time.
48000 is the standard for Digital Video, which came later than CDs.
Audio professionals say that the difference between 44100 and 48000 would be undetectable or barely detectable by humans.

サインインしてコメントする。

採用された回答

Shivam Gupta
Shivam Gupta 2019 年 3 月 4 日
編集済み: Walter Roberson 2019 年 3 月 4 日
To simultaneously play and record:
  1. Create the audioPlayerRecorder object and set its properties.
  2. Call the object with arguments, as if it were a function.
For more information, see:
  1 件のコメント
Walter Roberson
Walter Roberson 2019 年 3 月 4 日
編集済み: Walter Roberson 2019 年 3 月 4 日
This is for the case of recording incoming sound at the same time you are playing, not directly for the case of recording the sound that you are playing.
In order to use the above, you would need to use a hardware loopback connector -- which would end up converting to analog, emitting the signal, receiving the signal, converting to digital again.
Note: it is not possible to record outgoing sound using the winsound drivers without having a hardware loopback connector: the driver makes it impossible. However, digital loopback is a possibility with some other drivers.

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 3 月 4 日
You would probably only want to record what is playing if:
  • you need to measure the distoration characteristics of your audio system; or
  • you are using sound() to overlay multiple sounds and want to record the mix. Using sound() this way makes it pretty much impossible to synchronize the sounds, so this is not a good mixer.
What you would normally do instead is simply
audiowrite('FileNameGoeshere.wav', a, Fs)

カテゴリ

Help Center および File ExchangeAudio and Video Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by