mirror of https://github.com/adamdruppe/arsd.git
lol so many stupid errors
This commit is contained in:
parent
d13f62ac36
commit
60dda09f96
|
@ -45,6 +45,9 @@ module arsd.simpleaudio;
|
||||||
enum BUFFER_SIZE_FRAMES = 1024;//512;//2048;
|
enum BUFFER_SIZE_FRAMES = 1024;//512;//2048;
|
||||||
enum BUFFER_SIZE_SHORT = BUFFER_SIZE_FRAMES * 2;
|
enum BUFFER_SIZE_SHORT = BUFFER_SIZE_FRAMES * 2;
|
||||||
|
|
||||||
|
///
|
||||||
|
enum DEFAULT_VOLUME = 20;
|
||||||
|
|
||||||
version(Demo)
|
version(Demo)
|
||||||
void main() {
|
void main() {
|
||||||
|
|
||||||
|
@ -206,7 +209,7 @@ final class AudioPcmOutThread : Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Args in hertz and milliseconds
|
/// Args in hertz and milliseconds
|
||||||
void beep(int freq = 900, int dur = 150, int volume = 50) {
|
void beep(int freq = 900, int dur = 150, int volume = DEFAULT_VOLUME) {
|
||||||
Sample s;
|
Sample s;
|
||||||
s.operation = 0; // square wave
|
s.operation = 0; // square wave
|
||||||
s.frequency = SampleRate / freq;
|
s.frequency = SampleRate / freq;
|
||||||
|
@ -216,7 +219,7 @@ final class AudioPcmOutThread : Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
void noise(int dur = 150, int volume = 50) {
|
void noise(int dur = 150, int volume = DEFAULT_VOLUME) {
|
||||||
Sample s;
|
Sample s;
|
||||||
s.operation = 1; // noise
|
s.operation = 1; // noise
|
||||||
s.frequency = 0;
|
s.frequency = 0;
|
||||||
|
@ -226,7 +229,7 @@ final class AudioPcmOutThread : Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
void boop(float attack = 8, int freqBase = 500, int dur = 150, int volume = 50) {
|
void boop(float attack = 8, int freqBase = 500, int dur = 150, int volume = DEFAULT_VOLUME) {
|
||||||
Sample s;
|
Sample s;
|
||||||
s.operation = 5; // custom
|
s.operation = 5; // custom
|
||||||
s.volume = volume;
|
s.volume = volume;
|
||||||
|
@ -235,13 +238,13 @@ final class AudioPcmOutThread : Thread {
|
||||||
auto currentFrequency = cast(float) freqBase / (1 + cast(float) x / (cast(float) SampleRate / attack));
|
auto currentFrequency = cast(float) freqBase / (1 + cast(float) x / (cast(float) SampleRate / attack));
|
||||||
import std.math;
|
import std.math;
|
||||||
auto freq = 2 * PI / (cast(float) SampleRate / currentFrequency);
|
auto freq = 2 * PI / (cast(float) SampleRate / currentFrequency);
|
||||||
return cast(short) (sin(cast(float) freq * cast(float) x) * short.max * 100 / volume);
|
return cast(short) (sin(cast(float) freq * cast(float) x) * short.max * volume / 100);
|
||||||
};
|
};
|
||||||
addSample(s);
|
addSample(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
void blip(float attack = 6, int freqBase = 800, int dur = 150, int volume = 50) {
|
void blip(float attack = 6, int freqBase = 800, int dur = 150, int volume = DEFAULT_VOLUME) {
|
||||||
Sample s;
|
Sample s;
|
||||||
s.operation = 5; // custom
|
s.operation = 5; // custom
|
||||||
s.volume = volume;
|
s.volume = volume;
|
||||||
|
@ -250,13 +253,13 @@ final class AudioPcmOutThread : Thread {
|
||||||
auto currentFrequency = cast(float) freqBase * (1 + cast(float) x / (cast(float) SampleRate / attack));
|
auto currentFrequency = cast(float) freqBase * (1 + cast(float) x / (cast(float) SampleRate / attack));
|
||||||
import std.math;
|
import std.math;
|
||||||
auto freq = 2 * PI / (cast(float) SampleRate / currentFrequency);
|
auto freq = 2 * PI / (cast(float) SampleRate / currentFrequency);
|
||||||
return cast(short) (sin(cast(float) freq * cast(float) x) * short.max * 100 / volume);
|
return cast(short) (sin(cast(float) freq * cast(float) x) * short.max * volume / 100);
|
||||||
};
|
};
|
||||||
addSample(s);
|
addSample(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
version(none)
|
version(none)
|
||||||
void custom(int dur = 150, int volume = 50) {
|
void custom(int dur = 150, int volume = DEFAULT_VOLUME) {
|
||||||
Sample s;
|
Sample s;
|
||||||
s.operation = 5; // custom
|
s.operation = 5; // custom
|
||||||
s.volume = volume;
|
s.volume = volume;
|
||||||
|
@ -265,7 +268,7 @@ final class AudioPcmOutThread : Thread {
|
||||||
auto currentFrequency = 500.0 / (1 + cast(float) x / (cast(float) SampleRate / 8));
|
auto currentFrequency = 500.0 / (1 + cast(float) x / (cast(float) SampleRate / 8));
|
||||||
import std.math;
|
import std.math;
|
||||||
auto freq = 2 * PI / (cast(float) SampleRate / currentFrequency);
|
auto freq = 2 * PI / (cast(float) SampleRate / currentFrequency);
|
||||||
return cast(short) (sin(cast(float) freq * cast(float) x) * short.max * 100 / volume);
|
return cast(short) (sin(cast(float) freq * cast(float) x) * short.max * volume / 100);
|
||||||
};
|
};
|
||||||
addSample(s);
|
addSample(s);
|
||||||
}
|
}
|
||||||
|
@ -297,7 +300,7 @@ final class AudioPcmOutThread : Thread {
|
||||||
int operation;
|
int operation;
|
||||||
int frequency; /* in samples */
|
int frequency; /* in samples */
|
||||||
int duration; /* in samples */
|
int duration; /* in samples */
|
||||||
int volume; /* between 1 and 100 */
|
int volume; /* between 1 and 100. You should generally shoot for something lowish, like 20. */
|
||||||
int delay; /* in samples */
|
int delay; /* in samples */
|
||||||
|
|
||||||
int x;
|
int x;
|
||||||
|
@ -354,7 +357,7 @@ final class AudioPcmOutThread : Thread {
|
||||||
case 1: // noise
|
case 1: // noise
|
||||||
for(; i < sampleFinish; i++) {
|
for(; i < sampleFinish; i++) {
|
||||||
import std.random;
|
import std.random;
|
||||||
buffer[i] = uniform(short.min, short.max);
|
buffer[i] = uniform(cast(short) -cast(int)val, val);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
/+
|
/+
|
||||||
|
@ -440,10 +443,12 @@ final class AudioPcmOutThread : Thread {
|
||||||
else
|
else
|
||||||
val = buffer[i];
|
val = buffer[i];
|
||||||
|
|
||||||
int a = val + short.max;
|
int a = val;
|
||||||
int b = v + short.max;
|
int b = v;
|
||||||
val = a + b - (a * b)/(short.max*2);
|
int cap = a + b;
|
||||||
val -= short.max;
|
if(cap > short.max) cap = short.max;
|
||||||
|
else if(cap < short.min) cap = short.min;
|
||||||
|
val = cast(short) cap;
|
||||||
buffer[i] = cast(short) val;
|
buffer[i] = cast(short) val;
|
||||||
}
|
}
|
||||||
if(!ret) {
|
if(!ret) {
|
||||||
|
|
Loading…
Reference in New Issue