如何产生理论上可以产生合理音频的随机音频? [英] How to produce random audio frequencies that can theoretically produce sensible audio?

查看:79
本文介绍了如何产生理论上可以产生合理音频的随机音频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在撰写一篇关于这篇文章的文章,如果我们运行随机频率,我们会得到一个合理的音频,如下面我为随机图像(视频)所见,并在文章中包含此代码来解释我的观点,你能告诉我如何制作一个基本的声音,从高音调到低音调或相反音调?



我有什么试过:



 private void Timer1_Tick(object sender,EventArgs e)
{
for(int x = 0; x <400; x ++)
for(int y = 0; y< 400; y ++)
{
g.DrawRectangle(new Pen(Color.FromArgb(255) ,
RN.Next(256),
RN.Next(256),
RN.Next(256))),
x,y,
1,1 );
}
}











我不认为嘟嘟声会像人类演讲一样发挥合理音频的作用。



在1毫秒计时器中打勾:





使用System.Runtime.InteropServices; 
[DllImport(kernel32.dll)]
public static extern bool Beep(int freq,int duration);

Beep.Play(RN.Next(MAX_HZ),1);





它能完成这项工作吗? ?如果是的话,因为我不知道声音,我应该以Hz为单位的范围频率是什么。

解决方案

我确信有数学方法来产生您要求的声音文件。但这样的事情应该有效。



增加音高(例如,降低音调将向后调整相同的数据)基本上意味着频率需要增加文件播放。很可能你会想要一个sin-wave音频,因为它听起来好一点,但如果你只是想要非常简单的代码,坚持方波。



所以循环遍历波形文件数据缓冲区。

典型地,您将使用 sin(x *< frequencydefiningconstant>)*< amplitude> 其中x是音频缓冲区中的位置。如果将sin中的值更改为非linier表达式,则会得到音高变化。所以尝试 sin(x ^ y *< frequencydefiningconstant>)*< amplitude> (y应该非常接近1,因为样本在波形文件中非常快) 。不确定这是最好的结果,你可以玩其他非线性功能......或等待并希望有人得到更好的答案。



我会期待傅立叶变换是数学上正确的方法,因为它可以在频域(您可以指定线性增加/减少)和时域(波形文件中的样本索引)之间进行转换。如果这是你的论文的正确方法可能取决于观众。


不是一个解决方案,而是一个建议。如果你的意思是音乐,当你说合理的音频时,我建议生成0到127之间的随机整数值,使用该值就好像它是一个MIDI音符,然后通过查找表查找该音符的频率值。某种。 EX:MIDI 60 =中C = 261.6 Hz



这是常规的西方全音阶音乐。还有其他。



就播放音频而言,请查看public static void Beep(int frequency,int duration)以获取最基本的方法。有更好的方法,使用计算机音频功能而不是Beep。


无限猴子定理 - 维基百科 [ ^ ]



什么是SETI项目? |酷宇宙 [ ^ ]

I'm writing an article about that with endless time if we run random frequencies we would get a sensible audio, as seen below I made for random images (video) and included this code in the article to explain my point, also would you please teach me how to produce for example a basic sound beep that goes from a high pitch to a low pitch or the opposite?

What I have tried:

private void Timer1_Tick(object sender, EventArgs e)
        {
            for (int x = 0; x < 400; x++)
                for (int y = 0; y < 400; y++)
                {
                    g.DrawRectangle(new Pen(Color.FromArgb(255,
                        RN.Next(256),
                        RN.Next(256),
                        RN.Next(256))),
                        x,y,
                        1,1);
                }
        }






I don't think beep will do the job of sensible audio like human speech.

In a 1 ms timer tick:


using System.Runtime.InteropServices;
[DllImport("kernel32.dll")]
public static extern bool Beep(int freq, int duration);

Beep.Play(RN.Next(MAX_HZ),1);



Does it do the job? if yes, as I don't know about sound, what is the range frequency in Hz I should run.

解决方案

I am sure there are mathematical ways to produce the sound file you are requesting. But something like this should work.

Increasing the pitch (as an example, decreasing pitch will just be the same data backwards) basically means the frequency needs to be increasing as the file is played. Most likely you would want a sin-wave for your audio as it sounds a bit nicer, but if you just want really simple code, stick to square wave.

So loop over the length of your wave file data buffer.
Typially you would use sin(x * <frequencydefiningconstant>) * <amplitude> where x is the position in the audio buffer. If you change the value in sin to a non-linier expression, you will get variation in the pitch. so try sin(x^y * <frequencydefiningconstant>) * <amplitude> (y should be really close to 1, as samples come pretty fast in a wave file). Not sure this is the best result, you can play with other non-linier functions... or wait and hope someone comes with a better answer.

I would expect a Fourier transforms is the mathematical right way to do it as it can transform between the frequency domain (where you can specify a linier increase/decrease) and the time domain (your sample index in the wave file). If this is the right approach for your paper probably depends on the audience.


Not a solution, so much as a suggestion. If you mean music when you say "sensible audio", I'd suggest generating random integer values between 0 and 127, using that value as if it were a MIDI note, then looking up the frequency value of that note via a lookup table of some sort. EX: MIDI 60 = Middle C = 261.6 Hz

That's for regular "Western" diatonic music. There are others.

As far as playing the audio, look at public static void Beep (int frequency, int duration) for the most basic way of doing it. There are better ways, using the computers audio features rather than the Beep.


Infinite monkey theorem - Wikipedia[^]

What is the SETI project? | Cool Cosmos[^]


这篇关于如何产生理论上可以产生合理音频的随机音频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆