diff --git a/src/modules/ProjectorModule.cpp b/src/modules/ProjectorModule.cpp index f3133f60eb479574d4e7575fc66eec72c713e1b5..9eb8a592dd8c9b652b498026440915c94a7ebdb4 100644 --- a/src/modules/ProjectorModule.cpp +++ b/src/modules/ProjectorModule.cpp @@ -191,9 +191,8 @@ ProjectorModule::ProjectorModule(): Module() { //audio - m_nbTracks=50; - //m_maxAudioValue = (std::numeric_limits<int>::max())/(m_width * m_height); - m_maxAudioValue = (std::numeric_limits<int>::max())/(m_width); + m_nbTracks=3000; + m_maxAudioValue = (std::numeric_limits<int>::max())/(m_width * m_height); m_audioMixSize = AudioManager::getInstance()->getMixSize(); m_audioBufSize = AudioManager::getInstance()->getBufferSize(); m_imgBufSize = m_audioBufSize+3; diff --git a/src/shaders/render43.fs b/src/shaders/render43.fs index e7d5d17d8b9179303612567b1635ee36d969d4ec..32f34966897b7fe207295615f3f05049ca388590 100644 --- a/src/shaders/render43.fs +++ b/src/shaders/render43.fs @@ -110,6 +110,46 @@ float random (vec3 st){ out 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 note = 20 + color.x * 80; int ind=0;