Start audio
This commit is contained in:
parent
3352d9a234
commit
d0db60c02a
2 changed files with 52 additions and 1 deletions
1
assets/music
Normal file
1
assets/music
Normal file
File diff suppressed because one or more lines are too long
|
@ -12,6 +12,24 @@ SDL_Texture *texture;
|
|||
SDL_Surface *screenSurface;
|
||||
uint16_t screen[LCR_SETTING_RESOLUTION_X * LCR_SETTING_RESOLUTION_Y];
|
||||
|
||||
FILE *musicFile = 0;
|
||||
|
||||
void audioFillCallback(void *userdata, uint8_t *s, int l)
|
||||
{
|
||||
for (int i = 0; i < l; ++i)
|
||||
{
|
||||
unsigned char byte = 128;
|
||||
|
||||
if (musicFile)
|
||||
{
|
||||
if (!fread(&byte,1,1,musicFile))
|
||||
rewind(musicFile);
|
||||
}
|
||||
|
||||
s[i] = byte;
|
||||
}
|
||||
}
|
||||
|
||||
const uint8_t *keyboardState;
|
||||
|
||||
uint8_t LCR_keyPressed(uint8_t key)
|
||||
|
@ -60,9 +78,31 @@ void LCR_log(const char *str)
|
|||
int main(int argc, char *argv[])
|
||||
{
|
||||
uint8_t running = 1;
|
||||
|
||||
LCR_log("initializing game");
|
||||
LCR_gameInit();
|
||||
|
||||
SDL_Init(0);
|
||||
LCR_log("initializing SDL");
|
||||
SDL_Init(SDL_INIT_AUDIO);
|
||||
|
||||
LCR_log("initializing audio");
|
||||
SDL_AudioSpec audioSpec;
|
||||
SDL_memset(&audioSpec, 0, sizeof(audioSpec));
|
||||
audioSpec.callback = audioFillCallback;
|
||||
audioSpec.freq = 8000;
|
||||
audioSpec.format = AUDIO_U8;
|
||||
audioSpec.channels = 1;
|
||||
audioSpec.samples = 256;
|
||||
|
||||
if (SDL_OpenAudio(&audioSpec,NULL) < 0)
|
||||
fputs("could not initialize audio",stderr);
|
||||
|
||||
SDL_PauseAudio(0);
|
||||
|
||||
musicFile = fopen("assets/music","rb");
|
||||
|
||||
if (!musicFile)
|
||||
fputs("could not open music file",stderr);
|
||||
|
||||
window =
|
||||
SDL_CreateWindow("Licar", SDL_WINDOWPOS_UNDEFINED,
|
||||
|
@ -100,6 +140,8 @@ int main(int argc, char *argv[])
|
|||
SDL_PumpEvents();
|
||||
keyboardState = SDL_GetKeyboardState(NULL);
|
||||
|
||||
LCR_log("starting game loop");
|
||||
|
||||
while (running)
|
||||
{
|
||||
SDL_PumpEvents();
|
||||
|
@ -116,6 +158,14 @@ int main(int argc, char *argv[])
|
|||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
LCR_log("ending");
|
||||
|
||||
if (musicFile)
|
||||
fclose(musicFile);
|
||||
|
||||
SDL_PauseAudio(1);
|
||||
SDL_CloseAudio();
|
||||
|
||||
SDL_DestroyTexture(texture);
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
|
|
Loading…
Reference in a new issue