-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_synthesis.cpp
More file actions
107 lines (88 loc) · 3.97 KB
/
debug_synthesis.cpp
File metadata and controls
107 lines (88 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
Debug program to trace Advanced Synthesis Engine audio generation
*/
#include "Source/audio/AdvancedSynthesisEngine.h"
#include <iostream>
#include <iomanip>
int main()
{
std::cout << "=== Advanced Synthesis Engine Debug ===" << std::endl;
// Create engine
spawnclone::audio::AdvancedSynthesisEngine engine;
// Setup audio parameters
double sampleRate = 44100.0;
int blockSize = 512;
int numChannels = 2;
std::cout << "Preparing engine..." << std::endl;
engine.prepareToPlay(sampleRate, blockSize, numChannels);
// Test exactly like the failing test - no setSynthesisParameters call
std::cout << "Testing exactly like unit test (no setSynthesisParameters)" << std::endl;
// Check default parameters
auto params = engine.getSynthesisParameters();
std::cout << "Default masterVolume: " << params.masterVolume << std::endl;
std::cout << "Default wavetablePosition: " << params.wavetable.wavetablePosition << std::endl;
std::cout << "Default attack: " << params.envelope.attack << std::endl;
std::cout << "Default sustain: " << params.envelope.sustain << std::endl;
std::cout << "Default filter.enabled: " << (params.filter.enabled ? "true" : "false") << std::endl;
std::cout << "Default lfo.depth: " << params.modulation.lfoDepth << std::endl;
std::cout << "Default lfo.rate: " << params.modulation.lfoRate << std::endl;
std::cout << "Wavetables count: " << engine.getNumWavetables() << std::endl;
// Create audio buffer and MIDI
juce::AudioBuffer<float> buffer(numChannels, blockSize);
juce::MidiBuffer midiBuffer;
// Add note-on
auto noteOnMessage = juce::MidiMessage::noteOn(1, 60, 0.8f);
midiBuffer.addEvent(noteOnMessage, 0);
std::cout << "\nProcessing audio block with note-on..." << std::endl;
// Process block
buffer.clear();
engine.processBlock(buffer, midiBuffer);
// Check for audio output
float maxSample = 0.0f;
int nonZeroSamples = 0;
for (int channel = 0; channel < numChannels; ++channel)
{
auto* channelData = buffer.getReadPointer(channel);
for (int sample = 0; sample < blockSize; ++sample)
{
float sampleValue = std::abs(channelData[sample]);
if (sampleValue > 0.000001f)
{
nonZeroSamples++;
if (sampleValue > maxSample)
maxSample = sampleValue;
}
}
}
std::cout << "Active voices: " << engine.getCurrentVoiceCount() << std::endl;
std::cout << "Non-zero samples: " << nonZeroSamples << std::endl;
std::cout << "Max sample amplitude: " << std::fixed << std::setprecision(8) << maxSample << std::endl;
// Process multiple blocks to allow envelope attack phase
std::cout << "\nProcessing 5 more blocks to allow envelope attack..." << std::endl;
for (int i = 0; i < 5; ++i)
{
buffer.clear();
midiBuffer.clear(); // No more MIDI events
engine.processBlock(buffer, midiBuffer);
// Check max amplitude after each block
float blockMax = 0.0f;
for (int channel = 0; channel < numChannels; ++channel)
{
auto* channelData = buffer.getReadPointer(channel);
for (int sample = 0; sample < blockSize; ++sample)
{
blockMax = std::max(blockMax, std::abs(channelData[sample]));
}
}
std::cout << "Block " << (i+1) << " max amplitude: " << std::fixed << std::setprecision(8) << blockMax << std::endl;
}
std::cout << "Final active voices: " << engine.getCurrentVoiceCount() << std::endl;
// Show first few samples for debugging
std::cout << "\nFirst 10 samples channel 0:" << std::endl;
auto* channelData = buffer.getReadPointer(0);
for (int i = 0; i < 10; ++i)
{
std::cout << " Sample " << i << ": " << std::fixed << std::setprecision(8) << channelData[i] << std::endl;
}
return 0;
}