Change const to #define + cleanup

This commit is contained in:
Sheldon Lee 2024-10-13 23:03:27 +08:00
parent 64195dd5a9
commit 988bc52e57
4 changed files with 15 additions and 16 deletions

View File

@ -1,8 +1,6 @@
#include "audio.h"
#include "log.h"
const int MAX_RECORDING_SECONDS = 1;
static SDL_AudioSpec recording_spec;
static SDL_AudioSpec playback_spec;
static SDL_AudioSpec received_recording_spec;

View File

@ -3,6 +3,8 @@
#include <SDL2/SDL.h>
#define MAX_RECORDING_SECONDS 2
typedef struct audio_state {
int recording_device_id;
int playback_device_id;

20
main.c
View File

@ -5,8 +5,8 @@
#include "texture.h"
#include "audio.h"
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 480
typedef enum {
SELECTING_DEVICE,
@ -24,7 +24,6 @@ typedef struct state {
int init();
void destroy();
int select_device(SDL_KeyboardEvent* key_event, int max_index);
void application_state_to_string(application_state state, char* string);
SDL_Window* window = NULL;
@ -112,14 +111,16 @@ int main(int argc, char* argv[])
}
cleanup:
printf("Cleanup\n");
printf("Cleanup start\n");
audio_destroy(&state.audio);
printf("Audio done\n");
text_texture_free(&display_text_texture);
for (int i = 0; i < num_devices; i++) {
text_texture_free(&device_textures[i]);
}
printf("Texture done\n");
destroy();
printf("Done\n");
return 0;
}
@ -253,8 +254,11 @@ int init()
void destroy()
{
SDL_DestroyRenderer(renderer);
printf("Renderer done\n");
SDL_DestroyWindow(window);
printf("Window done\n");
TTF_Quit();
printf("TTF done\n");
SDL_Quit();
}
@ -286,13 +290,13 @@ void application_state_to_string(application_state state, char* string)
sprintf(string, "Selecting Device [0-9] -> [y/RET], ");
break;
case RECORDING:
sprintf(string, "Recording [ESC] to cancel");
sprintf(string, "Recording [ESC]: CANCEL");
break;
case RECORDED:
sprintf(string, "Recorded [y/RET] to play [ESC] to Select");
sprintf(string, "Recorded [y/RET]: PLAY | [ESC]: SELECT");
break;
case PLAYBACK:
sprintf(string, "Playing");
sprintf(string, "Playing [ESC]: CANCEL");
break;
}
}

View File

@ -21,13 +21,8 @@ $(OBJS): $(OBJD)/%.o: %.c
mkdir -p $(@D)
$(CC) $(CCFLAGS) -c $? -o $@
TARGET1 = test
$(TARGET1): example-test-code/audiotest.c
$(CC) $(CCFLAGS) $^ -o $(TARGET1) $(LDFLAGS)
clean:
rm -r $(TARGET) $(TARGET1) $(test) $(OBJD)
rm -r $(TARGET) $(TARGET1) $(OBJD)
run: $(TARGET)
./$(TARGET)