Fix console rendering old strings, refactor audio
Removed duplication of audio buffering code in audio update and streaming vorbis.
This commit is contained in:
		
							parent
							
								
									84a0f755ea
								
							
						
					
					
						commit
						9c3df0c488
					
				
							
								
								
									
										24
									
								
								src/Audio.c
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								src/Audio.c
									
									
									
									
									
								
							| @ -11,7 +11,6 @@ | |||||||
| #define AL_CHECK_ERROR() alCheckError_(__FILE__, __LINE__); | #define AL_CHECK_ERROR() alCheckError_(__FILE__, __LINE__); | ||||||
| void alCheckError_(const char *file, int line) | void alCheckError_(const char *file, int line) | ||||||
| { | { | ||||||
| 
 |  | ||||||
| 	ALenum errorCode; | 	ALenum errorCode; | ||||||
| 	while ((errorCode = alGetError()) != AL_NO_ERROR) | 	while ((errorCode = alGetError()) != AL_NO_ERROR) | ||||||
| 	{ | 	{ | ||||||
| @ -83,29 +82,16 @@ void audio_streamVorbis(AudioRenderer *audioRenderer, AudioVorbis *vorbis) | |||||||
| 
 | 
 | ||||||
| 	audioRenderer->audio = vorbis; | 	audioRenderer->audio = vorbis; | ||||||
| 	AudioVorbis *audio   = audioRenderer->audio; | 	AudioVorbis *audio   = audioRenderer->audio; | ||||||
| 
 |  | ||||||
| 	/* Pre-load vorbis data into audio chunks */ |  | ||||||
| 	for (i32 i = 0; i < ARRAY_COUNT(audioRenderer->bufferId); i++) |  | ||||||
| 	{ |  | ||||||
| 		i16 audioChunk[AUDIO_CHUNK_SIZE_] = {0}; |  | ||||||
| 		stb_vorbis_get_samples_short_interleaved( |  | ||||||
| 		    audio->file, audio->info.channels, audioChunk, AUDIO_CHUNK_SIZE_); |  | ||||||
| 
 |  | ||||||
| 		alBufferData(audioRenderer->bufferId[i], audioRenderer->format, |  | ||||||
| 		             audioChunk, AUDIO_CHUNK_SIZE_ * sizeof(i16), |  | ||||||
| 		             audio->info.sample_rate); |  | ||||||
| 	} |  | ||||||
| 
 |  | ||||||
| 	/* Queue and play buffers */ |  | ||||||
| 	alSourceQueueBuffers(audioRenderer->sourceId[0], |  | ||||||
| 	                     ARRAY_COUNT(audioRenderer->bufferId), |  | ||||||
| 	                     audioRenderer->bufferId); |  | ||||||
| 	alSourcePlay(audioRenderer->sourceId[0]); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void audio_updateAndPlay(AudioRenderer *audioRenderer) | void audio_updateAndPlay(AudioRenderer *audioRenderer) | ||||||
| { | { | ||||||
| 	AudioVorbis *audio = audioRenderer->audio; | 	AudioVorbis *audio = audioRenderer->audio; | ||||||
|  | 	if (!audio) | ||||||
|  | 	{ | ||||||
|  | 		DEBUG_LOG("audio_updateAndPlay() early exit: No audio stream connected"); | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
| 	ALint audioState; | 	ALint audioState; | ||||||
| 	alGetSourcei(audioRenderer->sourceId[0], AL_SOURCE_STATE, &audioState); | 	alGetSourcei(audioRenderer->sourceId[0], AL_SOURCE_STATE, &audioState); | ||||||
|  | |||||||
| @ -32,8 +32,13 @@ void debug_init(MemoryArena *arena, v2 windowSize, Font font) | |||||||
| 
 | 
 | ||||||
| void debug_consoleLog(char *string, char *file, int lineNum) | void debug_consoleLog(char *string, char *file, int lineNum) | ||||||
| { | { | ||||||
|  | 
 | ||||||
| 	i32 maxConsoleStrLen = ARRAY_COUNT(GLOBAL_debug.console[0]); | 	i32 maxConsoleStrLen = ARRAY_COUNT(GLOBAL_debug.console[0]); | ||||||
| 
 | 
 | ||||||
|  | 	/* Completely clear out current console line */ | ||||||
|  | 	for (i32 i = 0; i < maxConsoleStrLen; i++) | ||||||
|  | 		GLOBAL_debug.console[GLOBAL_debug.consoleIndex][i] = 0; | ||||||
|  | 
 | ||||||
| 	i32 strIndex = 0; | 	i32 strIndex = 0; | ||||||
| 	i32 fileStrLen = common_strlen(file); | 	i32 fileStrLen = common_strlen(file); | ||||||
| 	for (i32 count = 0; strIndex < maxConsoleStrLen; strIndex++, count++) | 	for (i32 count = 0; strIndex < maxConsoleStrLen; strIndex++, count++) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user