Skip to content
Snippets Groups Projects
Commit 70969ea2 authored by Florent Berthaut's avatar Florent Berthaut
Browse files

Added non pitched additive synthesis

parent 2fcaa88e
Branches
No related tags found
No related merge requests found
...@@ -191,9 +191,8 @@ ProjectorModule::ProjectorModule(): Module() { ...@@ -191,9 +191,8 @@ ProjectorModule::ProjectorModule(): Module() {
//audio //audio
m_nbTracks=50; m_nbTracks=3000;
//m_maxAudioValue = (std::numeric_limits<int>::max())/(m_width * m_height); m_maxAudioValue = (std::numeric_limits<int>::max())/(m_width * m_height);
m_maxAudioValue = (std::numeric_limits<int>::max())/(m_width);
m_audioMixSize = AudioManager::getInstance()->getMixSize(); m_audioMixSize = AudioManager::getInstance()->getMixSize();
m_audioBufSize = AudioManager::getInstance()->getBufferSize(); m_audioBufSize = AudioManager::getInstance()->getBufferSize();
m_imgBufSize = m_audioBufSize+3; m_imgBufSize = m_audioBufSize+3;
......
...@@ -110,6 +110,46 @@ float random (vec3 st){ ...@@ -110,6 +110,46 @@ float random (vec3 st){
out vec4 color; out vec4 color;
void additiveSynth(vec4 color) { void additiveSynth(vec4 color) {
int nbTracks=3000;
float note = 20.0 + floor(color.x * float(nbTracks))/float(nbTracks)*80.0;
int ind = int(color.x*float(nbTracks));
float freq=0.0;
//count this fragment
if(imageAtomicAdd(audioTex, ivec2(0, ind), 1)<1) {
//if the audio has not been generated by another fragment
//compute frequency
freq = float(440.0 * pow(2.0, (note-69.0)/12.0));
//retrieve either new or old phase, depending on if audio was processed
float phase = float(imageLoad(audioTex, ivec2(1, ind)).x);
if(audioNextBuf>0) {//if new phase
//retrieve it
phase = float(imageLoad(audioTex, ivec2(2, ind)).x);
//store it as previous phase
imageStore(audioTex, ivec2(1, ind), ivec4(int(phase)));
}
float outputPhase = phase;
float samplesPerPeriod = (audioRate/freq);
float phaseStep = 1.0;
for(int i=0; i<audioBufSize; i++) {
//compute and store value starting from 3rd column
float s = sin((phase/samplesPerPeriod) * 2.0 * M_PI);
imageStore(audioTex, ivec2(i+3, ind), ivec4(int(s*maxAudioValue)));
//increase phase
phase=mod(phase + phaseStep, samplesPerPeriod);
}
//remove audioMixSize steps and write phase to output
outputPhase=mod(outputPhase+phaseStep*(audioBufSize-audioMixSize),
samplesPerPeriod);
imageStore(audioTex, ivec2(2, ind), ivec4(int(outputPhase)));
}
}
void pitchedAdditiveSynth(vec4 color) {
float freq=0.0; float freq=0.0;
float note = 20 + color.x * 80; float note = 20 + color.x * 80;
int ind=0; int ind=0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment