Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | QonDonion |
Prevoisly on AudioStreamGeneratorPlayback:
https://forum.godotengine.org/152840/getting-something-from-ref-with-crashes-the-thing
yay sine wave :3!
[ [REDACTED] (DEBUG) 2566-05-06 21-32-29.mp4 - Google Drive ]
WITH:
void Oscillator::init() {
//the things
Oscillator::playback = Oscillator::get_stream_playback();
UtilityFunctions::print("playback_type ", typeid(Oscillator::playback).name());
//the wavw datae
Oscillator::waveTime = 0.0;
Oscillator::freq = 440;
}
void Oscillator::setAudioThing(int mix_rate, float buffer_length) {
Oscillator::stream.set_mix_rate(mix_rate);
Oscillator::stream.set_buffer_length(buffer_length);
Oscillator::waveData.resize(Oscillator::playback->get_frames_available());
for (int i = 0; i < Oscillator::waveData.size(); i++) {
Oscillator::waveData[i].resize(2);
}
UtilityFunctions::print("mix rate: ", Oscillator::stream.get_mix_rate());
UtilityFunctions::print("buffer length: ", Oscillator::stream.get_buffer_length());
UtilityFunctions::print("buffer size: ", Oscillator::waveData.size());
}
AND:
void Oscillator::threadSine() {
while (1) {
float interval = Oscillator::freq / Oscillator::stream.get_mix_rate();
int emptys = Oscillator::playback->get_frames_available();
while (emptys > 0) {
Oscillator::playback->push_frame(Vector2(sin((Oscillator::waveTime)*Math_TAU), sin((Oscillator::waveTime)*Math_TAU)));
Oscillator::waveTime = fmod(Oscillator::waveTime + interval, 1.0);
emptys -= 1;
}
}
}
MORE AND GDSCRIPT:
extends Oscillator
var threadReal = Thread.new()
# Called when the node enters the scene tree for the first time.
func _ready():
play()
init()
setAudioThing(44100, 0.05)
threadReal.start(threadSine)
func _process(delta):
#range 220-880
setFreq(%hzSlider.value)
wow
so cool. so fast.
BUT:
i want to store it inside a varible ( std::vector< std::vector< float > > )
so that i can display it on a oscillator waveform thing
and also so that i can do something with the data later
MORE BUT:
now it sounds like a paining sine wave (AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA)
OscillatorTest crime scene (haha get it? scene?!?!?? osijdcoajsdosidjaoi)
[ [REDACTED] (DEBUG) 2566-05-06 15-00-23.mp4 - Google Drive ]
MORE INFORMATION:
genSine:
void Oscillator::genSine() {
while (1) {
float interval = Oscillator::freq / Oscillator::stream.get_mix_rate();
for (int i = 0; i < Oscillator::waveData.size(); i++) {
Oscillator::waveData[i][0] = sin((Oscillator::waveTime)*Math_TAU);
Oscillator::waveData[i][1] = sin((Oscillator::waveTime)*Math_TAU);
Oscillator::waveTime = fmod(Oscillator::waveTime + interval, 1.0);
}
}
}
writeWave:
void Oscillator::writeWave() {
while (1) {
int i = 0;
int emptys = Oscillator::playback->get_frames_available();
while (emptys > 0) {
Oscillator::playback->push_frame(Vector2(Oscillator::waveData[i][0], Oscillator::waveData[i][1]));
i++;
emptys -= 1;
}
}
GDscript:
extends Oscillator
var threadReal = Thread.new()
var writeThread = Thread.new()
# Called when the node enters the scene tree for the first time.
func _ready():
play()
init()
setAudioThing(44100, 0.05)
threadReal.start(genSine)
writeThread.start(writeWave)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
setFreq(%hzSlider.value)
halp
THE WHOLE THING*:
gdextendsion:
https://drive.google.com/drive/folders/1sS1uQ3ICTn_uOB2lnWBF3_BpmJgZbrnm?usp=sharing
*that you need
EDITS:
edit1:
HOLY GOD (EXTREMELY LOUD)
edit2:
maybe it’s thread desync?
edit3:
it’s not thread desync
i put Oscillator::writeWave(); in genSine so that in runs on the same thread
and nope
still AAAAAAAAAAAAAAAAAAAAAAA
edit4:
wait a second…
edit5:
nope not that
edit6:
something about vector< vector< float > > perhaps?
edit7:
sleepring
edit8:
sleepring was not defined
see this:
[ Screenshot_74.png - Google Drive ]
i hope that helps somehow
sleeping
edit9:
i forgot to call it as a function
i did test it with double and long double
i thought it was a floating point percision thing
but nope
sleeping()
edit10:
TypeError: sleeping() missing 1 required positional argument ‘hours’
so i slept for 0 hours intead
it’s not something about vector< vector< float > >
edit11:
it appears that Oscillator::playback->get_frames_available() changes in value
edit12:
Suspect Oscillator::waveTime desnyc
edit13:
well… that’s certainly cool… but… like…
[ Screenshot_75.png - Google Drive ]