Change const to #define + cleanup
This commit is contained in:
parent
64195dd5a9
commit
988bc52e57
2
audio.c
2
audio.c
@ -1,8 +1,6 @@
|
|||||||
#include "audio.h"
|
#include "audio.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
const int MAX_RECORDING_SECONDS = 1;
|
|
||||||
|
|
||||||
static SDL_AudioSpec recording_spec;
|
static SDL_AudioSpec recording_spec;
|
||||||
static SDL_AudioSpec playback_spec;
|
static SDL_AudioSpec playback_spec;
|
||||||
static SDL_AudioSpec received_recording_spec;
|
static SDL_AudioSpec received_recording_spec;
|
||||||
|
2
audio.h
2
audio.h
@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
|
|
||||||
|
#define MAX_RECORDING_SECONDS 2
|
||||||
|
|
||||||
typedef struct audio_state {
|
typedef struct audio_state {
|
||||||
int recording_device_id;
|
int recording_device_id;
|
||||||
int playback_device_id;
|
int playback_device_id;
|
||||||
|
20
main.c
20
main.c
@ -5,8 +5,8 @@
|
|||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
#include "audio.h"
|
#include "audio.h"
|
||||||
|
|
||||||
const int SCREEN_WIDTH = 640;
|
#define SCREEN_WIDTH 640
|
||||||
const int SCREEN_HEIGHT = 480;
|
#define SCREEN_HEIGHT 480
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
SELECTING_DEVICE,
|
SELECTING_DEVICE,
|
||||||
@ -24,7 +24,6 @@ typedef struct state {
|
|||||||
int init();
|
int init();
|
||||||
void destroy();
|
void destroy();
|
||||||
int select_device(SDL_KeyboardEvent* key_event, int max_index);
|
int select_device(SDL_KeyboardEvent* key_event, int max_index);
|
||||||
|
|
||||||
void application_state_to_string(application_state state, char* string);
|
void application_state_to_string(application_state state, char* string);
|
||||||
|
|
||||||
SDL_Window* window = NULL;
|
SDL_Window* window = NULL;
|
||||||
@ -112,14 +111,16 @@ int main(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
printf("Cleanup\n");
|
printf("Cleanup start\n");
|
||||||
audio_destroy(&state.audio);
|
audio_destroy(&state.audio);
|
||||||
|
printf("Audio done\n");
|
||||||
text_texture_free(&display_text_texture);
|
text_texture_free(&display_text_texture);
|
||||||
for (int i = 0; i < num_devices; i++) {
|
for (int i = 0; i < num_devices; i++) {
|
||||||
text_texture_free(&device_textures[i]);
|
text_texture_free(&device_textures[i]);
|
||||||
}
|
}
|
||||||
|
printf("Texture done\n");
|
||||||
destroy();
|
destroy();
|
||||||
|
printf("Done\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,8 +254,11 @@ int init()
|
|||||||
void destroy()
|
void destroy()
|
||||||
{
|
{
|
||||||
SDL_DestroyRenderer(renderer);
|
SDL_DestroyRenderer(renderer);
|
||||||
|
printf("Renderer done\n");
|
||||||
SDL_DestroyWindow(window);
|
SDL_DestroyWindow(window);
|
||||||
|
printf("Window done\n");
|
||||||
TTF_Quit();
|
TTF_Quit();
|
||||||
|
printf("TTF done\n");
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,13 +290,13 @@ void application_state_to_string(application_state state, char* string)
|
|||||||
sprintf(string, "Selecting Device [0-9] -> [y/RET], ");
|
sprintf(string, "Selecting Device [0-9] -> [y/RET], ");
|
||||||
break;
|
break;
|
||||||
case RECORDING:
|
case RECORDING:
|
||||||
sprintf(string, "Recording [ESC] to cancel");
|
sprintf(string, "Recording [ESC]: CANCEL");
|
||||||
break;
|
break;
|
||||||
case RECORDED:
|
case RECORDED:
|
||||||
sprintf(string, "Recorded [y/RET] to play [ESC] to Select");
|
sprintf(string, "Recorded [y/RET]: PLAY | [ESC]: SELECT");
|
||||||
break;
|
break;
|
||||||
case PLAYBACK:
|
case PLAYBACK:
|
||||||
sprintf(string, "Playing");
|
sprintf(string, "Playing [ESC]: CANCEL");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
7
makefile
7
makefile
@ -21,13 +21,8 @@ $(OBJS): $(OBJD)/%.o: %.c
|
|||||||
mkdir -p $(@D)
|
mkdir -p $(@D)
|
||||||
$(CC) $(CCFLAGS) -c $? -o $@
|
$(CC) $(CCFLAGS) -c $? -o $@
|
||||||
|
|
||||||
TARGET1 = test
|
|
||||||
|
|
||||||
$(TARGET1): example-test-code/audiotest.c
|
|
||||||
$(CC) $(CCFLAGS) $^ -o $(TARGET1) $(LDFLAGS)
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -r $(TARGET) $(TARGET1) $(test) $(OBJD)
|
rm -r $(TARGET) $(TARGET1) $(OBJD)
|
||||||
|
|
||||||
run: $(TARGET)
|
run: $(TARGET)
|
||||||
./$(TARGET)
|
./$(TARGET)
|
||||||
|
Loading…
Reference in New Issue
Block a user