Compare commits
2 Commits
master
...
0cdac55d27
| Author | SHA1 | Date | |
|---|---|---|---|
|
0cdac55d27
|
|||
|
10bf0c6a06
|
66
main.c
66
main.c
@@ -14,6 +14,7 @@
|
||||
#define ATTACK_MS 100.f
|
||||
|
||||
#define SYNTH_PI 3.1415926535f
|
||||
#define SYNTH_VOLUME 0.5f
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// General SynthSound
|
||||
@@ -376,23 +377,77 @@ void pack(uint16_t* d, size_t length) {
|
||||
write_file("output.wav", buffer, fileSize);
|
||||
}
|
||||
|
||||
size_t detect_note_pressed(Note* note) {
|
||||
size_t is_pressed = 0;
|
||||
note->length = 16;
|
||||
if (IsKeyPressed(KEY_A)) {
|
||||
strcpy(note->name, "A4");
|
||||
is_pressed = 1;
|
||||
}
|
||||
if (IsKeyPressed(KEY_B)) {
|
||||
strcpy(note->name, "B4");
|
||||
is_pressed = 1;
|
||||
}
|
||||
if (IsKeyPressed(KEY_C)) {
|
||||
strcpy(note->name, "C4");
|
||||
is_pressed = 1;
|
||||
}
|
||||
if (IsKeyPressed(KEY_D)) {
|
||||
strcpy(note->name, "D4");
|
||||
is_pressed = 1;
|
||||
}
|
||||
if (IsKeyPressed(KEY_E)) {
|
||||
strcpy(note->name, "E4");
|
||||
is_pressed = 1;
|
||||
}
|
||||
if (IsKeyPressed(KEY_F)) {
|
||||
strcpy(note->name, "F4");
|
||||
is_pressed = 1;
|
||||
}
|
||||
if (IsKeyPressed(KEY_G)) {
|
||||
strcpy(note->name, "G4");
|
||||
is_pressed = 1;
|
||||
}
|
||||
return is_pressed;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------
|
||||
// Main
|
||||
//------------------------------------------------------------------------------------
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
const size_t width = 1280;
|
||||
const size_t height = 720;
|
||||
const size_t width = 640;
|
||||
const size_t height = 480;
|
||||
|
||||
InitWindow(width, height, "SeeSynth - v0.1");
|
||||
//SetTargetFPS(60);
|
||||
SetTargetFPS(60);
|
||||
|
||||
Note current_note = {
|
||||
.length = 1,
|
||||
.name = malloc(sizeof(char) * 3)
|
||||
};
|
||||
|
||||
InitAudioDevice();
|
||||
SetMasterVolume(SYNTH_VOLUME);
|
||||
AudioStream synth_stream = LoadAudioStream(SAMPLE_RATE, sizeof(float) * 8, 1);//float*8
|
||||
SetAudioStreamVolume(synth_stream, 0.01f);
|
||||
PlayAudioStream(synth_stream);
|
||||
// Main game loop
|
||||
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||
{
|
||||
// Update
|
||||
//----------------------------------------------------------------------------------
|
||||
// TODO: Update your variables here
|
||||
if (detect_note_pressed(¤t_note)) {
|
||||
SynthSound sound = get_note_sound(current_note);
|
||||
if (IsAudioStreamReady(synth_stream)) {
|
||||
if (IsAudioStreamProcessed(synth_stream)) {
|
||||
printf("Samples to play:%zu \n", sound.sample_count);
|
||||
UpdateAudioStream(synth_stream, sound.samples, sound.sample_count);
|
||||
}
|
||||
}
|
||||
//}
|
||||
printf("Note played: %s\n", current_note.name);
|
||||
}
|
||||
//----------------------------------------------------------------------------------
|
||||
|
||||
// Draw
|
||||
@@ -428,6 +483,9 @@ int main(int argc, char **argv) {
|
||||
|
||||
// De-Initialization
|
||||
//--------------------------------------------------------------------------------------
|
||||
StopAudioStream(synth_stream);
|
||||
UnloadAudioStream(synth_stream);
|
||||
CloseAudioDevice();
|
||||
CloseWindow(); // Close window and OpenGL context
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user