http://stackoverflow.com/questions/1302 ... -in-lazaru
Since there are many demoscene minds here, I think it won't hurt to ask for help.
Please help me with very specific question
Moderator: Moderators
Hi darkhog,
Generating sounds is really easy .. after all, PCM is simply a 1D ( usually unsigned 16-bit ) array. Attached is a example project that contains the formulas to generate Sine / Triangle / Square / Noise samples. Keep in mind that ZGE uses floating-point values ( instead of unsigned shorts ).
K
Generating sounds is really easy .. after all, PCM is simply a 1D ( usually unsigned 16-bit ) array. Attached is a example project that contains the formulas to generate Sine / Triangle / Square / Noise samples. Keep in mind that ZGE uses floating-point values ( instead of unsigned shorts ).
K
- Attachments
-
- Samples.zgeproj
- (1.44 KiB) Downloaded 875 times
Hi darkhog,
Anyway, if you'd want to generate a 1-second mono sine-wave at 44100Hz in C, the following ..
.. becomes this ..
As far as API's are concerned I'd recommend DirectSound on Windows, Core Audio on MacOS and ALSA on Linux.
K
A .zgeproj fits perfectly in the psuedo-code categorydarkhog wrote:As it has nothing to do with ZGE, I'd appreciate more Pascal/pseudocode example.

Code: Select all
<Sample Name="SineSample" Length="1">
<Producers>
<SampleExpression>
<Expression>
<![CDATA[this.Sample = sin(this.Time*PI*512);]]>
</Expression>
</SampleExpression>
</Producers>
</Sample>
Code: Select all
float sineWave[44100]; // Warning: Stack overflow ;-P
for(int i=0; i<44100; i++)
{
float time = (float)i / 44100.0f;
sineWave[i] = sin(time * PI * 512.0f);
}
K