Test
Audio signal generation code: sine, sawtooth, sweep
Preguntas del test (1)
1Write the code to generate a band limited 1000Hz sawtooth wave.
- A// Call to open the processing output
if(!ProcessBegin())
return;
short audio[2];
double t = 0;
for(int i=0; i<SampleFrames(); i++, t+= 1. / SampleRate())
{
ProcessReadFrame(audio);
double mix = 0.5 * audio[0] + 0.5 * audio[1];
double pongL = sin(2 * M_PI * 5 * t) * 0.5 + 0.5;
double pongR = 1 - pongL;
audio[0] = short(audio[0] * pongL);
audio[1] = short(audio[1] * pongR);
ProcessWriteFrame(audio);
// The progress control
if(!ProcessProgress(double(i) / SampleFrames()))
break;
}
// Call to close the generator output
ProcessEnd();
/////////////////////////////////////////////// - Bfor(double time=0.; time < duration; time += 1. / sampleRate)
{
double s = 0;
for(int h=1; h<(sampleRate / (2 * 1000)); h++)
s += sin(2 * M_PI * h * 1000 * t) / h;
short sample = short(amplitude *s);
audio[0] = audio[1] = sample;
GenerateFrame(audio);
} - Cdouble COscillator::GetSample()
{
double sample = amplitude * sin(radians);
radians += (2 * M_PI * m_freq1) / m_sampleRate;
return sample;
} - Ddouble radians = 0; // For the sine wave
double samplePeriod = 1. / sampleRate;
for(double time=0.; time < duration; time += samplePeriod)
{
double freq = 100 + (1000 - 100) * time / 10;
short sample = short(amplitude * sin(radians));
audio[0] = audio[1] = sample;
// Increment the phases
radians += (2 * M_PI * freq) / sampleRate;
GenerateFrame(audio);
}
/////////////////////////////////////////////////////////////////////////////
- A// Call to open the processing output
Información
- Descripción
- CEO/Managing Director Multimedia Computign Test sobre Sin título, creado por Laurenz h el 10/11/2021.
- Autor
- Laurenz h
- Idioma
- Deutsch
- Visitas
- 0
- Etiquetas
- Valoración
- Aún sin valoraciones Valora este test